Enabled product bundles
This commit is contained in:
@@ -0,0 +1,563 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Settings
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 1.0.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WC_Settings_Jetpack' ) ) :
|
||||
|
||||
class WC_Settings_Jetpack extends WC_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.0.0
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->id = 'jetpack';
|
||||
$this->label = __( 'Booster', 'woocommerce-jetpack' );
|
||||
|
||||
$this->cats = include( 'wcj-modules-cats.php' );
|
||||
|
||||
$this->custom_dashboard_modules = apply_filters( 'wcj_custom_dashboard_modules', array() );
|
||||
|
||||
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_cats_submenu' ) );
|
||||
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections_submenu' ) );
|
||||
|
||||
require_once( 'class-wcj-settings-custom-fields.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output cats
|
||||
*
|
||||
* @version 2.7.0
|
||||
*/
|
||||
function output_cats_submenu() {
|
||||
$current_cat = empty( $_REQUEST['wcj-cat'] ) ? 'dashboard' : sanitize_title( $_REQUEST['wcj-cat'] );
|
||||
if ( empty( $this->cats ) ) {
|
||||
return;
|
||||
}
|
||||
echo '<ul class="subsubsub" style="text-transform: uppercase !important; font-weight: bold; margin-bottom: 10px !important;">';
|
||||
$array_keys = array_keys( $this->cats );
|
||||
foreach ( $this->cats as $id => $label_info ) {
|
||||
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '&wcj-cat=' . sanitize_title( $id ) ) . '" class="' . ( $current_cat == $id ? 'current' : '' ) . '">' . $label_info['label'] . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
|
||||
}
|
||||
echo '</ul>' . '<br class="clear" />';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output sections (modules) sub menu
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @todo (maybe) for case insensitive sorting: `array_multisort( array_map( 'strtolower', $menu ), $menu );` instead of `asort( $menu );` (see http://php.net/manual/en/function.asort.php)
|
||||
*/
|
||||
function output_sections_submenu() {
|
||||
global $current_section;
|
||||
$sections = $this->get_sections();
|
||||
$current_cat = empty( $_REQUEST['wcj-cat'] ) ? 'dashboard' : sanitize_title( $_REQUEST['wcj-cat'] );
|
||||
if ( 'dashboard' === $current_cat ) {
|
||||
|
||||
// Counting modules
|
||||
$all = 0;
|
||||
$active = 0;
|
||||
foreach ( $this->module_statuses as $module_status ) {
|
||||
if ( isset( $module_status['id'] ) && isset( $module_status['default'] ) ) {
|
||||
if ( 'yes' === get_option( $module_status['id'], $module_status['default'] ) ) {
|
||||
$active++;
|
||||
} elseif ( wcj_is_module_deprecated( $module_status['id'], true ) ) {
|
||||
continue;
|
||||
}
|
||||
$all++;
|
||||
}
|
||||
}
|
||||
|
||||
$sections['alphabetically'] = __( 'Alphabetically', 'woocommerce-jetpack' ) . ' <span class="count">(' . $all . ')</span>';
|
||||
$sections['by_category'] = __( 'By Category', 'woocommerce-jetpack' ) . ' <span class="count">(' . $all . ')</span>';
|
||||
$sections['active'] = __( 'Active', 'woocommerce-jetpack' ) . ' <span class="count">(' . $active . ')</span>';
|
||||
$sections['manager'] = __( 'Manage Settings', 'woocommerce-jetpack' );
|
||||
if ( ! empty( $this->custom_dashboard_modules ) ) {
|
||||
foreach ( $this->custom_dashboard_modules as $custom_dashboard_module_id => $custom_dashboard_module_data ) {
|
||||
$sections[ $custom_dashboard_module_id ] = $custom_dashboard_module_data['title'];
|
||||
}
|
||||
}
|
||||
if ( '' == $current_section ) {
|
||||
$current_section = 'by_category';
|
||||
}
|
||||
}
|
||||
if ( ! empty( $this->cats[ $current_cat ]['all_cat_ids'] ) ) {
|
||||
foreach ( $sections as $id => $label ) {
|
||||
if ( ! in_array( $id, $this->cats[ $current_cat ]['all_cat_ids'] ) ) {
|
||||
unset( $sections[ $id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( empty( $sections ) || 1 === count( $sections ) ) {
|
||||
return;
|
||||
}
|
||||
foreach ( $this->cats[ $current_cat ]['all_cat_ids'] as $key => $id ) {
|
||||
if ( wcj_is_module_deprecated( $id, false, true ) ) {
|
||||
unset( $this->cats[ $current_cat ]['all_cat_ids'][ $key ] );
|
||||
}
|
||||
}
|
||||
$menu = array();
|
||||
foreach ( $this->cats[ $current_cat ]['all_cat_ids'] as $id ) {
|
||||
$menu[ $id ] = $sections[ $id ];
|
||||
}
|
||||
if ( 'dashboard' !== $current_cat && 'pdf_invoicing' !== $current_cat ) {
|
||||
asort( $menu );
|
||||
}
|
||||
$menu_links = array();
|
||||
foreach ( $menu as $id => $label ) {
|
||||
$url = admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '&wcj-cat=' . $current_cat . '§ion=' . sanitize_title( $id ) );
|
||||
$menu_links[] = '<a href="' . $url . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a>';
|
||||
}
|
||||
echo '<ul class="subsubsub">' . '<li>' . implode( '</li> | <li>', $menu_links ) . '</li>' . '</ul>' . '<br class="clear" />';
|
||||
}
|
||||
|
||||
/**
|
||||
* get_cat_by_section
|
||||
*/
|
||||
function get_cat_by_section( $section ) {
|
||||
foreach ( $this->cats as $id => $label_info ) {
|
||||
if ( ! empty( $label_info['all_cat_ids'] ) ) {
|
||||
if ( in_array( $section, $label_info['all_cat_ids'] ) ) {
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections (modules)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_sections() {
|
||||
return apply_filters( 'wcj_settings_sections', array( '' => __( 'Dashboard', 'woocommerce-jetpack' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* active.
|
||||
*
|
||||
* @version 2.8.0
|
||||
*/
|
||||
function active( $active ) {
|
||||
return ( 'yes' === $active ) ? 'active' : 'inactive';
|
||||
}
|
||||
|
||||
/**
|
||||
* is_dashboard_section.
|
||||
*
|
||||
* @version 3.0.0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
function is_dashboard_section( $current_section ) {
|
||||
return in_array( $current_section, array_merge( array( '', 'alphabetically', 'by_category', 'active', 'manager' ), array_keys( $this->custom_dashboard_modules ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @todo (maybe) admin_notices
|
||||
*/
|
||||
function output() {
|
||||
|
||||
global $current_section, $wcj_notice;
|
||||
|
||||
if ( '' != $wcj_notice ) {
|
||||
echo '<div id="wcj_message" class="updated"><p><strong>' . $wcj_notice . '</strong></p></div>';
|
||||
}
|
||||
|
||||
$is_dashboard = $this->is_dashboard_section( $current_section );
|
||||
|
||||
// Deprecated message
|
||||
if ( $replacement_module = wcj_is_module_deprecated( $current_section ) ) {
|
||||
echo '<div id="wcj_message" class="error">';
|
||||
echo '<p>';
|
||||
echo '<strong>';
|
||||
echo sprintf(
|
||||
__( 'Please note that current <em>%s</em> module is deprecated and will be removed in future updates. Please use <em>%s</em> module instead.', 'woocommerce-jetpack' ),
|
||||
WCJ()->modules[ $current_section ]->short_desc,
|
||||
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=jetpack&wcj-cat=' . $replacement_module['cat'] . '§ion=' . $replacement_module['module'] ) . '">' .
|
||||
$replacement_module['title'] . '</a>'
|
||||
);
|
||||
echo ' <span style="color:red;">' . __( 'Module will be removed from the module\'s list as soon as you disable it.', 'woocommerce-jetpack' ) . '</span>';
|
||||
echo '</strong>';
|
||||
echo '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// "Under development" message
|
||||
if ( isset( WCJ()->modules[ $current_section ]->dev ) && true === WCJ()->modules[ $current_section ]->dev ) {
|
||||
echo '<div id="wcj_message" class="error">';
|
||||
echo '<p>';
|
||||
echo '<strong>';
|
||||
echo sprintf( __( 'Please note that <em>%s</em> module is currently under development. Until stable module version is released, options can be changed or some options can be moved to paid plugin version.', 'woocommerce-jetpack' ), WCJ()->modules[ $current_section ]->short_desc );
|
||||
echo '</strong>';
|
||||
echo '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if ( 'yes' === get_option( 'wcj_admin_tools_enabled', 'no' ) && 'yes' === get_option( 'wcj_debuging_enabled', 'no' ) ) {
|
||||
// Breadcrumbs
|
||||
$breadcrumbs_html = '';
|
||||
$breadcrumbs_html .= '<p>';
|
||||
$breadcrumbs_html .= '<code>';
|
||||
$breadcrumbs_html .= __( 'WooCommerce', 'woocommerce-jetpack' );
|
||||
$breadcrumbs_html .= ' > ';
|
||||
$breadcrumbs_html .= __( 'Settings', 'woocommerce-jetpack' );
|
||||
$breadcrumbs_html .= ' > ';
|
||||
$breadcrumbs_html .= __( 'Booster', 'woocommerce-jetpack' );
|
||||
$breadcrumbs_html .= ' > ';
|
||||
foreach ( $this->cats as $id => $label_info ) {
|
||||
if ( $this->get_cat_by_section( $current_section ) === $id ) {
|
||||
$breadcrumbs_html .= $label_info['label'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( $is_dashboard && isset( $_GET['wcj-cat'] ) && 'dashboard' != $_GET['wcj-cat'] ) {
|
||||
$breadcrumbs_html .= $this->cats[ $_GET['wcj-cat'] ]['label'];
|
||||
}
|
||||
if ( ! $is_dashboard ) {
|
||||
$breadcrumbs_html .= ' > ';
|
||||
$sections = $this->get_sections();
|
||||
$breadcrumbs_html .= $sections[ $current_section ];
|
||||
}
|
||||
$breadcrumbs_html .= '</code>';
|
||||
$breadcrumbs_html .= '</p>';
|
||||
echo $breadcrumbs_html;
|
||||
}
|
||||
|
||||
$settings = $this->get_settings( $current_section );
|
||||
|
||||
if ( ! $is_dashboard ) {
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
} else {
|
||||
$this->output_dashboard( $current_section );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* output_dashboard.
|
||||
*
|
||||
* @version 3.4.0
|
||||
*/
|
||||
function output_dashboard( $current_section ) {
|
||||
|
||||
if ( '' == $current_section ) {
|
||||
$current_section = 'by_category';
|
||||
}
|
||||
|
||||
$the_settings = $this->get_settings();
|
||||
|
||||
echo '<h3>' . $the_settings[0]['title'] . '</h3>';
|
||||
if ( isset( $this->custom_dashboard_modules[ $current_section ] ) ) {
|
||||
echo '<p>' . $this->custom_dashboard_modules[ $current_section ]['desc'] . '</p>';
|
||||
} elseif ( 'manager' != $current_section ) {
|
||||
echo '<p>' . $the_settings[0]['desc'] . '</p>';
|
||||
} else {
|
||||
echo '<p>' . __( 'This section lets you export, import or reset all Booster\'s modules settings.', 'woocommerce-jetpack' ) . '</p>';
|
||||
}
|
||||
|
||||
if ( 'alphabetically' === $current_section ) {
|
||||
$this->output_dashboard_modules( $the_settings );
|
||||
} elseif ( 'by_category' === $current_section ) {
|
||||
foreach ( $this->cats as $cat_id => $cat_label_info ) {
|
||||
if ( 'dashboard' === $cat_id ) {
|
||||
continue;
|
||||
}
|
||||
if ( isset( $_GET['wcj-cat'] ) && 'dashboard' != $_GET['wcj-cat'] ) {
|
||||
if ( $cat_id != $_GET['wcj-cat'] ) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
echo '<h4>' . $cat_label_info['label'] . '</h4>';
|
||||
}
|
||||
$this->output_dashboard_modules( $the_settings, $cat_id );
|
||||
}
|
||||
} elseif ( 'active' === $current_section ) {
|
||||
$this->output_dashboard_modules( $the_settings, 'active_modules_only' );
|
||||
} elseif ( 'manager' === $current_section ) {
|
||||
$table_data = array(
|
||||
array(
|
||||
'<button style="width:100px;" class="button-primary" type="submit" name="booster_export_settings">' . __( 'Export', 'woocommerce-jetpack' ) . '</button>',
|
||||
'<em>' . __( 'Export all Booster\'s options to a file.', 'woocommerce-jetpack' ) . '</em>',
|
||||
),
|
||||
array(
|
||||
'<button style="width:100px;" class="button-primary" type="submit" name="booster_import_settings">' . __( 'Import', 'woocommerce-jetpack' ) . '</button>' .
|
||||
' ' . '<input type="file" name="booster_import_settings_file">',
|
||||
'<em>' . __( 'Import all Booster\'s options from a file.', 'woocommerce-jetpack' ) . '</em>',
|
||||
),
|
||||
array(
|
||||
'<button style="width:100px;" class="button-primary" type="submit" name="booster_reset_settings"' .
|
||||
wcj_get_js_confirmation( __( 'This will reset settings to defaults for all Booster modules. Are you sure?', 'woocommerce-jetpack' ) ) . '>' .
|
||||
__( 'Reset', 'woocommerce-jetpack' ) . '</button>',
|
||||
'<em>' . __( 'Reset all Booster\'s options.', 'woocommerce-jetpack' ) . '</em>',
|
||||
),
|
||||
array(
|
||||
'<button style="width:100px;" class="button-primary" type="submit" name="booster_reset_settings_meta"' .
|
||||
wcj_get_js_confirmation( __( 'This will delete all Booster meta. Are you sure?', 'woocommerce-jetpack' ) ) . '>' .
|
||||
__( 'Reset meta', 'woocommerce-jetpack' ) . '</button>',
|
||||
'<em>' . __( 'Reset all Booster\'s meta.', 'woocommerce-jetpack' ) . '</em>',
|
||||
),
|
||||
);
|
||||
$manager_settings = $this->get_manager_settings();
|
||||
foreach ( $manager_settings as $manager_settings_field ) {
|
||||
$table_data[] = array(
|
||||
'<label for="' . $manager_settings_field['id'] . '">' .
|
||||
'<input name="' . $manager_settings_field['id'] . '" id="' . $manager_settings_field['id'] . '" type="' . $manager_settings_field['type'] . '"' .
|
||||
' class="" value="1" ' . checked( get_option( $manager_settings_field['id'], $manager_settings_field['default'] ), 'yes', false ) . '>' .
|
||||
' ' . '<strong>' . $manager_settings_field['title'] . '</strong>' .
|
||||
'</label>',
|
||||
'<em>' . $manager_settings_field['desc'] . '</em>',
|
||||
);
|
||||
}
|
||||
echo wcj_get_table_html( $table_data, array( 'table_class' => 'widefat striped', 'table_heading_type' => 'none' ) );
|
||||
}
|
||||
|
||||
if ( isset( $this->custom_dashboard_modules[ $current_section ] ) ) {
|
||||
$table_data = array();
|
||||
foreach ( $this->custom_dashboard_modules[ $current_section ]['settings'] as $_settings ) {
|
||||
$table_data[] = array(
|
||||
$_settings['title'],
|
||||
'<label for="' . $_settings['id'] . '">' .
|
||||
'<input name="' . $_settings['id'] .
|
||||
'" id="' . $_settings['id'] .
|
||||
'" type="' . $_settings['type'] .
|
||||
'" class="' . $_settings['class'] .
|
||||
'" value="' . get_option( $_settings['id'], $_settings['default'] )
|
||||
. '">' . ' ' . '<em>' . $_settings['desc'] . '</em>' .
|
||||
'</label>',
|
||||
);
|
||||
}
|
||||
echo wcj_get_table_html( $table_data, array( 'table_class' => 'widefat striped', 'table_heading_type' => 'vertical' ) );
|
||||
}
|
||||
|
||||
$plugin_data = get_plugin_data( WCJ_PLUGIN_FILE );
|
||||
$plugin_title = ( isset( $plugin_data['Name'] ) ? '[' . $plugin_data['Name'] . '] ' : '' );
|
||||
echo '<p style="text-align:right;color:gray;font-size:x-small;font-style:italic;">' . $plugin_title .
|
||||
__( 'Version', 'woocommerce-jetpack' ) . ': ' . get_option( WCJ_VERSION_OPTION, 'N/A' ) . '</p>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* compare_for_usort.
|
||||
*/
|
||||
private function compare_for_usort( $a, $b ) {
|
||||
return strcmp( $a['title'], $b['title'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* output_dashboard_modules.
|
||||
*
|
||||
* @version 3.3.0
|
||||
*/
|
||||
function output_dashboard_modules( $settings, $cat_id = '' ) {
|
||||
?>
|
||||
<table class="wp-list-table widefat plugins">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><label class="screen-reader-text" for="cb-select-all-1"><?php _e( 'Select All', 'woocommerce-jetpack' ); ?></label><input id="cb-select-all-1" type="checkbox" style="margin-top:15px;"></th>
|
||||
<th scope="col" id="name" class="manage-column column-name" style=""><?php _e( 'Module', 'woocommerce-jetpack' ); ?></th>
|
||||
<th scope="col" id="description" class="manage-column column-description" style=""><?php _e( 'Description', 'woocommerce-jetpack' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th scope="col" class="manage-column column-cb check-column" style=""><label class="screen-reader-text" for="cb-select-all-2"><?php _e( 'Select All', 'woocommerce-jetpack' ); ?></label><input id="cb-select-all-2" type="checkbox" style="margin-top:15px;"></th>
|
||||
<th scope="col" class="manage-column column-name" style=""><?php _e( 'Module', 'woocommerce-jetpack' ); ?></th>
|
||||
<th scope="col" class="manage-column column-description" style=""><?php _e( 'Description', 'woocommerce-jetpack' ); ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody id="the-list"><?php
|
||||
$html = '';
|
||||
usort( $settings, array( $this, 'compare_for_usort' ) );
|
||||
$total_modules = 0;
|
||||
foreach ( $settings as $the_feature ) {
|
||||
if ( 'checkbox' !== $the_feature['type'] ) {
|
||||
continue;
|
||||
}
|
||||
$section = $the_feature['id'];
|
||||
$section = str_replace( 'wcj_', '', $section );
|
||||
$section = str_replace( '_enabled', '', $section );
|
||||
if ( wcj_is_module_deprecated( $section, false, true ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( '' != $cat_id ) {
|
||||
if ( 'active_modules_only' === $cat_id ) {
|
||||
if ( 'no' === get_option( $the_feature['id'], 'no' ) ) {
|
||||
continue;
|
||||
}
|
||||
} elseif ( $cat_id != $this->get_cat_by_section( $section ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$total_modules++;
|
||||
$html .= '<tr id="' . $the_feature['id'] . '" ' . 'class="' . $this->active( get_option( $the_feature['id'] ) ) . '">';
|
||||
$html .= '<th scope="row" class="check-column">';
|
||||
$html .= '<label class="screen-reader-text" for="' . $the_feature['id'] . '">' . $the_feature['desc'] . '</label>';
|
||||
$html .= '<input type="checkbox" name="' . $the_feature['id'] . '" value="1" id="' . $the_feature['id'] . '" ' . checked( get_option( $the_feature['id'] ), 'yes', false ) . '>';
|
||||
$html .= '</th>';
|
||||
$html .= '<td class="plugin-title">' . '<strong>' . $the_feature['title'] . '</strong>';
|
||||
$html .= '<div class="row-actions visible">';
|
||||
$html .= '<span class="0"><a href="' . admin_url() . 'admin.php?page=wc-settings&tab=jetpack&wcj-cat=' . $this->get_cat_by_section( $section ) . '§ion=' . $section . '">' . __( 'Settings', 'woocommerce' ) . '</a></span>';
|
||||
if ( isset( $the_feature['wcj_link'] ) && '' != $the_feature['wcj_link'] ) {
|
||||
$html .= ' | <span class="0"><a href="' . $the_feature['wcj_link'] . '?utm_source=module_documentation&utm_medium=dashboard_link&utm_campaign=booster_documentation" target="_blank">' . __( 'Documentation', 'woocommerce' ) . '</a></span>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '</td>';
|
||||
$html .= '<td class="column-description desc">';
|
||||
$html .= '<div class="plugin-description"><p>' . ( ( isset( $the_feature['wcj_desc'] ) ) ? $the_feature['wcj_desc'] : $the_feature['desc_tip'] ) . '</p></div>';
|
||||
$html .= '</td>';
|
||||
$html .= '</tr>';
|
||||
}
|
||||
echo $html;
|
||||
if ( 0 == $total_modules && 'active_modules_only' === $cat_id ) {
|
||||
echo '<tr><td colspan="3">' . '<em>' . __( 'No active modules found.', 'woocommerce-jetpack' ) . '</em>' . '</td></tr>';
|
||||
}
|
||||
?></tbody>
|
||||
</table><p style="color:gray;font-size:x-small;font-style:italic;"><?php echo __( 'Total Modules:' ) . ' ' . $total_modules; ?></p><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings.
|
||||
*
|
||||
* @version 3.6.0
|
||||
*/
|
||||
function save() {
|
||||
global $current_section;
|
||||
$settings = $this->get_settings( $current_section );
|
||||
WC_Admin_Settings::save_fields( $settings );
|
||||
add_action( 'admin_notices', array( $this, 'booster_message_global' ) );
|
||||
do_action( 'woojetpack_after_settings_save', $this->get_sections(), $current_section );
|
||||
}
|
||||
|
||||
/**
|
||||
* booster_message_global.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function booster_message_global() {
|
||||
if ( '' != ( $message = apply_filters( 'booster_message', '', 'global' ) ) ) {
|
||||
echo $message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get_manager_settings.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 2.6.0
|
||||
* @return array
|
||||
*/
|
||||
function get_manager_settings() {
|
||||
return array(
|
||||
array(
|
||||
'title' => __( 'Autoload Booster\'s Options', 'woocommerce-jetpack' ),
|
||||
'type' => 'checkbox',
|
||||
'desc' => __( 'Choose if you want Booster\'s options to be autoloaded when calling add_option. After saving this option, you need to Reset all Booster\'s settings. Leave default value (i.e. Enabled) if not sure.', 'woocommerce-jetpack' ),
|
||||
'id' => 'wcj_autoload_options',
|
||||
'default' => 'yes',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Use List Instead of Comma Separated Text for Products in Settings', 'woocommerce-jetpack' ),
|
||||
'type' => 'checkbox',
|
||||
'desc' => sprintf( __( 'Supported modules: %s.', 'woocommerce-jetpack' ), implode( ', ', array(
|
||||
__( 'Gateways per Product or Category', 'woocommerce-jetpack' ),
|
||||
__( 'Global Discount', 'woocommerce-jetpack' ),
|
||||
__( 'Product Info', 'woocommerce-jetpack' ),
|
||||
__( 'Product Input Fields', 'woocommerce-jetpack' ),
|
||||
__( 'Products XML', 'woocommerce-jetpack' ),
|
||||
__( 'Related Products', 'woocommerce-jetpack' ),
|
||||
) ) ),
|
||||
'id' => 'wcj_list_for_products',
|
||||
'default' => 'yes',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Use List Instead of Comma Separated Text for Products Categories in Settings', 'woocommerce-jetpack' ),
|
||||
'type' => 'checkbox',
|
||||
'desc' => sprintf( __( 'Supported modules: %s.', 'woocommerce-jetpack' ), implode( ', ', array(
|
||||
__( 'Product Info', 'woocommerce-jetpack' ),
|
||||
) ) ),
|
||||
'id' => 'wcj_list_for_products_cats',
|
||||
'default' => 'yes',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Use List Instead of Comma Separated Text for Products Tags in Settings', 'woocommerce-jetpack' ),
|
||||
'type' => 'checkbox',
|
||||
'desc' => sprintf( __( 'Supported modules: %s.', 'woocommerce-jetpack' ), implode( ', ', array(
|
||||
__( 'Product Info', 'woocommerce-jetpack' ),
|
||||
) ) ),
|
||||
'id' => 'wcj_list_for_products_tags',
|
||||
'default' => 'yes',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @version 3.0.0
|
||||
* @return array
|
||||
*/
|
||||
function get_settings( $current_section = '' ) {
|
||||
if ( ! $this->is_dashboard_section( $current_section ) ) {
|
||||
return apply_filters( 'wcj_settings_' . $current_section, array() );
|
||||
} elseif ( 'manager' === $current_section ) {
|
||||
return $this->get_manager_settings();
|
||||
} elseif ( isset( $this->custom_dashboard_modules[ $current_section ] ) ) {
|
||||
return $this->custom_dashboard_modules[ $current_section ]['settings'];
|
||||
} else {
|
||||
$cat_id = ( isset( $_GET['wcj-cat'] ) && '' != $_GET['wcj-cat'] ) ? $_GET['wcj-cat'] : 'dashboard';
|
||||
$settings[] = array(
|
||||
'title' => __( 'Booster for WooCommerce', 'woocommerce-jetpack' ) . ' - ' . $this->cats[ $cat_id ]['label'],
|
||||
'type' => 'title',
|
||||
'desc' => $this->cats[ $cat_id ]['desc'],
|
||||
'id' => 'wcj_' . $cat_id . '_options',
|
||||
);
|
||||
if ( 'dashboard' === $cat_id ) {
|
||||
$settings = array_merge( $settings, $this->module_statuses );
|
||||
} else {
|
||||
$cat_module_statuses = array();
|
||||
foreach ( $this->module_statuses as $module_status ) {
|
||||
$section = $module_status['id'];
|
||||
$section = str_replace( 'wcj_', '', $section );
|
||||
$section = str_replace( '_enabled', '', $section );
|
||||
if ( $cat_id === $this->get_cat_by_section( $section ) ) {
|
||||
$cat_module_statuses[] = $module_status;
|
||||
}
|
||||
}
|
||||
$settings = array_merge( $settings, $cat_module_statuses );
|
||||
}
|
||||
$settings[] = array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'wcj_' . $cat_id . '_options',
|
||||
'title' => '', // for usort
|
||||
);
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_module_statuses
|
||||
*/
|
||||
function add_module_statuses( $statuses ) {
|
||||
$this->module_statuses = $statuses;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WC_Settings_Jetpack();
|
||||
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Settings Custom Fields
|
||||
*
|
||||
* @version 3.4.5
|
||||
* @since 2.8.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WCJ_Settings_Custom_Fields' ) ) :
|
||||
|
||||
class WCJ_Settings_Custom_Fields {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function __construct() {
|
||||
add_action( 'woocommerce_admin_field_wcj_save_settings_button', array( $this, 'output_wcj_save_settings_button' ) );
|
||||
add_action( 'woocommerce_admin_field_wcj_number_plus_checkbox_start', array( $this, 'output_wcj_number_plus_checkbox_start' ) );
|
||||
add_action( 'woocommerce_admin_field_wcj_number_plus_checkbox_end', array( $this, 'output_wcj_number_plus_checkbox_end' ) );
|
||||
add_filter( 'woocommerce_admin_settings_sanitize_option', array( $this, 'format_wcj_number_plus_checkbox_end' ), PHP_INT_MAX, 3 );
|
||||
add_action( 'woocommerce_admin_field_custom_textarea', array( $this, 'output_custom_textarea' ) );
|
||||
add_filter( 'woocommerce_admin_settings_sanitize_option', array( $this, 'unclean_custom_textarea' ), PHP_INT_MAX, 3 );
|
||||
add_action( 'woocommerce_admin_field_custom_number', array( $this, 'output_custom_number' ) );
|
||||
add_action( 'woocommerce_admin_field_custom_link', array( $this, 'output_custom_link' ) );
|
||||
add_action( 'woocommerce_admin_field_module_tools', array( $this, 'output_module_tools' ) );
|
||||
add_filter( 'woocommerce_admin_settings_sanitize_option', array( $this, 'maybe_unclean_field' ), PHP_INT_MAX, 3 );
|
||||
add_action( 'woocommerce_admin_field_exchange_rate', array( $this, 'output_exchange_rate_settings_button' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* output_exchange_rate_settings_button.
|
||||
*
|
||||
* @version 3.4.5
|
||||
*/
|
||||
function output_exchange_rate_settings_button( $value ) {
|
||||
|
||||
$value['type'] = 'number';
|
||||
|
||||
$option_value = get_option( $value['id'], $value['default'] );
|
||||
|
||||
// Custom attribute handling
|
||||
$custom_attributes = array();
|
||||
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
|
||||
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
|
||||
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
|
||||
}
|
||||
} else {
|
||||
$custom_attributes = array( 'step="' . sprintf( "%.12f", 1 / pow( 10, 12 ) ) . '"', 'min="0"' );
|
||||
}
|
||||
$custom_attributes_button = array();
|
||||
if ( ! empty( $value['custom_attributes_button'] ) && is_array( $value['custom_attributes_button'] ) ) {
|
||||
foreach ( $value['custom_attributes_button'] as $attribute => $attribute_value ) {
|
||||
$custom_attributes_button[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
|
||||
}
|
||||
}
|
||||
$tip = '';
|
||||
$description = '';
|
||||
$exchange_rate_server = wcj_get_currency_exchange_rate_server_name( $value['custom_attributes_button']['currency_from'], $value['custom_attributes_button']['currency_to'] );
|
||||
$value_title = sprintf( __( 'Grab raw %s rate from %s.', 'woocommerce-jetpack' ), $value['value'], $exchange_rate_server ) .
|
||||
' ' . __( 'Doesn\'t apply rounding, offset etc.', 'woocommerce-jetpack' );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
|
||||
<?php echo $tip; ?>
|
||||
</th>
|
||||
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
|
||||
<input
|
||||
name="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
id="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
type="<?php echo esc_attr( $value['type'] ); ?>"
|
||||
style="<?php echo esc_attr( $value['css'] ); ?>"
|
||||
value="<?php echo esc_attr( $option_value ); ?>"
|
||||
class="<?php echo esc_attr( $value['class'] ); ?>"
|
||||
<?php echo implode( ' ', $custom_attributes ); ?>
|
||||
/>
|
||||
<input
|
||||
name="<?php echo esc_attr( $value['id'] . '_button' ); ?>"
|
||||
id="<?php echo esc_attr( $value['id'] . '_button' ); ?>"
|
||||
type="button"
|
||||
value="<?php echo esc_attr( $value['value'] ); ?>"
|
||||
title="<?php echo esc_attr( $value_title ); ?>"
|
||||
class="exchage_rate_button"
|
||||
<?php echo implode( ' ', $custom_attributes_button ); ?>
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe_unclean_field.
|
||||
*
|
||||
* @version 3.1.3
|
||||
* @since 3.1.3
|
||||
*/
|
||||
function maybe_unclean_field( $value, $option, $raw_value ) {
|
||||
return ( isset( $option['wcj_raw'] ) && $option['wcj_raw'] ? $raw_value : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* output_wcj_save_settings_button.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function output_wcj_save_settings_button( $value ) {
|
||||
// Output
|
||||
?><tr valign="top">
|
||||
<th scope="row" class="titledesc"></th>
|
||||
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
|
||||
<input name="save" class="button-primary woocommerce-save-button" type="submit" value="<?php echo esc_html( $value['title'] ); ?>">
|
||||
</td>
|
||||
</tr><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* format_wcj_number_plus_checkbox_end.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function format_wcj_number_plus_checkbox_end( $value, $option, $raw_value ) {
|
||||
return ( 'wcj_number_plus_checkbox_end' === $option['type'] ) ? ( '1' === $raw_value || 'yes' === $raw_value ? 'yes' : 'no' ) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* output_wcj_number_plus_checkbox_start.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function output_wcj_number_plus_checkbox_start( $value ) {
|
||||
// Custom attribute handling
|
||||
$custom_attributes = array();
|
||||
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
|
||||
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
|
||||
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
|
||||
}
|
||||
}
|
||||
// Description handling
|
||||
$field_description = WC_Admin_Settings::get_field_description( $value );
|
||||
extract( $field_description );
|
||||
// Option value
|
||||
$option_value = WC_Admin_Settings::get_option( $value['id'], $value['default'] );
|
||||
// Output
|
||||
?><tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
|
||||
<?php echo $tooltip_html; ?>
|
||||
</th>
|
||||
<td class="forminp forminp-number-checkbox">
|
||||
<input
|
||||
name="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
id="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
type="number"
|
||||
style="<?php echo esc_attr( $value['css'] ); ?>"
|
||||
value="<?php echo esc_attr( $option_value ); ?>"
|
||||
class="<?php echo esc_attr( $value['class'] ); ?>"
|
||||
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
|
||||
<?php echo implode( ' ', $custom_attributes ); ?>
|
||||
/> <?php echo $description . ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* output_wcj_number_plus_checkbox_end.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function output_wcj_number_plus_checkbox_end( $value ) {
|
||||
// Custom attribute handling
|
||||
$custom_attributes = array();
|
||||
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
|
||||
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
|
||||
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
|
||||
}
|
||||
}
|
||||
// Description handling
|
||||
$field_description = WC_Admin_Settings::get_field_description( $value );
|
||||
extract( $field_description );
|
||||
// Option value
|
||||
$option_value = WC_Admin_Settings::get_option( $value['id'], $value['default'] );
|
||||
// Output
|
||||
?><label for="<?php echo $value['id'] ?>">
|
||||
<input
|
||||
name="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
id="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
type="checkbox"
|
||||
class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
|
||||
value="1"
|
||||
<?php checked( $option_value, 'yes' ); ?>
|
||||
<?php echo implode( ' ', $custom_attributes ); ?>
|
||||
/> <?php echo $description ?>
|
||||
</label> <?php echo $tooltip_html; ?>
|
||||
</td>
|
||||
</tr><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* unclean_custom_textarea.
|
||||
*
|
||||
* @version 2.5.7
|
||||
* @since 2.5.7
|
||||
*/
|
||||
function unclean_custom_textarea( $value, $option, $raw_value ) {
|
||||
return ( 'custom_textarea' === $option['type'] ) ? $raw_value : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* output_custom_textarea.
|
||||
*
|
||||
* @version 2.6.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function output_custom_textarea( $value ) {
|
||||
$option_value = get_option( $value['id'], $value['default'] );
|
||||
$custom_attributes = ( isset( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) ?
|
||||
$value['custom_attributes'] : array();
|
||||
$description = ' <p class="description">' . $value['desc'] . '</p>';
|
||||
$tooltip_html = ( isset( $value['desc_tip'] ) && '' != $value['desc_tip'] ) ?
|
||||
'<span class="woocommerce-help-tip" data-tip="' . $value['desc_tip'] . '"></span>' : '';
|
||||
// Output
|
||||
?><tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
|
||||
<?php echo $tooltip_html; ?>
|
||||
</th>
|
||||
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
|
||||
<?php echo $description; ?>
|
||||
|
||||
<textarea
|
||||
name="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
id="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
style="<?php echo esc_attr( $value['css'] ); ?>"
|
||||
class="<?php echo esc_attr( $value['class'] ); ?>"
|
||||
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
|
||||
<?php echo implode( ' ', $custom_attributes ); ?>
|
||||
><?php echo esc_textarea( $option_value ); ?></textarea>
|
||||
</td>
|
||||
</tr><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* output_module_tools.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.3
|
||||
*/
|
||||
function output_module_tools( $value ) {
|
||||
?><tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
|
||||
<span class="woocommerce-help-tip" data-tip="<?php echo __( 'To use tools, module must be enabled.', 'woocommerce-jetpack' ); ?>"></span>
|
||||
</th>
|
||||
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
|
||||
<?php if ( isset( $_GET['section'] ) ) do_action( 'wcj_module_tools_' . $_GET['section'] ); ?>
|
||||
</td>
|
||||
</tr><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* output_custom_link.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.8
|
||||
*/
|
||||
function output_custom_link( $value ) {
|
||||
$tooltip_html = ( isset( $value['desc_tip'] ) && '' != $value['desc_tip'] ) ?
|
||||
'<span class="woocommerce-help-tip" data-tip="' . $value['desc_tip'] . '"></span>' : '';
|
||||
?><tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label><?php echo $tooltip_html; ?>
|
||||
</th>
|
||||
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
|
||||
<?php echo $value['link']; ?>
|
||||
</td>
|
||||
</tr><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* output_custom_number.
|
||||
*
|
||||
* @version 2.5.5
|
||||
*/
|
||||
function output_custom_number( $value ) {
|
||||
$type = 'number';
|
||||
$option_value = get_option( $value['id'], $value['default'] );
|
||||
$tooltip_html = ( isset( $value['desc_tip'] ) && '' != $value['desc_tip'] ) ?
|
||||
'<span class="woocommerce-help-tip" data-tip="' . $value['desc_tip'] . '"></span>' : '';
|
||||
$description = ' <span class="description">' . $value['desc'] . '</span>';
|
||||
$save_button = apply_filters( 'booster_option', '',
|
||||
' <input name="save" class="button-primary" type="submit" value="' . __( 'Save changes', 'woocommerce' ) . '">' );
|
||||
// Custom attribute handling
|
||||
$custom_attributes = array();
|
||||
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
|
||||
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
|
||||
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
|
||||
}
|
||||
}
|
||||
// Output
|
||||
?><tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
|
||||
<?php echo $tooltip_html; ?>
|
||||
</th>
|
||||
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
|
||||
<input
|
||||
name="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
id="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
type="<?php echo esc_attr( $type ); ?>"
|
||||
style="<?php echo esc_attr( $value['css'] ); ?>"
|
||||
value="<?php echo esc_attr( $option_value ); ?>"
|
||||
class="<?php echo esc_attr( $value['class'] ); ?>"
|
||||
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
|
||||
<?php echo implode( ' ', $custom_attributes ); ?>
|
||||
/><?php echo $save_button; ?><?php echo $description; ?>
|
||||
</td>
|
||||
</tr><?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Settings_Custom_Fields();
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Settings Manager - Import / Export / Reset Booster's settings
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WCJ_Settings_Manager' ) ) :
|
||||
|
||||
class WCJ_Settings_Manager {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @todo add options to import/export selected modules only
|
||||
*/
|
||||
function __construct() {
|
||||
add_action( 'wp_loaded', array( $this, 'manage_options' ), PHP_INT_MAX );
|
||||
}
|
||||
|
||||
/**
|
||||
* manage_options.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.5.2
|
||||
*/
|
||||
function manage_options() {
|
||||
if ( is_admin() ) {
|
||||
if ( ! function_exists( 'current_user_can' ) || ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
if ( isset( $_POST['booster_import_settings'] ) ) {
|
||||
$this->manage_options_import();
|
||||
}
|
||||
if ( isset( $_POST['booster_export_settings'] ) ) {
|
||||
$this->manage_options_export();
|
||||
}
|
||||
if ( isset( $_POST['booster_reset_settings'] ) ) {
|
||||
$this->manage_options_reset();
|
||||
}
|
||||
if ( isset( $_POST['booster_reset_settings_meta'] ) ) {
|
||||
$this->manage_options_reset_meta();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* manage_options_import.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 2.5.2
|
||||
*/
|
||||
function manage_options_import() {
|
||||
global $wcj_notice;
|
||||
if( ! isset( $_FILES['booster_import_settings_file']['tmp_name'] ) || '' == $_FILES['booster_import_settings_file']['tmp_name'] ) {
|
||||
$wcj_notice .= __( 'Please upload a file to import!', 'woocommerce-jetpack' );
|
||||
$import_settings = array();
|
||||
unset( $_POST['booster_import_settings'] );
|
||||
} else {
|
||||
$import_counter = 0;
|
||||
$import_settings = file_get_contents( $_FILES['booster_import_settings_file']['tmp_name'] );
|
||||
$import_settings = explode( PHP_EOL, preg_replace( '~(*BSR_ANYCRLF)\R~', PHP_EOL, $import_settings ) );
|
||||
if ( ! is_array( $import_settings ) || 2 !== count( $import_settings ) ) {
|
||||
$wcj_notice .= __( 'Wrong file format!', 'woocommerce-jetpack' );
|
||||
} else {
|
||||
$import_header = $import_settings[0];
|
||||
$required_header = 'Booster for WooCommerce';
|
||||
if ( $required_header !== substr( $import_header, 0, strlen( $required_header ) ) ) {
|
||||
$wcj_notice .= __( 'Wrong file format!', 'woocommerce-jetpack' );
|
||||
} else {
|
||||
$import_settings = json_decode( $import_settings[1], true );
|
||||
foreach ( $import_settings as $import_key => $import_setting ) {
|
||||
if ( strlen( $import_key ) > 4 && 'wcj_' === substr( $import_key, 0, 4 ) ) {
|
||||
update_option( $import_key, $import_setting );
|
||||
$import_counter++;
|
||||
}
|
||||
}
|
||||
$wcj_notice .= sprintf( __( '%d options successfully imported.', 'woocommerce-jetpack' ), $import_counter );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* manage_options_export.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.5.2
|
||||
*/
|
||||
function manage_options_export() {
|
||||
$export_settings = array();
|
||||
$export_counter = array();
|
||||
foreach ( WCJ()->modules as $module ) {
|
||||
$values = $module->get_settings();
|
||||
foreach ( $values as $value ) {
|
||||
if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
|
||||
if ( isset ( $_POST['booster_export_settings'] ) ) {
|
||||
$export_settings[ $value['id'] ] = get_option( $value['id'], $value['default'] );
|
||||
if ( ! isset( $export_counter[ $module->short_desc ] ) ) {
|
||||
$export_counter[ $module->short_desc ] = 0;
|
||||
}
|
||||
$export_counter[ $module->short_desc ]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$export_settings = json_encode( $export_settings );
|
||||
$export_settings = 'Booster for WooCommerce v' . get_option( WCJ_VERSION_OPTION, 'NA' ) . PHP_EOL . $export_settings;
|
||||
header( "Content-Type: application/octet-stream" );
|
||||
header( "Content-Disposition: attachment; filename=booster_settings.txt" );
|
||||
header( "Content-Type: application/octet-stream" );
|
||||
header( "Content-Type: application/download" );
|
||||
header( "Content-Description: File Transfer" );
|
||||
header( "Content-Length: " . strlen( $export_settings ) );
|
||||
echo $export_settings;
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* manage_options_reset_meta.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @todo order items meta
|
||||
* @todo `... LIKE 'wcj_%'`
|
||||
*/
|
||||
function manage_options_reset_meta() {
|
||||
global $wpdb, $wcj_notice;
|
||||
$delete_counter_meta = 0;
|
||||
$plugin_meta = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE '_wcj_%'" );
|
||||
foreach( $plugin_meta as $meta ) {
|
||||
delete_post_meta( $meta->post_id, $meta->meta_key );
|
||||
$delete_counter_meta++;
|
||||
}
|
||||
$wcj_notice .= sprintf( __( '%d meta successfully deleted.', 'woocommerce-jetpack' ), $delete_counter_meta );
|
||||
}
|
||||
|
||||
/**
|
||||
* manage_options_reset.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.5.2
|
||||
*/
|
||||
function manage_options_reset() {
|
||||
global $wpdb, $wcj_notice;
|
||||
$delete_counter_options = 0;
|
||||
$plugin_options = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'wcj_%'" );
|
||||
foreach( $plugin_options as $option ) {
|
||||
delete_option( $option->option_name );
|
||||
delete_site_option( $option->option_name );
|
||||
$delete_counter_options++;
|
||||
}
|
||||
$wcj_notice .= sprintf( __( '%d options successfully deleted.', 'woocommerce-jetpack' ), $delete_counter_options );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Settings_Manager();
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce Tools
|
||||
*
|
||||
* @version 3.5.3
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WCJ_Tools' ) ) :
|
||||
|
||||
class WCJ_Tools {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
if ( is_admin() ) {
|
||||
add_action( 'admin_menu', array( $this, 'add_wcj_tools' ), 100 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_wcj_tools.
|
||||
*
|
||||
* @version 3.5.3
|
||||
*/
|
||||
function add_wcj_tools() {
|
||||
add_submenu_page(
|
||||
'woocommerce',
|
||||
__( 'Booster for WooCommerce Tools', 'woocommerce-jetpack' ),
|
||||
__( 'Booster Tools', 'woocommerce-jetpack' ),
|
||||
( 'yes' === get_option( 'wcj_' . 'admin_tools' . '_enabled', 'no' ) && 'yes' === get_option( 'wcj_admin_tools_show_menus_to_admin_only', 'no' ) ? 'manage_options' : 'manage_woocommerce' ),
|
||||
'wcj-tools',
|
||||
array( $this, 'create_tools_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* create_tools_page.
|
||||
*
|
||||
* @version 2.3.10
|
||||
*/
|
||||
function create_tools_page() {
|
||||
|
||||
// Tabs
|
||||
$tabs = apply_filters( 'wcj_tools_tabs', array(
|
||||
array(
|
||||
'id' => 'dashboard',
|
||||
'title' => __( 'Tools Dashboard', 'woocommerce-jetpack' ),
|
||||
),
|
||||
) );
|
||||
$html = '<h2 class="nav-tab-wrapper woo-nav-tab-wrapper">';
|
||||
$active_tab = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : 'dashboard';
|
||||
foreach ( $tabs as $tab ) {
|
||||
$is_active = ( $active_tab === $tab['id'] ) ? 'nav-tab-active' : '';
|
||||
$html .= '<a href="' . add_query_arg( array( 'page' => 'wcj-tools', 'tab' => $tab['id'] ), get_admin_url() . 'admin.php' ) . '" class="nav-tab ' . $is_active . '">' . $tab['title'] . '</a>';
|
||||
}
|
||||
$html .= '</h2>';
|
||||
echo $html;
|
||||
|
||||
// Content
|
||||
if ( 'dashboard' === $active_tab ) {
|
||||
$title = __( 'Booster for WooCommerce Tools - Dashboard', 'woocommerce-jetpack' );
|
||||
$desc = __( 'This dashboard lets you check statuses and short descriptions of all available Booster for WooCommerce tools. Tools can be enabled through WooCommerce > Settings > Booster. Enabled tools will appear in the tabs menu above.', 'woocommerce-jetpack' );
|
||||
echo '<h3>' . $title . '</h3>';
|
||||
echo '<p>' . $desc . '</p>';
|
||||
echo '<table class="widefat" style="width:90%;">';
|
||||
echo '<tr>';
|
||||
echo '<th style="width:20%;">' . __( 'Tool', 'woocommerce-jetpack' ) . '</th>';
|
||||
echo '<th style="width:20%;">' . __( 'Module', 'woocommerce-jetpack' ) . '</th>';
|
||||
echo '<th style="width:50%;">' . __( 'Description', 'woocommerce-jetpack' ) . '</th>';
|
||||
echo '<th style="width:10%;">' . __( 'Status', 'woocommerce-jetpack' ) . '</th>';
|
||||
echo '</tr>';
|
||||
do_action( 'wcj_tools_' . 'dashboard' );
|
||||
echo '</table>';
|
||||
} else {
|
||||
do_action( 'wcj_tools_' . $active_tab );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Tools();
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Modules Array
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.2.0
|
||||
* @author Algoritmika Ltd.
|
||||
* @todo (maybe) split "Shipping & Orders", "Cart & Checkout", "Products", "Prices & Currencies" etc.
|
||||
*/
|
||||
|
||||
return apply_filters( 'wcj_modules', array(
|
||||
|
||||
'dashboard' => array(
|
||||
'label' => __( 'Dashboard', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'This dashboard lets you enable/disable any Booster\'s module. Each checkbox comes with short module\'s description. Please visit <a href="https://booster.io" target="_blank">https://booster.io</a> for detailed info on each feature.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'alphabetically',
|
||||
'by_category',
|
||||
'active',
|
||||
'manager',
|
||||
),
|
||||
),
|
||||
|
||||
'prices_and_currencies' => array(
|
||||
'label' => __( 'Prices & Currencies', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'Multicurrency, Price Converter, Wholesale Pricing, Name You Price, Price based on User Role and more.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'price_by_country',
|
||||
'multicurrency',
|
||||
'multicurrency_base_price',
|
||||
'currency_per_product',
|
||||
'currency',
|
||||
'currency_external_products',
|
||||
'bulk_price_converter',
|
||||
'wholesale_price',
|
||||
'product_open_pricing',
|
||||
'offer_price',
|
||||
'price_by_user_role',
|
||||
'product_price_by_formula',
|
||||
'global_discount',
|
||||
'currency_exchange_rates',
|
||||
'price_formats',
|
||||
),
|
||||
),
|
||||
|
||||
'labels' => array(
|
||||
'label' => __( 'Button & Price Labels', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'Add to Cart Labels, Call for Price, Custom Price Labels and more.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'price_labels',
|
||||
'call_for_price',
|
||||
'free_price',
|
||||
'add_to_cart',
|
||||
'more_button_labels',
|
||||
),
|
||||
),
|
||||
|
||||
'products' => array(
|
||||
'label' => __( 'Products', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'Bookings, Crowdfunding Products, Product Addons and Input Fields, Product Listings, Product Tabs and more.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'product_listings',
|
||||
'tax_display',
|
||||
'admin_products_list',
|
||||
'products_per_page',
|
||||
'product_tabs',
|
||||
'product_custom_info',
|
||||
'related_products',
|
||||
'cross_sells',
|
||||
'upsells',
|
||||
'sorting',
|
||||
'sku',
|
||||
'stock',
|
||||
'product_input_fields',
|
||||
'product_add_to_cart',
|
||||
'add_to_cart_button_visibility',
|
||||
'purchase_data',
|
||||
'product_bookings',
|
||||
'crowdfunding',
|
||||
'product_addons',
|
||||
'product_images',
|
||||
'sale_flash',
|
||||
'product_by_country',
|
||||
'product_by_user_role',
|
||||
'product_custom_visibility',
|
||||
'product_by_time',
|
||||
'product_by_date',
|
||||
'product_by_user',
|
||||
'products_xml',
|
||||
'product_bulk_meta_editor',
|
||||
'product_msrp',
|
||||
),
|
||||
),
|
||||
|
||||
'cart_and_checkout' => array(
|
||||
'label' => __( 'Cart & Checkout', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'Cart and Checkout Customization, Empty Cart Button, Mini Cart, Coupons and more.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'cart',
|
||||
'cart_customization',
|
||||
'empty_cart',
|
||||
'mini_cart',
|
||||
'url_coupons',
|
||||
'coupon_code_generator',
|
||||
'coupon_by_user_role',
|
||||
'checkout_core_fields',
|
||||
'checkout_custom_fields',
|
||||
'checkout_files_upload',
|
||||
'checkout_custom_info',
|
||||
'checkout_customization',
|
||||
'checkout_fees',
|
||||
'eu_vat_number',
|
||||
),
|
||||
),
|
||||
|
||||
'payment_gateways' => array(
|
||||
'label' => __( 'Payment Gateways', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'Custom Payment Gateways, Gateways Currency, Gateways Fees and Discounts and more.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'payment_gateways',
|
||||
'payment_gateways_icons',
|
||||
'payment_gateways_fees',
|
||||
'payment_gateways_per_category',
|
||||
'payment_gateways_currency',
|
||||
'payment_gateways_by_currency',
|
||||
'payment_gateways_min_max',
|
||||
'payment_gateways_by_country',
|
||||
'payment_gateways_by_user_role',
|
||||
'payment_gateways_by_shipping',
|
||||
),
|
||||
),
|
||||
|
||||
'shipping_and_orders' => array(
|
||||
'label' => __( 'Shipping & Orders', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'Order Custom Statuses, Order Minimum Amount, Order Numbers, Custom Shipping Methods and more.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'shipping',
|
||||
'shipping_options',
|
||||
'shipping_icons',
|
||||
'shipping_description',
|
||||
'shipping_time',
|
||||
'left_to_free_shipping',
|
||||
'shipping_calculator',
|
||||
'shipping_by_user_role',
|
||||
'shipping_by_products',
|
||||
'shipping_by_cities',
|
||||
'shipping_by_order_amount',
|
||||
'address_formats',
|
||||
'orders',
|
||||
'admin_orders_list',
|
||||
'order_min_amount',
|
||||
'order_numbers',
|
||||
'order_custom_statuses',
|
||||
'order_quantities',
|
||||
'max_products_per_user',
|
||||
),
|
||||
),
|
||||
|
||||
'pdf_invoicing' => array(
|
||||
'label' => __( 'PDF Invoicing & Packing Slips', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'PDF Documents', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'pdf_invoicing',
|
||||
'pdf_invoicing_numbering',
|
||||
'pdf_invoicing_templates',
|
||||
'pdf_invoicing_header',
|
||||
'pdf_invoicing_footer',
|
||||
'pdf_invoicing_styling',
|
||||
'pdf_invoicing_page',
|
||||
'pdf_invoicing_emails',
|
||||
'pdf_invoicing_display',
|
||||
'pdf_invoicing_advanced',
|
||||
),
|
||||
),
|
||||
|
||||
'emails_and_misc' => array(
|
||||
'label' => __( 'Emails & Misc.', 'woocommerce-jetpack' ),
|
||||
'desc' => __( 'Emails, Reports, Export, Admin Tools, General Options and more.', 'woocommerce-jetpack' ),
|
||||
'all_cat_ids' => array(
|
||||
'general',
|
||||
'breadcrumbs',
|
||||
'admin_bar',
|
||||
'export',
|
||||
'my_account',
|
||||
'old_slugs',
|
||||
'reports',
|
||||
'admin_tools',
|
||||
'emails',
|
||||
'email_options',
|
||||
'emails_verification',
|
||||
'wpml',
|
||||
'custom_css',
|
||||
'custom_js',
|
||||
'track_users',
|
||||
'modules_by_user_roles',
|
||||
'product_info', // deprecated
|
||||
),
|
||||
),
|
||||
|
||||
) );
|
||||
Reference in New Issue
Block a user