在访问我新创建的插件页面时,出现“您没有足够的权限访问此页面”

时间:2012-01-20 作者:daniel trifunovic

我正在遵循“编写您自己的插件教程”,我制作了它,激活了它,并将其添加到设置中,以拥有自己的插件页面,但在尝试访问该插件页面时,我会收到上面的消息,说“我没有足够的权限访问此页面”,即使我以管理员身份登录,并且我确实这样做了chmod -R 777 到wordpress目录??

还有什么可能出错?

Plugin code follows:

oscommerce_importer.php

<?php  
    /* 
    Plugin Name: OSCommerce Product Display 
    Plugin URI: http://www.orangecreative.net 
    Description: Plugin for displaying products from an OSCommerce shopping cart database 
    Author: C. Lupu 
    Version: 1.0 
    Author URI: http://www.orangecreative.net 
    */  

    function oscimp_admin() {  
     include(\'oscommerce_import_admin.php\');  
}  

    function oscimp_admin_actions() {  
      add_options_page("OSCommerce Product Display", "OSCommerce Product Display", 1, "OSCommerce Product Display", "oscimp_admin");  
    }  

    add_action(\'admin_menu\', \'oscimp_admin_actions\');  


?>

oscommerce_import_admin.php

 <div class="wrap">  
  <?php    echo "<h2>" . __( \'OSCommerce Product Display Options\', \'oscimp_trdom\' ) . "</h2>"; ?>  

  <form name="oscimp_form" method="post" action="<?php echo str_replace( \'%7E\', \'~\', $_SERVER[\'REQUEST_URI\']); ?>">  
      <input type="hidden" name="oscimp_hidden" value="Y">  
      <?php    echo "<h4>" . __( \'OSCommerce Database Settings\', \'oscimp_trdom\' ) . "</h4>"; ?>  
      <p><?php _e("Database host: " ); ?><input type="text" name="oscimp_dbhost" value="<?php echo $dbhost; ?>" size="20"><?php _e(" ex: localhost" ); ?></p>  
      <p><?php _e("Database name: " ); ?><input type="text" name="oscimp_dbname" value="<?php echo $dbname; ?>" size="20"><?php _e(" ex: oscommerce_shop" ); ?></p>  
      <p><?php _e("Database user: " ); ?><input type="text" name="oscimp_dbuser" value="<?php echo $dbuser; ?>" size="20"><?php _e(" ex: root" ); ?></p>  
      <p><?php _e("Database password: " ); ?><input type="text" name="oscimp_dbpwd" value="<?php echo $dbpwd; ?>" size="20"><?php _e(" ex: secretpassword" ); ?></p>  
      <hr />  
      <?php    echo "<h4>" . __( \'OSCommerce Store Settings\', \'oscimp_trdom\' ) . "</h4>"; ?>  
      <p><?php _e("Store URL: " ); ?><input type="text" name="oscimp_store_url" value="<?php echo $store_url; ?>" size="20"><?php _e(" ex: http://www.yourstore.com/" ); ?></p>  
      <p><?php _e("Product image folder: " ); ?><input type="text" name="oscimp_prod_img_folder" value="<?php echo $prod_img_folder; ?>" size="20"><?php _e(" ex: http://www.yourstore.com/images/" ); ?></p>  

      <p class="submit">  
      <input type="submit" name="Submit" value="<?php _e(\'Update Options\', \'oscimp_trdom\' ) ?>" />  
      </p>  
  </form>  
 </div>  
谢谢

1 个回复
最合适的回答,由SO网友:mor7ifer 整理而成

add_options_page("OSCommerce Product Display", "OSCommerce Product Display", 1, "OSCommerce Product Display", "oscimp_admin");

应该是

add_options_page( \'OSCommerce Product Display\', \'OSCommerce Product Display\', \'administrator\', \'os_commerce_display_main\', \'oscimp_admin\' );

解决方案未经测试。文档:Roles and Capabilities, add_options_page

第三个参数是能力,而不是用户级别或您所想的任何参数。我将其设置为admin,如果您想要不同的设置,请参阅有关角色和功能的文档。您所犯的另一个错误是菜单段塞中有空格,它可能是这样工作的,但它可能会造成混乱。您还应该仔细查看Wordpress Coding Standards 如果你想做插件开发。

结束

相关推荐