Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Build a WordPress Plugin Building WordPress Widgets, and Shortcodes Adding Custom Styles to Plugin Front End

Joachim Hagege
Joachim Hagege
16,297 Points

Display_tooltip is not defined in the Building Wordpress Widgets.

Hello guys, in the make your own WP plugin, for some reason my $display_tooltip variable is not accesible in the front-end.php template. My code never enters <?php if( $display_tooltip == '1' ): ?> even when it's checked in the settings.

I tried to debut it by printing its value but it's not even defined.

I believed than an update in WP broke the code of the course and is no longer compatible. Probably in the "update function"

For reference:

function widget( $args, $instance ) {
    // Widget output

    extract( $args );
    $title = apply_filters( 'widget_title' , $instance['title'] );
    $num_badges = $instance['num_badges'];
    $display_tooltip = $instance['display_tooltip'];

    $options = get_option( 'wptreehouse_badges' );
    $wptreehouse_profile = $options['wptreehouse_profile'];

    require( 'inc/front-end.php' );

}

function update( $new_instance, $old_instance ) {
    // Save widget options

    $instance = $old_instance;
    $instance['title'] = strip_tags($new_instance['title']);
    $instance['num_badges'] = strip_tags($new_instance['num_badges']);
    $instance['display_tooltip'] = strip_tags($new_instance['display_tooltip']);

    return $instance;
}

function form( $instance ) {
    // Output admin widget options form

    $title = esc_attr($instance['title']);
    $num_badges = esc_attr($instance['num_badges']);
    $display_tooltip = esc_attr($instance['display_tooltip']);

    $options = get_option( 'wptreehouse_badges' );
    $wptreehouse_profile = $options['wptreehouse_profile'];

    require( 'inc/widget-fields.php' );

}

Please help, I already lost 8 hours on this one... Thank you so much!!!

2 Answers

Kevin Murphy
Kevin Murphy
24,380 Points

Hi Joachim,

Unfortunately I don't have a smoking gun for you, but FWIW I just completed this project and I can affirm that in my project the tooltips displayed as expected. My version of WP was 3.9.1 w/ 2014 theme, working on local server. I went through your included code line by line, did not see any discrepancies.

I'm not sure if you are at the stage where you expect to be seeing tooltips and are not seeing them or if something else prompted you to check the value for $display_tooltip. My guess is it's the former. If you haven't tried it, you may want to comment out your code and paste in the project code for sections that you suspect aren't working as expected.

On a related note, the exact section you have above I spent an hour (at least) today debugging an issue in which the tooltip setting would not update. FINALLY tracked it down that I had display_tooltip as $display_tooltip for the index in the form function - argh. I finally found it by comparing little snippets of the project code to my code. So I've gotten quite acquainted with the section you have above, do not see any errors. But may still want to try A/B'ing it. Good luck!

Joachim Hagege
Joachim Hagege
16,297 Points

Thank you SO MUCH for your thorough answer it helped me a great deal. Unfortunately I was dumb enough to put the widget in the "Secondary area" and not with the rest of the widgets and for some reason the theme we are using doesn't "activate" the secondary zone...

So frustrating... But it's behind me.. I really appreciate your help!!

Kevin Murphy
Kevin Murphy
24,380 Points

Great, glad to hear you figured it out!