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'; $rtl = is_rtl() ? '.rtl' : ''; 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' . $rtl . '.js', array('jquery'), true, false ); wp_register_script( 'jquery-ui-slider-rtl', $this->admin_plugin_url() . '/assets/js/ui-slider/jquery.ui.slider.rtl' . $suffix . '.js', array('jquery'), true, true ); 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_register_script( 'a3rev-metabox-ui', $this->admin_plugin_url() . '/assets/js/data-meta-boxes.js', array( 'jquery' ), true, true ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'wp-color-picker' ); if ( is_rtl() ) { wp_enqueue_script( 'jquery-ui-slider-rtl' ); } else { 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' ); wp_enqueue_script( 'a3rev-metabox-ui' ); } // 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' . $suffix . '.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' . $suffix . '.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' ); wp_enqueue_style( 'a3rev-metabox-ui-style', $this->admin_plugin_url() . '/assets/css/a3_admin_metabox.css' ); if ( is_rtl() ) { wp_enqueue_style( 'a3rev-admin-ui-style-rtl', $this->admin_plugin_url() . '/assets/css/admin-ui-style.rtl' . $suffix . '.css' ); wp_enqueue_style( 'a3rev-metabox-ui-style-rtl', $this->admin_plugin_url() . '/assets/css/a3_admin_metabox.rtl' . $suffix . '.css' ); } } // End admin_css_load() /*-----------------------------------------------------------------------------------*/ /* get_success_message */ /*-----------------------------------------------------------------------------------*/ public function get_success_message( $message = '' ) { if ( trim( $message ) == '' ) $message = __( 'Settings successfully saved.' , 'a3_portfolios' ); return '

' . $message . '

'; } /*-----------------------------------------------------------------------------------*/ /* get_error_message */ /*-----------------------------------------------------------------------------------*/ public function get_error_message( $message = '' ) { if ( trim( $message ) == '' ) $message = __( 'Error: Settings can not save.' , 'a3_portfolios' ); return '

' . $message . '

'; } /*-----------------------------------------------------------------------------------*/ /* get_reset_message */ /*-----------------------------------------------------------------------------------*/ public function get_reset_message( $message = '' ) { if ( trim( $message ) == '' ) $message = __( 'Settings successfully reseted.' , 'a3_portfolios' ); return '

' . $message . '

'; } /*-----------------------------------------------------------------------------------*/ /* 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_portfolios' ), '300 italic' => __( 'Thin/Italic', 'a3_portfolios' ), 'normal' => __( 'Normal', 'a3_portfolios' ), 'italic' => __( 'Italic', 'a3_portfolios' ), 'bold' => __( 'Bold', 'a3_portfolios' ), 'bold italic' => __( 'Bold/Italic', 'a3_portfolios' ), ); return apply_filters( $this->plugin_name . '_font_weights', $font_weights ); } /*-----------------------------------------------------------------------------------*/ /* Get Border Styles */ /*-----------------------------------------------------------------------------------*/ public function get_border_styles() { $border_styles = array ( 'solid' => __( 'Solid', 'a3_portfolios' ), 'double' => __( 'Double', 'a3_portfolios' ), 'dashed' => __( 'Dashed', 'a3_portfolios' ), 'dotted' => __( 'Dotted', 'a3_portfolios' ), 'groove' => __( 'Groove', 'a3_portfolios' ), 'ridge' => __( 'Ridge', 'a3_portfolios' ), 'inset' => __( 'Inset', 'a3_portfolios' ), 'outset' => __( 'Outset', 'a3_portfolios' ), ); 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_portfolio_fonts_face, $a3_portfolio_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 . '_before_settings_save_reset' ); 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 ) . '_after_settings_save' ); do_action( $this->plugin_name . '_after_settings_save_reset' ); } do_action( $this->plugin_name . '-' . trim( $form_key ) . '_settings_init' ); do_action( $this->plugin_name . '_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"; if ( ! empty( $value['id'] ) ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $value['id'] ) . '_start' ); break; // Standard text inputs and subtypes like 'number' case 'text': case 'email': case 'number': case 'password' : $type = $value['type']; ?>settings_get_option( $value['id'] . '[width]', $value['default']['width'] ); $height = $this->settings_get_option( $value['id'] . '[height]', $value['default']['height'] ); $crop = checked( 1, $this->settings_get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false ); } else { $width = $option_value['width']; $height = $option_value['height']; $crop = checked( 1, $option_value['crop'], false ); } ?> $name_attribute, 'id' => $id_attribute, 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'show_option_none' => ' ', 'class' => 'a3rev-ui-' . sanitize_title( $value['type'] ) . ' ' . $value['class'], 'echo' => false, 'selected' => absint( $option_value ) ); if( isset( $value['args'] ) ) $args = wp_parse_args( $value['args'], $args ); ?>settings_get_option( $value['id'] . '[size]', $value['default']['size'] ); $face = $this->settings_get_option( $value['id'] . '[face]', $value['default']['face'] ); $style = $this->settings_get_option( $value['id'] . '[style]', $value['default']['style'] ); $color = $this->settings_get_option( $value['id'] . '[color]', $value['default']['color'] ); } else { $size = $option_value['size']; $face = $option_value['face']; $style = $option_value['style']; $color = $option_value['color']; } ?>settings_get_option( $value['id'] . '[width]', $value['default']['width'] ); $style = $this->settings_get_option( $value['id'] . '[style]', $value['default']['style'] ); $color = $this->settings_get_option( $value['id'] . '[color]', $value['default']['color'] ); } else { $width = $option_value['width']; $style = $option_value['style']; $color = $option_value['color']; } // For Border Corner if ( ! isset( $value['min'] ) ) $value['min'] = 0; if ( ! isset( $value['max'] ) ) $value['max'] = 100; if ( ! isset( $value['increment'] ) ) $value['increment'] = 1; if ( trim( $option_name ) != '' && $value['separate_option'] != false ) { $corner = $this->settings_get_option( $value['id'] . '[corner]', $value['default']['corner'] ); if ( ! isset( $value['default']['rounded_value'] ) ) $value['default']['rounded_value'] = 3; $rounded_value = $this->settings_get_option( $value['id'] . '[rounded_value]', $value['default']['rounded_value'] ); if ( ! isset( $value['default']['top_left_corner'] ) ) $value['default']['top_left_corner'] = 3; $top_left_corner = $this->settings_get_option( $value['id'] . '[top_left_corner]', $value['default']['top_left_corner'] ); if ( ! isset( $value['default']['top_right_corner'] ) ) $value['default']['top_right_corner'] = 3; $top_right_corner = $this->settings_get_option( $value['id'] . '[top_right_corner]', $value['default']['top_right_corner'] ); if ( ! isset( $value['default']['bottom_left_corner'] ) ) $value['default']['bottom_left_corner'] = 3; $bottom_left_corner = $this->settings_get_option( $value['id'] . '[bottom_left_corner]', $value['default']['bottom_left_corner'] ); if ( ! isset( $value['default']['bottom_right_corner'] ) ) $value['default']['bottom_right_corner'] = 3; $bottom_right_corner = $this->settings_get_option( $value['id'] . '[bottom_right_corner]', $value['default']['bottom_right_corner'] ); } else { if ( ! isset( $option_value['corner'] ) ) $option_value['corner'] = ''; $corner = $option_value['corner']; if ( ! isset( $option_value['rounded_value'] ) ) $option_value['rounded_value'] = 3; $rounded_value = $option_value['rounded_value']; if ( ! isset( $option_value['top_left_corner'] ) ) $option_value['top_left_corner'] = 3; $top_left_corner = $option_value['top_left_corner']; if ( ! isset( $option_value['top_right_corner'] ) ) $option_value['top_right_corner'] = 3; $top_right_corner = $option_value['top_right_corner']; if ( ! isset( $option_value['bottom_left_corner'] ) ) $option_value['bottom_left_corner'] = 3; $bottom_left_corner = $option_value['bottom_left_corner']; if ( ! isset( $option_value['bottom_right_corner'] ) ) $option_value['bottom_right_corner'] = 3; $bottom_right_corner = $option_value['bottom_right_corner']; } if ( trim( $rounded_value ) == '' || trim( $rounded_value ) <= 0 ) $rounded_value = $value['min']; $rounded_value = intval( $rounded_value ); if ( trim( $top_left_corner ) == '' || trim( $top_left_corner ) <= 0 ) $top_left_corner = $rounded_value; $top_left_corner = intval( $top_left_corner ); if ( trim( $top_right_corner ) == '' || trim( $top_right_corner ) <= 0 ) $top_right_corner = $rounded_value; $top_right_corner = intval( $top_right_corner ); if ( trim( $bottom_left_corner ) == '' || trim( $bottom_left_corner ) <= 0 ) $bottom_left_corner = $rounded_value; $bottom_left_corner = intval( $bottom_left_corner ); if ( trim( $bottom_right_corner ) == '' || trim( $bottom_right_corner ) <= 0 ) $bottom_right_corner = $rounded_value; $bottom_right_corner = intval( $bottom_right_corner ); ?>settings_get_option( $value['id'] . '[width]', $value['default']['width'] ); $style = $this->settings_get_option( $value['id'] . '[style]', $value['default']['style'] ); $color = $this->settings_get_option( $value['id'] . '[color]', $value['default']['color'] ); } else { $width = $option_value['width']; $style = $option_value['style']; $color = $option_value['color']; } ?>settings_get_option( $value['id'] . '[corner]', $value['default']['corner'] ); if ( ! isset( $value['default']['rounded_value'] ) ) $value['default']['rounded_value'] = 3; $rounded_value = $this->settings_get_option( $value['id'] . '[rounded_value]', $value['default']['rounded_value'] ); if ( ! isset( $value['default']['top_left_corner'] ) ) $value['default']['top_left_corner'] = 3; $top_left_corner = $this->settings_get_option( $value['id'] . '[top_left_corner]', $value['default']['top_left_corner'] ); if ( ! isset( $value['default']['top_right_corner'] ) ) $value['default']['top_right_corner'] = 3; $top_right_corner = $this->settings_get_option( $value['id'] . '[top_right_corner]', $value['default']['top_right_corner'] ); if ( ! isset( $value['default']['bottom_left_corner'] ) ) $value['default']['bottom_left_corner'] = 3; $bottom_left_corner = $this->settings_get_option( $value['id'] . '[bottom_left_corner]', $value['default']['bottom_left_corner'] ); if ( ! isset( $value['default']['bottom_right_corner'] ) ) $value['default']['bottom_right_corner'] = 3; $bottom_right_corner = $this->settings_get_option( $value['id'] . '[bottom_right_corner]', $value['default']['bottom_right_corner'] ); } else { if ( ! isset( $option_value['corner'] ) ) $option_value['corner'] = ''; $corner = $option_value['corner']; if ( ! isset( $option_value['rounded_value'] ) ) $option_value['rounded_value'] = 3; $rounded_value = $option_value['rounded_value']; if ( ! isset( $option_value['top_left_corner'] ) ) $option_value['top_left_corner'] = 3; $top_left_corner = $option_value['top_left_corner']; if ( ! isset( $option_value['top_right_corner'] ) ) $option_value['top_right_corner'] = 3; $top_right_corner = $option_value['top_right_corner']; if ( ! isset( $option_value['bottom_left_corner'] ) ) $option_value['bottom_left_corner'] = 3; $bottom_left_corner = $option_value['bottom_left_corner']; if ( ! isset( $option_value['bottom_right_corner'] ) ) $option_value['bottom_right_corner'] = 3; $bottom_right_corner = $option_value['bottom_right_corner']; } if ( trim( $rounded_value ) == '' || trim( $rounded_value ) <= 0 ) $rounded_value = $value['min']; $rounded_value = intval( $rounded_value ); if ( trim( $top_left_corner ) == '' || trim( $top_left_corner ) <= 0 ) $top_left_corner = $rounded_value; $top_left_corner = intval( $top_left_corner ); if ( trim( $top_right_corner ) == '' || trim( $top_right_corner ) <= 0 ) $top_right_corner = $rounded_value; $top_right_corner = intval( $top_right_corner ); if ( trim( $bottom_left_corner ) == '' || trim( $bottom_left_corner ) <= 0 ) $bottom_left_corner = $rounded_value; $bottom_left_corner = intval( $bottom_left_corner ); if ( trim( $bottom_right_corner ) == '' || trim( $bottom_right_corner ) <= 0 ) $bottom_right_corner = $rounded_value; $bottom_right_corner = intval( $bottom_right_corner ); ?>settings_get_option( $value['id'] . '[enable]', $value['default']['enable'] ); $h_shadow = $this->settings_get_option( $value['id'] . '[h_shadow]', $value['default']['h_shadow'] ); $v_shadow = $this->settings_get_option( $value['id'] . '[v_shadow]', $value['default']['v_shadow'] ); $blur = $this->settings_get_option( $value['id'] . '[blur]', $value['default']['blur'] ); $spread = $this->settings_get_option( $value['id'] . '[spread]', $value['default']['spread'] ); $color = $this->settings_get_option( $value['id'] . '[color]', $value['default']['color'] ); $inset = $this->settings_get_option( $value['id'] . '[inset]', $value['default']['inset'] ); } else { if ( ! isset( $option_value['enable'] ) ) $option_value['enable'] = 0; $enable = $option_value['enable']; if ( ! isset( $option_value['inset'] ) ) $option_value['inset'] = ''; $h_shadow = $option_value['h_shadow']; $v_shadow = $option_value['v_shadow']; $blur = $option_value['blur']; $spread = $option_value['spread']; $color = $option_value['color']; $inset = $option_value['inset']; } ?>plugin_name . '_admin_field_' . $value['type'], $value ); break; } } // :) 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 ); } 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 ); } } } } if ( $end_heading_id !== false ) { if ( trim( $end_heading_id ) != '' ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $end_heading_id ) . '_end' ); echo '
/>
/>
    0 ) { foreach ( $value['options'] as $val => $text ) { ?>
    0 ) { foreach ( $value['onoff_options'] as $i_option ) { if ( ! isset( $i_option['checked_label'] ) ) $i_option['checked_label'] = __( 'ON', 'a3_portfolios' ); if ( ! isset( $i_option['unchecked_label'] ) ) $i_option['unchecked_label'] = __( 'OFF', 'a3_portfolios' ); if ( ! isset( $i_option['val'] ) ) $i_option['val'] = 1; if ( ! isset( $i_option['text'] ) ) $i_option['text'] = ''; ?>
  • class="a3rev-ui-onoff_radio " checked_label="" unchecked_label="" type="radio" value="" />
/>
/>
/>
/>
/>
px
px
px
px
/>
/>
px
px
px
px
/>
/> />
/>
upload_input( $name_attribute, $id_attribute, $option_value, $value['default'], esc_html( $value['name'] ), $class, esc_attr( $value['css'] ) , '' );?>
$name_attribute, 'wpautop' => true, 'editor_class' => 'a3rev-ui-' . sanitize_title( $value['type'] ) . ' ' . esc_attr( $value['class'] ), 'textarea_rows' => $value['textarea_rows'] ) ); ?>
settings_get_option( $text_field['id'], $text_field['default'] ); } // Get option value when it's an element from option array else { if ( $key != false ) { $option_value = ( isset( $option_values[ $id_attribute ][ $key ] ) ) ? $option_values[ $id_attribute ][ $key ] : $text_field['default']; } else { $option_value = ( isset( $option_values[ $id_attribute ] ) ) ? $option_values[ $id_attribute ] : $text_field['default']; } } // Generate name and id attributes if ( trim( $option_name ) == '' ) { $name_attribute = esc_attr( $text_field['id'] ); } elseif ( $value['separate_option'] != false ) { $name_attribute = esc_attr( $text_field['id'] ); $id_attribute = esc_attr( $option_name ) . '_' . $id_attribute; } else { // Array value if ( strstr( $text_field['id'], '[' ) ) { $name_attribute = esc_attr( $option_name ) . '[' . $id_attribute . ']' . str_replace( $id_attribute . '[', '[', esc_attr( $text_field['id'] ) ); } else { $name_attribute = esc_attr( $option_name ) . '[' . esc_attr( $text_field['id'] ) . ']'; } $id_attribute = esc_attr( $option_name ) . '_' . $id_attribute; } ?>
' . "\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' ); ?>