Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having an issue with one site in which my plugin is installed. The "settings" page will not load. When I click on "settings", it loads the settings page but the page is blank after the "Upgrade to 3.1" nag div as if there was a die() there.

I have two files, plugin.php and plugin-admin.php

I've got code in plugin.php to set up the admin page:

$my_dir = plugins_url('/img', __FILE__);
add_options_page( 
    'MY! Settings', 
    'MY! Settings', 
    'manage_options', 
    'my-plugin-admin.php', 
    'my_settings_admin', 
    $my_dir.'/favicon.png', 'top'
);
register_setting( 'my_settings_options', 'my_settings', 'my_settings_validate' );

function my_settings_admin(){
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    include_once dirname(__FILE__) . '/my-plugin-admin.php';
}

define( 'my_BASENAME', plugin_basename( __FILE__ ) );
define( 'my_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
define( 'my_FILENAME', str_replace( my_BASEFOLDER.'/', '', plugin_basename(__FILE__)));

The "My Settings" link shows up under the "Settings" menu fine, and the link appears to be going to the correct page, but the script does not load and nothing will trace inside of my-plugin-admin.php

Any ideas?

UPDATE: with t31os help, here's the updated function that fixes the problem:

function my_settings_admin(){
    include_once dirname(__FILE__) . '/my-plugin-admin.php';
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

I simply had to move the wp_rewrite and flush rules after the include statement. Although I don't know why.

share|improve this question
    
Maybe a problem with the flush rules call? Tried without it? (Just a wild guess).. –  t31os Mar 29 '11 at 22:05
    
@t31os: Bingo. Please make this your answer if you like and I'll upvote and select. I had to comment out the flush rules. Why? –  Scott B Mar 30 '11 at 3:55
add comment

2 Answers 2

up vote 2 down vote accepted

If i had to venture a guess at the cause of the problem my initial thought would be toward the flush rules call.

As Andy said, having debug on helps a great deal, and if you really don't want to see the errors, you can always use the debug log instead, using the following in your config file..

define('WP_DEBUG', true);          // Turn on debug mode
define('WP_DEBUG_LOG', true);      // Logs errors to wp-content/debug.log
define('WP_DEBUG_DISPLAY', false); // Disable displaying errors

With regard to your settings update not redirecting, typically that occurs when the nonce(s) are missing or incorrect, though i'll admit it could be something else in your case.

Any errors shown with debug on? (or in the log if you're using that method?)

share|improve this answer
    
Thanks. That was it. I just had to move the flush rules after the include statement. Although I don't yet know why –  Scott B Mar 30 '11 at 15:04
add comment

When I use the code you provided I see the "MY! Settings" menu item as the top item in the Settings menu and it has an unexpected URL.

The call to add_options_page should be wrapped in a function hooked to the admin_menu action.

function my_admin_menu() {
    add_options_page(
        'MY! Settings',
        'MY! Settings',
        'manage_options',
        'my-admin',
        'my_settings_admin'
    );
}
add_action( 'admin_menu', 'my_admin_menu' );

In general, use define( 'WP_DEBUG', true ) in your wp-config.php so you can see errors and warnings.

share|improve this answer
    
Thanks Andy, I have it wrapped inside a function, my mistake for not specifying that. –  Scott B Mar 30 '11 at 3:23
    
The problem is as t31os indicated, the flush rules. I had to place them after the include once rather than before. Now the script loads. However, with debug on, my clicks to save the options are directing to options.php and not back to the plugin options as expected. –  Scott B Mar 30 '11 at 4:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.