admin管理员组

文章数量:1414628

So I'm still learning about the Settings API on WordPress and can't seem to figure out how to handle admin notices on an empty database and then have validation.

Registration:

function register_insta_heading()
{
    add_settings_section(
        "", //1. Linked to: add_settings_section(section)
        "", //Section title
        null,
        "insta_heading_field"); //1. Linked to: add_settings_field(page)

    add_settings_field(
        "",
        "Heading", //Add the 'Access Token' title
        "heading_display", //Call posts_number_display function
        "insta_heading_field", //2. Linked to: do_settings_field
        "");

    register_setting(
        'instagram-settings',
        'insta_heading' );
}

Display:

function heading_display() {
    ?>
    <label for="insta_heading">
        <?php if (empty(get_option('insta_heading'))): ?>
            <div class="notice notice-error is-dismissible">
                <p><?php _e('Please input a module heading', 'instagram-enabler'); ?></p>
            </div>
            <input type="text" name="insta_heading" id="insta_heading" value="<?php echo get_option('insta_heading'); ?>" size="64" class="regular-text code" />
        <?php else: ?>
            <input type="text" name="insta_heading" id="insta_heading" value="<?php echo get_option('insta_heading'); ?>" size="64" class="regular-text code" />
        <?php endif; ?>
    </label>
    <p class="description">
        <?php _e("Enter the module heading", "instagram-enabler"); ?>
    </p>
    <?php
}
add_action( 'admin_init', 'register_insta_heading' );

Show:

function instagram_showpage() {
    ?>
    <div class="wrap">
    <h2>Instagram</h2>
    <form method="post" action="options.php">
        <table class="form-table">
            <?php
                settings_fields( 'instagram-settings' );
                do_settings_sections("insta_heading_field");
                submit_button();
            ?>
        </table>
    </form>
    </div><?php
}

本文标签: pluginsShow admin notice on incorrect value on form field