!empty($title) returns 1 when $title is empty
-
Working on revamping a site and discovered a strange quirk.
In the widget function code, there is a line that says:
function widget( $args, $instance ) { extract($args); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ); echo $before_widget; if ( !empty( $title ) ) { echo $before_title . '[' . $title . '] ' . !empty( $title ) . $after_title; } ?> <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div> <?php echo $after_widget; }The Boolean at the
!empty($title)is supposed to pass a 0 if the $title has no value, but for some reason, it returns a 1. I have looked in the database and everything and can not ascertain what is the challenge.(I added the brackets to test the issue)
Any ideas friends? I do have PHP Text Widget installed, but it is using the stock textwidget codebase.
-
Additional debugging:
- I have turned off all of the plugins
- I have checked and the value of
''is given to `$title'</li>
<li>When I swapempty( $instance['title'] )forempty( $title ), the code works. (no titles show on the text widgets)</li>
<li>When I print out$title, I see a space. - On another instance of WP, I have no problem with this code.
Help?
Additional debugging:
- I have turned off all of the plugins
- I have checked and the value of
''is given to `$title'</li>
<li>When I swapempty( $instance['title'] )forempty( $title ), the code works (no titles show on the text widgets)</li>
<li>When I print out$title, I see a space. - On another instance of WP, I have no problem with this code.
Help?
Additional debugging:
- I have turned off all of the plugins
- I have checked and the value of
''is given to$title - When I swap
empty( $instance['title'] )forempty( $title ), the code works (no titles show on the text widgets) - When I print out
$title, I see a space. - On another instance of WP, I have no problem with this code.
Help?
Sorry for the reposts – looks like the caching had some issues.
And now I have explored and seen that the line that is likely to be the challenge is the resulting
apply_filtersline.$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );The question I have is why would the
apply_filtersfunction return a single space when the value after the?is clearly an empty value.Any reason why that would happen?
This topic is NOT resolved, but no one is responding. I am going to create a different post to resolve this.
The topic ‘!empty($title) returns 1 when $title is empty’ is closed to new replies.