admin管理员组文章数量:1434014
I'm working on my first plugin. I am having difficulty getting the settings_fields function to display the results of the settings fields' callback functions. I've been studying the settings api, but I cannot figure out where I've gone wrong. I've attached a screenshot of what is rendering, as well as the code in question. Thanks for any help provided.
Result:
if(!class_exists('ce_add_scripts')){
class ce_add_scripts{
function __construct(){
add_action('admin_init', array(&$this,'ceas_admin_init'));
add_action('admin_menu', array(&$this,'ceas_admin_menu'));
add_action('wp_head', array(&$this,'ceas_wp_head'));
add_action('wp_footer', array(&$this,'ceas_wp_footer'));
}
function ceas_admin_menu(){
add_submenu_page(
'tools.php',
'CE Add Scripts',
'CE Add Scripts',
'update_plugins',
'ceas_menu_page',
array(&$this,'ceas_page_callback') );
}
function ceas_admin_init(){
$args= array(
'type'=>'string',
'default'=>NULL,);
register_setting(
'ceas_options',
'ceas_main_settings',
$args);
add_settings_section(
'ceas_options_section',
'Insert Scripts to Head or Footer',
array(&$this,'ceas_section_display'),
'ceas_menu_page');
add_settings_field(
'ceas_options_field_0',
'Head Script Entry',
'ceas_head_script',
'CE Add Scripts',
'ceas_options_section');
add_settings_field(
'ceas_options_field_1',
'Footer Script Entry',
'ceas_footer_script',
'CE Add Scripts',
'ceas_options_section');
}
function ceas_section_display(){
echo 'Add scripts to the Head or Footer';
}
function ceas_head_script(){
$options = get_option('ceas_main_settings');
echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_0]'>";
echo $options['ceas_options_field_0'];
echo "</textarea>";
}
function ceas_footer_script(){
$options = get_option('ceas_main_settings');
echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_1]'>";
echo $options['ceas_options_field_1'];
echo "</textarea>";
}
function ceas_page_callback(){
echo "<div class='wrap'>
<form action='options.php' method='post'>
<h1>CE Add Scripts Settings</h1>";
settings_fields("ceas_options");
do_settings_sections('ceas_menu_page');
submit_button();
echo "</form>
</div>";
}
}
$ce_actualize= new ce_add_scripts();
}
I'm working on my first plugin. I am having difficulty getting the settings_fields function to display the results of the settings fields' callback functions. I've been studying the settings api, but I cannot figure out where I've gone wrong. I've attached a screenshot of what is rendering, as well as the code in question. Thanks for any help provided.
Result:
if(!class_exists('ce_add_scripts')){
class ce_add_scripts{
function __construct(){
add_action('admin_init', array(&$this,'ceas_admin_init'));
add_action('admin_menu', array(&$this,'ceas_admin_menu'));
add_action('wp_head', array(&$this,'ceas_wp_head'));
add_action('wp_footer', array(&$this,'ceas_wp_footer'));
}
function ceas_admin_menu(){
add_submenu_page(
'tools.php',
'CE Add Scripts',
'CE Add Scripts',
'update_plugins',
'ceas_menu_page',
array(&$this,'ceas_page_callback') );
}
function ceas_admin_init(){
$args= array(
'type'=>'string',
'default'=>NULL,);
register_setting(
'ceas_options',
'ceas_main_settings',
$args);
add_settings_section(
'ceas_options_section',
'Insert Scripts to Head or Footer',
array(&$this,'ceas_section_display'),
'ceas_menu_page');
add_settings_field(
'ceas_options_field_0',
'Head Script Entry',
'ceas_head_script',
'CE Add Scripts',
'ceas_options_section');
add_settings_field(
'ceas_options_field_1',
'Footer Script Entry',
'ceas_footer_script',
'CE Add Scripts',
'ceas_options_section');
}
function ceas_section_display(){
echo 'Add scripts to the Head or Footer';
}
function ceas_head_script(){
$options = get_option('ceas_main_settings');
echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_0]'>";
echo $options['ceas_options_field_0'];
echo "</textarea>";
}
function ceas_footer_script(){
$options = get_option('ceas_main_settings');
echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_1]'>";
echo $options['ceas_options_field_1'];
echo "</textarea>";
}
function ceas_page_callback(){
echo "<div class='wrap'>
<form action='options.php' method='post'>
<h1>CE Add Scripts Settings</h1>";
settings_fields("ceas_options");
do_settings_sections('ceas_menu_page');
submit_button();
echo "</form>
</div>";
}
}
$ce_actualize= new ce_add_scripts();
}
Share
Improve this question
edited Apr 9, 2019 at 5:32
Karun
1,3471 gold badge9 silver badges22 bronze badges
asked Apr 8, 2019 at 23:16
Doug L.Doug L.
1
1 Answer
Reset to default 0The the code below:
if(!class_exists('ce_add_scripts')){
class ce_add_scripts{
function __construct(){
add_action('admin_init', array(&$this,'ceas_admin_init'));
add_action('admin_menu', array(&$this,'ceas_admin_menu'));
add_action('wp_head', array(&$this,'ceas_wp_head'));
add_action('wp_footer', array(&$this,'ceas_wp_footer'));
}
function ceas_admin_menu(){
add_submenu_page(
'tools.php',
'CE Add Scripts',
'CE Add Scripts',
'update_plugins',
'ceas_menu_page',
array(&$this,'ceas_page_callback') );
}
function ceas_admin_init(){
$args= array(
'type'=>'string',
'default'=>NULL,);
register_setting(
'ceas_options',
'ceas_main_settings',
$args);
add_settings_section(
'ceas_options_section',
'Insert Scripts to Head or Footer',
array(&$this,'ceas_section_display'),
'ceas_menu_page');
add_settings_field(
'ceas_options_field_0',
'Head Script Entry',
'ceas_head_script',
'CE Add Scripts',
'ceas_options_section');
add_settings_field(
'ceas_options_field_1',
'Footer Script Entry',
'ceas_footer_script',
'CE Add Scripts',
'ceas_options_section');
}
function ceas_section_display(){
echo 'Add scripts to the Head or Footer';
}
function ceas_head_script(){
$options = get_option('ceas_main_settings');
if(!isset($options['ceas_options_field_0'])){
$options['ceas_options_field_0'] = '';
}
echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_0]'>";
echo $options['ceas_options_field_0'];
echo "</textarea>";
}
function ceas_footer_script(){
$options = get_option('ceas_main_settings');
if(!isset($options['ceas_options_field_1'])){
$options['ceas_options_field_1'] = '';
}
echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_1]'>";
echo $options['ceas_options_field_1'];
echo "</textarea>";
}
function ceas_page_callback(){
echo "<div class='wrap'>
<form action='options.php' method='post'>
<h1>CE Add Scripts Settings</h1>";
settings_fields("ceas_options");
do_settings_sections('ceas_menu_page');
$this->ceas_head_script();
$this->ceas_footer_script();
submit_button();
echo "</form>
</div>";
}
}
$ce_actualize= new ce_add_scripts();
}
本文标签: pluginsSettings Fields not showing up in Submenu Page
版权声明:本文标题:plugins - Settings Fields not showing up in Submenu Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745612327a2666187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论