admin_includes();
add_action( 'init', array( $this, 'init_scripts' ) );
add_action( 'init', array( $this, 'init_styles' ) );
}
/*-----------------------------------------------------------------------------------*/
/* Init scripts */
/*-----------------------------------------------------------------------------------*/
public function init_scripts() {
$admin_pages = $this->admin_pages();
if ( is_admin() && isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $admin_pages ) ) {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_script_load' ) );
do_action( $this->plugin_name . '_init_scripts' );
}
}
/*-----------------------------------------------------------------------------------*/
/* Init styles */
/*-----------------------------------------------------------------------------------*/
public function init_styles() {
$admin_pages = $this->admin_pages();
if ( is_admin() && isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $admin_pages ) ) {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_css_load' ) );
do_action( $this->plugin_name . '_init_styles' );
}
}
/*-----------------------------------------------------------------------------------*/
/* admin_script_load */
/*-----------------------------------------------------------------------------------*/
public function admin_script_load() {
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_register_script( 'chosen', $this->admin_plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), true, false );
wp_register_script( 'a3rev-chosen-new', $this->admin_plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), true, false );
wp_register_script( 'a3rev-style-checkboxes', $this->admin_plugin_url() . '/assets/js/iphone-style-checkboxes.js', array('jquery'), true, false );
wp_register_script( 'a3rev-admin-ui-script', $this->admin_plugin_url() . '/assets/js/admin-ui-script.js', array('jquery'), true, true );
wp_register_script( 'a3rev-typography-preview', $this->admin_plugin_url() . '/assets/js/a3rev-typography-preview.js', array('jquery'), false, true );
wp_register_script( 'a3rev-settings-preview', $this->admin_plugin_url() . '/assets/js/a3rev-settings-preview.js', array('jquery'), false, true );
wp_register_script( 'jquery-tiptip', $this->admin_plugin_url() . '/assets/js/tipTip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), true, true );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'jquery-ui-slider' );
wp_enqueue_script( 'chosen' );
wp_enqueue_script( 'a3rev-chosen-new' );
wp_enqueue_script( 'a3rev-style-checkboxes' );
wp_enqueue_script( 'a3rev-admin-ui-script' );
wp_enqueue_script( 'a3rev-typography-preview' );
wp_enqueue_script( 'a3rev-settings-preview' );
wp_enqueue_script( 'jquery-tiptip' );
} // End admin_script_load()
/*-----------------------------------------------------------------------------------*/
/* admin_css_load */
/*-----------------------------------------------------------------------------------*/
public function admin_css_load () {
global $wp_version;
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'a3rev-admin-ui-style', $this->admin_plugin_url() . '/assets/css/admin-ui-style.css' );
if ( version_compare( $wp_version, '3.8', '>=' ) ) {
wp_enqueue_style( 'a3rev-admin-flat-ui-style', $this->admin_plugin_url() . '/assets/css/admin-flat-ui-style.css' );
}
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'a3rev-chosen-new-style', $this->admin_plugin_url() . '/assets/js/chosen/chosen' . $suffix . '.css' );
wp_enqueue_style( 'a3rev-tiptip-style', $this->admin_plugin_url() . '/assets/js/tipTip/tipTip.css' );
} // End admin_css_load()
/*-----------------------------------------------------------------------------------*/
/* get_success_message */
/*-----------------------------------------------------------------------------------*/
public function get_success_message( $message = '' ) {
if ( trim( $message ) == '' ) $message = __( 'Settings successfully saved.' , 'a3_responsive_slider' );
return '
';
}
/*-----------------------------------------------------------------------------------*/
/* get_error_message */
/*-----------------------------------------------------------------------------------*/
public function get_error_message( $message = '' ) {
if ( trim( $message ) == '' ) $message = __( 'Error: Settings can not save.' , 'a3_responsive_slider' );
return '';
}
/*-----------------------------------------------------------------------------------*/
/* get_reset_message */
/*-----------------------------------------------------------------------------------*/
public function get_reset_message( $message = '' ) {
if ( trim( $message ) == '' ) $message = __( 'Settings successfully reseted.' , 'a3_responsive_slider' );
return '';
}
/*-----------------------------------------------------------------------------------*/
/* admin_includes */
/* Include required core files used in admin UI.
/*-----------------------------------------------------------------------------------*/
public function admin_includes() {
// Includes Font Face Lib
include_once( 'includes/fonts_face.php' );
// Includes Uploader Lib
include_once( 'includes/uploader/class-uploader.php' );
}
/*-----------------------------------------------------------------------------------*/
/* Get Font Weights */
/*-----------------------------------------------------------------------------------*/
public function get_font_weights() {
$font_weights = array (
'300' => __( 'Thin', 'a3_responsive_slider' ),
'300 italic' => __( 'Thin/Italic', 'a3_responsive_slider' ),
'normal' => __( 'Normal', 'a3_responsive_slider' ),
'italic' => __( 'Italic', 'a3_responsive_slider' ),
'bold' => __( 'Bold', 'a3_responsive_slider' ),
'bold italic' => __( 'Bold/Italic', 'a3_responsive_slider' ),
);
return apply_filters( $this->plugin_name . '_font_weights', $font_weights );
}
/*-----------------------------------------------------------------------------------*/
/* Get Border Styles */
/*-----------------------------------------------------------------------------------*/
public function get_border_styles() {
$border_styles = array (
'solid' => __( 'Solid', 'a3_responsive_slider' ),
'double' => __( 'Double', 'a3_responsive_slider' ),
'dashed' => __( 'Dashed', 'a3_responsive_slider' ),
'dotted' => __( 'Dotted', 'a3_responsive_slider' ),
'groove' => __( 'Groove', 'a3_responsive_slider' ),
'ridge' => __( 'Ridge', 'a3_responsive_slider' ),
'inset' => __( 'Inset', 'a3_responsive_slider' ),
'outset' => __( 'Outset', 'a3_responsive_slider' ),
);
return apply_filters( $this->plugin_name . '_border_styles', $border_styles );
}
/*-----------------------------------------------------------------------------------*/
/* Get Settings Default Function - get_settings_default */
/* Just called for when option values is an array and it's in single option name for all settings
/*-----------------------------------------------------------------------------------*/
public function get_settings_default( $options, $option_name = '' ) {
$default_settings = array();
if ( !is_array( $options ) || count( $options ) < 1 ) return $default_settings;
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
switch ( $value['type'] ) {
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
// Do not include when it's separate option
if ( isset( $text_field['separate_option'] ) && $text_field['separate_option'] != false ) continue;
// Remove [, ] characters from id argument
if ( strstr( $text_field['id'], '[' ) ) {
parse_str( esc_attr( $text_field['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $text_field['id'] );
}
$default_settings[$id_attribute] = $text_field['default'];
}
break;
default :
// Do not include when it's separate option
if ( isset( $value['separate_option'] ) && $value['separate_option'] != false ) continue;
// Remove [, ] characters from id argument
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $value['id'] );
}
$default_settings[$id_attribute] = $value['default'];
break;
}
}
if ( trim( $option_name ) != '' ) $default_settings = apply_filters( $this->plugin_name . '_' . $option_name . '_default_settings' , $default_settings );
if ( ! is_array( $default_settings ) ) $default_settings = array();
return $default_settings;
}
/*-----------------------------------------------------------------------------------*/
/* Get Settings Function - get_settings */
/*-----------------------------------------------------------------------------------*/
public function get_settings( $options, $option_name = '' ) {
if ( !is_array( $options ) || count( $options ) < 1 ) return;
$new_settings = array(); $new_single_setting = ''; // :)
// Get settings for option values is an array and it's in single option name for all settings
if ( trim( $option_name ) != '' ) {
global $$option_name;
$default_settings = $this->get_settings_default( $options, $option_name );
$current_settings = get_option( $option_name );
if ( ! is_array( $current_settings ) ) $current_settings = array();
$current_settings = array_merge( $default_settings, $current_settings );
$current_settings = array_map( array( $this, 'admin_stripslashes' ), $current_settings );
$current_settings = apply_filters( $this->plugin_name . '_' . $option_name . '_get_settings' , $current_settings );
$$option_name = $current_settings;
}
// Get settings for option value is stored as a record or it's spearate option
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
// Remove [, ] characters from id argument
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $value['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
global $$id_attribute;
$current_setting = get_option( $id_attribute, $value['default'] );
switch ( $value['type'] ) {
// Array textfields
case 'wp_editor' :
if ( is_array( $current_setting ) )
$current_setting = array_map( array( $this, 'stripslashes' ), $current_setting );
elseif ( ! is_null( $current_setting ) )
$current_setting = stripslashes( $current_setting );
break;
default:
if ( is_array( $current_setting ) )
$current_setting = array_map( array( $this, 'admin_stripslashes' ), $current_setting );
elseif ( ! is_null( $current_setting ) )
$current_setting = esc_attr( stripslashes( $current_setting ) );
break;
}
$current_setting = apply_filters( $this->plugin_name . '_' . $id_attribute . '_get_setting' , $current_setting );
$$id_attribute = $current_setting;
}
}
// :)
if ( ! isset( $this->is_free_plugin ) || ! $this->is_free_plugin ) {
$fs = array( 0 => 'c', 1 => 'p', 2 => 'h', 3 => 'i', 4 => 'e', 5 => 'n', 6 => 'k', 7 => '_' );
$cs = array( 0 => 'U', 1 => 'g', 2 => 'p', 3 => 'r', 4 => 'd', 5 => 'a', 6 => 'e', 7 => '_' );
$check_settings_save = true;
if ( isset( $this->class_name ) && ! class_exists( $this->class_name . $cs[7] . $cs[0] . $cs[2] . $cs[1] . $cs[3] . $cs[5] . $cs[4] . $cs[6] ) ) {
$check_settings_save = false;
}
if ( ! function_exists( $this->plugin_name . $fs[7] . $fs[0] . $fs[2] . $fs[4] . $fs[0] . $fs[6] . $fs[7] . $fs[1] . $fs[3] . $fs[5] ) ) {
$check_settings_save = false;
}
if ( ! $check_settings_save ) {
if ( trim( $option_name ) != '' ) {
update_option( $option_name, $new_settings );
$$option_name = $new_settings;
}
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['free_version'] ) ) $value['free_version'] = false;
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
// Remove [, ] characters from id argument
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $value['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
update_option( $id_attribute, $new_single_setting );
$$id_attribute = $new_single_setting;
}
}
}
}
return true;
}
/*-----------------------------------------------------------------------------------*/
/* Save Settings Function - save_settings */
/*-----------------------------------------------------------------------------------*/
public function save_settings( $options, $option_name = '' ) {
if ( !is_array( $options ) || count( $options ) < 1 ) return;
if ( empty( $_POST ) ) return false;
$update_options = array();
$update_separate_options = array();
//var_dump($_POST);
// Get settings for option value is stored as a record or it's spearate option
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
// Remove [, ] characters from id argument
$key = false;
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
$key = key( $option_array[ $id_attribute ] );
} else {
$id_attribute = esc_attr( $value['id'] );
}
// Get the option name
$option_value = null;
switch ( $value['type'] ) {
// Checkbox type
case 'checkbox' :
case 'onoff_checkbox' :
case 'switcher_checkbox' :
if ( ! isset( $value['checked_value'] ) ) $value['checked_value'] = 1;
if ( ! isset( $value['unchecked_value'] ) ) $value['unchecked_value'] = 0;
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $key != false ) {
if ( isset( $_POST[ $id_attribute ][ $key ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
} else {
if ( isset( $_POST[ $id_attribute ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
}
} else {
if ( $key != false ) {
if ( isset( $_POST[ $option_name ][ $id_attribute ][ $key ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
}
}
break;
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
// Remove [, ] characters from id argument
$key = false;
if ( strstr( $text_field['id'], '[' ) ) {
parse_str( esc_attr( $text_field['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
$key = key( $option_array[ $id_attribute ] );
} else {
$id_attribute = esc_attr( $text_field['id'] );
}
// Get the option name
$option_value = null;
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $key != false ) {
if ( isset( $_POST[ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $id_attribute ] ) ) {
$option_value = $_POST[ $id_attribute ];
} else {
$option_value = '';
}
}
} else {
if ( $key != false ) {
if ( isset( $_POST[ $option_name ][ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ];
} else {
$option_value = '';
}
}
}
if ( strstr( $text_field['id'], '[' ) ) {
// Set keys and value
$key = key( $option_array[ $id_attribute ] );
$update_options[ $id_attribute ][ $key ] = $option_value;
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ][ $key ] = $option_value;
}
} else {
$update_options[ $id_attribute ] = $option_value;
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ] = $option_value;
}
}
}
break;
// Other types
default :
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $key != false ) {
if ( isset( $_POST[ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $id_attribute ] ) ) {
$option_value = $_POST[ $id_attribute ];
} else {
$option_value = '';
}
}
} else {
if ( $key != false ) {
if ( isset( $_POST[ $option_name ][ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ];
} else {
$option_value = '';
}
}
}
break;
}
if ( !in_array( $value['type'], array( 'array_textfields' ) ) ) {
if ( strstr( $value['id'], '[' ) ) {
// Set keys and value
$key = key( $option_array[ $id_attribute ] );
$update_options[ $id_attribute ][ $key ] = $option_value;
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ][ $key ] = $option_value;
}
} else {
$update_options[ $id_attribute ] = $option_value;
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ] = $option_value;
}
}
}
}
// Save settings for option values is an array and it's in single option name for all settings
if ( trim( $option_name ) != '' ) {
update_option( $option_name, $update_options );
}
// Save options if each option save in a row
if ( count( $update_options ) > 0 && trim( $option_name ) == '' ) {
foreach ( $update_options as $name => $value ) {
update_option( $name, $value );
}
}
// Save separate options
if ( count( $update_separate_options ) > 0 ) {
foreach ( $update_separate_options as $name => $value ) {
update_option( $name, $value );
}
}
return true;
}
/*-----------------------------------------------------------------------------------*/
/* Reset Function - reset_settings */
/*-----------------------------------------------------------------------------------*/
public function reset_settings( $options, $option_name = '', $reset = false, $free_version = false ) {
if ( !is_array( $options ) || count( $options ) < 1 ) return;
// Update settings default for option values is an array and it's in single option name for all settings
if ( trim( $option_name ) != '' ) {
$default_settings = $this->get_settings_default( $options, $option_name );
$current_settings = get_option( $option_name );
if ( ! is_array( $current_settings ) ) $current_settings = array();
$current_settings = array_merge( $default_settings, $current_settings );
if ( $reset && !$free_version ) {
update_option( $option_name, $default_settings );
} else {
if ( $free_version ) {
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
switch ( $value['type'] ) {
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
if ( ! isset( $text_field['free_version'] ) ) {
if ( ! isset( $value['free_version'] ) )
$text_field['free_version'] = false;
else
$text_field['free_version'] = $value['free_version'];
}
if ( $text_field['free_version'] ) unset( $default_settings[ $text_field['id']] );
}
break;
default :
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['free_version'] ) ) $value['free_version'] = false;
if ( $value['free_version'] ) unset( $default_settings[ $value['id']] );
break;
}
}
$current_settings = array_merge( $current_settings, $default_settings );
update_option( $option_name, $current_settings );
} else {
update_option( $option_name, $current_settings );
}
}
}
// Update settings default for option value is stored as a record or it's spearate option
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['free_version'] ) ) $value['free_version'] = false;
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
switch ( $value['type'] ) {
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
if ( ! isset( $text_field['free_version'] ) ) {
if ( ! isset( $value['free_version'] ) )
$text_field['free_version'] = false;
else
$text_field['free_version'] = $value['free_version'];
}
// Remove [, ] characters from id argument
if ( strstr( $text_field['id'], '[' ) ) {
parse_str( esc_attr( $text_field['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $text_field['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $reset && $text_field['free_version'] && !$free_version ) {
update_option( $id_attribute, $text_field['default'] );
} elseif ( $reset && !$text_field['free_version'] ) {
update_option( $id_attribute, $text_field['default'] );
} else {
add_option( $id_attribute, $text_field['default'] );
}
}
}
break;
default :
// Remove [, ] characters from id argument
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $value['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $reset && $value['free_version'] && !$free_version ) {
update_option( $id_attribute, $value['default'] );
} elseif ( $reset && !$value['free_version'] ) {
update_option( $id_attribute, $value['default'] );
} else {
add_option( $id_attribute, $value['default'] );
}
}
break;
}
}
}
/*-----------------------------------------------------------------------------------*/
/* Get Option Value Function - settings_get_option */
/* Just called for when each option has an option value for settings
/*-----------------------------------------------------------------------------------*/
public function settings_get_option( $option_name, $default = '' ) {
// Array value
if ( strstr( $option_name, '[' ) ) {
parse_str( $option_name, $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$option_name = current( $option_keys );
// Get value
$option_values = get_option( $option_name, '' );
$key = key( $option_array[ $option_name ] );
if ( isset( $option_values[ $key ] ) )
$option_value = $option_values[ $key ];
else
$option_value = null;
// Single value
} else {
$option_value = get_option( $option_name, null );
}
if ( is_array( $option_value ) )
$option_value = array_map( 'stripslashes', $option_value );
elseif ( ! is_null( $option_value ) )
$option_value = stripslashes( $option_value );
return $option_value === null ? $default : $option_value;
}
/**
* Output admin fields.
*
*
* @access public
* @param array $options : Opens array to output
* @param text $form_key : It's unique key for form to get correct save and reset action for this form
* @param text $option_name : Save all settings as array into database for a single option name
* @param array $form_messages : { 'success_message' => '', 'error_message' => '', 'reset_message' => '' }
* @return void
* ========================================================================
* Option Array Structure :
* type => heading | text | email | number | password | color | textarea | select | multiselect | radio | onoff_radio | checkbox | onoff_checkbox
* | switcher_checkbox | image_size | single_select_page | typography | border | border_styles | border_corner | box_shadow
* | slider | upload | wp_editor | array_textfields |
*
* id => text
* name => text
* free_version => true | false : if Yes then when save settings with $free_version = true, it does reset this option
* class => text
* css => text
* default => text : apply for other types
* array( 'width' => '125', 'height' => '125', 'crop' => 1 ) : apply image_size only
* array( 'size' => '9px', 'face' => 'Arial', 'style' => 'normal', 'color' => '#515151' ) : apply for typography only
* array( 'width' => '1px', 'style' => 'normal', 'color' => '#515151', 'corner' => 'rounded' | 'square' , 'top_left_corner' => 3,
* 'top_right_corner' => 3, 'bottom_left_corner' => 3, 'bottom_right_corner' => 3 ) : apply for border only
* array( 'width' => '1px', 'style' => 'normal', 'color' => '#515151' ) : apply for border_styles only
* array( 'corner' => 'rounded' | 'square' , 'top_left_corner' => 3, 'top_right_corner' => 3, 'bottom_left_corner' => 3,
* 'bottom_right_corner' => 3 ) : apply for border_corner only
* array( 'enable' => 1|0, 'h_shadow' => '5px' , 'v_shadow' => '5px', 'blur' => '2px' , 'spread' => '2px', 'color' => '#515151',
* 'inset' => '' | 'insert' ) : apply for box_shadow only
*
* desc => text
* desc_tip => text
* separate_option => true | false
* custom_attributes => array
* view_doc => allowed html code : apply for heading only
* placeholder => text : apply for input, email, number, password, textarea, select, multiselect and single_select_page
* hide_if_checked => true | false : apply for checkbox only
* show_if_checked => true | false : apply for checkbox only
* checkboxgroup => start | end : apply for checkbox only
* checked_value => text : apply for checkbox, onoff_checkbox, switcher_checkbox only ( it's value set to database when checkbox is checked )
* unchecked_value => text : apply for checkbox, onoff_checkbox, switcher_checkbox only ( it's value set to database when checkbox is unchecked )
* checked_label => text : apply for onoff_checkbox, switcher_checkbox only ( set it to show the text instead ON word default )
* unchecked_label => text : apply for onoff_checkbox, switcher_checkbox only ( set it to show the text instead OFF word default )
* options => array : apply for select, multiselect, radio types
*
* onoff_options => array : apply for onoff_radio only
* ---------------- example ---------------------
* array(
* array( 'val' => 1,
* 'text' => 'Top',
* 'checked_label' => 'ON',
* 'unchecked_value' => 'OFF' ),
*
* array( 'val' => 2,
* 'text' => 'Bottom',
* 'checked_label' => 'ON',
* 'unchecked_value' => 'OFF' ),
* )
* ---------------------------------------------
*
* args => array : apply for single_select_page only
* min => number : apply for slider, border, border_corner types only
* max => number : apply for slider, border, border_corner types only
* increment => number : apply for slider, border, border_corner types only
* textarea_rows => number : apply for wp_editor type only
*
* ids => array : apply for array_textfields only
* ---------------- example ---------------------
* array(
* array( 'id' => 'box_margin_top',
* 'name' => 'Top',
* 'class' => '',
* 'css' => 'width:40px;',
* 'default' => '10px' ),
*
* array( 'id' => 'box_margin_top',
* 'name' => 'Top',
* 'class' => '',
* 'css' => 'width:40px;',
* 'default' => '10px' ),
* )
* ---------------------------------------------
*
*/
public function admin_forms( $options, $form_key, $option_name = '', $form_messages = array() ) {
global $a3_responsive_slider_fonts_face, $a3_responsive_slider_uploader, $current_subtab;
$new_settings = array(); $new_single_setting = ''; // :)
$admin_message = '';
if ( isset( $_POST['form_name_action'] ) && $_POST['form_name_action'] == $form_key ) {
do_action( $this->plugin_name . '-' . trim( $form_key ) . '_before_settings_save' );
// Save settings action
if ( isset( $_POST['bt_save_settings'] ) ) {
$this->save_settings( $options, $option_name );
$admin_message = $this->get_success_message( ( isset( $form_messages['success_message'] ) ) ? $form_messages['success_message'] : '' );
}
// Reset settings action
elseif ( isset( $_POST['bt_reset_settings'] ) ) {
$this->reset_settings( $options, $option_name, true );
$admin_message = $this->get_success_message( ( isset( $form_messages['reset_message'] ) ) ? $form_messages['reset_message'] : '' );
}
}
do_action( $this->plugin_name . '-' . trim( $form_key ) . '_settings_init' );
$option_values = array();
if ( trim( $option_name ) != '' ) {
$option_values = get_option( $option_name, array() );
if ( is_array( $option_values ) )
$option_values = array_map( array( $this, 'admin_stripslashes' ), $option_values );
else
$option_values = array();
$default_settings = $this->get_settings_default( $options, $option_name );
$option_values = array_merge($default_settings, $option_values);
}
if ( !is_array( $options ) || count( $options ) < 1 ) return '';
?>
' . "\n\n";
if ( trim( $end_heading_id ) != '' ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $end_heading_id ) . '_after' );
}
if ( ! empty( $value['id'] ) )
$end_heading_id = $value['id'];
else
$end_heading_id = '';
$view_doc = ( isset( $value['view_doc'] ) ) ? $value['view_doc'] : '';
if ( ! empty( $value['id'] ) ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $value['id'] ) . '_before' );
echo '' . "\n\n";
if ( stristr( $value['class'], 'pro_feature_fields' ) !== false && ! empty( $value['id'] ) ) $this->upgrade_top_message( true, sanitize_title( $value['id'] ) );
elseif ( stristr( $value['class'], 'pro_feature_fields' ) !== false ) $this->upgrade_top_message( true );
echo ( ! empty( $value['name'] ) ) ? '
'. esc_html( $value['name'] ) .' '. $view_doc .' ' : '';
if ( ! empty( $value['desc'] ) ) echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
echo '
' . "\n\n";
echo '
' . "\n\n";
if ( trim( $end_heading_id ) != '' ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $end_heading_id ) . '_after' );
}
?>
plugin_name . '-' . trim( $form_key ) . '_settings_end' ); ?>