Skip Navigation

[Resolved] empty function on view behaves strangely on one page

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 15 replies, has 2 voices.

Last updated by Christian Cox 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1390275
Untitled-1.jpg

Link to a page where the issue can be seen:
hidden link

I expected to see:
View shortcodes are not triggered on that page, but other pages works fine and on my test site with the same code it works:
hidden link

But other pages with the same view on my main site works good:
hidden link

What make the thing goes wrong is the conditional line:

[wpv-conditional if="( NOT(empty($(wpcf-video-quote))) )"]
        <blockquote class="blockquote text-center interview-one-video-quote">
            [types field='video-quote' output='raw'][/types]
        </blockquote>
        [/wpv-conditional]

if I do this:

[wpv-conditional if="( '[types field='video-quote' output='raw'][/types]' ne '' )"]

there is no error, but the the conditional doesn't work with that way of testing if a custom field is empty.

#1390287

there are 2 fields that I check with NOT empty, if I remove the content on each fields on the admin WP page, it works. If there is one content in either of the field it doesn't trigger the shortcodes.

#1390631

Hello, it's odd that it works differently in different environments. That leads me to believe it could be related to this issue:
https://toolset.com/errata/conditionals-including-special-characters-might-fail/

I noticed that this particular quote contains a special kind of angled quotation marks, which might be counted as special characters. As a quick test, can you remove those quotation marks and replace them with the following character?

"

If this does not completely solve the problem, please add the debug attribute to the conditional so I can see a bit more about what's going on:

[wpv-conditional if="( '[types field="video-quote" output="raw"][/types]' ne '' )" debug="true"]
        <blockquote class="blockquote text-center interview-one-video-quote">
            [types field='video-quote' output='raw'][/types]
        </blockquote>
        [/wpv-conditional]

Reload the page on the front-end of the site, and let me know if any additional debug information is displayed.

#1390635

thanks for your reply.
The problem comes from the content of the field: there were some quote like that “ that were stored on the field video-quote. I replaced them with this quote: " and it works now.
I can print here the message that I got:
[types field='video-quote' output='raw'][/types]
####################
wpv-conditional attributes
####################
Array
(
[if] => ( 'At a certain point, I was able to say: “but I choose love“.' ne '' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( 'At a certain point, I was able to say: “but I choose love“.' ne '' )
--------------------
After replacing 1 general variables and comparing strings: ( 'At a certain point, I was able to say: “but I choose love“.' ne '' )
Comparing At a certain point, I was able to say: “but I choose love“. to

That's kind of a strange behaviour...

#1390637

but now the conditional is not trigged. It doesn't show the text from video-quote if I use this:
[wpv-conditional if="( '[types field="video-quote" output="raw"][/types]' ne '' )" debug="true"]
even though the field contains some information

#1390641

and this is what I get from the debug if I do this:
[wpv-conditional if="( NOT(empty($(wpcf-video-quote))) )" debug="true"]

the short codes are not working even though I changed the quote

[types field='video-quote' output='raw'][/types]
####################
wpv-conditional attributes
####################
Array
(
[if] => ( NOT(empty($(wpcf-video-quote))) )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( NOT(empty($(wpcf-video-quote))) )
--------------------
--------------------
Converted expression: ( NOT(empty('At a certain point, I was able to say: but I choose love.')) )
--------------------

#1390729

Okay thanks. I'd like to check out the setting for a specific regex interpreter on your server. Do you have a PHP info page available? If not, I can show you how to add one. See "How to check the PHP version" here: https://toolset.com/toolset-requirements/

Upload this file to the production server so I can check the settings for PCRE. If it's enabled in production, we can try disabling it to see if the regex parser is part of the problem or not. Please let me know when the file is uploaded, or if you need assistance I'll be glad to help with that.

#1390891

here is the link to the phpinfo:
hidden link

#1391291

Thanks, I can see pcre.jit is enabled. Can you temporarily add this line to your wp-config.php file just before it says "That's all, stop editing" to disable pcre.jit?

ini_set('pcre.jit', false);

Then test the conditional page again and let me know if the results are any different.

#1391455

ok, done.
If I use that:
[wpv-conditional if="( NOT(empty($(wpcf-transcript))) )"]
it works
If I use that:
[wpv-conditional if="( '[types field="transcript" output="raw"][/types]' ne '' )"]

it doesn't work

#1391479

I upgrade my server to php 7.4 RC6 and I've got the same problem.
I've turned off and on:
ini_set('pcre.jit', false);

it doesn't change the fact that [wpv-conditional if="( '[types field="transcript" output="raw"][/types]' ne '' )"] is not trigged on certain content

But at least I can use [wpv-conditional if="( NOT(empty($(wpcf-transcript))) )"] which seems to work ok

#1391481

my testing serveur also behaves the same with php 7.4RC6

#1391523

But at least I can use [wpv-conditional if="( NOT(empty($(wpcf-transcript))) )"] which seems to work ok
Okay so it sounds like you have a working solution. If this approach doesn't work consistently, or you find that you continue running into issues like this, I'll be glad to make a clone of your site and try to investigate in more detail. Let me know how you would like to proceed.

#1392285

My issue is resolved now. Thank you!

#1396191

Hello
still the same issue, I did some test and Toolset seems to behaves in strange ways, here is the code:

In functions.php, I wrote a shortcodes to display the taxonomy of a custom post type but with a link to something different then the normal taxonomy link, I did 2 versions, one with the shortcode that return the full link and one with just the names of the taxonomies. I also wrote a shortcode to get the strlen of a string:

add_shortcode( 'wpv_taxonomy_list_for_one_post_nobug', 'wpv_taxonomy_list_for_one_post_nobug_func' );
function wpv_taxonomy_list_for_one_post_nobug_func( $atts ) {
  	extract( shortcode_atts( array(
        'post_id' => ''
    ), $atts ) );
	
	$interview_terms = wp_get_object_terms( $post_id,  'interview-theme' );
 	$return = "";
	
	if ( ! empty( $interview_terms ) ) {
		if ( ! is_wp_error( $interview_terms ) ) {
				foreach( $interview_terms as $term ) {
					$return .= $term->name . ' '; 
				}
		}else return "";
	}else return "";
	
	return $return;
}

add_shortcode( 'wpv_taxonomy_list_for_one_post', 'wpv_taxonomy_list_for_one_post_func' );
function wpv_taxonomy_list_for_one_post_func( $atts ) {
  	extract( shortcode_atts( array(
        'post_id' => ''
    ), $atts ) );
	
	$interview_terms = wp_get_object_terms( $post_id,  'interview-theme' );
 	$return = "";
	
	if ( ! empty( $interview_terms ) ) {
		if ( ! is_wp_error( $interview_terms ) ) {
				foreach( $interview_terms as $term ) {
					$return .= '<a href="' . esc_url( get_bloginfo('url') . '/peace-media-library/?wpv-interview-theme=' . $term->slug ) . '">' . esc_html( $term->name ) . '</a> - '; 
				}
		}else return "";
	}else return "";
	
	$return = substr($return, 0, -3);
	return $return;
}

// get all taxonomy for one interview with link to the Main media library search page
add_shortcode( 'wpv_get_length_string', 'wpv_get_length_string_func' );
function wpv_get_length_string_func( $atts ) {
  	extract( shortcode_atts( array(
        'string' => ''
    ), $atts ) );
	
	return strlen($string);
}

Then in my view I tested each functions to see how it's behaves:

<h1> BUG: </h1>
      Taxonomy: [wpv_taxonomy_list_for_one_post post_id="[wpv-post-id]"] <br>
      Count bug because of special chars??? : [wpv_get_length_string string="[wpv_taxonomy_list_for_one_post post_id="[wpv-post-id]"]"] <br>
      Taxonomy without link: [wpv_taxonomy_list_for_one_post_nobug post_id="[wpv-post-id]"]<br>
      Count no bug: [wpv_get_length_string string="[wpv_taxonomy_list_for_one_post_nobug post_id="[wpv-post-id]"]"] <br>      
     
      Conditionnal not working either way 1: 
	[wpv-conditional if="('[wpv_taxonomy_list_for_one_post post_id="[wpv-post-id]" ]' ne '' )" ]
<p class="interview-many-taxonomies"><i class="fad fa-align-justify" style=""></i> [wpv_taxonomy_list_for_one_post post_id="[wpv-post-id]" ]</p>
[/wpv-conditional]
      
      Conditionnal not working either way 2:
	[wpv-conditional if="('[wpv_taxonomy_list_for_one_post_nobug post_id="[wpv-post-id]"]" ]' ne '' )" ]coucou
<p class="interview-many-taxonomies"><i class="fad fa-align-justify" style=""></i> [wpv_taxonomy_list_for_one_post post_id="[wpv-post-id]" ]</p>
[/wpv-conditional]
     

Here is the result hidden link
as you can see, the shortcode that count the number of characters doesn't work with a string that contains link.
And then when I do a conditional on the taxonomy it isn't triggered.