id = $id; $this->name = $name ? $name : $id; $this->options = array(); $this->data = get_option($this->id); add_action( 'admin_init', array($this, 'admin_init') ); add_action( 'admin_menu', array($this, 'admin_menu') ); } function admin_menu() { global $themenamefull; $page = add_theme_page( $themenamefull.' Options', $themenamefull.' Options', 'edit_theme_options', $this->id, array( $this, 'render' ) ); add_action( "admin_print_styles-$page", array($this, 'load_styles') ); add_action( "admin_print_scripts-$page", array($this, 'load_scripts') ); add_action( "wp_before_admin_bar_render", array($this, 'add_admin_bar') ); } function admin_init() { register_setting( $this->id, $this->id, array($this, 'validate_data') ); } function load_styles() { wp_enqueue_style('admin-style', CLASSY_OPTIONS_FRAMEWORK_URL.'css/admin-style.css'); wp_enqueue_style('color-picker', CLASSY_OPTIONS_FRAMEWORK_URL.'css/colorpicker.css'); wp_enqueue_style('thickbox'); } function load_scripts() { // Inline scripts from options-interface.php add_action('admin_head', array($this, 'admin_head')); // Enqueued scripts wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('thickbox'); wp_enqueue_script('color-picker', CLASSY_OPTIONS_FRAMEWORK_URL.'js/colorpicker.js', array('jquery')); wp_enqueue_script('options-custom', CLASSY_OPTIONS_FRAMEWORK_URL.'js/options-custom.js', array('jquery')); wp_enqueue_script('theme-options-custom', get_template_directory_uri().'/library/js/theme-options-custom.js', array('jquery')); wp_enqueue_script('media-uploader', CLASSY_OPTIONS_FRAMEWORK_URL.'js/of-medialibrary-uploader.js', array('jquery')); } function add_admin_bar() { global $wp_admin_bar; $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => $this->id, 'title' => $this->name, 'href' => admin_url( 'themes.php?page=' . $this->id ) )); } function admin_head() { do_action( 'optionsframework_custom_scripts' ); } function get($id) { $option = $this->find_option_by_id($id); return isset( $this->data[$id] ) ? $this->data[$id] : (( $option && isset($option['default'] )) ? $option['default'] : null); } function find_option_by_id($id) { foreach($this->options as $option) { if(isset($option['id']) && $option['id'] == $id) { return $option; } } return false; } function add( $option ) { $this->options[] = $option; } function render() { global $themenamefull; settings_errors(); ?>

CyberChimpsWelcome to ! Learn more now about upgrading to Business Pro today.

options as $option) { if(isset($option['id']) && isset($option['default'])) { $ret[$option['id']] = $option['default']; } } return $ret; } function validate_data( $input ) { /* * Restore Defaults. * * In the event that the user clicked the "Restore Defaults" * button, the options defined in the theme's options.php * file will be added to the option for the active theme. */ if ( isset( $_POST['reset'] ) || ! isset( $_POST['update'] ) ) { add_settings_error( $this->id, 'restore_defaults', __( 'Default options restored.', 'optionsframework' ), 'updated fade' ); return $this->default_data(); } if( isset( $_POST['import' ] ) ) { if( trim( $_POST['import' ] ) ) { $string = stripslashes( trim( $_POST['import'] ) ); $try = unserialize( $string ); if($try) { add_settings_error( $this->id, 'import', __( 'Options Imported', 'optionsframework' ), 'updated fade' ); return $try; } else { add_settings_error( $this->id, 'import', __( 'Invalid Data for Import', 'optionsframework' ), 'updated fade' ); } } } /* * Update Settings. */ if ( isset( $_POST['update'] ) ) { $clean = array(); foreach ( $this->options as $option ) { if ( ! isset( $option['id'] ) ) { continue; } if ( ! isset( $option['type'] ) ) { continue; } $id = preg_replace( '/\W/', '', strtolower( $option['id'] ) ); // Set checkbox to false if it wasn't sent in the $_POST if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) { $input[$id] = '0'; } // Set each item in the multicheck to false if it wasn't sent in the $_POST if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) { foreach ( $option['options'] as $key => $value ) { $input[$id][$key] = '0'; } } if ( 'upload' == $option['type'] ) { if ($_FILES[$id]['name'] != '') { $overrides = array('test_form' => false); $file = wp_handle_upload($_FILES[$id], $overrides); $clean[$id] = $file; } elseif(isset($_POST["{$id}_text"]) && $_POST["{$id}_text"] != '') { $input['file'] = array('url' => $_POST["{$id}_text"]); $clean[$id] = array('url' => $_POST["{$id}_text"]); } else { $clean[$id] = null; } } // For a value to be submitted to database it must pass through a sanitization filter if ( has_filter( 'cof_sanitize_' . $option['type'] ) && isset( $input[$id] ) ) { $clean[$id] = apply_filters( 'cof_sanitize_' . $option['type'], $input[$id], $option ); } } add_settings_error( $this->id, 'save_options', __( 'Options saved.', 'optionsframework' ), 'updated fade' ); return $clean; } } function fields() { global $allowedtags; $option_name = $this->id; $settings = $this->data; $options = $this->options; $counter = 0; $menu = ''; $output = ''; foreach ($options as $value) { $counter++; $val = ''; $select_value = ''; $checked = ''; // Wrap all options if ( ($value['type'] != "heading") && ($value['type'] != "info" && $value['type'] != "subsection" && $value['type'] != "subsection_end") && $value['type'] != "open_outersection" && $value['type'] != "close_outersection" ) { // Keep all ids lowercase with no spaces $value['id'] = isset( $value['id'] ) ? preg_replace('/\W/', '', strtolower($value['id']) ) : ""; $id = 'section-' . $value['id']; $class = 'section '; if ( isset( $value['type'] ) ) { $class .= ' section-' . $value['type']; } if ( isset( $value['class'] ) ) { $class .= ' ' . $value['class']; } $output .= '
'."\n"; $output .= '

' . esc_html( $value['name'] ) . '

' . "\n"; $output .= '
' . "\n" . '
' . "\n"; } // Set default value to $val if ( isset( $value['default']) ) { $val = $value['default']; } // If the option is already saved, ovveride $val if ( ($value['type'] != "heading") && ($value['type'] != "info" && $value['type'] != "subsection" && $value['type'] != "subsection_end") && $value['type'] != "open_outersection" && $value['type'] != "close_outersection" ) { if ( isset($settings[($value['id'])]) ) { $val = $settings[($value['id'])]; // Striping slashes of non-array options if (!is_array($val)) { $val = stripslashes($val); } } } // If there is a description save it for labels $explain_value = ''; if ( isset( $value['desc'] ) ) { $explain_value = $value['desc']; } switch ( $value['type'] ) { // Basic text input case 'text': $output .= ''; break; // Textarea case 'textarea': $cols = '8'; $ta_value = ''; if(isset($value['options'])){ $ta_options = $value['options']; if(isset($ta_options['cols'])){ $cols = $ta_options['cols']; } else { $cols = '8'; } } $val = stripslashes( $val ); $output .= ''; break; // Select Box case 'select': $output .= ''; break; // Radio Box case "radio": $name = $option_name .'['. $value['id'] .']'; foreach ($value['options'] as $key => $option) { $id = $option_name . '-' . $value['id'] .'-'. $key; $output .= '
'; } break; // Image Selectors case "images": $name = $option_name .'['. $value['id'] .']'; foreach ( $value['options'] as $key => $option ) { $selected = ''; $checked = ''; if ( $val != '' ) { if ( $val == $key ) { $selected = ' of-radio-img-selected'; $checked = ' checked="checked"'; } } $output .= ''; $output .= '
' . esc_html( $key ) . '
'; $output .= '' . $option .''; } break; // Checkbox case "checkbox": $output .= ''; $output .= ''; break; // Multicheck case "multicheck": foreach ($value['options'] as $key => $option) { $checked = ''; $label = $option; $option = preg_replace('/\W/', '', strtolower($key)); $id = $option_name . '-' . $value['id'] . '-'. $option; $name = $option_name . '[' . $value['id'] . '][' . $option .']'; if ( isset($val[$option]) ) { $checked = checked($val[$option], 1, false); } $output .= '
'; } break; // Color picker case "color": $output .= '
'; $output .= ''; break; // Uploader case "upload": // $output .= optionsframework_medialibrary_uploader( $value['id'], $val, null ); // New AJAX Uploader using Media Library if(isset($val['url'])) { $output .= "Preview:
" . "
"; } $output .= "      URL "; $output .= " or upload File: "; break; // Typography case 'typography': $typography_stored = $val; // Font Size $output .= ''; // Font Face $output .= ''; // Font Weight $output .= ''; // Font Color $output .= '
'; $output .= ''; break; // Background case 'background': $background = $val; // Background Color $output .= '
'; $output .= ''; // Background Image - New AJAX Uploader using Media Library if (!isset($background['image'])) { $background['image'] = ''; } $output .= optionsframework_medialibrary_uploader( $value['id'], $background['image'], null, '',0,'image'); $class = 'of-background-properties'; if ( '' == $background['image'] ) { $class .= ' hide'; } $output .= '
'; // Background Repeat $output .= ''; // Background Position $output .= ''; // Background Attachment $output .= ''; $output .= '
'; break; // Info case "info": $class = 'section'; if ( isset( $value['type'] ) ) { $class .= ' section-' . $value['type']; } if ( isset( $value['class'] ) ) { $class .= ' ' . $value['class']; } $output .= '
' . "\n"; if ( isset($value['name']) ) { $output .= '

' . ( $value['name'] ) . '

' . "\n"; } if ( isset( $value['desc'] ) ) { $output .= wpautop( wp_kses( $value['desc'], $allowedtags) ) . "\n"; } $output .= '
' . "\n"; break; case "export": $output .= ""; break; case "import": $output .= ""; break; // Heading for Navigation case "heading": if($counter >= 2){ $output .= '
'."\n"; } $jquery_click_hook = preg_replace('/\W/', '', strtolower($value['name']) ); $jquery_click_hook = "of-option-" . $jquery_click_hook; $menu .= '
  • '; $icon = isset($value['icon']) ? " style=\"background-image: url({$value['icon']}); background-position: 8px center; background-repeat: no-repeat; \"" : ""; $menu .= '' . esc_html( $value['name'] ) . '
  • '; $output .= '

    ' . esc_html( $value['name'] ) . '

    ' . "\n"; break; case "subsection": $id = strtolower(preg_replace("/\W/", "", $value['name'])); $output .= "

    {$value['name']}" // . "" . "

    "; break; case "subsection_end": $output .= "
    "; break; case "open_outersection": $output .= "
    "; break; case "close_outersection": $output .= "
    "; break; case "section_order": $root = get_template_directory_uri(); $values = explode(",", $val); $output .= "
    "; $output .= "
    "; $output .= "
    Inactive Elements
    "; $output .= "
    "; foreach($value['options'] as $k => $v) { if(in_array($k, $values)) continue; $output .= "
    "; $output .= ""; $output .= "{$v}"; $output .= "
    "; } $output .= "
    "; $output .= "
    "; $output .= "
    "; $output .= "
    "; $output .= "
    Active Elements
    "; $output .= "
    Drag & Drop Elements
    "; $output .= "
    "; foreach($values as $k) { if(!$k) continue; if(!isset($value['options'][$k])) continue; $val = $value['options'][$k]; $output .= "
    "; $output .= ""; $output .= "{$val}"; $output .= "
    "; } $output .= "
    "; $output .= "
    "; $output .= ""; $output .= "
    "; break; } if ( ($value['type'] != "heading") && ($value['type'] != "info" && $value['type'] != "subsection" && $value['type'] != "subsection_end") && $value['type'] != "open_outersection" && $value['type'] != "close_outersection" ) { if ( $value['type'] != "checkbox" ) { $output .= '
    '; } $explain_value = ''; if ( isset( $value['desc'] ) ) { $explain_value = $value['desc']; } $output .= "
    "; if ( $value['type'] != "checkbox" ) { $output .= '
    ' . wp_kses( $explain_value, $allowedtags) . '
    '."\n"; } $output .= '
    '."\n"; } } $output .= ''; return array($output,$menu); } function section($text, $options = array()) { if(isset($options['icon'])) { $this->add( array( 'type' => 'heading', 'name' => $text, 'icon' => $options['icon'])); } else { $this->add( array( 'type' => 'heading', 'name' => $text) ); } return $this; } function subsection($text) { $this->add( array( 'type' => 'subsection', 'name' => $text) ); return $this; } function subsection_end() { $this->add( array( 'type' => 'subsection_end' ) ); return $this; } function info($message) { $this->add( array( 'type' => 'info', 'name' => $message ) ); return $this; } function text( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'text', 'name' => $label ) ); return $this; } function textarea( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'textarea', 'name' => $label ) ); return $this; } function radio( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'radio', 'name' => $label, 'options' => $options['options'] ) ); return $this; } function images( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'images', 'name' => $label, 'options' => $options['options'] ) ); return $this; } function checkbox( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'checkbox', 'name' => $label ) ); return $this; } function multicheck( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'multicheck', 'name' => $label, 'options' => $options['options'] ) ); return $this; } function color( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'color', 'name' => $label ) ); return $this; } function upload( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'upload', 'name' => $label ) ); return $this; } function typography( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'typography', 'name' => $label ) ); return $this; } function select( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'select', 'name' => $label ) ); return $this; } function section_order( $key, $label = "", $options = array() ) { $this->add( $options + array( 'id' => $key, 'type' => 'section_order', 'name' => $label ) ); return $this; } function export( $label ) { $this->add( array( 'type' => 'export', 'name' => $label ) ); return $this; } function import( $label ) { $this->add( array( 'type' => 'import', 'name' => $label ) ); return $this; } function open_outersection() { $this->add( array( 'type' => 'open_outersection' ) ); return $this; } function close_outersection() { $this->add( array( 'type' => 'close_outersection' ) ); return $this; } function remove_section( $name ) { $started = false; foreach($this->options as $k => $option) { if( $started && $option['type'] == 'heading' ) { $end_index = $k; break; } if($option['type'] == 'heading' && $option['name'] == $name) { $started = true; $start_index = $k; } } if(!isset($end_index) ) { $end_index = count($this->options) - 1; } array_splice($this->options, $start_index, $end_index - $start_index ); return $this; } }