• Resolved sdickert

    (@sdickert)


    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter sdickert

    (@sdickert)

    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 swap empty( $instance['title'] ) for empty( $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?

    Thread Starter sdickert

    (@sdickert)

    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 swap empty( $instance['title'] ) for empty( $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?

    Thread Starter sdickert

    (@sdickert)

    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'] ) for empty( $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?

    Thread Starter sdickert

    (@sdickert)

    Sorry for the reposts – looks like the caching had some issues.

    Thread Starter sdickert

    (@sdickert)

    And now I have explored and seen that the line that is likely to be the challenge is the resulting apply_filters line.

    $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );

    The question I have is why would the apply_filters function return a single space when the value after the ? is clearly an empty value.

    Any reason why that would happen?

    Thread Starter sdickert

    (@sdickert)

    This topic is NOT resolved, but no one is responding. I am going to create a different post to resolve this.

    https://www.ads-software.com/support/topic/apply_filters-returns-a-non-empty-string-when-the-value-is-empty?replies=1#post-5229290

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘!empty($title) returns 1 when $title is empty’ is closed to new replies.