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.
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..
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?)
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 theadmin_menu
action.In general, use
define( 'WP_DEBUG', true )
in yourwp-config.php
so you can see errors and warnings.