0

Hi guys I have been working with the settings API and my code won't run. I have an options page called "kaipo", and the callback function in that add_options_page function will output "hii" from kaipo_menu_callback function. That is the only part of my code that actually runs. When I declare my section the function that should output "hellooooo" does not print and also my input fields does not display. i.e the functions Kaipo_footer_message_display and Kaipo_message_display does not print anything. Have I registered something wrongly? please help me!!

 <?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');
0

That's because you need to print your settings fields in Kaipo_menu_callback, something like:

<?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
}

I would strongly suggest reading the settings API in detail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.