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() 的论据之一是能力,正确值为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 - 使用jQuery遍历JSON数据

css - 有没有办法使用CSS隐藏单选按钮?

javascript - 如何检查一个 float 是否是另一个数的整数次幂

c# - 是否可以通过Ajax上传文件?

php - MySQL,PHP,登录信息正确,但“无法连接到数据库”错误

php - 运行 Symfony 命令时无法加载 PHP 类

html - 仅表格单元格的内边框

html - 在小屏幕上固定定位的按钮

javascript - 颜色选择器在 Safari 浏览器中不起作用

javascript - onClick 仅适用于其他人