Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress How to Build a WordPress Plugin Building a WordPress Plugin Settings Page CRUD with the WordPress Options Table

S Ananda
S Ananda
9,474 Points

Username not showing. Can't find error.

I've looked at my code a bunch and did an inspect. I've obviously got a problem I just can't see. On inspect it shows that I don't have anything in my value in this line of code. <input name="wptreehouse_username" id="wptreehouse_username" type="text" value="<?php echo $wptreehouse_username; ?>" />

Here's my code in full.

<div class="wrap">

    <div id="icon-options-general" class="icon32"></div>
    <h1>The Official Treehouse Badges Plugin</h1>

    <div id="poststuff">

        <div id="post-body" class="metabox-holder columns-2">

            <!-- main content -->
            <div id="post-body-content">

                <div class="meta-box-sortables ui-sortable">

                    <?php if ( !isset( $wptreehouse_username ) || $wptreehouse_username = '' ) :
                    ?>

                    <div class="postbox">

                        <div class="handlediv" title="Click to toggle"><br></div>
                        <!-- Toggle -->

                        <h2 class="hndle"><span>Let's Get Started</span>
                        </h2>

                        <div class="inside">

                            <form name="wptreehouse_username_form" method="post" action="">

                            <input type="hidden" name="wptreehouse_form_submitted" value="Y">

                            <table class="form-table">
                                <tr>
                                    <td>
                                        <label for="wptreehouse_username">Treehouse Username</label>
                                        </td>
                                    <td>
                                        <input name="wptreehouse_username" id="wptreehouse_username" type="text" value="" class="regular-text" />
                                    </td>
                                </tr>

                            </table>

                            <p>
                            <input class="button-primary" type="submit" name="wptreehouse_username_submit" value="Save" />
                            </p>

                            </form>

                        </div>
                        <!-- .inside -->

                    </div>
                    <!-- .postbox -->

                    <?php else: ?>

                    <div class="postbox">

                        <div class="handlediv" title="Click to toggle"><br></div>
                        <!-- Toggle -->

                        <h2 class="hndle"><span>Most Recent Badges</span>
                        </h2>

                        <div class="inside">

                            <P>Below are your 20 most recent badges</p>

                            <ul class="wptreehouse-badges">

                                <?php for( $i = 0; $i < 20; $i++ ): ?>
                                <li>
                                    <ul>
                                        <li>
                                            <img width="120px" src="<?php echo $plugin_url . '/images/wp-badge.png'; ?>">                               
                                        </li>                                       
                                        <li class="wptreehouse-badge-name">
                                            <a href="#">Badge Name</a>
                                        </li>
                                        <li class="wptreehouse-project-name">
                                            <a href="#">Project Name</a>
                                        </li>
                                    </ul>                                   
                                </li>                               
                                <?php endfor; ?>

                                    </ul>

                        </div>
                        <!-- .inside -->

                    </div>
                    <!-- .postbox -->

                    <?php endif; ?>

                </div>
                <!-- .meta-box-sortables .ui-sortable -->

            </div>
            <!-- post-body-content -->

            <!-- sidebar -->
            <div id="postbox-container-1" class="postbox-container">

                <div class="meta-box-sortables">

                    <?php if ( isset( $wptreehouse_username ) || $wptreehouse_username != '' ) :
                    ?>

                    <div class="postbox">

                    <h3><span>Mike the Frog's Profile</span></h3>
                        <div class="inside">

                            <p><img width="100%" class="wptreehouse-gravatar" src="<?php echo $plugin_url . '/images/mike-the-frog.png'; ?>" alt="Mike the Frog Gravatar"></p>

                        </div> <!-- .inside -->

                        <ul class="wptreehouse-badges-and-points">                          

                                <li>Badges: <strong>200</strong></li>
                                <li>Points: <strong>10000</strong></li>

                        </ul>

                        <form name="wptreehouse_username_form" method="post" action="">

                            <input type="hidden" name="wptreehouse_form_submitted" value="Y">

                            <p>
                                        <label for="wptreehouse_username">Username</label>
                            </p>
                            <p>
                                <input name="wptreehouse_username" id="wptreehouse_username" type="text" value="<?php echo $wptreehouse_username; ?>" />       
                                <input class="button-primary" type="submit" name="wptreehouse_username_submit" value="Update" />
                            </p>

                        </form>

                    </div>
                    <!-- .postbox -->

                    <?php endif; ?>

                </div>
                <!-- .meta-box-sortables -->

            </div>
            <!-- #postbox-container-1 .postbox-container -->

        </div>
        <!-- #post-body .metabox-holder .columns-2 -->

        <br class="clear">
    </div>
    <!-- #poststuff -->

</div> <!-- .wrap -->

Here's the line from the inspector. Notice it doesn't show anything in the value field:

<input name="wptreehouse_username" id="wptreehouse_username" type="text" value="">

Brandyn Lordi
Brandyn Lordi
17,776 Points

This question is a bit old and it has probably been solved since, but i'll chime in for anyone reading since there are no current answers:

the plugin file (wp-treehouse-badges.php) is where $wptreehouse_username is being set, and then requiring our page wrapper file afterwards. If your username is returning null, this first file might be a good place to start looking for errors, typos, etc.

Unfortunately, the code for that file wasn't posted here but this is most likely the root cause. Hopefully this helps some!