admin管理员组文章数量:1125569
as everyone knows, when we want to display some setting section in some specific page, normally we must pass to it the slug-name of the page where we want to dispay it . it work 100% , but the problem that i faced is that when i wanted to work in just one Theme Page Option with Tabbed Navigation , i tried to follow the core rules so i did that to create two section and separate them with tabbed navigation in order to not interfere with the nonces . That's My Code .
// These Are The registering settings for the Fields .
register_setting( 'busymarket-header-settings', 'busymarkets-breadcrumb-setting' );
register_setting( 'busymarket-footer-settings', 'busymarkets-main-footer-setting' );
register_setting( 'busymarket-footer-settings', 'busymarkets-left-btm-footer-setting' );
register_setting( 'busymarket-footer-settings', 'busymarkets-right-btm-footer-setting' );
$active_tab = 'header_options';
if ( isset( $_GET[ 'tab' ] ) ) {
if ( $_GET[ 'tab' ] == 'header_options' ) {
$active_tab = 'header_options';
} else if ( $_GET[ 'tab' ] == 'footer_options' ) {
$active_tab = 'footer_options';
}
}
<!-- Create A Tabbed Navigation For The Settings API -->
<h2 class="nav-tab-wrapper">
<a href="<?php echo admin_url( '?page=busymarkets-theme-panel&tab=header_options' ); ?>" class="nav-tab<?php echo $active_tab == 'header_options' ? ' nav-tab-active' : ''; ?>">Header Options</a>
<a href="<?php echo admin_url( '?page=busymarkets-theme-panel&tab=footer_options' ); ?>" class="nav-tab<?php echo $active_tab == 'footer_options' ? ' nav-tab-active' : ''; ?>">Footer Options</a>
</h2>
// The 'busymarket-header-settings' is The Option Group For The Header option .
// The 'busymarket-footer-settings' is The Option Group For The Footer option .
if ( $active_tab == 'footer_options' ) {
// Footer Settings Registering .
settings_fields( 'busymarket-footer-settings' );
do_settings_sections( 'busymarkets-theme-panel' );
} else if ( $active_tab == 'header_options' ) {
// Footer Settings Registering .
settings_fields( 'busymarket-header-settings' );
do_settings_sections( 'busymarkets-theme-panel' );
}
submit_button();
The problem here is that actually the function do_settings_sections()
Accepts the slug-name of the page where we want to output the section fields , and the fact that i'm using tab navigation i did a conditional code as you see below to not interfere with nonces and only display one section setting for every tab , But it didn't work .
I saw in a lot of tutorials that some developers work with a specific slug-name far from the slug-name of the page , whichever tab i click , i see the same section field , nothing happen and nothing changes .
So please, is there any solution to get thsi stuff work properly ?
as everyone knows, when we want to display some setting section in some specific page, normally we must pass to it the slug-name of the page where we want to dispay it . it work 100% , but the problem that i faced is that when i wanted to work in just one Theme Page Option with Tabbed Navigation , i tried to follow the core rules so i did that to create two section and separate them with tabbed navigation in order to not interfere with the nonces . That's My Code .
// These Are The registering settings for the Fields .
register_setting( 'busymarket-header-settings', 'busymarkets-breadcrumb-setting' );
register_setting( 'busymarket-footer-settings', 'busymarkets-main-footer-setting' );
register_setting( 'busymarket-footer-settings', 'busymarkets-left-btm-footer-setting' );
register_setting( 'busymarket-footer-settings', 'busymarkets-right-btm-footer-setting' );
$active_tab = 'header_options';
if ( isset( $_GET[ 'tab' ] ) ) {
if ( $_GET[ 'tab' ] == 'header_options' ) {
$active_tab = 'header_options';
} else if ( $_GET[ 'tab' ] == 'footer_options' ) {
$active_tab = 'footer_options';
}
}
<!-- Create A Tabbed Navigation For The Settings API -->
<h2 class="nav-tab-wrapper">
<a href="<?php echo admin_url( '?page=busymarkets-theme-panel&tab=header_options' ); ?>" class="nav-tab<?php echo $active_tab == 'header_options' ? ' nav-tab-active' : ''; ?>">Header Options</a>
<a href="<?php echo admin_url( '?page=busymarkets-theme-panel&tab=footer_options' ); ?>" class="nav-tab<?php echo $active_tab == 'footer_options' ? ' nav-tab-active' : ''; ?>">Footer Options</a>
</h2>
// The 'busymarket-header-settings' is The Option Group For The Header option .
// The 'busymarket-footer-settings' is The Option Group For The Footer option .
if ( $active_tab == 'footer_options' ) {
// Footer Settings Registering .
settings_fields( 'busymarket-footer-settings' );
do_settings_sections( 'busymarkets-theme-panel' );
} else if ( $active_tab == 'header_options' ) {
// Footer Settings Registering .
settings_fields( 'busymarket-header-settings' );
do_settings_sections( 'busymarkets-theme-panel' );
}
submit_button();
The problem here is that actually the function do_settings_sections()
Accepts the slug-name of the page where we want to output the section fields , and the fact that i'm using tab navigation i did a conditional code as you see below to not interfere with nonces and only display one section setting for every tab , But it didn't work .
I saw in a lot of tutorials that some developers work with a specific slug-name far from the slug-name of the page , whichever tab i click , i see the same section field , nothing happen and nothing changes .
So please, is there any solution to get thsi stuff work properly ?
Share Improve this question edited Mar 30, 2018 at 10:17 Simo Patrek asked Mar 30, 2018 at 9:43 Simo PatrekSimo Patrek 1121 gold badge4 silver badges15 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 1Incase anyone stumbles across this, I recently encountered the same issue and was able to render the differnet using do_setting_fields( $page, $section )
instead of do_settings_sections( $page )
.
As per the settings api, do_settings_sections prints out all settings sections added to a particular settings page, whilst do_settings_fields prints out the settings fields for a particular settings section.
If you check the manual: https://developer.wordpress.org/reference/functions/add_settings_section/
You can use the $args['before_section']
and the $args['after_section']
to wrap a section with e.g. '<div class="tab-content">'.$section.'</div>'
. After that you only need the proper javascript code.
Another possible solution is giving a different $page
for all the sections. In theory this variable should be the page slug, but in practice it can be anything.
Yet another option is using do_setting_fields
with a table wrapper as Phil wrote.
What I prefer is the second and I use the form id, which is usually the plugin prefix, the storage id and the storage action e.g. myplugin_mysettings_update
. I usually have one section for each form. When I store multiple entities in a settings option I append the entity id too e.g. myplugin_mysettings_123_update
, so I can display all the update forms on a single page. I use the same form id as a prefix for input field ids so all input fields can have a unique id. I found that a single section for each tab is not the best solution.
本文标签: Display Each Setting Section In Each Specific Tab within Same PageSettings API
版权声明:本文标题:Display Each Setting Section In Each Specific Tab within Same Page || Settings API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736625291a1945661.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
settings_field()
. Where is yourregister_setting()
? – Bikash Waiba Commented Mar 30, 2018 at 10:06