Я разрабатываю плагин, и он работает нормально, но на странице настроек, когда я сохраняю параметры, он сохраняет настройки текущей вкладки, но удаляет все данные на других.
Я попытался добавить IF в reister_Settings, который проверяет, является ли active_tab текущей вкладкой перед сохранением, но перенаправляет меня на редактирование. php после сохранения.
Код:
add_action('admin_menu', 'register_webinar_style_submenu_page');
function register_webinar_style_submenu_page() {
add_submenu_page( 'edit.php?post_type=webinars', 'Settings', 'Webinars Settings', 'manage_options', 'webinars-settings', 'webinar_style_page_callback' );
}
function wacfw_register_settings() {
global $post;
/* Business Name */
add_option( 'wacfw_setting_business_name');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_business_name', 'wacfw_business_name_callback' );
/* Show Website Header */
add_option( 'wacfw_setting_show_header');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_show_header', 'wacfw_show_header_callback' );
/* Header Background image */
add_option( 'wacfw_setting_header_background');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_header_background', 'wacfw_setting_header_background' );
/* Logo */
add_option( 'wacfw_setting_logo');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_logo', 'wacfw_logo_callback' );
/* Logo Size */
add_option( 'wacfw_setting_logo_size');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_logo_size', 'wacfw_logo_size_callback' );
/* Webinar Header Background Color */
add_option( 'wacfw_setting_header_color');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_header_color', 'wacfw_setting_header_color' );
/* Header hide triangle */
add_option( 'wacfw_setting_hide_triangle');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_hide_triangle', 'wacfw_setting_hide_triangle' );
/* Header Form Title */
add_option( 'wacfw_setting_form_title');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_form_title', 'wacfw_setting_form_title' );
/* Hide Website Footer */
add_option( 'wacfw_setting_hide_website_footer');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_hide_website_footer', 'wacfw_setting_hide_website_footer' );
/* Hide Template Footer */
add_option( 'wacfw_setting_hide_template_footer');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_hide_template_footer', 'wacfw_setting_hide_template_footer' );
/* Footer background */
add_option( 'wacfw_setting_footer_color');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_footer_color', 'wacfw_setting_footer_color' );
/* Footer text color */
add_option( 'wacfw_setting_footer_text_color');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_footer_text_color', 'wacfw_setting_footer_text_color' );
/* Footer text color */
add_option( 'wacfw_setting_logo_on_footer');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_logo_on_footer', 'wacfw_setting_logo_on_footer' );
/* Custom Footer Text */
add_option( 'wacfw_setting_footer_text');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_footer_text', 'wacfw_setting_footer_text' );
/* Custom Footer Font Size */
add_option( 'wacfw_setting_footer_font_size');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_footer_font_size', 'wacfw_setting_footer_font_size' );
/* Main Color */
add_option( 'wacfw_setting_main_color');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_main_color', 'wacfw_setting_main_color' );
/* Title Color */
add_option( 'wacfw_setting_title_color');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_title_color', 'wacfw_setting_title_color' );
/* Show - Duration */
add_option( 'wacfw_setting_show_duration');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_show_duration', 'wacfw_show_duration_callback' );
/* Show - Price */
add_option( 'wacfw_setting_show_price');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_show_price', 'wacfw_show_price_callback' );
/* Show - Date */
add_option( 'wacfw_setting_show_date');
register_setting( 'wacfw_settings_options_group', 'wacfw_setting_show_date', 'wacfw_show_date_callback' );
}
}
add_action( 'admin_init', 'wacfw_register_settings' );
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general_options';
global $post;
// Nonce field to validate form request came from current site
wp_nonce_field( basename( __FILE__ ), 'webinar_settings' );
?>
<!-- Create a header in the default WordPress 'wrap' container -->
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2 class="wacfw-h2">- Settings -</h2>
<?php settings_errors(); ?>
<?php
if( isset( $_GET[ 'tab' ] ) ) {
$active_tab = $_GET[ 'tab' ];
} // end if
$wacfw_settings_tabs = array( 'general_options' => 'General Options', 'template' => 'Template', 'social_options' => 'Social Options', 'sharing_options' => 'Sharing Options', 'emails' => 'Emails' );
echo ' <h2 class="wacfw-nav-tab-wrapper">';
foreach( $wacfw_settings_tabs as $wacfw_settings_tab => $name ){
//echo "<a class='nav-tab$class' href='edit.php?post_type=webinars&page=webinars-settings&tab=$wacfw_settings_tab'>$name</a>";
$wacfw_tab_class_active ='';
if ($active_tab == $wacfw_settings_tab){
$wacfw_tab_class_active='wacfw-nav-tab-active';
}
echo'<a href="edit.php?post_type=webinars&page=webinars-settings&tab='.$wacfw_settings_tab.'" class="nav-tab wacfw-nav-tab '.$wacfw_tab_class_active.' ">'.$name.'</a>';
}
echo '</h2>';
?>
<form method="post" action="options.php" class="wacfw-settings-content">
<div class="webinar-settings-form">
<?php
settings_fields( 'wacfw_settings_options_group' );
if( $active_tab == 'general_options' ) {
// Get the date data if it's already been entered
settings_fields( 'blueray_theme_display_options_page' );
do_settings_sections( 'blueray_theme_display_options_page' );
?>
<h3>General Options</h3>
<div class="wacfw-field">
<label for="wacfw_setting_business_name">Business/Corporation Name</label>
<input type="text" id="wacfw_setting_business_name" name="wacfw_setting_business_name" value="<?php echo get_option('wacfw_setting_business_name'); ?>" />
</div>
<div class="wacfw-field">
<label for="wacfw_setting_currency">Currency</label>
<input type="text" id="wacfw_setting_currency" name="wacfw_setting_business_name" value="<?php echo get_woocommerce_currency_symbol() ?>" disabled />
<p class="wacfw_input_notice">You can modify this on <a href="admin.php?page=wc-settings&tab=general#pricing_options-description" target="_blank">Woocommerce Settings Page</a></p>
</div>
<?php
}
if( $active_tab == 'template' ) {
// Get the date data if it's already been entered
?>
<h3>Header</h3>
<div class="wacfw-field-checkbox">
<!-- Show website header -->
<div class="wacfw-two-options-box">
<label for="wacfw_setting_show_header">Show Header</label><br>
<input type="checkbox" id="wacfw_setting_show_header" name="wacfw_setting_show_header" value="1" <?php if (get_option('wacfw_setting_show_header')){echo 'checked';} ?>/>
<p class="wacfw_input_notice_checkbox">Mark this option to show your header on the template page</p>
</div>
<!-- Hide Triangle under title -->
<div class="wacfw-two-options-box">
<label for="wacfw_setting_hide_triangle">Hide Triangle Under Title</label><br>
<input type="checkbox" id="wacfw_setting_hide_triangle" name="wacfw_setting_hide_triangle" value="1" <?php if (get_option('wacfw_setting_hide_triangle')){echo 'checked';} ?>/>
<p class="wacfw_input_notice_checkbox">Mark this option to hide the triangle Separator under the title</p>
</div>
</div>
<!-- Logo -->
<div class="wacfw-field">
<label for="wacfw_setting_logo">Logo</label>
<?php
if (get_option('wacfw_setting_logo')){
echo '<img class="wacfw_logo_print" src="'.get_option('wacfw_setting_logo').'">';
}
?>
<input id="wacfw_setting_logo" type="text" name="wacfw_setting_logo" value="<?php echo get_option('wacfw_setting_logo'); ?>" />
<input id="wacfw_upload_image_button" type="button" class="button-primary" value="Insert Image"/>
</div>
<!-- Logo Size -->
<div class="wacfw-field">
<label for="wacfw_setting_logo_size">Logo Width</label>
<input type="text" id="wacfw_setting_logo_size" name="wacfw_setting_logo_size" value="<?php echo get_option('wacfw_setting_logo_size'); ?>" />
<p class="wacfw_input_notice">Example: <b>150px</b> or <b>15%</b> - Default: <b>20%</b> </p>
</div>
<!-- Header Background -->
<div class="wacfw-field">
<label for="wacfw_setting_header_background">Header Background Image</label>
<?php
if (get_option('wacfw_setting_header_background')){
echo '<img class="wacfw_background_print" src="'.get_option('wacfw_setting_header_background').'">';
}
?>
<input id="wacfw_setting_header_background" type="text" name="wacfw_setting_header_background" value="<?php echo get_option('wacfw_setting_header_background'); ?>" />
<input id="wacfw_setting_header_background" type="button" class="button-primary" value="Insert Image" />
<p class="wacfw_input_notice">Recommended Size: 1280px x 410px</p>
</div>
<div class="divider"></div> <!-- Separator -->
<h3>Content</h3>
<div class="wacfw-field-checkbox">
<div class="wacfw-field">
<label for="wacfw_setting_form_title">Form Title</label>
<input type="text" id="wacfw_setting_form_title" name="wacfw_setting_form_title" value="<?php echo get_option('wacfw_setting_form_title'); ?>" />
</div>
</div>
<!-- Icons -->
<p class="wacfw-tree-options-settings">Show Icons</p>
<div class="wacfw-field-checkbox">
<div class="wacfw-tree-options-box">
<input type="checkbox" id="wacfw_setting_show_duration" name="wacfw_setting_show_duration" value="1" <?php if (get_option('wacfw_setting_show_duration')){echo 'checked';} ?>/>
<label for="wacfw_setting_show_duration">Show Duration</label>
</div>
<div class="wacfw-tree-options-box">
<input type="checkbox" id="wacfw_setting_show_price" name="wacfw_setting_show_price" value="1" <?php if (get_option('wacfw_setting_show_price')){echo 'checked';} ?>/>
<label for="wacfw_setting_show_price">Show Price</label>
</div>
<div class="wacfw-tree-options-box">
<input type="checkbox" id="wacfw_setting_show_date" name="wacfw_setting_show_date" value="1" <?php if (get_option('wacfw_setting_show_date')){echo 'checked';} ?>/>
<label for="wacfw_setting_show_date">Show Date</label>
</div>
</div>
<div class="divider"></div> <!-- Separator -->
<h3>Footer</h3>
<div class="wacfw-field-checkbox">
<!-- Hide Your Website Footer -->
<div class="wacfw-two-options-box">
<label for="wacfw_setting_hide_website_footer">Hide Your Website Footer</label><br>
<input type="checkbox" id="wacfw_setting_hide_website_footer" name="wacfw_setting_hide_website_footer" value="1" <?php if (get_option('wacfw_setting_hide_website_footer')){echo 'checked';} ?>/>
</div>
<!-- Hide Template Footer -->
<div class="wacfw-two-options-box">
<label for="wacfw_setting_hide_template_footer">Hide Template Footer</label><br>
<input type="checkbox" id="wacfw_setting_hide_template_footer" name="wacfw_setting_hide_template_footer" value="1" <?php if (get_option('wacfw_setting_hide_template_footer')){echo 'checked';} ?>/>
</div>
</div>
<div class="wacfw-field">
<label for="wacfw_setting_footer_text">Custom Footer Text</label>
<textarea type="text" id="wacfw_setting_footer_text" name="wacfw_setting_footer_text" value="<?php echo get_option('wacfw_setting_footer_text'); ?>" /></textarea>
<p class="wacfw_input_notice">Just available using the template footer - HTML Allowed</p>
</div>
<div class="wacfw-field">
<label for="wacfw_setting_footer_font_size">Footer Font Size</label>
<input type="text" id="wacfw_setting_footer_font_size" name="wacfw_setting_footer_font_size" value="<?php echo get_option('wacfw_setting_footer_font_size'); ?>"/>
<p class="wacfw_input_notice">Example: 12px or 1.2em - Default 12px</p>
</div>
<div class="wacfw-two-options-box">
<label for="wacfw_setting_logo_on_footer">Show Logo On Footer</label><br>
<input type="checkbox" id="wacfw_setting_logo_on_footer" name="wacfw_setting_logo_on_footer" value="1" <?php if (get_option('wacfw_setting_logo_on_footer')){echo 'checked';} ?>/>
<p class="wacfw_input_notice_checkbox">Just available using the template footer</p>
</div>
<div class="divider"></div> <!-- Separator -->
<h3>Colors</h3>
<!-- Colors -->
<div class="wacfw-field-checkbox">
<!-- Main Color -->
<div class="wacfw-tree-options-box">
<label for="wacfw_setting_header_color">Header & Footer Background</label><br>
<input type="text" name="wacfw_setting_header_color" id="wacfw_setting_header_color" value="<?php echo get_option('wacfw_setting_header_color'); ?>" data-default-color="#2F54A4" />
<script>jQuery(document).ready(function($){
$('#wacfw_setting_header_color').wpColorPicker();
});</script>
</div>
<!-- Main Color -->
<div class="wacfw-tree-options-box">
<label for="wacfw_setting_main_color">Main Color</label><br>
<input type="text" name="wacfw_setting_main_color" id="wacfw_setting_main_color" value="<?php echo get_option('wacfw_setting_main_color'); ?>" data-default-color="#2F54A4" />
<script>jQuery(document).ready(function($){
$('#wacfw_setting_main_color').wpColorPicker();
});</script>
</div>
<!-- Title Color -->
<div class="wacfw-tree-options-box">
<label for="wacfw_setting_title_color">Title Color</label><br>
<input type="text" name="wacfw_setting_title_color" id="wacfw_setting_title_color" value="<?php echo get_option('wacfw_setting_title_color'); ?>" data-default-color="#FFFFFF" />
<script>jQuery(document).ready(function($){
$('#wacfw_setting_title_color').wpColorPicker();
});</script>
</div>
</div>
<div class="wacfw-field-checkbox">
<!-- Main Color -->
<div class="wacfw-tree-options-box">
<label for="wacfw_setting_footer_color">Footer Background</label><br>
<input type="text" name="wacfw_setting_footer_color" id="wacfw_setting_footer_color" value="<?php echo get_option('wacfw_setting_footer_color'); ?>" data-default-color="#2F54A4" />
<script>jQuery(document).ready(function($){
$('#wacfw_setting_footer_color').wpColorPicker();
});</script>
</div>
<div class="wacfw-tree-options-box">
<label for="wacfw_setting_footer_text_color">Footer Text Color</label><br>
<input type="text" name="wacfw_setting_footer_text_color" id="wacfw_setting_footer_text_color" value="<?php echo get_option('wacfw_setting_footer_text_color'); ?>" data-default-color="#FFFFF" />
<script>jQuery(document).ready(function($){
$('#wacfw_setting_footer_text_color').wpColorPicker();
});</script>
</div>
</div>
<div class="divider"></div> <!-- Separator -->
<?php
}
if( $active_tab == 'social_options' ) {
// Get the date data if it's already been entered
echo'<h3>Social options</h3>';
echo 'hola';
}
if( $active_tab == 'sharing_options' ) {
echo'<h3>Sharing Settings</h3>';
echo 'hola';
settings_fields( 'sandbox_theme_social_options' );
do_settings_sections( 'sandbox_theme_social_options' );
echo 'social options';
} // end if/else
if( $active_tab == 'emails' ) {
// Get the date data if it's already been entered
echo'<h3>Emails</h3>';
?>
<table class="form-table">
<tbody><tr valign="top">
<td class="wc_emails_wrapper" colspan="2">
<table class="wc_emails widefat" cellspacing="0">
<thead class="wacwfwtableheader">
<tr>
<th class="wc-email-settings-table-status">Status</th><th class="wc-email-settings-table-name">Email</th><th class="wc-email-settings-table-email_type">Content type</th><th class="wc-email-settings-table-recipient">Recipient(s)</th><th class="wc-email-settings-table-actions"></th> </tr>
</thead>
<tbody>
<tr><td class="wc-email-settings-table-status"><span class="status-enabled tips">Enabled</span></td><td class="wc-email-settings-table-name">
<a href="https://testing.dmmediasolutions.co.uk/wp-admin/admin.php?page=wc-settings&tab=email&section=wc_customer_cancel_order">Cancelled Order to Customer</a>
<span class="woocommerce-help-tip"></span>
</td><td class="wc-email-settings-table-email_type">
text/html
</td><td class="wc-email-settings-table-recipient">
Customer
</td><td class="wc-email-settings-table-actions">
<a class="button alignright" href="https://testing.dmmediasolutions.co.uk/wp-admin/admin.php?page=wc-settings&tab=email&section=wc_customer_cancel_order">Manage</a>
</td></tr>
</tbody>
</table>
</td>
</tr>
</tbody></table>
<?php
}
submit_button();
?>
</form>
</div><!-- /.wrap -->
<?php
echo '</div>';
}
Любая помощь приветствуется. Спасибо