Updated settings page - individual page per tab for reduced lag

This commit is contained in:
Mike Jolley 2011-09-15 17:37:38 +01:00
parent 08cd989229
commit 16565712a5
11 changed files with 188 additions and 198 deletions

View File

@ -34,13 +34,8 @@ function install_woocommerce() {
woocommerce_tables_install();
woocommerce_default_taxonomies();
// Clear cron
wp_clear_scheduled_hook('woocommerce_update_sale_prices_schedule_check');
update_option('woocommerce_update_sale_prices', 'no');
// Flush Rules
global $wp_rewrite;
$wp_rewrite->flush_rules();
flush_rewrite_rules( false );
// Update version
update_option( "woocommerce_db_version", WOOCOMMERCE_VERSION );

View File

@ -15,9 +15,7 @@
function woocommerce_update_options($options) {
if(!isset($_POST) || !$_POST) return false;
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'woocommerce-settings') ) die( __('Action failed. Please refresh the page and retry.', 'woothemes') );
foreach ($options as $value) {
if (isset($value['id']) && $value['id']=='woocommerce_tax_rates') :
@ -128,12 +126,8 @@ function woocommerce_update_options($options) {
function woocommerce_admin_fields($options) {
global $woocommerce;
$counter = 1;
foreach ($options as $value) :
switch($value['type']) :
case 'tab':
echo '<div id="'.$value['type'].$counter.'" class="panel">';
break;
case 'title':
if (isset($value['name']) && $value['name']) echo '<h3>'.$value['name'].'</h3>';
if (isset($value['desc']) && $value['desc']) echo wpautop(wptexturize($value['desc']));
@ -205,10 +199,6 @@ function woocommerce_admin_fields($options) {
</td>
</tr><?php
break;
case 'tabend':
echo '</div>';
$counter++;
break;
case 'single_select_page' :
$page_setting = (int) get_option($value['id']);
@ -338,107 +328,6 @@ function woocommerce_admin_fields($options) {
</tr>
<?php
break;
case "shipping_options" :
$links = array();
foreach ($woocommerce->shipping->shipping_methods as $method) :
$title = ($method->method_title) ? ucwords($method->method_title) : ucwords($method->id);
$links[] = '<a href="#shipping-'.$method->id.'">'.$title.'</a>';
endforeach;
echo '<div class="subsubsub_section"><ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';
foreach ($woocommerce->shipping->shipping_methods as $method) :
echo '<div class="section" id="shipping-'.$method->id.'">';
$method->admin_options();
echo '</div>';
endforeach;
echo '</div>';
break;
case "gateway_options" :
$links = array();
foreach ($woocommerce->payment_gateways->payment_gateways() as $gateway) :
$title = ($gateway->method_title) ? ucwords($gateway->method_title) : ucwords($gateway->id);
$links[] = '<a href="#gateway-'.$gateway->id.'">'.$title.'</a>';
endforeach;
echo '<div class="subsubsub_section"><ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';
foreach ($woocommerce->payment_gateways->payment_gateways() as $gateway) :
echo '<div class="section" id="gateway-'.$gateway->id.'">';
$gateway->admin_options();
echo '</div>';
endforeach;
echo '</div>';
break;
default :
do_action('woocommerce_settings_field_type_' . $value['type']);
break;
endswitch;
endforeach;
?>
<script type="text/javascript">
// Tabs
jQuery('.woo-nav-tab-wrapper a:first').addClass('nav-tab-active');
jQuery('div.panel:not(div.panel:first)').hide();
jQuery('.woo-nav-tab-wrapper a').click(function(){
jQuery('.woo-nav-tab-wrapper a').removeClass('nav-tab-active');
jQuery(this).addClass('nav-tab-active');
jQuery('div.panel').hide();
jQuery( jQuery(this).attr('href') ).show();
jQuery.cookie('woocommerce_settings_tab_index', jQuery(this).index('.woo-nav-tab-wrapper a'))
return false;
});
<?php if (isset($_COOKIE['woocommerce_settings_tab_index']) && $_COOKIE['woocommerce_settings_tab_index'] > 0) : ?>
jQuery('.woo-nav-tab-wrapper a:eq(<?php echo $_COOKIE['woocommerce_settings_tab_index']; ?>)').click();
<?php endif; ?>
// Subsubsub tabs
jQuery('ul.subsubsub li a').click(function(){
jQuery('a', jQuery(this).closest('ul.subsubsub')).removeClass('current');
jQuery(this).addClass('current');
jQuery('.section', jQuery(this).closest('.subsubsub_section')).hide();
jQuery( jQuery(this).attr('href') ).show();
return false;
});
jQuery('ul.subsubsub').each(function(){
jQuery('li a:eq(0)', jQuery(this)).click();
});
// Countries
jQuery('select#woocommerce_allowed_countries').change(function(){
if (jQuery(this).val()=="specific") {
jQuery(this).parent().parent().next('tr.multi_select_countries').show();
} else {
jQuery(this).parent().parent().next('tr.multi_select_countries').hide();
}
}).change();
// Country Multiselect boxes
jQuery(".country_multiselect").multiselect({
noneSelectedText: '<?php _e('Select countries/states', 'woothemes'); ?>',
selectedList: 4
});
</script>
<?php
}

View File

@ -11,17 +11,13 @@
*/
/**
* $woocommerce_settings
*
* This variable contains all the options used on the settings page
* Define settings for the WooCommerce settings pages
*/
global $woocommerce_settings;
$woocommerce_settings = apply_filters('woocommerce_settings', array(
$woocommerce_settings['general'] = apply_filters('woocommerce_general_settings', array(
array( 'type' => 'tab', 'tabname' => __('General', 'woothemes') ),
array( 'name' => 'General Options', 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
array( 'name' => 'General Options', 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
array(
'name' => __('Base Country/Region', 'woothemes'),
@ -104,11 +100,12 @@ $woocommerce_settings = apply_filters('woocommerce_settings', array(
),
array( 'type' => 'sectionend', 'id' => 'general_options'),
array( 'type' => 'tabend'),
array( 'type' => 'tab', 'tabname' => __('Pages', 'woothemes') ),
)); // End general settings
$woocommerce_settings['pages'] = apply_filters('woocommerce_page_settings', array(
array( 'name' => 'Page setup', 'type' => 'title', 'desc' => '', 'id' => 'page_options' ),
array(
@ -216,11 +213,12 @@ $woocommerce_settings = apply_filters('woocommerce_settings', array(
),
array( 'type' => 'sectionend', 'id' => 'page_options'),
array( 'type' => 'tabend'),
array( 'type' => 'tab', 'tabname' => __('Catalog', 'woothemes') ),
)); // End pages settings
$woocommerce_settings['catalog'] = apply_filters('woocommerce_catalog_settings', array(
array( 'name' => __('Catalog Options', 'woothemes'), 'type' => 'title','desc' => '', 'id' => 'catalog_options' ),
array(
@ -380,6 +378,11 @@ $woocommerce_settings = apply_filters('woocommerce_settings', array(
array( 'type' => 'sectionend', 'id' => 'pricing_options' ),
)); // End catalog settings
$woocommerce_settings['inventory'] = apply_filters('woocommerce_inventory_settings', array(
array( 'name' => __('Inventory Options', 'woothemes'), 'type' => 'title','desc' => '', 'id' => 'inventory_options' ),
array(
@ -436,12 +439,13 @@ $woocommerce_settings = apply_filters('woocommerce_settings', array(
),
array( 'type' => 'sectionend', 'id' => 'inventory_options'),
array( 'type' => 'tabend'),
array( 'type' => 'tab', 'tabname' => __('Shipping', 'woothemes') ),
array( 'name' => __('Shipping Options', 'woothemes'), 'type' => 'title','desc' => '', 'id' => '' ),
)); // End inventory settings
$woocommerce_settings['shipping'] = apply_filters('woocommerce_shipping_settings', array(
array( 'name' => __('Shipping Options', 'woothemes'), 'type' => 'title','desc' => '', 'id' => 'shipping_options' ),
array(
'name' => __('Calculate shipping', 'woothemes'),
@ -467,20 +471,13 @@ $woocommerce_settings = apply_filters('woocommerce_settings', array(
'type' => 'checkbox'
),
array( 'type' => 'sectionend'),
array( 'type' => 'tabend'),
array( 'type' => 'tab', 'tabname' => __('Shipping Methods', 'woothemes') ),
array( 'type' => 'shipping_options'),
array( 'type' => 'sectionend'),
array( 'type' => 'sectionend', 'id' => 'shipping_options'),
)); // End shipping settings
$woocommerce_settings['tax'] = apply_filters('woocommerce_tax_settings', array(
array( 'type' => 'tabend'),
array( 'type' => 'tab', 'tabname' => __('Tax', 'woothemes') ),
array( 'name' => __('Tax Options', 'woothemes'), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
array(
@ -535,16 +532,7 @@ $woocommerce_settings = apply_filters('woocommerce_settings', array(
array( 'type' => 'sectionend', 'id' => 'tax_options'),
array( 'type' => 'tabend'),
array( 'type' => 'tab', 'tabname' => __('Payment Gateways', 'woothemes') ),
array( 'type' => 'gateway_options'),
array( 'type' => 'tabend')
) );
)); // End tax settings
/**
* Settings page
@ -552,12 +540,28 @@ $woocommerce_settings = apply_filters('woocommerce_settings', array(
* Handles the display of the main woocommerce settings page in admin.
*/
function woocommerce_settings() {
global $woocommerce_settings;
global $woocommerce, $woocommerce_settings;
if (woocommerce_update_options( $woocommerce_settings )) :
do_action('woocommerce_update_options');
flush_rewrite_rules( false );
wp_redirect( add_query_arg('saved', 'true', admin_url('admin.php?page=woocommerce') ));
$current_tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'general';
if(isset($_POST) && $_POST) :
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'woocommerce-settings') ) die( __('Action failed. Please refresh the page and retry.', 'woothemes') );
switch ($current_tab) :
case "general" :
case "pages" :
case "catalog" :
case "inventory" :
case "shipping" :
case "tax" :
woocommerce_update_options($woocommerce_settings[$current_tab]);
break;
endswitch;
do_action( 'woocommerce_update_options' );
do_action( 'woocommerce_update_options_' . $current_tab );
flush_rewrite_rules( false );
wp_redirect( add_query_arg('saved', 'true', admin_url('admin.php?page=woocommerce&tab=' . $current_tab ) ));
endif;
if (isset($_GET['saved']) && $_GET['saved']) :
@ -569,19 +573,135 @@ function woocommerce_settings() {
<form method="post" id="mainform" action="">
<div class="icon32 icon32-woocommerce-settings" id="icon-woocommerce"><br></div><h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
<?php
$counter = 1;
foreach ($woocommerce_settings as $value) {
if ( 'tab' == $value['type'] ) :
echo '<a href="#'.$value['type'].$counter.'" class="nav-tab">'.$value['tabname'].'</a>';
$counter++;
endif;
}
$tabs = array(
'general' => __('General', 'woothemes'),
'pages' => __('Pages', 'woothemes'),
'catalog' => __('Catalog', 'woothemes'),
'inventory' => __('Inventory', 'woothemes'),
'shipping' => __('Shipping', 'woothemes'),
'tax' => __('Tax', 'woothemes'),
'shipping_methods' => __('Shipping Methods', 'woothemes'),
'payment_gateways' => __('Payment Gateways', 'woothemes')
);
foreach ($tabs as $name => $label) :
echo '<a href="'.admin_url('admin.php?page=woocommerce&tab='.$name).'" class="nav-tab ';
if($current_tab==$name) echo 'nav-tab-active';
echo '">'.$label.'</a>';
endforeach;
?>
<?php do_action('woocommerce_settings_tabs'); ?>
</h2>
<?php wp_nonce_field('woocommerce-settings', '_wpnonce', true, true); ?>
<?php woocommerce_admin_fields($woocommerce_settings); ?>
<?php
switch ($current_tab) :
case "general" :
case "pages" :
case "catalog" :
case "inventory" :
case "shipping" :
case "tax" :
woocommerce_admin_fields($woocommerce_settings[$current_tab]);
break;
case "shipping_methods" :
$links = array();
foreach ($woocommerce->shipping->shipping_methods as $method) :
$title = ($method->method_title) ? ucwords($method->method_title) : ucwords($method->id);
$links[] = '<a href="#shipping-'.$method->id.'">'.$title.'</a>';
endforeach;
echo '<div class="subsubsub_section"><ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';
foreach ($woocommerce->shipping->shipping_methods as $method) :
echo '<div class="section" id="shipping-'.$method->id.'">';
$method->admin_options();
echo '</div>';
endforeach;
echo '</div>';
break;
case "payment_gateways" :
$links = array();
foreach ($woocommerce->payment_gateways->payment_gateways() as $gateway) :
$title = ($gateway->method_title) ? ucwords($gateway->method_title) : ucwords($gateway->id);
$links[] = '<a href="#gateway-'.$gateway->id.'">'.$title.'</a>';
endforeach;
echo '<div class="subsubsub_section"><ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';
foreach ($woocommerce->payment_gateways->payment_gateways() as $gateway) :
echo '<div class="section" id="gateway-'.$gateway->id.'">';
$gateway->admin_options();
echo '</div>';
endforeach;
echo '</div>';
break;
default :
do_action( 'woocommerce_settings_tabs_' . $current_tab );
break;
endswitch;
?>
<p class="submit"><input name="save" class="button-primary" type="submit" value="<?php _e('Save changes', 'woothemes') ?>" /></p>
</form>
<script type="text/javascript">
// Subsubsub tabs
jQuery('ul.subsubsub li a:eq(0)').addClass('current');
jQuery('.subsubsub_section .section:gt(0)').hide();
jQuery('ul.subsubsub li a').click(function(){
jQuery('a', jQuery(this).closest('ul.subsubsub')).removeClass('current');
jQuery(this).addClass('current');
jQuery('.section', jQuery(this).closest('.subsubsub_section')).hide();
jQuery( jQuery(this).attr('href') ).show();
return false;
});
// Countries
jQuery('select#woocommerce_allowed_countries').change(function(){
if (jQuery(this).val()=="specific") {
jQuery(this).parent().parent().next('tr.multi_select_countries').show();
} else {
jQuery(this).parent().parent().next('tr.multi_select_countries').hide();
}
}).change();
// Country Multiselect boxes
jQuery(".country_multiselect").multiselect({
noneSelectedText: '<?php _e('Select countries/states', 'woothemes'); ?>',
selectedList: 4
});
// Edit prompt
jQuery(function(){
var changed = false;
jQuery('input, textarea, select, checkbox').change(function(){
changed = true;
});
jQuery('.woo-nav-tab-wrapper a').click(function(){
if (changed) {
window.onbeforeunload = function() {
return '<?php echo __('The changes you made will be lost if you navigate away from this page.', 'woothemes'); ?>';
}
} else {
window.onbeforeunload = '';
}
});
jQuery('.submit input').click(function(){
window.onbeforeunload = '';
});
});
</script>
</div>
<?php
}

View File

@ -113,20 +113,6 @@ return true;return $(e.target).parents().children().filter('div.blockUI').length
return;var e=pageBlockEls[back===true?pageBlockEls.length-1:0];if(e)
e.focus();};function center(el,x,y){var p=el.parentNode,s=el.style;var l=((p.offsetWidth-el.offsetWidth)/2)-sz(p,'borderLeftWidth');var t=((p.offsetHeight-el.offsetHeight)/2)-sz(p,'borderTopWidth');if(x)s.left=l>0?(l+'px'):'0';if(y)s.top=t>0?(t+'px'):'0';};function sz(el,p){return parseInt($.css(el,p))||0;};})(jQuery);
/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie=function(key,value,options){if(arguments.length>1&&String(value)!=="[object Object]"){options=jQuery.extend({},options);if(value===null||value===undefined){options.expires=-1;}
if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days);}
value=String(value);return(document.cookie=[encodeURIComponent(key),'=',options.raw?value:encodeURIComponent(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''));}
options=value||{};var result,decode=options.raw?function(s){return s;}:decodeURIComponent;return(result=new RegExp('(?:^|; )'+encodeURIComponent(key)+'=([^;]*)').exec(document.cookie))?decode(result[1]):null;};
/*
* Date prototype extensions. Doesn't depend on any
* other code. Doens't overwrite existing methods.

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,7 @@ class woocommerce_bacs extends woocommerce_payment_gateway {
$this->iban = get_option('woocommerce_bacs_iban');
$this->bic = get_option('woocommerce_bacs_bic');
add_action('woocommerce_update_options', array(&$this, 'process_admin_options'));
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
add_option('woocommerce_bacs_enabled', 'no');
add_option('woocommerce_bacs_title', __('Direct Bank Transer', 'woothemes'));
add_option('woocommerce_bacs_description', __('Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order wont be shipped until the funds have cleared in our account.', 'woothemes'));

View File

@ -20,7 +20,7 @@ class woocommerce_cheque extends woocommerce_payment_gateway {
$this->title = get_option('woocommerce_cheque_title');
$this->description = get_option('woocommerce_cheque_description');
add_action('woocommerce_update_options', array(&$this, 'process_admin_options'));
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
add_option('woocommerce_cheque_enabled', 'yes');
add_option('woocommerce_cheque_title', __('Cheque Payment', 'woothemes') );
add_option('woocommerce_cheque_description', __('Please send your cheque to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'woothemes'));

View File

@ -30,7 +30,7 @@ class woocommerce_moneybookers extends woocommerce_payment_gateway {
add_action('valid-moneybookers-status-report', array(&$this, 'successful_request') );
add_action('woocommerce_update_options', array(&$this, 'process_admin_options'));
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
add_option('woocommerce_moneybookers_enabled', 'yes');
add_option('woocommerce_moneybookers_email', '');
add_option('woocommerce_moneybookers_title', 'moneybookers');

View File

@ -31,7 +31,7 @@ class woocommerce_paypal extends woocommerce_payment_gateway {
add_action( 'init', array(&$this, 'check_ipn_response') );
add_action('valid-paypal-standard-ipn-request', array(&$this, 'successful_request') );
add_action('woocommerce_update_options', array(&$this, 'process_admin_options'));
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
add_option('woocommerce_paypal_enabled', 'yes');
add_option('woocommerce_paypal_email', '');
add_option('woocommerce_paypal_title', __('PayPal', 'woothemes') );

View File

@ -23,7 +23,7 @@ class flat_rate extends woocommerce_shipping_method {
$this->cost = get_option('woocommerce_flat_rate_cost');
$this->fee = get_option('woocommerce_flat_rate_handling_fee');
add_action('woocommerce_update_options', array(&$this, 'process_admin_options'));
add_action('woocommerce_update_options_shipping_methods', array(&$this, 'process_admin_options'));
add_option('woocommerce_flat_rate_availability', 'all');
add_option('woocommerce_flat_rate_title', 'Flat Rate');
add_option('woocommerce_flat_rate_tax_status', 'taxable');

View File

@ -20,7 +20,7 @@ class free_shipping extends woocommerce_shipping_method {
$this->availability = get_option('woocommerce_free_shipping_availability');
$this->countries = get_option('woocommerce_free_shipping_countries');
add_action('woocommerce_update_options', array(&$this, 'process_admin_options'));
add_action('woocommerce_update_options_shipping_methods', array(&$this, 'process_admin_options'));
add_option('woocommerce_free_shipping_availability', 'all');
add_option('woocommerce_free_shipping_title', 'Free Shipping');
}