Initialize settings classes
This commit is contained in:
162
includes/admin/settings/class-sp-settings-accounts.php
Normal file
162
includes/admin/settings/class-sp-settings-accounts.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Account Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Accounts' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Accounts
|
||||
*/
|
||||
class SP_Settings_Accounts extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'account';
|
||||
$this->label = __( 'Accounts', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
|
||||
return apply_filters( 'sportspress_' . $this->id . '_settings', array(
|
||||
|
||||
array( 'title' => __( 'Account Pages', 'sportspress' ), 'type' => 'title', 'desc' => __( 'These pages need to be set so that SportsPress knows where to send users to access account related functionality.', 'sportspress' ), 'id' => 'account_page_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'My Account Page', 'sportspress' ),
|
||||
'desc' => __( 'Page contents:', 'sportspress' ) . ' [' . apply_filters( 'sportspress_my_account_shortcode_tag', 'sportspress_my_account' ) . ']',
|
||||
'id' => 'sportspress_myaccount_page_id',
|
||||
'type' => 'single_select_page',
|
||||
'default' => '',
|
||||
'class' => 'chosen_select_nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'account_page_options' ),
|
||||
|
||||
array( 'title' => __( 'My Account Endpoints', 'sportspress' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions on the accounts pages. They should be unique.', 'sportspress' ), 'id' => 'account_endpoint_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'View Order', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the My Account → View Order page', 'sportspress' ),
|
||||
'id' => 'sportspress_myaccount_view_order_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'view-order',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Edit Account', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the My Account → Edit Account page', 'sportspress' ),
|
||||
'id' => 'sportspress_myaccount_edit_account_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'edit-account',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Edit Address', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the My Account → Edit Address page', 'sportspress' ),
|
||||
'id' => 'sportspress_myaccount_edit_address_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'edit-address',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Lost Password', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the My Account → Lost Password page', 'sportspress' ),
|
||||
'id' => 'sportspress_myaccount_lost_password_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'lost-password',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Logout', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the triggering logout. You can add this to your menus via a custom link: yoursite.com/?customer-logout=true', 'sportspress' ),
|
||||
'id' => 'sportspress_logout_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'customer-logout',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'account_endpoint_options' ),
|
||||
|
||||
array( 'title' => __( 'Registration Options', 'sportspress' ), 'type' => 'title', 'id' => 'account_registration_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Enable Registration', 'sportspress' ),
|
||||
'desc' => __( 'Enable registration on the "Checkout" page', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_signup_and_login_from_checkout',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Enable registration on the "My Account" page', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_myaccount_registration',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Display returning customer login reminder on the "Checkout" page', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_checkout_login_reminder',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Account Creation', 'sportspress' ),
|
||||
'desc' => __( 'Automatically generate username from customer email', 'sportspress' ),
|
||||
'id' => 'sportspress_registration_generate_username',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Automatically generate customer password', 'sportspress' ),
|
||||
'id' => 'sportspress_registration_generate_password',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'account_registration_options'),
|
||||
|
||||
)); // End pages settings
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Accounts();
|
||||
322
includes/admin/settings/class-sp-settings-checkout.php
Normal file
322
includes/admin/settings/class-sp-settings-checkout.php
Normal file
@@ -0,0 +1,322 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Shipping Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Payment_Gateways' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Payment_Gateways
|
||||
*/
|
||||
class SP_Settings_Payment_Gateways extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'checkout';
|
||||
$this->label = _x( 'Checkout', 'Settings tab label', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_admin_field_payment_gateways', array( $this, 'payment_gateways_setting' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
'' => __( 'Checkout Options', 'sportspress' )
|
||||
);
|
||||
|
||||
// Load shipping methods so we can show any global options they may have
|
||||
$payment_gateways = SP()->payment_gateways->payment_gateways();
|
||||
|
||||
foreach ( $payment_gateways as $gateway ) {
|
||||
|
||||
$title = empty( $gateway->method_title ) ? ucfirst( $gateway->id ) : $gateway->method_title;
|
||||
|
||||
$sections[ strtolower( get_class( $gateway ) ) ] = esc_html( $title );
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
return apply_filters( 'sportspress_payment_gateways_settings', array(
|
||||
|
||||
array( 'title' => __( 'Checkout Process', 'sportspress' ), 'type' => 'title', 'id' => 'checkout_process_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Coupons', 'sportspress' ),
|
||||
'desc' => __( 'Enable the use of coupons', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_coupons',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'sportspress' ),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => _x( 'Checkout', 'Settings group label', 'sportspress' ),
|
||||
'desc' => __( 'Enable guest checkout', 'sportspress' ),
|
||||
'desc_tip' => __( 'Allows customers to checkout without creating an account.', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_guest_checkout',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Force secure checkout', 'sportspress' ),
|
||||
'id' => 'sportspress_force_ssl_checkout',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
'show_if_checked' => 'option',
|
||||
'desc_tip' => __( 'Force SSL (HTTPS) on the checkout pages (an SSL Certificate is required).', 'sportspress' ),
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Un-force HTTPS when leaving the checkout', 'sportspress' ),
|
||||
'id' => 'sportspress_unforce_ssl_checkout',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'checkout_process_options'),
|
||||
|
||||
array( 'title' => __( 'Checkout Pages', 'sportspress' ), 'desc' => __( 'These pages need to be set so that SportsPress knows where to send users to checkout.', 'sportspress' ), 'type' => 'title', 'id' => 'checkout_page_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Cart Page', 'sportspress' ),
|
||||
'desc' => __( 'Page contents:', 'sportspress' ) . ' [' . apply_filters( 'sportspress_cart_shortcode_tag', 'sportspress_cart' ) . ']',
|
||||
'id' => 'sportspress_cart_page_id',
|
||||
'type' => 'single_select_page',
|
||||
'default' => '',
|
||||
'class' => 'chosen_select_nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Checkout Page', 'sportspress' ),
|
||||
'desc' => __( 'Page contents:', 'sportspress' ) . ' [' . apply_filters( 'sportspress_checkout_shortcode_tag', 'sportspress_checkout' ) . ']',
|
||||
'id' => 'sportspress_checkout_page_id',
|
||||
'type' => 'single_select_page',
|
||||
'default' => '',
|
||||
'class' => 'chosen_select_nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Terms and Conditions', 'sportspress' ),
|
||||
'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'sportspress' ),
|
||||
'id' => 'sportspress_terms_page_id',
|
||||
'default' => '',
|
||||
'class' => 'chosen_select_nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'type' => 'single_select_page',
|
||||
'desc_tip' => true,
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'checkout_page_options' ),
|
||||
|
||||
array( 'title' => __( 'Checkout Endpoints', 'sportspress' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'sportspress' ), 'id' => 'account_endpoint_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Pay', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the Checkout → Pay page', 'sportspress' ),
|
||||
'id' => 'sportspress_checkout_pay_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'order-pay',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Order Received', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the Checkout → Pay page', 'sportspress' ),
|
||||
'id' => 'sportspress_checkout_order_received_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'order-received',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Add Payment Method', 'sportspress' ),
|
||||
'desc' => __( 'Endpoint for the Checkout → Add Payment Method page', 'sportspress' ),
|
||||
'id' => 'sportspress_myaccount_add_payment_method_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'add-payment-method',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'checkout_endpoint_options' ),
|
||||
|
||||
array( 'title' => __( 'Payment Gateways', 'sportspress' ), 'desc' => __( 'Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.', 'sportspress' ), 'type' => 'title', 'id' => 'payment_gateways_options' ),
|
||||
|
||||
array( 'type' => 'payment_gateways' ),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'payment_gateways_options' ),
|
||||
|
||||
)); // End payment_gateway settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
// Load shipping methods so we can show any global options they may have
|
||||
$payment_gateways = SP()->payment_gateways->payment_gateways();
|
||||
|
||||
if ( $current_section ) {
|
||||
foreach ( $payment_gateways as $gateway ) {
|
||||
if ( strtolower( get_class( $gateway ) ) == strtolower( $current_section ) ) {
|
||||
$gateway->admin_options();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output payment gateway settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function payment_gateways_setting() {
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Gateway Display', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="sp_gateways widefat" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php
|
||||
$columns = apply_filters( 'sportspress_payment_gateways_setting_columns', array(
|
||||
'default' => __( 'Default', 'sportspress' ),
|
||||
'name' => __( 'Gateway', 'sportspress' ),
|
||||
'id' => __( 'Gateway ID', 'sportspress' ),
|
||||
'status' => __( 'Status', 'sportspress' ),
|
||||
'settings' => ''
|
||||
) );
|
||||
|
||||
foreach ( $columns as $key => $column ) {
|
||||
echo '<th class="' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$default_gateway = get_option( 'sportspress_default_gateway' );
|
||||
|
||||
foreach ( SP()->payment_gateways->payment_gateways() as $gateway ) {
|
||||
|
||||
echo '<tr>';
|
||||
|
||||
foreach ( $columns as $key => $column ) {
|
||||
switch ( $key ) {
|
||||
case 'default' :
|
||||
echo '<td width="1%" class="default">
|
||||
<input type="radio" name="default_gateway" value="' . esc_attr( $gateway->id ) . '" ' . checked( $default_gateway, esc_attr( $gateway->id ), false ) . ' />
|
||||
<input type="hidden" name="gateway_order[]" value="' . esc_attr( $gateway->id ) . '" />
|
||||
</td>';
|
||||
break;
|
||||
case 'name' :
|
||||
echo '<td class="name">
|
||||
' . $gateway->get_title() . '
|
||||
</td>';
|
||||
break;
|
||||
case 'id' :
|
||||
echo '<td class="id">
|
||||
' . esc_html( $gateway->id ) . '
|
||||
</td>';
|
||||
break;
|
||||
case 'status' :
|
||||
echo '<td class="status">';
|
||||
|
||||
if ( $gateway->enabled == 'yes' )
|
||||
echo '<span class="status-enabled tips" data-tip="' . __ ( 'Enabled', 'sportspress' ) . '">' . __ ( 'Enabled', 'sportspress' ) . '</span>';
|
||||
else
|
||||
echo '-';
|
||||
|
||||
echo '</td>';
|
||||
break;
|
||||
case 'settings' :
|
||||
echo '<td class="settings">
|
||||
<a class="button" href="' . admin_url( 'admin.php?page=sp-settings&tab=checkout§ion=' . strtolower( get_class( $gateway ) ) ) . '">' . __( 'Settings', 'sportspress' ) . '</a>
|
||||
</td>';
|
||||
break;
|
||||
default :
|
||||
do_action( 'sportspress_payment_gateways_setting_column_' . $key, $gateway );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
SP()->payment_gateways->process_admin_options();
|
||||
|
||||
} elseif ( class_exists( $current_section ) ) {
|
||||
|
||||
$current_section_class = new $current_section();
|
||||
|
||||
do_action( 'sportspress_update_options_payment_gateways_' . $current_section_class->id );
|
||||
|
||||
SP()->payment_gateways()->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Payment_Gateways();
|
||||
378
includes/admin/settings/class-sp-settings-config.php
Normal file
378
includes/admin/settings/class-sp-settings-config.php
Normal file
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Configure Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Config' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Configure
|
||||
*/
|
||||
class SP_Settings_Config extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'config';
|
||||
$this->label = __( 'Configure', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_admin_field_results', array( $this, 'results_setting' ) );
|
||||
add_action( 'sportspress_admin_field_outcomes', array( $this, 'outcomes_setting' ) );
|
||||
add_action( 'sportspress_admin_field_columns', array( $this, 'columns_setting' ) );
|
||||
add_action( 'sportspress_admin_field_metrics', array( $this, 'metrics_setting' ) );
|
||||
add_action( 'sportspress_admin_field_performance', array( $this, 'performance_setting' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
return apply_filters('sportspress_event_settings', array(
|
||||
|
||||
array( 'title' => __( 'Configure SportsPress', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'config_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Sport', 'sportspress' ),
|
||||
'id' => 'sportspress_sport',
|
||||
'default' => 'soccer',
|
||||
'type' => 'select',
|
||||
'options' => SP()->sports->options,
|
||||
),
|
||||
|
||||
array( 'type' => 'results' ),
|
||||
|
||||
array( 'type' => 'outcomes' ),
|
||||
|
||||
array( 'type' => 'columns' ),
|
||||
|
||||
array( 'type' => 'metrics' ),
|
||||
|
||||
array( 'type' => 'performance' ),
|
||||
|
||||
array( 'type' => 'statistics' ),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'config_options' ),
|
||||
|
||||
)); // End event settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
|
||||
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section, $wpdb;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
|
||||
} else {
|
||||
|
||||
$this->save_tax_rates();
|
||||
|
||||
}
|
||||
|
||||
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output results settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function results_setting() {
|
||||
$main_result = get_option( 'sportspress_main_result', 0 );
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_result',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Results', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th scope="col" class="edit"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="main_result" value="0" <?php checked( $main_result, 0 ); ?>></th>
|
||||
<th colspan="3"><label for="main_result_0">
|
||||
<?php
|
||||
if ( sizeof( $data ) > 0 ):
|
||||
$default = end( $data );
|
||||
reset( $data );
|
||||
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
|
||||
else:
|
||||
_e( 'Default', 'sportspress' );
|
||||
endif;
|
||||
?>
|
||||
</label></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="radio"><input type="radio" id="main_result_<?php echo $row->post_name; ?>" name="main_result" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
|
||||
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
|
||||
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output outcomes settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function outcomes_setting() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Outcomes', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th scope="col" class="edit"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo $row->post_name; ?></td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_outcome' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_outcome' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output columns settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function columns_setting() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_column',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Columns', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Equation', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Rounding', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Sort Order', 'sportspress' ); ?></th>
|
||||
<th scope="col" class="edit"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo $row->post_name; ?></td>
|
||||
<td><?php echo sportspress_get_post_equation( $row->ID, $row->post_name ); ?></td>
|
||||
<td><?php echo sportspress_get_post_precision( $row->ID ); ?></td>
|
||||
<td><?php echo sportspress_get_post_order( $row->ID ); ?></td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_column' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_column' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output metrics settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function metrics_setting() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_metric',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Metrics', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Positions', 'sportspress' ); ?></th>
|
||||
<th scope="col"> </th>
|
||||
<th scope="col" class="edit"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo get_the_terms ( $row->ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : '—'; ?></td>
|
||||
<td> </td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_metric' ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_metric' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output performance settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function performance_setting() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_performance',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Performance', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Positions', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Calculate', 'sportspress' ); ?></th>
|
||||
<th scope="col" class="edit"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo get_the_terms ( $row->ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : '—'; ?></td>
|
||||
<td><?php echo sportspress_get_post_calculate( $row->ID ); ?></td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_performance' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_performance' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Config();
|
||||
213
includes/admin/settings/class-sp-settings-emails.php
Normal file
213
includes/admin/settings/class-sp-settings-emails.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Email Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Emails' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Emails
|
||||
*/
|
||||
class SP_Settings_Emails extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'email';
|
||||
$this->label = __( 'Emails', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
'' => __( 'Email Options', 'sportspress' )
|
||||
);
|
||||
|
||||
// Define emails that can be customised here
|
||||
$mailer = SP()->mailer();
|
||||
$email_templates = $mailer->get_emails();
|
||||
|
||||
foreach ( $email_templates as $email ) {
|
||||
$title = empty( $email->title ) ? ucfirst( $email->id ) : ucfirst( $email->title );
|
||||
|
||||
$sections[ strtolower( get_class( $email ) ) ] = esc_html( $title );
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
return apply_filters('sportspress_email_settings', array(
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'email_recipient_options' ),
|
||||
|
||||
array( 'title' => __( 'Email Sender Options', 'sportspress' ), 'type' => 'title', 'desc' => __( 'The following options affect the sender (email address and name) used in SportsPress emails.', 'sportspress' ), 'id' => 'email_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( '"From" Name', 'sportspress' ),
|
||||
'desc' => '',
|
||||
'id' => 'sportspress_email_from_name',
|
||||
'type' => 'text',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => esc_attr(get_bloginfo('title')),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( '"From" Email Address', 'sportspress' ),
|
||||
'desc' => '',
|
||||
'id' => 'sportspress_email_from_address',
|
||||
'type' => 'email',
|
||||
'custom_attributes' => array(
|
||||
'multiple' => 'multiple'
|
||||
),
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => get_option('admin_email'),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'email_options' ),
|
||||
|
||||
array( 'title' => __( 'Email Template', 'sportspress' ), 'type' => 'title', 'desc' => sprintf(__( 'This section lets you customise the SportsPress emails. <a href="%s" target="_blank">Click here to preview your email template</a>. For more advanced control copy <code>sportspress/templates/emails/</code> to <code>yourtheme/sportspress/emails/</code>.', 'sportspress' ), wp_nonce_url(admin_url('?preview_sportspress_mail=true'), 'preview-mail')), 'id' => 'email_template_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Header Image', 'sportspress' ),
|
||||
'desc' => sprintf(__( 'Enter a URL to an image you want to show in the email\'s header. Upload your image using the <a href="%s">media uploader</a>.', 'sportspress' ), admin_url('media-new.php')),
|
||||
'id' => 'sportspress_email_header_image',
|
||||
'type' => 'text',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => '',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Email Footer Text', 'sportspress' ),
|
||||
'desc' => __( 'The text to appear in the footer of SportsPress emails.', 'sportspress' ),
|
||||
'id' => 'sportspress_email_footer_text',
|
||||
'css' => 'width:100%; height: 75px;',
|
||||
'type' => 'textarea',
|
||||
'default' => get_bloginfo('title') . ' - ' . __( 'Powered by SportsPress', 'sportspress' ),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Base Colour', 'sportspress' ),
|
||||
'desc' => __( 'The base colour for SportsPress email templates. Default <code>#557da1</code>.', 'sportspress' ),
|
||||
'id' => 'sportspress_email_base_color',
|
||||
'type' => 'color',
|
||||
'css' => 'width:6em;',
|
||||
'default' => '#557da1',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Background Colour', 'sportspress' ),
|
||||
'desc' => __( 'The background colour for SportsPress email templates. Default <code>#f5f5f5</code>.', 'sportspress' ),
|
||||
'id' => 'sportspress_email_background_color',
|
||||
'type' => 'color',
|
||||
'css' => 'width:6em;',
|
||||
'default' => '#f5f5f5',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Email Body Background Colour', 'sportspress' ),
|
||||
'desc' => __( 'The main body background colour. Default <code>#fdfdfd</code>.', 'sportspress' ),
|
||||
'id' => 'sportspress_email_body_background_color',
|
||||
'type' => 'color',
|
||||
'css' => 'width:6em;',
|
||||
'default' => '#fdfdfd',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Email Body Text Colour', 'sportspress' ),
|
||||
'desc' => __( 'The main body text colour. Default <code>#505050</code>.', 'sportspress' ),
|
||||
'id' => 'sportspress_email_text_color',
|
||||
'type' => 'color',
|
||||
'css' => 'width:6em;',
|
||||
'default' => '#505050',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'email_template_options' ),
|
||||
|
||||
)); // End email settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
// Define emails that can be customised here
|
||||
$mailer = SP()->mailer();
|
||||
$email_templates = $mailer->get_emails();
|
||||
|
||||
if ( $current_section ) {
|
||||
foreach ( $email_templates as $email ) {
|
||||
if ( strtolower( get_class( $email ) ) == $current_section ) {
|
||||
$email->admin_options();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
|
||||
} else {
|
||||
|
||||
// Load mailer
|
||||
$mailer = SP()->mailer();
|
||||
|
||||
if ( class_exists( $current_section ) ) {
|
||||
$current_section_class = new $current_section();
|
||||
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section_class->id );
|
||||
SP()->mailer()->init();
|
||||
} else {
|
||||
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Emails();
|
||||
708
includes/admin/settings/class-sp-settings-events.php
Normal file
708
includes/admin/settings/class-sp-settings-events.php
Normal file
@@ -0,0 +1,708 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Event Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Events' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Events
|
||||
*/
|
||||
class SP_Settings_Events extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'events';
|
||||
$this->label = __( 'Events', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
if ( $tax_classes )
|
||||
foreach ( $tax_classes as $class )
|
||||
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
|
||||
return apply_filters('sportspress_event_settings', array(
|
||||
|
||||
array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Delimiter', 'sportspress' ),
|
||||
'id' => 'sportspress_event_teams_delimiter',
|
||||
'default' => 'vs',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'vs' => sprintf( '%s vs %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'v' => sprintf( '%s v %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'—' => sprintf( '%s — %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'/' => sprintf( '%s / %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_based_on',
|
||||
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
|
||||
'default' => 'shipping',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'shipping' => __( 'Customer shipping address', 'sportspress' ),
|
||||
'billing' => __( 'Customer billing address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Default Customer Address:', 'sportspress' ),
|
||||
'id' => 'sportspress_default_customer_address',
|
||||
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
|
||||
'default' => 'base',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'No address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' ),
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
|
||||
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
|
||||
'id' => 'sportspress_shipping_tax_class',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => 'title',
|
||||
'type' => 'select',
|
||||
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Rounding', 'sportspress' ),
|
||||
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_round_at_subtotal',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Additional Tax Classes', 'sportspress' ),
|
||||
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_classes',
|
||||
'css' => 'width:100%; height: 65px;',
|
||||
'type' => 'textarea',
|
||||
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices in the shop:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_shop',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Price display suffix:', 'sportspress' ),
|
||||
'id' => 'sportspress_price_display_suffix',
|
||||
'default' => '',
|
||||
'type' => 'text',
|
||||
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_cart',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display tax totals:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_total_display',
|
||||
'default' => 'itemized',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'single' => __( 'As a single total', 'sportspress' ),
|
||||
'itemized' => __( 'Itemized', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'results' ),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'event_options' ),
|
||||
|
||||
)); // End event settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
|
||||
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section, $wpdb;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
|
||||
} else {
|
||||
|
||||
$this->save_tax_rates();
|
||||
|
||||
}
|
||||
|
||||
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output tax rate tables
|
||||
*/
|
||||
public function output_tax_rates() {
|
||||
global $sportspress, $current_section, $wpdb;
|
||||
|
||||
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
|
||||
$limit = 100;
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
?>
|
||||
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
|
||||
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
|
||||
<table class="sp_tax_rates sp_input_table sortable widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="sort"> </th>
|
||||
|
||||
<th width="8%"><?php _e( 'Country Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'State Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'City', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Rate %', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Tax Name', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="10">
|
||||
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
|
||||
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
|
||||
|
||||
<div class="pagination">
|
||||
<?php
|
||||
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
|
||||
'base' => add_query_arg( 'p', '%#%' ),
|
||||
'type' => 'plain',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
|
||||
'current' => $page
|
||||
) ) );
|
||||
?>
|
||||
</div>
|
||||
|
||||
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody id="rates">
|
||||
<?php
|
||||
$rates = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
|
||||
WHERE tax_rate_class = %s
|
||||
ORDER BY tax_rate_order
|
||||
LIMIT %d, %d
|
||||
" ,
|
||||
sanitize_title( $current_class ),
|
||||
( $page - 1 ) * $limit,
|
||||
$limit
|
||||
) );
|
||||
|
||||
foreach ( $rates as $rate ) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
|
||||
|
||||
<td class="country" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="state" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="postcode">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="city">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="rate" width="8%">
|
||||
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="name" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="priority" width="8%">
|
||||
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="compound" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
|
||||
</td>
|
||||
|
||||
<td class="apply_to_shipping" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
jQuery( function() {
|
||||
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$current = $tbody.find('tr.current');
|
||||
$current.find('input').val('');
|
||||
$current.find('input.remove_tax_rate').val('1');
|
||||
|
||||
$current.each(function(){
|
||||
if ( jQuery(this).is('.new') )
|
||||
jQuery(this).remove();
|
||||
else
|
||||
jQuery(this).hide();
|
||||
});
|
||||
} else {
|
||||
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .export').click(function() {
|
||||
|
||||
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
|
||||
|
||||
jQuery('#rates tr:visible').each(function() {
|
||||
var row = '';
|
||||
jQuery(this).find('td:not(.sort) input').each(function() {
|
||||
|
||||
if ( jQuery(this).is('.checkbox') ) {
|
||||
|
||||
if ( jQuery(this).is(':checked') ) {
|
||||
val = 1;
|
||||
} else {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var val = jQuery(this).val();
|
||||
|
||||
if ( ! val )
|
||||
val = jQuery(this).attr('placeholder');
|
||||
}
|
||||
|
||||
row = row + val + ',';
|
||||
});
|
||||
row = row + '<?php echo $current_class; ?>';
|
||||
//row.substring( 0, row.length - 1 );
|
||||
csv_data = csv_data + row + "\n";
|
||||
});
|
||||
|
||||
jQuery(this).attr( 'href', encodeURI( csv_data ) );
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .insert').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
var size = $tbody.find('tr').size();
|
||||
var code = '<tr class="new">\
|
||||
<td class="sort"> </td>\
|
||||
<td class="country" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="state" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="postcode">\
|
||||
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="city">\
|
||||
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="rate" width="8%">\
|
||||
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="name" width="8%">\
|
||||
<input type="text" name="tax_rate_name[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="priority" width="8%">\
|
||||
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="compound" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="apply_to_shipping" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
|
||||
</td>\
|
||||
</tr>';
|
||||
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$tbody.find('tr.current').after( code );
|
||||
} else {
|
||||
$tbody.append( code );
|
||||
}
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
|
||||
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
|
||||
});
|
||||
|
||||
var availableCountries = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
|
||||
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
var availableStates = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
|
||||
foreach ( $label as $code => $state )
|
||||
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save tax rates
|
||||
*/
|
||||
public function save_tax_rates() {
|
||||
global $wpdb, $current_section;
|
||||
|
||||
// Get class
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
|
||||
// Get POST data
|
||||
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
|
||||
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
|
||||
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
|
||||
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
|
||||
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
|
||||
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
|
||||
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
|
||||
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
|
||||
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
|
||||
|
||||
$i = 0;
|
||||
|
||||
// Loop posted fields
|
||||
foreach ( $tax_rate_country as $key => $value ) {
|
||||
|
||||
// new keys are inserted...
|
||||
if ( $key == 'new' ) {
|
||||
|
||||
foreach ( $value as $new_key => $new_value ) {
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
|
||||
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
)
|
||||
);
|
||||
|
||||
$tax_rate_id = $wpdb->insert_id;
|
||||
|
||||
if ( ! empty( $postcode ) ) {
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $city ) ) {
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// ...whereas the others are updated
|
||||
} else {
|
||||
|
||||
$tax_rate_id = absint( $key );
|
||||
|
||||
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
|
||||
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
),
|
||||
array(
|
||||
'tax_rate_id' => $tax_rate_id
|
||||
)
|
||||
);
|
||||
|
||||
if ( isset( $tax_rate_postcode[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $tax_rate_city[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ] );
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
if ( $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Events();
|
||||
69
includes/admin/settings/class-sp-settings-general.php
Normal file
69
includes/admin/settings/class-sp-settings-general.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress General Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_General' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Admin_Settings_General
|
||||
*/
|
||||
class SP_Settings_General extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'general';
|
||||
$this->label = __( 'General', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
return apply_filters( 'sportspress_general_settings', array(
|
||||
|
||||
array( 'title' => __( 'General Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Tables', 'sportspress' ),
|
||||
'desc' => __( 'Responsive', 'sportspress' ),
|
||||
'id' => 'sportspress_tables_responsive',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Sortable', 'sportspress' ),
|
||||
'id' => 'sportspress_tables_sortable',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'general_options' ),
|
||||
|
||||
)); // End general settings
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_General();
|
||||
74
includes/admin/settings/class-sp-settings-integrations.php
Normal file
74
includes/admin/settings/class-sp-settings-integrations.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Integration Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Integrations' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Integrations
|
||||
*/
|
||||
class SP_Settings_Integrations extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'integration';
|
||||
$this->label = __( 'Integration', 'sportspress' );
|
||||
|
||||
if ( isset( SP()->integrations ) && SP()->integrations->get_integrations() ) {
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
global $current_section;
|
||||
|
||||
$sections = array();
|
||||
|
||||
$integrations = SP()->integrations->get_integrations();
|
||||
|
||||
if ( ! $current_section )
|
||||
$current_section = current( $integrations )->id;
|
||||
|
||||
foreach ( $integrations as $integration ) {
|
||||
$title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title;
|
||||
|
||||
$sections[ strtolower( $integration->id ) ] = esc_html( $title );
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$integrations = SP()->integrations->get_integrations();
|
||||
|
||||
if ( isset( $integrations[ $current_section ] ) )
|
||||
$integrations[ $current_section ]->admin_options();
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Integrations();
|
||||
94
includes/admin/settings/class-sp-settings-page.php
Normal file
94
includes/admin/settings/class-sp-settings-page.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Settings Page/Tab
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Page' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Page
|
||||
*/
|
||||
class SP_Settings_Page {
|
||||
|
||||
protected $id = '';
|
||||
protected $label = '';
|
||||
|
||||
/**
|
||||
* Add this page to settings
|
||||
*/
|
||||
public function add_settings_page( $pages ) {
|
||||
$pages[ $this->id ] = $this->label;
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output sections
|
||||
*/
|
||||
public function output_sections() {
|
||||
global $current_section;
|
||||
|
||||
$sections = $this->get_sections();
|
||||
|
||||
if ( empty( $sections ) )
|
||||
return;
|
||||
|
||||
echo '<ul class="subsubsub">';
|
||||
|
||||
$array_keys = array_keys( $sections );
|
||||
|
||||
foreach ( $sections as $id => $label )
|
||||
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
|
||||
|
||||
echo '</ul><br class="clear" />';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section;
|
||||
|
||||
$settings = $this->get_settings();
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
|
||||
if ( $current_section )
|
||||
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
783
includes/admin/settings/class-sp-settings-players.php
Normal file
783
includes/admin/settings/class-sp-settings-players.php
Normal file
@@ -0,0 +1,783 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Player Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Players' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Players
|
||||
*/
|
||||
class SP_Settings_Players extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'players';
|
||||
$this->label = __( 'Players', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
if ( $tax_classes )
|
||||
foreach ( $tax_classes as $class )
|
||||
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
|
||||
return apply_filters('sportspress_event_settings', array(
|
||||
|
||||
array( 'title' => __( 'Player Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Enable Players', 'sportspress' ),
|
||||
'desc' => __( 'Enable taxes and tax calculations', 'sportspress' ),
|
||||
'id' => 'sportspress_calc_taxes',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox'
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Prices Entered With Tax', 'sportspress' ),
|
||||
'id' => 'sportspress_prices_include_tax',
|
||||
'default' => 'no',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'vs' => sprintf( '%s vs %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) ),
|
||||
'v' => sprintf( '%s v %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) ),
|
||||
'—' => sprintf( '%s — %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) ),
|
||||
'/' => sprintf( '%s / %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_based_on',
|
||||
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
|
||||
'default' => 'shipping',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'shipping' => __( 'Customer shipping address', 'sportspress' ),
|
||||
'billing' => __( 'Customer billing address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Default Customer Address:', 'sportspress' ),
|
||||
'id' => 'sportspress_default_customer_address',
|
||||
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
|
||||
'default' => 'base',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'No address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' ),
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
|
||||
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
|
||||
'id' => 'sportspress_shipping_tax_class',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => 'title',
|
||||
'type' => 'select',
|
||||
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Rounding', 'sportspress' ),
|
||||
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_round_at_subtotal',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Additional Tax Classes', 'sportspress' ),
|
||||
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_classes',
|
||||
'css' => 'width:100%; height: 65px;',
|
||||
'type' => 'textarea',
|
||||
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices in the shop:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_shop',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Price display suffix:', 'sportspress' ),
|
||||
'id' => 'sportspress_price_display_suffix',
|
||||
'default' => '',
|
||||
'type' => 'text',
|
||||
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_cart',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display tax totals:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_total_display',
|
||||
'default' => 'itemized',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'single' => __( 'As a single total', 'sportspress' ),
|
||||
'itemized' => __( 'Itemized', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'results' ),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'event_options' ),
|
||||
|
||||
)); // End event settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
|
||||
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section, $wpdb;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
|
||||
} else {
|
||||
|
||||
$this->save_tax_rates();
|
||||
|
||||
}
|
||||
|
||||
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output tax rate tables
|
||||
*/
|
||||
public function output_tax_rates() {
|
||||
global $sportspress, $current_section, $wpdb;
|
||||
|
||||
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
|
||||
$limit = 100;
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
?>
|
||||
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
|
||||
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
|
||||
<table class="sp_tax_rates sp_input_table sortable widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="sort"> </th>
|
||||
|
||||
<th width="8%"><?php _e( 'Country Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'State Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'City', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Rate %', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Tax Name', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="10">
|
||||
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
|
||||
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
|
||||
|
||||
<div class="pagination">
|
||||
<?php
|
||||
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
|
||||
'base' => add_query_arg( 'p', '%#%' ),
|
||||
'type' => 'plain',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
|
||||
'current' => $page
|
||||
) ) );
|
||||
?>
|
||||
</div>
|
||||
|
||||
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody id="rates">
|
||||
<?php
|
||||
$rates = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
|
||||
WHERE tax_rate_class = %s
|
||||
ORDER BY tax_rate_order
|
||||
LIMIT %d, %d
|
||||
" ,
|
||||
sanitize_title( $current_class ),
|
||||
( $page - 1 ) * $limit,
|
||||
$limit
|
||||
) );
|
||||
|
||||
foreach ( $rates as $rate ) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
|
||||
|
||||
<td class="country" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="state" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="postcode">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="city">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="rate" width="8%">
|
||||
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="name" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="priority" width="8%">
|
||||
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="compound" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
|
||||
</td>
|
||||
|
||||
<td class="apply_to_shipping" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
jQuery( function() {
|
||||
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$current = $tbody.find('tr.current');
|
||||
$current.find('input').val('');
|
||||
$current.find('input.remove_tax_rate').val('1');
|
||||
|
||||
$current.each(function(){
|
||||
if ( jQuery(this).is('.new') )
|
||||
jQuery(this).remove();
|
||||
else
|
||||
jQuery(this).hide();
|
||||
});
|
||||
} else {
|
||||
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .export').click(function() {
|
||||
|
||||
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
|
||||
|
||||
jQuery('#rates tr:visible').each(function() {
|
||||
var row = '';
|
||||
jQuery(this).find('td:not(.sort) input').each(function() {
|
||||
|
||||
if ( jQuery(this).is('.checkbox') ) {
|
||||
|
||||
if ( jQuery(this).is(':checked') ) {
|
||||
val = 1;
|
||||
} else {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var val = jQuery(this).val();
|
||||
|
||||
if ( ! val )
|
||||
val = jQuery(this).attr('placeholder');
|
||||
}
|
||||
|
||||
row = row + val + ',';
|
||||
});
|
||||
row = row + '<?php echo $current_class; ?>';
|
||||
//row.substring( 0, row.length - 1 );
|
||||
csv_data = csv_data + row + "\n";
|
||||
});
|
||||
|
||||
jQuery(this).attr( 'href', encodeURI( csv_data ) );
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .insert').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
var size = $tbody.find('tr').size();
|
||||
var code = '<tr class="new">\
|
||||
<td class="sort"> </td>\
|
||||
<td class="country" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="state" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="postcode">\
|
||||
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="city">\
|
||||
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="rate" width="8%">\
|
||||
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="name" width="8%">\
|
||||
<input type="text" name="tax_rate_name[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="priority" width="8%">\
|
||||
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="compound" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="apply_to_shipping" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
|
||||
</td>\
|
||||
</tr>';
|
||||
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$tbody.find('tr.current').after( code );
|
||||
} else {
|
||||
$tbody.append( code );
|
||||
}
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
|
||||
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
|
||||
});
|
||||
|
||||
var availableCountries = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
|
||||
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
var availableStates = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
|
||||
foreach ( $label as $code => $state )
|
||||
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save tax rates
|
||||
*/
|
||||
public function save_tax_rates() {
|
||||
global $wpdb, $current_section;
|
||||
|
||||
// Get class
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
|
||||
// Get POST data
|
||||
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
|
||||
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
|
||||
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
|
||||
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
|
||||
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
|
||||
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
|
||||
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
|
||||
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
|
||||
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
|
||||
|
||||
$i = 0;
|
||||
|
||||
// Loop posted fields
|
||||
foreach ( $tax_rate_country as $key => $value ) {
|
||||
|
||||
// new keys are inserted...
|
||||
if ( $key == 'new' ) {
|
||||
|
||||
foreach ( $value as $new_key => $new_value ) {
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
|
||||
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
)
|
||||
);
|
||||
|
||||
$tax_rate_id = $wpdb->insert_id;
|
||||
|
||||
if ( ! empty( $postcode ) ) {
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $city ) ) {
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// ...whereas the others are updated
|
||||
} else {
|
||||
|
||||
$tax_rate_id = absint( $key );
|
||||
|
||||
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
|
||||
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
),
|
||||
array(
|
||||
'tax_rate_id' => $tax_rate_id
|
||||
)
|
||||
);
|
||||
|
||||
if ( isset( $tax_rate_postcode[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $tax_rate_city[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ] );
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
if ( $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output results settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function results_setting() {
|
||||
$main_result = get_option( 'sportspress_main_result', 0 );
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_result',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Results', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th class="edit"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="main_result" value="0" <?php checked( $main_result, 0 ); ?>></th>
|
||||
<th colspan="3"><label for="main_result_0">
|
||||
<?php
|
||||
if ( sizeof( $data ) > 0 ):
|
||||
$default = end( $data );
|
||||
reset( $data );
|
||||
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
|
||||
else:
|
||||
_e( 'Default', 'sportspress' );
|
||||
endif;
|
||||
?>
|
||||
</label></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="radio"><input type="radio" id="main_result_<?php echo $row->post_name; ?>" name="main_result" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
|
||||
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
|
||||
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Players();
|
||||
458
includes/admin/settings/class-sp-settings-products.php
Normal file
458
includes/admin/settings/class-sp-settings-products.php
Normal file
@@ -0,0 +1,458 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Product Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Products' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Products
|
||||
*/
|
||||
class SP_Settings_Products extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'products';
|
||||
$this->label = __( 'Products', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
'' => __( 'Product Options', 'sportspress' ),
|
||||
'inventory' => __( 'Inventory', 'sportspress' )
|
||||
);
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$settings = $this->get_settings( $current_section );
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section;
|
||||
|
||||
$settings = $this->get_settings( $current_section );
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
|
||||
if ( $current_section == 'inventory' ) {
|
||||
|
||||
return apply_filters('sportspress_inventory_settings', array(
|
||||
|
||||
array( 'title' => __( 'Inventory Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'inventory_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Manage Stock', 'sportspress' ),
|
||||
'desc' => __( 'Enable stock management', 'sportspress' ),
|
||||
'id' => 'sportspress_manage_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox'
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Hold Stock (minutes)', 'sportspress' ),
|
||||
'desc' => __( 'Hold stock (for unpaid orders) for x minutes. When this limit is reached, the pending order will be cancelled. Leave blank to disable.', 'sportspress' ),
|
||||
'id' => 'sportspress_hold_stock_minutes',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1
|
||||
),
|
||||
'css' => 'width:50px;',
|
||||
'default' => '60',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Notifications', 'sportspress' ),
|
||||
'desc' => __( 'Enable low stock notifications', 'sportspress' ),
|
||||
'id' => 'sportspress_notify_low_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Enable out of stock notifications', 'sportspress' ),
|
||||
'id' => 'sportspress_notify_no_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Notification Recipient', 'sportspress' ),
|
||||
'desc' => '',
|
||||
'id' => 'sportspress_stock_email_recipient',
|
||||
'type' => 'email',
|
||||
'default' => get_option( 'admin_email' ),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Low Stock Threshold', 'sportspress' ),
|
||||
'desc' => '',
|
||||
'id' => 'sportspress_notify_low_stock_amount',
|
||||
'css' => 'width:50px;',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1
|
||||
),
|
||||
'default' => '2',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Out Of Stock Threshold', 'sportspress' ),
|
||||
'desc' => '',
|
||||
'id' => 'sportspress_notify_no_stock_amount',
|
||||
'css' => 'width:50px;',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1
|
||||
),
|
||||
'default' => '0',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Out Of Stock Visibility', 'sportspress' ),
|
||||
'desc' => __( 'Hide out of stock items from the catalog', 'sportspress' ),
|
||||
'id' => 'sportspress_hide_out_of_stock_items',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox'
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Stock Display Format', 'sportspress' ),
|
||||
'desc' => __( 'This controls how stock is displayed on the frontend.', 'sportspress' ),
|
||||
'id' => 'sportspress_stock_format',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => '',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'Always show stock e.g. "12 in stock"', 'sportspress' ),
|
||||
'low_amount' => __( 'Only show stock when low e.g. "Only 2 left in stock" vs. "In Stock"', 'sportspress' ),
|
||||
'no_amount' => __( 'Never show stock amount', 'sportspress' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'inventory_options'),
|
||||
|
||||
));
|
||||
|
||||
} else {
|
||||
|
||||
// Get shop page
|
||||
$shop_page_id = sp_get_page_id('shop');
|
||||
|
||||
$base_slug = ($shop_page_id > 0 && get_page( $shop_page_id )) ? get_page_uri( $shop_page_id ) : 'shop';
|
||||
|
||||
$sportspress_prepend_shop_page_to_products_warning = '';
|
||||
|
||||
if ( $shop_page_id > 0 && sizeof(get_pages("child_of=$shop_page_id")) > 0 )
|
||||
$sportspress_prepend_shop_page_to_products_warning = ' <mark class="notice">' . __( 'Note: The shop page has children - child pages will not work if you enable this option.', 'sportspress' ) . '</mark>';
|
||||
|
||||
return apply_filters( 'sportspress_product_settings', array(
|
||||
|
||||
array( 'title' => __( 'Product Listings', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'catalog_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Product Archive / Shop Page', 'sportspress' ),
|
||||
'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'sportspress' ), admin_url( 'options-permalink.php' ) ),
|
||||
'id' => 'sportspress_shop_page_id',
|
||||
'type' => 'single_select_page',
|
||||
'default' => '',
|
||||
'class' => 'chosen_select_nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'sportspress' ),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shop Page Display', 'sportspress' ),
|
||||
'desc' => __( 'This controls what is shown on the product archive.', 'sportspress' ),
|
||||
'id' => 'sportspress_shop_page_display',
|
||||
'class' => 'chosen_select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => '',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'Show products', 'sportspress' ),
|
||||
'subcategories' => __( 'Show subcategories', 'sportspress' ),
|
||||
'both' => __( 'Show both', 'sportspress' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Default Category Display', 'sportspress' ),
|
||||
'desc' => __( 'This controls what is shown on category archives.', 'sportspress' ),
|
||||
'id' => 'sportspress_category_archive_display',
|
||||
'class' => 'chosen_select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => '',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'Show products', 'sportspress' ),
|
||||
'subcategories' => __( 'Show subcategories', 'sportspress' ),
|
||||
'both' => __( 'Show both', 'sportspress' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Default Product Sorting', 'sportspress' ),
|
||||
'desc' => __( 'This controls the default sort order of the catalog.', 'sportspress' ),
|
||||
'id' => 'sportspress_default_catalog_orderby',
|
||||
'class' => 'chosen_select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'title',
|
||||
'type' => 'select',
|
||||
'options' => apply_filters('sportspress_default_catalog_orderby_options', array(
|
||||
'menu_order' => __( 'Default sorting (custom ordering + name)', 'sportspress' ),
|
||||
'popularity' => __( 'Popularity (sales)', 'sportspress' ),
|
||||
'rating' => __( 'Average Rating', 'sportspress' ),
|
||||
'date' => __( 'Sort by most recent', 'sportspress' ),
|
||||
'price' => __( 'Sort by price (asc)', 'sportspress' ),
|
||||
'price-desc' => __( 'Sort by price (desc)', 'sportspress' ),
|
||||
)),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Add to cart', 'sportspress' ),
|
||||
'desc' => __( 'Redirect to the cart page after successful addition', 'sportspress' ),
|
||||
'id' => 'sportspress_cart_redirect_after_add',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start'
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_ajax_add_to_cart',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end'
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'catalog_options' ),
|
||||
|
||||
array( 'title' => __( 'Product Data', 'sportspress' ), 'type' => 'title', 'id' => 'product_data_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Weight Unit', 'sportspress' ),
|
||||
'desc' => __( 'This controls what unit you will define weights in.', 'sportspress' ),
|
||||
'id' => 'sportspress_weight_unit',
|
||||
'class' => 'chosen_select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'kg',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'kg' => __( 'kg', 'sportspress' ),
|
||||
'g' => __( 'g', 'sportspress' ),
|
||||
'lbs' => __( 'lbs', 'sportspress' ),
|
||||
'oz' => __( 'oz', 'sportspress' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Dimensions Unit', 'sportspress' ),
|
||||
'desc' => __( 'This controls what unit you will define lengths in.', 'sportspress' ),
|
||||
'id' => 'sportspress_dimension_unit',
|
||||
'class' => 'chosen_select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'cm',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'm' => __( 'm', 'sportspress' ),
|
||||
'cm' => __( 'cm', 'sportspress' ),
|
||||
'mm' => __( 'mm', 'sportspress' ),
|
||||
'in' => __( 'in', 'sportspress' ),
|
||||
'yd' => __( 'yd', 'sportspress' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Product Ratings', 'sportspress' ),
|
||||
'desc' => __( 'Enable ratings on reviews', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_review_rating',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Ratings are required to leave a review', 'sportspress' ),
|
||||
'id' => 'sportspress_review_rating_required',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Show "verified owner" label for customer reviews', 'sportspress' ),
|
||||
'id' => 'sportspress_review_rating_verification_label',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Only allow reviews from "verified owners"', 'sportspress' ),
|
||||
'id' => 'sportspress_review_rating_verification_required',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'product_data_options' ),
|
||||
|
||||
array( 'title' => __( 'Product Image Sizes', 'sportspress' ), 'type' => 'title','desc' => sprintf(__( 'These settings affect the actual dimensions of images in your catalog - the display on the front-end will still be affected by CSS styles. After changing these settings you may need to <a href="%s">regenerate your thumbnails</a>.', 'sportspress' ), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'id' => 'image_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Catalog Images', 'sportspress' ),
|
||||
'desc' => __( 'This size is usually used in product listings', 'sportspress' ),
|
||||
'id' => 'shop_catalog_image_size',
|
||||
'css' => '',
|
||||
'type' => 'image_width',
|
||||
'default' => array(
|
||||
'width' => '150',
|
||||
'height' => '150',
|
||||
'crop' => true
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Single Product Image', 'sportspress' ),
|
||||
'desc' => __( 'This is the size used by the main image on the product page.', 'sportspress' ),
|
||||
'id' => 'shop_single_image_size',
|
||||
'css' => '',
|
||||
'type' => 'image_width',
|
||||
'default' => array(
|
||||
'width' => '300',
|
||||
'height' => '300',
|
||||
'crop' => 1
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Product Thumbnails', 'sportspress' ),
|
||||
'desc' => __( 'This size is usually used for the gallery of images on the product page.', 'sportspress' ),
|
||||
'id' => 'shop_thumbnail_image_size',
|
||||
'css' => '',
|
||||
'type' => 'image_width',
|
||||
'default' => array(
|
||||
'width' => '90',
|
||||
'height' => '90',
|
||||
'crop' => 1
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'image_options' ),
|
||||
|
||||
array( 'title' => __( 'Downloadable Products', 'sportspress' ), 'type' => 'title', 'id' => 'digital_download_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'File Download Method', 'sportspress' ),
|
||||
'desc' => __( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, <code>X-Accel-Redirect</code>/ <code>X-Sendfile</code> can be used to serve downloads instead (server requires <code>mod_xsendfile</code>).', 'sportspress' ),
|
||||
'id' => 'sportspress_file_download_method',
|
||||
'type' => 'select',
|
||||
'class' => 'chosen_select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'force',
|
||||
'desc_tip' => true,
|
||||
'options' => array(
|
||||
'force' => __( 'Force Downloads', 'sportspress' ),
|
||||
'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'sportspress' ),
|
||||
'redirect' => __( 'Redirect only', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Access Restriction', 'sportspress' ),
|
||||
'desc' => __( 'Downloads require login', 'sportspress' ),
|
||||
'id' => 'sportspress_downloads_require_login',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'no',
|
||||
'desc_tip' => __( 'This setting does not apply to guest purchases.', 'sportspress' ),
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Grant access to downloadable products after payment', 'sportspress' ),
|
||||
'id' => 'sportspress_downloads_grant_access_after_payment',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'yes',
|
||||
'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'sportspress' ),
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'digital_download_options' ),
|
||||
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Products();
|
||||
281
includes/admin/settings/class-sp-settings-shipping.php
Normal file
281
includes/admin/settings/class-sp-settings-shipping.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Shipping Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Shipping' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Shipping
|
||||
*/
|
||||
class SP_Settings_Shipping extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'shipping';
|
||||
$this->label = __( 'Shipping', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_admin_field_shipping_methods', array( $this, 'shipping_methods_setting' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
'' => __( 'Shipping Options', 'sportspress' )
|
||||
);
|
||||
|
||||
// Load shipping methods so we can show any global options they may have
|
||||
$shipping_methods = SP()->shipping->load_shipping_methods();
|
||||
|
||||
foreach ( $shipping_methods as $method ) {
|
||||
|
||||
if ( ! $method->has_settings() ) continue;
|
||||
|
||||
$title = empty( $method->method_title ) ? ucfirst( $method->id ) : $method->method_title;
|
||||
|
||||
$sections[ strtolower( get_class( $method ) ) ] = esc_html( $title );
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
return apply_filters('sportspress_shipping_settings', array(
|
||||
|
||||
array( 'title' => __( 'Shipping Options', 'sportspress' ), 'type' => 'title', 'id' => 'shipping_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping Calculations', 'sportspress' ),
|
||||
'desc' => __( 'Enable shipping', 'sportspress' ),
|
||||
'id' => 'sportspress_calc_shipping',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start'
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Enable the shipping calculator on the cart page', 'sportspress' ),
|
||||
'id' => 'sportspress_enable_shipping_calc',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Hide shipping costs until an address is entered', 'sportspress' ),
|
||||
'id' => 'sportspress_shipping_cost_requires_address',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping Display Mode', 'sportspress' ),
|
||||
'desc' => __( 'This controls how multiple shipping methods are displayed on the frontend.', 'sportspress' ),
|
||||
'id' => 'sportspress_shipping_method_format',
|
||||
'default' => '',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'' => __( 'Display shipping methods with "radio" buttons', 'sportspress' ),
|
||||
'select' => __( 'Display shipping methods in a dropdown', 'sportspress' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping Destination', 'sportspress' ),
|
||||
'desc' => __( 'Ship to billing address by default', 'sportspress' ),
|
||||
'id' => 'sportspress_ship_to_billing',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false,
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Only ship to the users billing address', 'sportspress' ),
|
||||
'id' => 'sportspress_ship_to_billing_address_only',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false,
|
||||
'show_if_checked' => 'yes',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Restrict shipping to Location(s)', 'sportspress' ),
|
||||
'desc' => sprintf( __( 'Choose which countries you want to ship to, or choose to ship to all <a href="%s">locations you sell to</a>.', 'sportspress' ), admin_url( 'admin.php?page=sp-settings&tab=general' ) ),
|
||||
'id' => 'sportspress_ship_to_countries',
|
||||
'default' => '',
|
||||
'type' => 'select',
|
||||
'class' => 'chosen_select',
|
||||
'desc_tip' => false,
|
||||
'options' => array(
|
||||
'' => __( 'Ship to all countries you sell to', 'sportspress' ),
|
||||
'all' => __( 'Ship to all countries', 'sportspress' ),
|
||||
'specific' => __( 'Ship to specific countries only', 'sportspress' )
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Specific Countries', 'sportspress' ),
|
||||
'desc' => '',
|
||||
'id' => 'sportspress_specific_ship_to_countries',
|
||||
'css' => '',
|
||||
'default' => '',
|
||||
'type' => 'multi_select_countries'
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'shipping_methods',
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'shipping_options' ),
|
||||
|
||||
)); // End shipping settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
// Load shipping methods so we can show any global options they may have
|
||||
$shipping_methods = SP()->shipping->load_shipping_methods();
|
||||
|
||||
if ( $current_section ) {
|
||||
foreach ( $shipping_methods as $method ) {
|
||||
if ( strtolower( get_class( $method ) ) == strtolower( $current_section ) && $method->has_settings() ) {
|
||||
$method->admin_options();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output shipping method settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function shipping_methods_setting() {
|
||||
$default_shipping_method = esc_attr( get_option('sportspress_default_shipping_method') );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Shipping Methods', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="sp_shipping widefat" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="default"><?php _e( 'Default', 'sportspress' ); ?></th>
|
||||
<th class="name"><?php _e( 'Name', 'sportspress' ); ?></th>
|
||||
<th class="id"><?php _e( 'ID', 'sportspress' ); ?></th>
|
||||
<th class="status"><?php _e( 'Status', 'sportspress' ); ?></th>
|
||||
<th class="settings"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th width="1%" class="default">
|
||||
<input type="radio" name="default_shipping_method" value="" <?php checked( $default_shipping_method, '' ); ?> />
|
||||
</th>
|
||||
<th><?php _e( 'No default', 'sportspress' ); ?></th>
|
||||
<th colspan="3"><span class="description"><?php _e( 'Drag and drop the above shipping methods to control their display order.', 'sportspress' ); ?></span></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( SP()->shipping->load_shipping_methods() as $key => $method ) {
|
||||
echo '<tr>
|
||||
<td width="1%" class="default">
|
||||
<input type="radio" name="default_shipping_method" value="' . esc_attr( $method->id ) . '" ' . checked( $default_shipping_method, $method->id, false ) . ' />
|
||||
<input type="hidden" name="method_order[]" value="' . esc_attr( $method->id ) . '" />
|
||||
</td>
|
||||
<td class="name">
|
||||
' . $method->get_title() . '
|
||||
</td>
|
||||
<td class="id">
|
||||
' . $method->id . '
|
||||
</td>
|
||||
<td class="status">';
|
||||
|
||||
if ( $method->enabled == 'yes' )
|
||||
echo '<span class="status-enabled tips" data-tip="' . __ ( 'Enabled', 'sportspress' ) . '">' . __ ( 'Enabled', 'sportspress' ) . '</span>';
|
||||
else
|
||||
echo '-';
|
||||
|
||||
echo '</td>
|
||||
<td class="settings">';
|
||||
|
||||
if ( $method->has_settings ) {
|
||||
echo '<a class="button" href="' . admin_url( 'admin.php?page=sp-settings&tab=shipping§ion=' . strtolower( get_class( $method ) ) ) . '">' . __( 'Settings', 'sportspress' ) . '</a>';
|
||||
}
|
||||
|
||||
echo '</td>
|
||||
</tr>';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
SP()->shipping->process_admin_options();
|
||||
|
||||
} elseif ( class_exists( $current_section ) ) {
|
||||
|
||||
$current_section_class = new $current_section();
|
||||
|
||||
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section_class->id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Shipping();
|
||||
735
includes/admin/settings/class-sp-settings-tax.php
Normal file
735
includes/admin/settings/class-sp-settings-tax.php
Normal file
@@ -0,0 +1,735 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Tax Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Tax' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Tax
|
||||
*/
|
||||
class SP_Settings_Tax extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'tax';
|
||||
$this->label = __( 'Tax', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
'' => __( 'Tax Options', 'sportspress' ),
|
||||
'standard' => __( 'Standard Rates', 'sportspress' )
|
||||
);
|
||||
|
||||
// Get tax classes and display as links
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
|
||||
if ( $tax_classes )
|
||||
foreach ( $tax_classes as $class )
|
||||
$sections[ sanitize_title( $class ) ] = sprintf( __( '%s Rates', 'sportspress' ), $class );
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
if ( $tax_classes )
|
||||
foreach ( $tax_classes as $class )
|
||||
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
|
||||
return apply_filters('sportspress_tax_settings', array(
|
||||
|
||||
array( 'title' => __( 'Tax Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Enable Taxes', 'sportspress' ),
|
||||
'desc' => __( 'Enable taxes and tax calculations', 'sportspress' ),
|
||||
'id' => 'sportspress_calc_taxes',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox'
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Prices Entered With Tax', 'sportspress' ),
|
||||
'id' => 'sportspress_prices_include_tax',
|
||||
'default' => 'no',
|
||||
'type' => 'radio',
|
||||
'desc_tip' => __( 'This option is important as it will affect how you input prices. Changing it will not update existing products.', 'sportspress' ),
|
||||
'options' => array(
|
||||
'yes' => __( 'Yes, I will enter prices inclusive of tax', 'sportspress' ),
|
||||
'no' => __( 'No, I will enter prices exclusive of tax', 'sportspress' )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_based_on',
|
||||
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
|
||||
'default' => 'shipping',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'shipping' => __( 'Customer shipping address', 'sportspress' ),
|
||||
'billing' => __( 'Customer billing address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Default Customer Address:', 'sportspress' ),
|
||||
'id' => 'sportspress_default_customer_address',
|
||||
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
|
||||
'default' => 'base',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'No address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' ),
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
|
||||
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
|
||||
'id' => 'sportspress_shipping_tax_class',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => 'title',
|
||||
'type' => 'select',
|
||||
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Rounding', 'sportspress' ),
|
||||
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_round_at_subtotal',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Additional Tax Classes', 'sportspress' ),
|
||||
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_classes',
|
||||
'css' => 'width:100%; height: 65px;',
|
||||
'type' => 'textarea',
|
||||
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices in the shop:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_shop',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Price display suffix:', 'sportspress' ),
|
||||
'id' => 'sportspress_price_display_suffix',
|
||||
'default' => '',
|
||||
'type' => 'text',
|
||||
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_cart',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display tax totals:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_total_display',
|
||||
'default' => 'itemized',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'single' => __( 'As a single total', 'sportspress' ),
|
||||
'itemized' => __( 'Itemized', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'tax_options' ),
|
||||
|
||||
)); // End tax settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
|
||||
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section, $wpdb;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
|
||||
} else {
|
||||
|
||||
$this->save_tax_rates();
|
||||
|
||||
}
|
||||
|
||||
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output tax rate tables
|
||||
*/
|
||||
public function output_tax_rates() {
|
||||
global $sportspress, $current_section, $wpdb;
|
||||
|
||||
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
|
||||
$limit = 100;
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
?>
|
||||
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
|
||||
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
|
||||
<table class="sp_tax_rates sp_input_table sortable widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="sort"> </th>
|
||||
|
||||
<th width="8%"><?php _e( 'Country Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'State Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'City', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Rate %', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Tax Name', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="10">
|
||||
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
|
||||
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
|
||||
|
||||
<div class="pagination">
|
||||
<?php
|
||||
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
|
||||
'base' => add_query_arg( 'p', '%#%' ),
|
||||
'type' => 'plain',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
|
||||
'current' => $page
|
||||
) ) );
|
||||
?>
|
||||
</div>
|
||||
|
||||
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody id="rates">
|
||||
<?php
|
||||
$rates = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
|
||||
WHERE tax_rate_class = %s
|
||||
ORDER BY tax_rate_order
|
||||
LIMIT %d, %d
|
||||
" ,
|
||||
sanitize_title( $current_class ),
|
||||
( $page - 1 ) * $limit,
|
||||
$limit
|
||||
) );
|
||||
|
||||
foreach ( $rates as $rate ) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
|
||||
|
||||
<td class="country" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="state" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="postcode">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="city">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="rate" width="8%">
|
||||
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="name" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="priority" width="8%">
|
||||
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="compound" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
|
||||
</td>
|
||||
|
||||
<td class="apply_to_shipping" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
jQuery( function() {
|
||||
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$current = $tbody.find('tr.current');
|
||||
$current.find('input').val('');
|
||||
$current.find('input.remove_tax_rate').val('1');
|
||||
|
||||
$current.each(function(){
|
||||
if ( jQuery(this).is('.new') )
|
||||
jQuery(this).remove();
|
||||
else
|
||||
jQuery(this).hide();
|
||||
});
|
||||
} else {
|
||||
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .export').click(function() {
|
||||
|
||||
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
|
||||
|
||||
jQuery('#rates tr:visible').each(function() {
|
||||
var row = '';
|
||||
jQuery(this).find('td:not(.sort) input').each(function() {
|
||||
|
||||
if ( jQuery(this).is('.checkbox') ) {
|
||||
|
||||
if ( jQuery(this).is(':checked') ) {
|
||||
val = 1;
|
||||
} else {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var val = jQuery(this).val();
|
||||
|
||||
if ( ! val )
|
||||
val = jQuery(this).attr('placeholder');
|
||||
}
|
||||
|
||||
row = row + val + ',';
|
||||
});
|
||||
row = row + '<?php echo $current_class; ?>';
|
||||
//row.substring( 0, row.length - 1 );
|
||||
csv_data = csv_data + row + "\n";
|
||||
});
|
||||
|
||||
jQuery(this).attr( 'href', encodeURI( csv_data ) );
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .insert').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
var size = $tbody.find('tr').size();
|
||||
var code = '<tr class="new">\
|
||||
<td class="sort"> </td>\
|
||||
<td class="country" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="state" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="postcode">\
|
||||
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="city">\
|
||||
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="rate" width="8%">\
|
||||
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="name" width="8%">\
|
||||
<input type="text" name="tax_rate_name[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="priority" width="8%">\
|
||||
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="compound" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="apply_to_shipping" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
|
||||
</td>\
|
||||
</tr>';
|
||||
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$tbody.find('tr.current').after( code );
|
||||
} else {
|
||||
$tbody.append( code );
|
||||
}
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
|
||||
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
|
||||
});
|
||||
|
||||
var availableCountries = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
|
||||
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
var availableStates = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
|
||||
foreach ( $label as $code => $state )
|
||||
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save tax rates
|
||||
*/
|
||||
public function save_tax_rates() {
|
||||
global $wpdb, $current_section;
|
||||
|
||||
// Get class
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
|
||||
// Get POST data
|
||||
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
|
||||
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
|
||||
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
|
||||
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
|
||||
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
|
||||
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
|
||||
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
|
||||
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
|
||||
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
|
||||
|
||||
$i = 0;
|
||||
|
||||
// Loop posted fields
|
||||
foreach ( $tax_rate_country as $key => $value ) {
|
||||
|
||||
// new keys are inserted...
|
||||
if ( $key == 'new' ) {
|
||||
|
||||
foreach ( $value as $new_key => $new_value ) {
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
|
||||
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
)
|
||||
);
|
||||
|
||||
$tax_rate_id = $wpdb->insert_id;
|
||||
|
||||
if ( ! empty( $postcode ) ) {
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $city ) ) {
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// ...whereas the others are updated
|
||||
} else {
|
||||
|
||||
$tax_rate_id = absint( $key );
|
||||
|
||||
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
|
||||
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
),
|
||||
array(
|
||||
'tax_rate_id' => $tax_rate_id
|
||||
)
|
||||
);
|
||||
|
||||
if ( isset( $tax_rate_postcode[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $tax_rate_city[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ] );
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
if ( $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Tax();
|
||||
783
includes/admin/settings/class-sp-settings-teams.php
Normal file
783
includes/admin/settings/class-sp-settings-teams.php
Normal file
@@ -0,0 +1,783 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Team Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Teams' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Teams
|
||||
*/
|
||||
class SP_Settings_Teams extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'teams';
|
||||
$this->label = __( 'Teams', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
if ( $tax_classes )
|
||||
foreach ( $tax_classes as $class )
|
||||
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
|
||||
return apply_filters('sportspress_event_settings', array(
|
||||
|
||||
array( 'title' => __( 'Team Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Enable Teams', 'sportspress' ),
|
||||
'desc' => __( 'Enable taxes and tax calculations', 'sportspress' ),
|
||||
'id' => 'sportspress_calc_taxes',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox'
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Prices Entered With Tax', 'sportspress' ),
|
||||
'id' => 'sportspress_prices_include_tax',
|
||||
'default' => 'no',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'vs' => sprintf( '%s vs %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'v' => sprintf( '%s v %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'—' => sprintf( '%s — %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
|
||||
'/' => sprintf( '%s / %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_based_on',
|
||||
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
|
||||
'default' => 'shipping',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'shipping' => __( 'Customer shipping address', 'sportspress' ),
|
||||
'billing' => __( 'Customer billing address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' )
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Default Customer Address:', 'sportspress' ),
|
||||
'id' => 'sportspress_default_customer_address',
|
||||
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
|
||||
'default' => 'base',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'No address', 'sportspress' ),
|
||||
'base' => __( 'Shop base address', 'sportspress' ),
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
|
||||
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
|
||||
'id' => 'sportspress_shipping_tax_class',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => 'title',
|
||||
'type' => 'select',
|
||||
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Rounding', 'sportspress' ),
|
||||
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_round_at_subtotal',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Additional Tax Classes', 'sportspress' ),
|
||||
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_classes',
|
||||
'css' => 'width:100%; height: 65px;',
|
||||
'type' => 'textarea',
|
||||
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices in the shop:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_shop',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Price display suffix:', 'sportspress' ),
|
||||
'id' => 'sportspress_price_display_suffix',
|
||||
'default' => '',
|
||||
'type' => 'text',
|
||||
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_display_cart',
|
||||
'default' => 'excl',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'incl' => __( 'Including tax', 'sportspress' ),
|
||||
'excl' => __( 'Excluding tax', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Display tax totals:', 'sportspress' ),
|
||||
'id' => 'sportspress_tax_total_display',
|
||||
'default' => 'itemized',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'single' => __( 'As a single total', 'sportspress' ),
|
||||
'itemized' => __( 'Itemized', 'sportspress' ),
|
||||
),
|
||||
'autoload' => false
|
||||
),
|
||||
|
||||
array( 'type' => 'results' ),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'event_options' ),
|
||||
|
||||
)); // End event settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
|
||||
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section, $wpdb;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
|
||||
$settings = $this->get_settings();
|
||||
SP_Admin_Settings::save_fields( $settings );
|
||||
|
||||
} else {
|
||||
|
||||
$this->save_tax_rates();
|
||||
|
||||
}
|
||||
|
||||
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output tax rate tables
|
||||
*/
|
||||
public function output_tax_rates() {
|
||||
global $sportspress, $current_section, $wpdb;
|
||||
|
||||
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
|
||||
$limit = 100;
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
?>
|
||||
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
|
||||
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
|
||||
<table class="sp_tax_rates sp_input_table sortable widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="sort"> </th>
|
||||
|
||||
<th width="8%"><?php _e( 'Country Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'State Code', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th><?php _e( 'City', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Rate %', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Tax Name', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?> <span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="10">
|
||||
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
|
||||
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
|
||||
|
||||
<div class="pagination">
|
||||
<?php
|
||||
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
|
||||
'base' => add_query_arg( 'p', '%#%' ),
|
||||
'type' => 'plain',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
|
||||
'current' => $page
|
||||
) ) );
|
||||
?>
|
||||
</div>
|
||||
|
||||
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody id="rates">
|
||||
<?php
|
||||
$rates = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
|
||||
WHERE tax_rate_class = %s
|
||||
ORDER BY tax_rate_order
|
||||
LIMIT %d, %d
|
||||
" ,
|
||||
sanitize_title( $current_class ),
|
||||
( $page - 1 ) * $limit,
|
||||
$limit
|
||||
) );
|
||||
|
||||
foreach ( $rates as $rate ) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
|
||||
|
||||
<td class="country" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="state" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="postcode">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="city">
|
||||
<input type="text" value="<?php
|
||||
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
|
||||
echo esc_attr( implode( '; ', $locations ) );
|
||||
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="rate" width="8%">
|
||||
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="name" width="8%">
|
||||
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="priority" width="8%">
|
||||
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
|
||||
</td>
|
||||
|
||||
<td class="compound" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
|
||||
</td>
|
||||
|
||||
<td class="apply_to_shipping" width="8%">
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
jQuery( function() {
|
||||
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$current = $tbody.find('tr.current');
|
||||
$current.find('input').val('');
|
||||
$current.find('input.remove_tax_rate').val('1');
|
||||
|
||||
$current.each(function(){
|
||||
if ( jQuery(this).is('.new') )
|
||||
jQuery(this).remove();
|
||||
else
|
||||
jQuery(this).hide();
|
||||
});
|
||||
} else {
|
||||
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .export').click(function() {
|
||||
|
||||
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
|
||||
|
||||
jQuery('#rates tr:visible').each(function() {
|
||||
var row = '';
|
||||
jQuery(this).find('td:not(.sort) input').each(function() {
|
||||
|
||||
if ( jQuery(this).is('.checkbox') ) {
|
||||
|
||||
if ( jQuery(this).is(':checked') ) {
|
||||
val = 1;
|
||||
} else {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var val = jQuery(this).val();
|
||||
|
||||
if ( ! val )
|
||||
val = jQuery(this).attr('placeholder');
|
||||
}
|
||||
|
||||
row = row + val + ',';
|
||||
});
|
||||
row = row + '<?php echo $current_class; ?>';
|
||||
//row.substring( 0, row.length - 1 );
|
||||
csv_data = csv_data + row + "\n";
|
||||
});
|
||||
|
||||
jQuery(this).attr( 'href', encodeURI( csv_data ) );
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates .insert').click(function() {
|
||||
var $tbody = jQuery('.sp_tax_rates').find('tbody');
|
||||
var size = $tbody.find('tr').size();
|
||||
var code = '<tr class="new">\
|
||||
<td class="sort"> </td>\
|
||||
<td class="country" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="state" width="8%">\
|
||||
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="postcode">\
|
||||
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="city">\
|
||||
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="rate" width="8%">\
|
||||
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="name" width="8%">\
|
||||
<input type="text" name="tax_rate_name[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="priority" width="8%">\
|
||||
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="compound" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
|
||||
</td>\
|
||||
<td class="apply_to_shipping" width="8%">\
|
||||
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
|
||||
</td>\
|
||||
</tr>';
|
||||
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$tbody.find('tr.current').after( code );
|
||||
} else {
|
||||
$tbody.append( code );
|
||||
}
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
|
||||
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
|
||||
});
|
||||
|
||||
var availableCountries = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
|
||||
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
var availableStates = [<?php
|
||||
$countries = array();
|
||||
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
|
||||
foreach ( $label as $code => $state )
|
||||
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save tax rates
|
||||
*/
|
||||
public function save_tax_rates() {
|
||||
global $wpdb, $current_section;
|
||||
|
||||
// Get class
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
$current_class = '';
|
||||
|
||||
foreach( $tax_classes as $class )
|
||||
if ( sanitize_title( $class ) == $current_section )
|
||||
$current_class = $class;
|
||||
|
||||
// Get POST data
|
||||
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
|
||||
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
|
||||
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
|
||||
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
|
||||
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
|
||||
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
|
||||
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
|
||||
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
|
||||
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
|
||||
|
||||
$i = 0;
|
||||
|
||||
// Loop posted fields
|
||||
foreach ( $tax_rate_country as $key => $value ) {
|
||||
|
||||
// new keys are inserted...
|
||||
if ( $key == 'new' ) {
|
||||
|
||||
foreach ( $value as $new_key => $new_value ) {
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
|
||||
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
)
|
||||
);
|
||||
|
||||
$tax_rate_id = $wpdb->insert_id;
|
||||
|
||||
if ( ! empty( $postcode ) ) {
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $city ) ) {
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// ...whereas the others are updated
|
||||
} else {
|
||||
|
||||
$tax_rate_id = absint( $key );
|
||||
|
||||
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sanitize + format
|
||||
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
|
||||
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
|
||||
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
|
||||
$name = sanitize_text_field( $tax_rate_name[ $key ] );
|
||||
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
|
||||
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
|
||||
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
|
||||
|
||||
if ( ! $name )
|
||||
$name = __( 'Tax', 'sportspress' );
|
||||
|
||||
if ( $country == '*' )
|
||||
$country = '';
|
||||
|
||||
if ( $state == '*' )
|
||||
$state = '';
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . "sportspress_tax_rates",
|
||||
array(
|
||||
'tax_rate_country' => $country,
|
||||
'tax_rate_state' => $state,
|
||||
'tax_rate' => $rate,
|
||||
'tax_rate_name' => $name,
|
||||
'tax_rate_priority' => $priority,
|
||||
'tax_rate_compound' => $compound,
|
||||
'tax_rate_shipping' => $shipping,
|
||||
'tax_rate_order' => $i,
|
||||
'tax_rate_class' => sanitize_title( $current_class )
|
||||
),
|
||||
array(
|
||||
'tax_rate_id' => $tax_rate_id
|
||||
)
|
||||
);
|
||||
|
||||
if ( isset( $tax_rate_postcode[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
|
||||
$postcodes = explode( ';', $postcode );
|
||||
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
|
||||
|
||||
$postcode_query = array();
|
||||
|
||||
foreach( $postcodes as $postcode )
|
||||
if ( strstr( $postcode, '-' ) ) {
|
||||
$postcode_parts = explode( '-', $postcode );
|
||||
|
||||
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
|
||||
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
|
||||
if ( ! $i )
|
||||
continue;
|
||||
|
||||
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
|
||||
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
|
||||
|
||||
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $postcode )
|
||||
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
|
||||
}
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $tax_rate_city[ $key ] ) ) {
|
||||
// Delete old
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
|
||||
|
||||
// Add changed
|
||||
$city = sanitize_text_field( $tax_rate_city[ $key ] );
|
||||
$cities = explode( ';', $city );
|
||||
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
|
||||
foreach( $cities as $city ) {
|
||||
if ( $city ) {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . "sportspress_tax_rate_locations",
|
||||
array(
|
||||
'location_code' => $city,
|
||||
'tax_rate_id' => $tax_rate_id,
|
||||
'location_type' => 'city',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output results settings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function results_setting() {
|
||||
$main_result = get_option( 'sportspress_main_result', 0 );
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_result',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Results', 'sportspress' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th class="edit"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="main_result" value="0" <?php checked( $main_result, 0 ); ?>></th>
|
||||
<th colspan="3"><label for="main_result_0">
|
||||
<?php
|
||||
if ( sizeof( $data ) > 0 ):
|
||||
$default = end( $data );
|
||||
reset( $data );
|
||||
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
|
||||
else:
|
||||
_e( 'Default', 'sportspress' );
|
||||
endif;
|
||||
?>
|
||||
</label></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="radio"><input type="radio" id="main_result_<?php echo $row->post_name; ?>" name="main_result" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
|
||||
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
|
||||
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Teams();
|
||||
83
includes/admin/settings/class-sp-settings-text.php
Normal file
83
includes/admin/settings/class-sp-settings-text.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Text Settings
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Settings_Text' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Settings_Text
|
||||
*/
|
||||
class SP_Settings_Text extends SP_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'text';
|
||||
$this->label = __( 'Text', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
if ( $tax_classes )
|
||||
foreach ( $tax_classes as $class )
|
||||
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
|
||||
$settings = array( array( 'title' => __( 'Text Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'text_options' ) );
|
||||
|
||||
$this->strings =& SP()->text->strings;
|
||||
foreach ( $this->strings as $string ):
|
||||
$settings[] = array(
|
||||
'title' => $string,
|
||||
'id' => 'sportspress_text_' . sanitize_title( $string ),
|
||||
'default' => '',
|
||||
'placeholder' => $string,
|
||||
'type' => 'text',
|
||||
);
|
||||
endforeach;
|
||||
|
||||
$settings[] = array( 'type' => 'sectionend', 'id' => 'text_options' );
|
||||
|
||||
return apply_filters( 'sportspress_event_settings', $settings ); // End text settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
|
||||
|
||||
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
SP_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Settings_Text();
|
||||
@@ -162,12 +162,5 @@ function sportspress_options_validate( $input ) {
|
||||
}
|
||||
|
||||
function sportspress_add_menu_page() {
|
||||
add_options_page(
|
||||
__( 'SportsPress', 'sportspress' ),
|
||||
__( 'SportsPress', 'sportspress' ),
|
||||
'manage_options',
|
||||
'sportspress',
|
||||
'sportspress_options'
|
||||
);
|
||||
}
|
||||
add_action( 'admin_menu', 'sportspress_add_menu_page' );
|
||||
|
||||
Reference in New Issue
Block a user