settings_api = new WeDevs_Settings_API;
// Used for getting sliders list in settings
$this->mspdb = new MSP_DB;
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 11 );
add_action( 'admin_action_msp_envato_license', array( $this, 'envato_license_updated' ) );
add_action( 'admin_footer', array( $this, 'print_setting_script' ) );
add_filter( 'axiom_wedev_setting_section_submit_button', array( $this, 'section_submit_button' ), 10, 2 );
}
function admin_init() {
//set the settings
$this->settings_api->set_sections( $this->get_settings_sections() );
$this->settings_api->set_fields ( $this->get_settings_fields() );
//initialize settings
$this->settings_api->admin_init();
$this->flush_sliders_cache();
}
function flush_sliders_cache(){
if( isset( $_POST['msp_general_setting'] ) ){
if( isset( $_POST['msp_general_setting']['_enable_cache'] ) && 'on' == $_POST['msp_general_setting']['_enable_cache'] ){
msp_flush_all_sliders_cache();
}
}
}
// Get list of sliders
function list_sliders() {
$html = '';
$sliders = $this->mspdb->get_sliders();
$html = '
';
return $html;
}
function section_submit_button( $button_markup, $section ){
if( isset( $section['id'] ) && 'msp_envato_license' == $section['id'] ){
$is_license_actived = get_option( MSWP_SLUG . '_is_license_actived', 0 );
return sprintf( '%1$s%5$s',
__( 'Activate License', MSWP_TEXT_DOMAIN ), __( 'Deactivate License', MSWP_TEXT_DOMAIN ), (int)$is_license_actived,
__( 'Validating ..', MSWP_TEXT_DOMAIN ), 'is not actived
' );
}
if( isset( $section['id'] ) && 'msp_replacer' == $section['id'] ){
return sprintf( '',
__( 'Start', MSWP_TEXT_DOMAIN ), wp_create_nonce( 'msprp-nonce' ) );
}
return $button_markup;
}
function admin_menu() {
add_submenu_page(
MSWP_SLUG,
__( 'Settings' , MSWP_TEXT_DOMAIN ),
__( 'Settings' , MSWP_TEXT_DOMAIN ),
apply_filters( 'masterslider_setting_capability', 'manage_options' ),
MSWP_SLUG . '-setting',
array( $this, 'render_setting_page' )
);
}
function get_settings_sections() {
$sections = array(
array(
'id' => 'msp_general_setting',
'title' => __( 'General Settings', MSWP_TEXT_DOMAIN )
)
);
if( ! apply_filters( MSWP_SLUG.'_disable_auto_update', 0 ) ) {
$sections[] = array(
'id' => 'msp_envato_license',
'title' => __( 'Activation', MSWP_TEXT_DOMAIN ),
'desc' => __( 'By activating your license you can enable "automatic update" for Master Slider and grant access to premium sample sliders library. A valida and direct license of Master Slider is required.', MSWP_TEXT_DOMAIN ) . ' ' . __( 'More about activating and deactivating license', MSWP_TEXT_DOMAIN ) . ''
);
}
$woo_enabled = msp_is_plugin_active( 'woocommerce/woocommerce.php' );
$woo_section_desc = $woo_enabled ? '': __( 'You need to install and activate WooCommerce plugin to use following options.', MSWP_TEXT_DOMAIN );
$sections[] = array(
'id' => 'msp_woocommerce',
'title' => __( 'WooCommerce Setting', MSWP_TEXT_DOMAIN ),
'desc' => $woo_section_desc
);
$sections[] = array(
'id' => 'msp_advanced',
'title' => __( 'Advanced Setting', MSWP_TEXT_DOMAIN )
);
$sections[] = array(
'id' => 'msp_replacer',
'title' => __( 'Replace Settings', MSWP_TEXT_DOMAIN )
);
return $sections;
}
/**
* Returns all the settings fields
*
* @return array settings fields
*/
function get_settings_fields() {
$settings_fields = array();
$settings_fields['msp_general_setting'] = array(
array(
'name' => 'hide_info_table',
'label' => __( 'Hide info table', MSWP_TEXT_DOMAIN ),
'desc' => __( 'If you want to hide "Latest video tutorials" table on master slider admin panel check this field.', MSWP_TEXT_DOMAIN ),
'type' => 'checkbox'
),
array(
'name' => '_enable_cache',
'label' => __( 'Enable cache?', MSWP_TEXT_DOMAIN ),
'desc' => __( 'Enable cache to make Masterslider even more faster!', MSWP_TEXT_DOMAIN ),
'type' => 'checkbox'
),
array(
'name' => '_cache_period',
'label' => __( 'Cache period time', MSWP_TEXT_DOMAIN ),
'desc' => __( 'The cache refresh time in hours. Cache is also cleared when you click on "Save Changes" in slider panel.', MSWP_TEXT_DOMAIN ),
'type' => 'text',
'default' => '12',
'sanitize_callback' => 'floatval'
)
);
if( ! apply_filters( MSWP_SLUG.'_disable_auto_update', 0 ) ) {
$settings_fields['msp_envato_license'] = array(
array(
'name' => 'username',
'label' => __( 'Your Envato Username' , MSWP_TEXT_DOMAIN ),
'desc' => sprintf( ' (%s)',
__( 'How to find your envato username', MSWP_TEXT_DOMAIN ) ),
'type' => 'text',
'default' => ''
),
array(
'name' => 'purchase_code',
'label' => __( 'Master Slider Purchase Code' , MSWP_TEXT_DOMAIN ),
'desc' => __( 'Please enter purchase code for your Master Slider', MSWP_TEXT_DOMAIN ) . sprintf( ' (%s)',
__( "How to find your Item's Purchase Code", MSWP_TEXT_DOMAIN ) ),
'type' => 'password',
'default' => ''
)
);
}
$settings_fields['msp_woocommerce'] = array(
array(
'name' => 'enable_single_product_slider',
'label' => __( 'Enable slider in product single page', 'wedevs' ),
'desc' => __( 'Replace woocommerce default product slider in product single page with Masterslider', MSWP_TEXT_DOMAIN ),
'type' => 'checkbox'
)
);
$settings_fields['msp_advanced'] = array(
array(
'name' => 'allways_load_ms_assets',
'label' => __( 'Load assets on all pages?', MSWP_TEXT_DOMAIN ),
'desc' => __( 'By default, Master Slider will load corresponding JavaScript files on demand. but if you need to load assets on all pages, check this option. ( For example, if you plan to load Master Slider via Ajax, you need to check this option ) ', MSWP_TEXT_DOMAIN ),
'type' => 'checkbox'
)
);
$settings_fields['msp_replacer'] = array(
array(
'name' => 'msprp_list_sliders',
'label' => __( 'Select Slider', MSWP_TEXT_DOMAIN ),
'desc' => $this->list_sliders(),
'type' => 'html',
),
array(
'name' => 'msprp_search',
'label' => __( 'Search for:', MSWP_TEXT_DOMAIN ),
'desc' => ' ',
'type' => 'html'
),
array(
'name' => 'msprp_replace',
'label' => __( 'Replace with:', MSWP_TEXT_DOMAIN ),
'desc' => '',
'type' => 'html'
),
array(
'name' => 'msprp_case_sensitive',
'label' => '',
'desc' => '',
'type' => 'html'
),
array(
'name' => 'msprp_where',
'label' => __( 'Replace in:', MSWP_TEXT_DOMAIN ),
'desc' => ' ',
'type' => 'html'
),
array(
'name' => 'msprp_backup',
'label' => '',
'desc' => '',
'type' => 'html'
)
);
return $settings_fields;
}
function render_setting_page() {
echo '';
$this->settings_api->show_navigation();
$this->settings_api->show_forms();
echo '
';
}
/**
* Get all the pages
*
* @return array page names with key value pairs
*/
function get_pages() {
$pages = get_pages();
$pages_options = array();
if ( $pages ) {
foreach ($pages as $page) {
$pages_options[$page->ID] = $page->post_title;
}
}
return $pages_options;
}
/**
* This code uses localstorage for displaying active tabs
*
*/
function print_setting_script() {
if( ! ( isset( $_REQUEST['page'] ) && 'masterslider-setting' == $_REQUEST['page'] ) )
return;
?>