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 a WordPress Plugin Settings Page Working with Forms in a WordPress Plugin Settings Page

Caroline Forslund
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Caroline Forslund
Front End Web Development Techdegree Graduate 36,096 Points

Settings page turns blank when I insert if-statement

Everything seems to be right. I put in my if-statement and I get this error from WP_DEBUG:

Parse error: syntax error, unexpected 'else' (T_ELSE) in /Applications/MAMP/htdocs/localwp.com/wp-content/plugins/wpgithub-statistics/inc/options-page-wrapper.php on line 55

I can't see what I do different from the instruction video. My code in options-page-wrapper.php looks like this:

<h3><?php esc_attr_e( 'GitHub Statistics Plugin Settings Page', 'wp_admin_style' ); ?></h3>

<div class="wrap">

    <div id="icon-options-general" class="icon32"></div>
    <h2><?php esc_attr_e( "Let's get started", 'wp_admin_style' ); ?></h2>

    <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( $wpgithub_statistics_username ) || $wpgithub_statistics_username == '' ); ?>

                        <div class="postbox">

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

                            <h3 class="hndle"><span><?php esc_attr_e( 'My GitHub Account', 'wp_admin_style' ); ?></span>
                            </h3>

                            <div class="inside">

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

                                <input type="hidden" name="wpgithub_statistics_form_submitted" value="Y" />

                                    <table class="form-table">
                                        <tr>
                                            <td>
                                                <label for="wpgithub_statistics_username">GitHub User Name</label>
                                            </td>
                                            <td>
                                                <input name="wpgithub_statistics_username" 
                                                id="wpgithub_statistics_username"
                                                type="text" value="" class="regular-text" />
                                            </td>
                                        </tr>
                                    </table>

                                    <input class="button-primary" type="submit" name="Example" value="<?php esc_attr_e( 'Update user' ); ?>" />

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

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

                    <?php else; ?>

                        <div class="postbox">

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

                            <h3 class="hndle"><span><?php esc_attr_e( 'My Organization', 'wp_admin_style' ); ?></span>
                            </h3>

                            <div class="inside">
                                <p>Below are the projects within your organization</p>  
                            </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">

                    <div class="postbox">

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

                        <h3 class="hndle"><span><?php esc_attr_e(
                                    'Your GitHub Profile', 'wp_admin_style'
                                ); ?></span></h3>

                        <div class="inside">
                            <img width="120px" src="<?php echo $plugin_url . '/images/carrolin.jpg'; ?>" />
                            <p>
                                Carro Forslund
                            </p>
                        </div>
                        <!-- .inside -->

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

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

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

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

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

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

1 Answer

Try taking a look at this http://blog.teamtreehouse.com/tip-for-streamlining-your-php-ifstatements

I'm still a novice, but I think you should try replacing the semicolons after if and else to be colons. From the error it sounds like the parser thought your statement was over too early.