javascript - 尝试将菜单页面添加到 WordPress 管理站点

标签 javascript php css wordpress plugins

我正在尝试向我的管理站点添加一个菜单页面,并向 Word Press 站点添加一个页脚。但是,没有任何显示。没有错误消息。我从 YouTube 上复制了这段代码,显然这段代码适用于编写教程的人,但不适用于我。

我安装了它,但没有任何显示。请帮忙!

这是我的代码:

 <?php
    /**
    * Plugin Name: SBESS
    * Plugin URI: sbess.ca
    * Description: This plugin is to modify the email address of the current website.
    * Version: 1.0.0
    * Author: Rihao Kang
    * Author URI: sbess.ca
    * License: GPL2
    */

    ?>


    <?php
    // put the footer message into database
    function sbess_install(){
        add_option ('sbess_powerby', 'What..sup');

    }


    function sbess_deactive(){
        delete_option ('sbess_powerby');

    }

    function sbess_footer(){
        echo'<center>'.get_option('sbess_powerby').'</center>';

    }

    function sbess_menu(){

    //title of the webpage the when the title is clicked
    //actually text when it is used for the link
    //detect the perticular the user can access the menu
    //unique name provided for this particular menu, identify the menu
        add_menu_page('sbess','sbess','manage_option','sbessmenu','sbess_main_page');
    }

    function sbess_main_page(){

        echo'<h2>SBESS</h2>Welcome to SBESS ';
    }


// activation of the o
    register_activation_hook (_File, 'sbess_install');
    register_deactivation_hook (_File, 'sbess_deactive');
    add_action ('wp_footer','sbess_footer');
    add_action('admin_menu','sbess_menu');

    ?>

最佳答案

您采用的方法是正确的,您遇到的问题归结为一个简单的错字。

add_menu_page() 的参数之一是 capability,正确的值是 manage_options,而在您的代码中,您将其作为 manage_option .

add_menu_page( 'sbess', 'sbess', 'manage_options', 'sbessmenu', 'sbess_main_page' );

进一步阅读:https://codex.wordpress.org/Function_Reference/add_menu_page

同样对于激活和停用 Hook ,第一个参数需要从 _File 更改为 __FILE__

关于javascript - 尝试将菜单页面添加到 WordPress 管理站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30288354/

相关文章:

php - 在sql语句中包含变量的正确方法是什么

css - 我想把两个 div 放在一个 div 中

javascript - 多个自定义标记上的 google maps api v3 信息窗口中的动态内容

javascript - 具有 O(1) 查找的对象的数据结构?

javascript - 使用 d3.js 在鼠标悬停时在圆圈内显示文本

css - 中间带圆圈的单杠

javascript - Y 轴上的值消失(隐藏在标签下)

javascript - jQuery .size() 函数不适用于变量

php mail() 在 IIS 6 中不起作用

javascript - JSON.parse() 不适用于变量类型字符串,但如果直接使用,它可以处理其内容