简体   繁体   中英

Wordpress theme options error

I was making a custom theme options page for a wordpress theme following this tutorial: http://theme.fm/2011/08/using-the-color-picker-in-your-wordpress-theme-options-2152/

Everything was fine until I added the color picker function and script. Now every time I go onto the theme options page it's just a blank screen with an error from firebug. as shown in this picture.

http://i.stack.imgur.com/bR4P2.png

I deleted the color picker stuff but it's still doing it. I'm fairly new to javascript and php so i have no idea what's going on here.

Here's the code for my theme options page.

function mb_options_admin_menu() {
$page = add_theme_page( 'Theme Options', 'Theme Options', 'edit_theme_options', 'mb_options-theme-options', 'mb_options_theme_options' );
add_action( 'admin_print_styles-' . $page, 'mb_options_admin_scripts' );
}
add_action( 'admin_menu', 'mb_options_admin_menu' );

function mb_options_admin_scripts() {
// We'll put some javascript & css here later
}

function mb_options_theme_options() {
?>
<div class="wrap">
    <div id="icon-themes" class="icon32" ><br></div>
    <h2>My Theme Options</h2>

    <form method="post" action="options.php">
        <?php wp_nonce_field( 'update-options' ); ?>
        <?php settings_fields( 'mb_options-theme-options' ); ?>
        <?php do_settings_sections( 'mb_options-theme-options' ); ?>
        <p class="submit">
            <input name="Submit" type="submit" class="button-primary" value="Save Changes" />
        </p >
    </form>
</div>
<?php
}

function mb_options_admin_init() {
register_setting( 'mb_options-theme-options', 'mb_options-theme-options' );
add_settings_section( 'section_general', 'General Settings', 'mb_options_section_general', 'mb_options-theme-options' );
add_settings_field( 'link_color', 'Link Color', 'mb_options_setting_color', 'mb_options-theme-options', 'section_general' );
add_settings_field( 'link_hover_color', 'Link Hover Color', 'mb_options_hover_setting_color', 'mb_options-theme-options', 'section_general' );
}
add_action( 'admin_init', 'mb_options_admin_init' );

function mb_options_section_general() {
_e( 'The general section description goes here.' );
}

function mb_options_setting_color() {
$options = get_option( 'mb_options-theme-options' );
?>
<input type="text" name="mb_options-theme-options[link_color]" value="<?php echo esc_attr( $options['link_color'] ); ?>" />
<?php
}

function mb_options_hover_setting_color() {
$options = get_option( 'mb_options-theme-options' );
?>
<input type="text" name="mb_options-theme-options[link_hover_color]" value="<?php echo esc_attr( $options['link_hover_color'] ); ?>" />
<?php
}

function mb_options_link_color() {
$options = get_option( 'mb_options-theme-options' );
$link_color = $options['link_color'];
$link_hover_color = $options['link_hover_color'];
echo "<style> a { color: $link_color; } a:hover { color: $link_hover_color; } </style>";
}
add_action( 'wp_enqueue_scripts', 'mb_options_link_color' );

Can anyone please tell me what's going wrong here and any ways to fix it ?

It seems the error was due to the prefixes i was using. Solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM