设置API回调函数不会显示吗?

时间:2015-04-17 作者:75Kane

大家好,我一直在使用设置API,我的代码不会运行。我有一个名为“kaipo”的选项页,其中的回调函数add\\u options\\u page函数将从kaipo\\u menu\\u回调函数输出“hii”。这是我的代码中唯一实际运行的部分。当我声明我的节时,应该输出“Helloooo”的函数不会打印,并且我的输入字段也不会显示。i、 e Kaipo\\u footer\\u message\\u display和Kaipo\\u message\\u display功能不打印任何内容。我有没有注册错误?请帮帮我!!

 <?php
/*
* Plugin Name: Kaipo2
* Plugin URI: http://www.kaipochat.com
* Description: Chat By Interest
* Version: 1.0
* Author: JSL
* Author URI: http://www.kaipochat.com
* License: GPL2
*/

function Kaipo_add_options_page(){

    add_options_page(
        \'Kaipo\', //text to be displayed in title bar
        \'Kaipo\', //text displayed to menu
        \'administrator\', //required capability to users
        \'kaipo_menu_page\', //slug
        \'Kaipo_menu_callback\' //callback function
    );
}
//options page display
function Kaipo_menu_callback(){
    echo "hii";
}
//Register a new settings field on the General Settings page of the WordPress dashboard

function Kaipo_initialize_settings_field(){

    //introduce section rendered through the options page
    add_settings_section(
        \'footer_section\', //ID of field
        \'Footer Options\', //text used to label field
        \'Kaipo_footer_message_display\', //callback function to render the field
        \'kaipo_menu_page\' //ID of the page on which this section is rendered (must match the slug of add_options_page())
    );

    //define settings field
    add_settings_field(
        \'footer_message\', //ID of the field
        \'Footer Message\', //Text to label the field
        \'Kaipo_message_display\', //call back function to render the field
        \'kaipo_menu_page\',   //the page on which we are rendering the field
        \'footer_section\' //the section to which we are adding the settings
    );

    //register the \'footer_message\' setting with the \'General\' section
    register_setting(
        \'footer_section\',
        \'footer_message\'
    );
}//end of function

add_action(\'admin_init\', \'Kaipo_initialize_settings_field\');

//options page section display
function Kaipo_footer_message_display(){
  echo "helloooooo";
}

//renders the input field for Footer Message in the General Settings section
function Kaipo_message_display(){
    echo \'<input type="text" name="footer_message" id="footer_message" value="\' . get_option(\'footer_message\') . \'" />\';
}




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

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

这是因为您需要在中打印设置字段Kaipo_menu_callback, 类似于:

<?php

function Kaipo_menu_callback() {
    ?>

<div class="wrap">
    <h2>Kaipo</h2>
    <form action="options.php" method="post"><?php

        do_settings_sections( \'kaipo_menu_page\' );
        settings_fields( \'kaipo_menu_page\' );
        submit_button();

    ?></form>
</div>

<?php
}
我强烈建议阅读settings API 详细地

结束

相关推荐