James Johnson wrote:
The Akismet Configuration under Plugins works -- I believe this has always
worked, even pre changeset 3025 -- but no luck with Akismet Spam under
Manage.  Its giving the same cannot redeclare error.

It's like I was saying...

The value passed in as the $file parameter to add_management_page() can have absolutely nothing to do with the plugin's filename, as long as you:

1) Pass a unique value among all active plugins.
2) Also supply the $function parameter.
3) Remain consistent with whatever value you pass for the sake of linking to those pages.

Either of the attached diffs to akismet.php both work. One uses basename(__FILE__), which is sensible. The other uses the word "squidoo" to illustrate my point.

Either of these solutions could cause a problem if you have two active plugins using the same filename/identifier located in different directories, which is the best reason to use plugin_basename(__FILE__) or just "__FILE__" (which is reduced in add_submenu_page() using plugin_basename() anyway), since it creates a unique index for plugin files in different locations.

The solution would then be to apply the patch to admin.php, which fixes a fairly simple forehead-slapping bug and makes all of these issues go away. :)

Owen

Index: admin.php
===================================================================
--- admin.php   (revision 3336)
+++ admin.php   (working copy)
@@ -45,7 +45,7 @@
 // Handle plugin admin pages.
 if (isset($_GET['page'])) {
        $plugin_page = stripslashes($_GET['page']);
-       $plugin_page = plugin_basename($_GET['page']);
+       $plugin_page = plugin_basename($plugin_page);
        $page_hook = get_plugin_page_hook($plugin_page, $pagenow);
 
        if ( $page_hook ) {
Index: akismet.php
===================================================================
--- akismet.php (revision 4227)
+++ akismet.php (working copy)
@@ -13,7 +13,7 @@
 function ksd_config_page() {
        global $wpdb;
        if ( function_exists('add_submenu_page') )
-               add_submenu_page('plugins.php', 'Akismet Configuration', 
'Akismet Configuration', 1, __FILE__, 'akismet_conf');
+               add_submenu_page('plugins.php', 'Akismet Configuration', 
'Akismet Configuration', 1, 'squidoo', 'akismet_conf');
 }
 
 function akismet_conf() {
@@ -57,9 +57,9 @@
 
 if ( !get_option('wordpress_api_key') && !isset($_POST['submit']) ) {
        function akismet_warning() {
-       $path = plugin_basename(__FILE__);
+       $path = basename(__FILE__);
                echo "
-               <div id='akismet-warning' class='updated 
fade-ff0000'><p><strong>".__('Akismet is not active.')."</strong> 
".sprintf(__('You must <a href="%1$s">enter your WordPress.com API key</a> for 
it to work.'), "plugins.php?page=$path")."</p></div>
+               <div id='akismet-warning' class='updated 
fade-ff0000'><p><strong>".__('Akismet is not active.')."</strong> 
".sprintf(__('You must <a href="%1$s">enter your WordPress.com API key</a> for 
it to work.'), "plugins.php?page=squidoo")."</p></div>
                <style type='text/css'>
                #adminmenu { margin-bottom: 5em; }
                #akismet-warning { position: absolute; top: 7em; }
@@ -185,7 +185,7 @@
        global $wpdb;
        $count = sprintf(__('Akismet Spam (%s)'), ksd_spam_count());
        if ( function_exists('add_management_page') )
-               add_management_page(__('Akismet Spam'), $count, 1, __FILE__, 
'ksd_caught');
+               add_management_page(__('Akismet Spam'), $count, 1, 'squidoo', 
'ksd_caught');
 }
 
 function ksd_caught() {
@@ -284,9 +284,9 @@
        $count = get_option('akismet_spam_count');
        if ( !$count )
                return;
-       $path = plugin_basename(__FILE__);
+       $path = basename(__FILE__);
        echo '<h3>'.__('Spam').'</h3>';
-       echo '<p>'.sprintf(__('<a href="%1$s">Akismet</a> has protected your 
site from <a href="%2$s">%3$s spam comments</a>.'), 'http://akismet.com/', 
"edit.php?page=$path", $count).'</p>';
+       echo '<p>'.sprintf(__('<a href="%1$s">Akismet</a> has protected your 
site from <a href="%2$s">%3$s spam comments</a>.'), 'http://akismet.com/', 
"edit.php?page=squidoo", $count).'</p>';
 }
 
 add_action('activity_box_end', 'akismet_stats');
Index: akismet.php
===================================================================
--- akismet.php (revision 4227)
+++ akismet.php (working copy)
@@ -13,7 +13,7 @@
 function ksd_config_page() {
        global $wpdb;
        if ( function_exists('add_submenu_page') )
-               add_submenu_page('plugins.php', 'Akismet Configuration', 
'Akismet Configuration', 1, __FILE__, 'akismet_conf');
+               add_submenu_page('plugins.php', 'Akismet Configuration', 
'Akismet Configuration', 1, basename(__FILE__), 'akismet_conf');
 }
 
 function akismet_conf() {
@@ -57,7 +57,7 @@
 
 if ( !get_option('wordpress_api_key') && !isset($_POST['submit']) ) {
        function akismet_warning() {
-       $path = plugin_basename(__FILE__);
+       $path = basename(__FILE__);
                echo "
                <div id='akismet-warning' class='updated 
fade-ff0000'><p><strong>".__('Akismet is not active.')."</strong> 
".sprintf(__('You must <a href="%1$s">enter your WordPress.com API key</a> for 
it to work.'), "plugins.php?page=$path")."</p></div>
                <style type='text/css'>
@@ -185,7 +185,7 @@
        global $wpdb;
        $count = sprintf(__('Akismet Spam (%s)'), ksd_spam_count());
        if ( function_exists('add_management_page') )
-               add_management_page(__('Akismet Spam'), $count, 1, __FILE__, 
'ksd_caught');
+               add_management_page(__('Akismet Spam'), $count, 1, 
basename(__FILE__), 'ksd_caught');
 }
 
 function ksd_caught() {
@@ -284,7 +284,7 @@
        $count = get_option('akismet_spam_count');
        if ( !$count )
                return;
-       $path = plugin_basename(__FILE__);
+       $path = basename(__FILE__);
        echo '<h3>'.__('Spam').'</h3>';
        echo '<p>'.sprintf(__('<a href="%1$s">Akismet</a> has protected your 
site from <a href="%2$s">%3$s spam comments</a>.'), 'http://akismet.com/', 
"edit.php?page=$path", $count).'</p>';
 }
_______________________________________________
wp-testers mailing list
[email protected]
http://lists.automattic.com/mailman/listinfo/wp-testers

Reply via email to