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 '
';
$array_keys = array_keys( $this->cats );
foreach ( $this->cats as $id => $label_info ) {
echo '' . $label_info['label'] . ' ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' ';
}
echo ' ' . ' ';
}
/**
* 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' ) . ' (' . $all . ') ';
$sections['by_category'] = __( 'By Category', 'woocommerce-jetpack' ) . ' (' . $all . ') ';
$sections['active'] = __( 'Active', 'woocommerce-jetpack' ) . ' (' . $active . ') ';
$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[] = '' . $label . ' ';
}
echo '' . '' . implode( ' | ', $menu_links ) . ' ' . ' ' . ' ';
}
/**
* 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 '';
}
$is_dashboard = $this->is_dashboard_section( $current_section );
// Deprecated message
if ( $replacement_module = wcj_is_module_deprecated( $current_section ) ) {
echo '';
echo '
';
echo '';
echo sprintf(
__( 'Please note that current %s module is deprecated and will be removed in future updates. Please use %s module instead.', 'woocommerce-jetpack' ),
WCJ()->modules[ $current_section ]->short_desc,
'' .
$replacement_module['title'] . ' '
);
echo ' ' . __( 'Module will be removed from the module\'s list as soon as you disable it.', 'woocommerce-jetpack' ) . ' ';
echo ' ';
echo '
';
echo '
';
}
// "Under development" message
if ( isset( WCJ()->modules[ $current_section ]->dev ) && true === WCJ()->modules[ $current_section ]->dev ) {
echo '';
echo '
';
echo '';
echo sprintf( __( 'Please note that %s 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 ' ';
echo '
';
echo '
';
}
if ( 'yes' === get_option( 'wcj_admin_tools_enabled', 'no' ) && 'yes' === get_option( 'wcj_debuging_enabled', 'no' ) ) {
// Breadcrumbs
$breadcrumbs_html = '';
$breadcrumbs_html .= '';
$breadcrumbs_html .= '';
$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 .= '';
$breadcrumbs_html .= '
';
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 '' . $the_settings[0]['title'] . ' ';
if ( isset( $this->custom_dashboard_modules[ $current_section ] ) ) {
echo '' . $this->custom_dashboard_modules[ $current_section ]['desc'] . '
';
} elseif ( 'manager' != $current_section ) {
echo '' . $the_settings[0]['desc'] . '
';
} else {
echo '' . __( 'This section lets you export, import or reset all Booster\'s modules settings.', 'woocommerce-jetpack' ) . '
';
}
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 '' . $cat_label_info['label'] . ' ';
}
$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(
'' . __( 'Export', 'woocommerce-jetpack' ) . ' ',
'' . __( 'Export all Booster\'s options to a file.', 'woocommerce-jetpack' ) . ' ',
),
array(
'' . __( 'Import', 'woocommerce-jetpack' ) . ' ' .
' ' . ' ',
'' . __( 'Import all Booster\'s options from a file.', 'woocommerce-jetpack' ) . ' ',
),
array(
'' .
__( 'Reset', 'woocommerce-jetpack' ) . ' ',
'' . __( 'Reset all Booster\'s options.', 'woocommerce-jetpack' ) . ' ',
),
array(
'' .
__( 'Reset meta', 'woocommerce-jetpack' ) . ' ',
'' . __( 'Reset all Booster\'s meta.', 'woocommerce-jetpack' ) . ' ',
),
);
$manager_settings = $this->get_manager_settings();
foreach ( $manager_settings as $manager_settings_field ) {
$table_data[] = array(
'' .
' ' .
' ' . '' . $manager_settings_field['title'] . ' ' .
' ',
'' . $manager_settings_field['desc'] . ' ',
);
}
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'],
'' .
' ' . ' ' . '' . $_settings['desc'] . ' ' .
' ',
);
}
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 '' . $plugin_title .
__( 'Version', 'woocommerce-jetpack' ) . ': ' . get_option( WCJ_VERSION_OPTION, 'N/A' ) . '
';
}
/**
* 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 = '' ) {
?>
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();