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 How to Create a Plugin Template with a Settings Page

Ty Yamaguchi
Ty Yamaguchi
25,397 Points

Plugin could not be activated because it triggered a fatal error.

When I try to activate the plugin wordpress gives me this error message:

Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /wp-content/plugins/wptreehouse-badges/wptreehouse-badges.php on line 40

Here is my code:

<?php

/*
 *  Plugin Name: Official Treehouse Badges Plugin
 *  Plugin URI: http://wptreehouse.com/wptreehouse-badges-plugin/
 *  Description: Provides both widgets and shortcodes to help you display your Treehouse profile badges on your website.  The official Treehouse badges plugin.
 *  Version: 1.0
 *  Author: Zac Gordon
 *  Author URI: http://wp.zacgordon.com
 *  License: GPL2
 *
*/

/*
 *  Add a link to our plugin in the admin menu
 *  under 'Settings > Treehouse Badges'
 *
*/

function wptreehouse_badges_menu() {

    /*
     *  Use the add_options_page function
     *  add_options_page( $page_title, $menu_title, $capability, $menu-slug, $function )
     *
    */

    add_options_page(
        'Official Treehouse Badges Plugin',
        'Treehouse Badges',
        'manage_options',
        'wptreehouse-badges',
        'wptreehouse_badges_options_page'
    );

}
add_action( 'admin_menu', 'wptreehouse_badges_menu')


function wptreehouse_badges_options_page() {

    if( !current_user_can( 'manage_options' ) ) {
        wp_die( 'You do not have sufficient permissions to access this page.' );
    }

    echo '<p>Welcome to our plugin page</p>';

}
?>

Any suggestions on why this is not working?

2 Answers

Gareth Borcherds
Gareth Borcherds
9,372 Points

You are missing a semi colon after add_action( 'admin_menu', 'wptreehouse_badges_menu').

Anytime you see unexpected php error, it means that you probably forgot to end another piece of code right before the line number they gave you.

Ty Yamaguchi
Ty Yamaguchi
25,397 Points

Thanks Gareth! I'll remember to look for missing semi colons the next time I get an unexpected error.

Gareth Borcherds
Gareth Borcherds
9,372 Points

Did that resolve your issue then? Be sure to mark best answer if it's solved.

Zander Curtis
Zander Curtis
10,634 Points

Thanks Gareth for all you do to make the Treehouse Community the best in the market. Go TeamTreehouse! Let's go change the world.