选项页面未显示在设置菜单下

时间:2016-12-13 作者:The WP Intermediate

<?php
/*
 *  Plugin Name: Official Treehouse Badges Plugin
 *  Plugin URI: http://wptreehouse.com/wptreehouse-badges-plugin/
 *  Description: Provides both widgets and shortcodes to help you display your Treehouse profile badges on your website.  The official Treehouse badges plugin.
 *  Version: 1.0
 *  Author: Editorial Staff
 *  Author URI: http://wp.zacgordon.com
 *  License: GPL2
 *
*/


/*---------------------------------------*/
/* 1. ASSIGN GLOBAL VARIABLE */
/*---------------------------------------*/


/*---------------------------------------*/
/* 2. PLUGIN ADMIN MENU */
/*---------------------------------------*/

function basic_treehouse_badges_menu() {
  /*
     *  Use the add_options_page function
     *  add_options_page( $page_title, $menu_title, $capability, $menu-slug, $function )
     *
    */
  add_options_page(
    \'Official Tree House Badges Plugin\',
    \'Treehouse Badges\',
    \'manage options\',
    \'wp-treehouse-badges\',
    \'wptreehouse_badges_option_page\'
  );
}
add_action(\'admin_menu\',\'basic_treehouse_badges_menu\');

function wptreehouse_badges_option_page() {
  if( !current_user_can (\'manage_options\')) {
    wp_die(\'You do not have sufficient permission to acces this page.\');
  }
  echo \'<p> welcome to our plugin page </p>\';
}    


?>
我只是一个初学者,已经编写了一个非常简单的基本插件结构。

是什么错误导致“树屋徽章”菜单名没有出现在WordPress管理部分的设置菜单下。

2 个回复
最合适的回答,由SO网友:Dave Romsey 整理而成

唯一的问题是,在使用add_options_page(). 能力应为manage_options. 请注意下划线,无空格:

function basic_treehouse_badges_menu() {
  /*
     *  Use the add_options_page function
     *  add_options_page( $page_title, $menu_title, $capability, $menu-slug, $function )
     *
    */
  add_options_page(
    \'Official Tree House Badges Plugin\',
    \'Treehouse Badges\',
    \'manage_options\',
    \'wp-treehouse-badges\',
    \'wptreehouse_badges_option_page\'
  );
}
add_action(\'admin_menu\',\'basic_treehouse_badges_menu\');

function wptreehouse_badges_option_page() {
  if( !current_user_can (\'manage_options\')) {
    wp_die(\'You do not have sufficient permission to acces this page.\');
  }
  echo \'<p> welcome to our plugin page </p>\';
}    

SO网友:fmeaddons

您使用的代码中有错误\'manage options\' 而不是\'manage_options\'

所以正确的代码是

add_options_page(
    \'Official Tree House Badges Plugin\',
    \'Treehouse Badges\',
    \'manage_options\',
    \'wp-treehouse-badges\',
    \'wptreehouse_badges_option_page\'
  );
Here 您可以阅读有关“管理”菜单的更多信息。