0

Been breaking my keyboard over this. Did a proper install, uploaded the database to a fresh MySQL and been working on using child themes properly. But there is something plaguing me I can not figure out.

On my new install (ver2.whowhatwhy.com) I intentionally left some of my widgets blank. I would expect, when reading the default-widgets.php file in wp-includes that there would be no title element showing on that widget.

Instead, the title widget is showing because, for some reason, the value being passed by apply_filters is a space, rather than a blank value when the $instance['title'] is blank.

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

Has anyone seen this before? The problem I have is that the original installation has no problem with this call (returns a blank value).

If you go to the site, you can see the vardumps of the different elements of the code:

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 . '] ' . $after_title; } ?>
            <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
        <?php
        echo $after_widget;
    }

I also removed all of the widgets and then replaced the one widget on the page. This is what is in the database:

@Otto - I also looked in the database and eliminated all of the other widgets. And here is what I found:

a:2:{i:916707761;a:3:{s:5:"title";s:0:"";s:4:"text";s:1333:"<table width="297" bgcolor="#000000">
  <tr>
    <td width="297" bordercolor="0"><!-- BEGIN: Constant Contact Stylish Email Newsletter Form -->
<div align="center">
<div style="width:267px; background-color: #000000;">
<form name="ccoptin" action="http://visitor.r20.constantcontact.com/d.jsp" target="_blank" method="post" style="margin-bottom:3;">
  <p><span class="style1" style="font-family: Arial, Helvetica, sans-serif"><font style="font-family:Arial; font-size:18px; color:#666666;"><span class="style4">Do you need the truth?</span><br>
    </font><span style="font-size: 12px"><font style="font-family:Arial; font-size:14px; color:#FF0000;">Sign up for our weekly email updates and stay informed. </font></span></span></p>
  <p>
        <input type="text" name="ea" size="22" value="" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:14px; border:1px solid #999999;">
        <input type="submit" name="go" value="JOIN" class="submit"  style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10px;">
        <input type="hidden" name="llr" value="">
        <input type="hidden" name="m" value="">
        <input type="hidden" name="p" value="">
    </p>
</form>
</div>
</div>
</td>
  </tr>
</table>
<div style="margin-bottom: 2px;">&nbsp;</div>
";s:6:"filter";b:0;}s:12:"_multiwidget";i:1;}

Note where the a:3 is, you can see that the title value is an empty string with no length.

So, why would apply_filters return a non-empty value?

5
  • 1
    Is the title actually blank, or is there a space in it? A string with a space in it is not an empty value.
    – Otto
    Feb 11 '14 at 19:07
  • @Otto - there is no value between the two quotes (see the line). But for some reason, the output of apply_filters or the value found in $title is a space.
    – Sanford
    Feb 12 '14 at 11:39
  • No, I mean, in the widget itself, is there a space in the title? That line just checks to see if the data in the widget is empty. If it's not empty (contains a space), then it uses it. You need to look at the data, not the code.
    – Otto
    Feb 12 '14 at 13:41
  • @Otto - nothing in the data shows a space. If you look at the site - the third vardump shows what is in the instance($title) which is empty/devoid of anything. For some reason the $title assignment adds a space to the variable. Any idea why?
    – Sanford
    Feb 13 '14 at 11:06
  • @Otto - I also looked in the database and eliminated all of the other widgets. And here is what I found:
    – Sanford
    Feb 13 '14 at 13:40
1

The problem is in the theme you're using. This has been reported before:

https://core.trac.wordpress.org/ticket/21430

Seems that Elegant Themes don't like their widgets to not have titles. So they have a function called "et_widget_force_title" which changes blank titles into titles with a single space.

In case of doubt, always try disabling plugins and switching to the default theme. You never can tell what other plugins or themes are doing.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.