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
版权声明:本文标题:plugins - Show admin notice on incorrect value on form field 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745164184a2645593.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论