* @copyright Copyright (c) 2012, Derek Herman * @since 2.0 */ /** * Runs directly after the Theme Options are save. * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_after_theme_options_save' ) ) { function ot_after_theme_options_save() { $page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : ''; $updated = isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ? true : false; /* only execute after the theme options are saved */ if ( 'ot-theme-options' == $page && $updated ) { /* grab a copy of the theme options */ $options = get_option( 'option_tree' ); /* execute the action hook and pass the theme options to it */ do_action( 'ot_after_theme_options_save', $options ); } } } /** * Validate the options by type before saving. * * This function will run on only some of the option types * as all of them don't need to be validated, just the * ones users are going to input data into; because they * can't be trusted. * * @param mixed Setting value * @param string Setting type * @param string Setting field ID * @return mixed * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_validate_setting' ) ) { function ot_validate_setting( $input, $type, $field_id ) { /* exit early if missing data */ if ( ! $input || ! $type || ! $field_id ) return $input; $input = apply_filters( 'ot_validate_setting', $input, $type, $field_id ); if ( 'background' == $type ) { $input['background-color'] = ot_validate_setting( $input['background-color'], 'colorpicker', $field_id ); $input['background-image'] = ot_validate_setting( $input['background-image'], 'upload', $field_id ); } else if ( 'colorpicker' == $type ) { /* return empty & set error */ if ( 0 === preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $input ) ) { $input = ''; add_settings_error( 'option-tree', 'invalid_hex', __( 'The Colorpicker only allows valid hexadecimal values.', 'option-tree' ), 'error' ); } } else if ( in_array( $type, array( 'css', 'text', 'textarea', 'textarea-simple' ) ) ) { if ( ! current_user_can( 'unfiltered_html' ) && OT_ALLOW_UNFILTERED_HTML == false ) { $input = wp_kses_post( $input ); } } else if ( 'measurement' == $type ) { $input[0] = sanitize_text_field( $input[0] ); } else if ( 'typography' == $type ) { $input['font-color'] = ot_validate_setting( $input['font-color'], 'colorpicker', $field_id ); } else if ( 'upload' == $type ) { $input = sanitize_text_field( $input ); } $input = apply_filters( 'ot_after_validate_setting', $input, $type, $field_id ); return $input; } } /** * Setup the default admin styles * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_admin_styles' ) ) { function ot_admin_styles() { wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION ); } } /** * Setup the default admin scripts * * @uses add_thickbox() Include Thickbox for file uploads * @uses wp_enqueue_script() Add OptionTree scripts * @uses wp_localize_script() Used to include arbitrary Javascript data * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_admin_scripts' ) ) { function ot_admin_scripts() { /* enqueue admin scripts */ add_thickbox(); /* load the colorpicker */ wp_enqueue_script( 'ot-colorpicker-js', OT_URL . 'assets/js/ot-colorpicker.js', array( 'jquery' ), OT_VERSION ); /* load all the required scripts */ wp_enqueue_script( 'ot-admin-js', OT_URL . 'assets/js/ot-admin.js', array( 'jquery', 'jquery-ui-tabs', 'jquery-ui-sortable', 'media-upload', 'thickbox' ), OT_VERSION ); /* create localized JS array */ $localized_array = array( 'ajax' => admin_url( 'admin-ajax.php' ), 'upload_text' => __( 'Send to OptionTree', 'option-tree' ), 'remove_media_text' => __( 'Remove Media', 'option-tree' ), 'reset_agree' => __( 'Are you sure you want to reset back to the defaults?', 'option-tree' ), 'remove_no' => __( 'You can\'t remove this! But you can edit the values.', 'option-tree' ), 'remove_agree' => __( 'Are you sure you want to remove this?', 'option-tree' ), 'activate_layout_agree' => __( 'Are you sure you want to activate this layout?', 'option-tree' ), 'setting_limit' => __( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' ) ); /* localized script attached to 'option_tree' */ wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array ); } } /** * Returns the ID of a custom post type by post_name. * * @uses get_results() * * @return int * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_get_media_post_ID' ) ) { function ot_get_media_post_ID() { global $wpdb; return $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE `post_name` = 'media' AND `post_type` = 'option-tree' AND `post_status` = 'private'" ); } } /** * Register custom post type & create the media post used to attach images. * * @uses get_results() * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_create_media_post' ) ) { function ot_create_media_post() { register_post_type( 'option-tree', array( 'labels' => array( 'name' => __( 'Option Tree', 'option-tree' ) ), 'public' => true, 'show_ui' => false, 'capability_type' => 'post', 'exclude_from_search' => true, 'hierarchical' => false, 'rewrite' => false, 'supports' => array( 'title', 'editor' ), 'can_export' => true, 'show_in_nav_menus' => false ) ); /* look for custom page */ $post_id = ot_get_media_post_ID(); /* no post exists */ if ( $post_id == 0 ) { /* create post object */ $_p = array(); $_p['post_title'] = 'Media'; $_p['post_status'] = 'private'; $_p['post_type'] = 'option-tree'; $_p['comment_status'] = 'closed'; $_p['ping_status'] = 'closed'; /* insert the post into the database */ wp_insert_post( $_p ); } } } /** * Setup default settings array. * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_default_settings' ) ) { function ot_default_settings() { global $wpdb, $table_prefix; if ( ! get_option( 'option_tree_settings' ) ) { $section_count = 0; $settings_count = 0; $settings = array(); if ( mysql_num_rows( mysql_query( "SHOW TABLES LIKE '{$table_prefix}option_tree'" ) ) == 1 && $old_settings = $wpdb->get_results( "SELECT * FROM {$table_prefix}option_tree ORDER BY item_sort ASC" ) ) { foreach ( $old_settings as $setting ) { /* heading is a section now */ if ( $setting->item_type == 'heading' ) { /* add section to the sections array */ $settings['sections'][$section_count]['id'] = $setting->item_id; $settings['sections'][$section_count]['title'] = $setting->item_title; /* save the last section id to use in creating settings */ $section = $setting->item_id; /* increment the section count */ $section_count++; } else { /* add setting to the settings array */ $settings['settings'][$settings_count]['id'] = $setting->item_id; $settings['settings'][$settings_count]['label'] = $setting->item_title; $settings['settings'][$settings_count]['desc'] = $setting->item_desc; $settings['settings'][$settings_count]['section'] = $section; $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( $setting->item_type ); $settings['settings'][$settings_count]['std'] = ''; $settings['settings'][$settings_count]['class'] = ''; /* textarea rows */ $rows = ''; if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) { if ( (int) $setting->item_options > 0 ) { $rows = (int) $setting->item_options; } else { $rows = 15; } } $settings['settings'][$settings_count]['rows'] = $rows; /* post type */ $post_type = ''; if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) { if ( '' != $setting->item_options ) { $post_type = $setting->item_options; } else { $post_type = 'post'; } } $settings['settings'][$settings_count]['post_type'] = $post_type; /* choices */ $choices = array(); if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) { if ( '' != $setting->item_options ) { $choices = ot_convert_string_to_array( $setting->item_options ); } } $settings['settings'][$settings_count]['choices'] = $choices; $settings_count++; } } /* make sure each setting has a section just incase */ if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { foreach( $settings['settings'] as $k => $setting ) { if ( '' == $setting['section'] ) { $settings['settings'][$k]['section'] = $settings['sections'][0]['id']; } } } } /* if array if not properly formed create fallback settings array */ if ( ! isset( $settings['sections'] ) || ! isset( $settings['settings'] ) ) { $settings = array( 'sections' => array( array( 'id' => 'general', 'title' => __( 'General', 'option-tree' ) ) ), 'settings' => array( array( 'id' => 'sample_text', 'label' => __( 'Sample Text Field Label', 'option-tree' ), 'desc' => __( 'Description for the sample text field.', 'option-tree' ), 'section' => 'general', 'type' => 'text', 'std' => '', 'class' => '', 'rows' => '', 'post_type' => '', 'choices' => array() ) ) ); } /* update the settings array */ update_option( 'option_tree_settings', $settings ); /* get option tree array */ $options = get_option( 'option_tree' ); /* validate options */ if ( is_array( $options ) ) { foreach( $settings['settings'] as $setting ) { if ( isset( $options[$setting['id']] ) ) { $content = ot_stripslashes( $options[$setting['id']] ); $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); } } /* update the option tree array */ update_option( 'option_tree', $options ); } } } } /** * Helper function to update the CSS option type after save. * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_save_css' ) ) { function ot_save_css( $options ) { /* grab a copy of the settings */ $settings = get_option( 'option_tree_settings' ); /* has settings */ if ( isset( $settings['settings'] ) ) { /* loop through sections and insert CSS when needed */ foreach( $settings['settings'] as $k => $setting ) { /* is the CSS option type */ if ( isset( $setting['type'] ) && 'css' == $setting['type'] ) { /* insert CSS into dynamic.css */ if ( isset( $options[$setting['id']] ) && '' !== $options[$setting['id']] ) { ot_insert_css_with_markers( $setting['id'], $options[$setting['id']] ); /* remove old CSS from dynamic.css */ } else { ot_remove_old_css( $setting['id'] ); } } } } } } /** * Helper function to load filters for XML mime type. * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_add_xml_to_upload_filetypes' ) ) { function ot_add_xml_to_upload_filetypes() { add_filter( 'upload_mimes', 'ot_upload_mimes' ); add_filter( 'wp_mime_type_icon', 'ot_xml_mime_type_icon', 10, 2 ); } } /** * Filter 'upload_mimes' and add xml. * * @param array $mimes An array of valid upload mime types * @return array * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_upload_mimes' ) ) { function ot_upload_mimes( $mimes ) { $mimes['xml'] = 'application/xml'; return $mimes; } } /** * Filters 'wp_mime_type_icon' and have xml display as a document. * * @param string $icon The mime icon * @param string $mime The mime type * @return string * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_xml_mime_type_icon' ) ) { function ot_xml_mime_type_icon( $icon, $mime ) { if ( $mime == 'application/xml' || $mime == 'text/xml' ) return wp_mime_type_icon( 'document' ); return $icon; } } /** * Import before the screen is displayed. * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_import' ) ) { function ot_import() { /* check and verify import xml nonce */ if ( isset( $_POST['import_xml_nonce'] ) && wp_verify_nonce( $_POST['import_xml_nonce'], 'import_xml_form' ) ) { /* import input value */ $file = isset( $_POST['import_xml'] ) ? esc_url( $_POST['import_xml'] ) : ''; /* validate xml file */ if ( preg_match( "/(.xml)$/i", $file ) && class_exists( 'SimpleXMLElement' ) && function_exists( 'file_get_contents' ) ) { $settings = ot_import_xml( $file ); } /* default message */ $message = 'failed'; /* cleanup, save, & show success message */ if ( isset( $settings ) && ! empty( $settings ) ) { /* delete file */ if ( $file ) { global $wpdb; $attachmentid = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$file'" ); wp_delete_attachment( $attachmentid, true ); } /* update settings */ update_option( 'option_tree_settings', $settings ); /* set message */ $message = 'success'; } /* redirect */ wp_redirect( add_query_arg( array( 'action' => 'import-xml', 'message' => $message ), $_POST['_wp_http_referer'] ) ); exit; } /* check and verify import settings nonce */ if ( isset( $_POST['import_settings_nonce'] ) && wp_verify_nonce( $_POST['import_settings_nonce'], 'import_settings_form' ) ) { /* textarea value */ $textarea = isset( $_POST['import_settings'] ) ? unserialize( base64_decode( $_POST['import_settings'] ) ) : ''; /* default message */ $message = 'failed'; /* is array: save & show success message */ if ( is_array( $textarea ) ) { update_option( 'option_tree_settings', $textarea ); $message = 'success'; } /* redirect */ wp_redirect( add_query_arg( array( 'action' => 'import-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ); exit; } /* check and verify import theme options data nonce */ if ( isset( $_POST['import_data_nonce'] ) && wp_verify_nonce( $_POST['import_data_nonce'], 'import_data_form' ) ) { /* default message */ $message = 'failed'; /* textarea value */ $options = isset( $_POST['import_data'] ) ? unserialize( base64_decode( $_POST['import_data'] ) ) : ''; /* get settings array */ $settings = get_option( 'option_tree_settings' ); /* has options */ if ( is_array( $options ) ) { /* validate options */ if ( is_array( $settings ) ) { foreach( $settings['settings'] as $setting ) { if ( isset( $options[$setting['id']] ) ) { $content = ot_stripslashes( $options[$setting['id']] ); $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); } } } /* update the option tree array */ update_option( 'option_tree', $options ); $message = 'success'; } /* redirect accordingly */ wp_redirect( add_query_arg( array( 'action' => 'import-data', 'message' => $message ), $_POST['_wp_http_referer'] ) ); exit; } /* check and verify import layouts nonce */ if ( isset( $_POST['import_layouts_nonce'] ) && wp_verify_nonce( $_POST['import_layouts_nonce'], 'import_layouts_form' ) ) { /* default message */ $message = 'failed'; /* textarea value */ $layouts = isset( $_POST['import_layouts'] ) ? unserialize( base64_decode( $_POST['import_layouts'] ) ) : ''; /* get settings array */ $settings = get_option( 'option_tree_settings' ); /* has layouts */ if ( is_array( $layouts ) ) { /* validate options */ if ( is_array( $settings ) ) { foreach( $layouts as $key => $value ) { if ( $key == 'active_layout' ) continue; $options = unserialize( base64_decode( $value ) ); foreach( $settings['settings'] as $setting ) { if ( isset( $options[$setting['id']] ) ) { $content = ot_stripslashes( $options[$setting['id']] ); $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); } } $layouts[$key] = base64_encode( serialize( $options ) ); } } /* update the option tree array */ if ( isset( $layouts['active_layout'] ) ) { update_option( 'option_tree', unserialize( base64_decode( $layouts[$layouts['active_layout']] ) ) ); } /* update the option tree layouts array */ update_option( 'option_tree_layouts', $layouts ); $message = 'success'; } /* redirect accordingly */ wp_redirect( add_query_arg( array( 'action' => 'import-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ); exit; } return false; } } /** * Export before the screen is displayed. * * @return void * * @access public * @since 2.0.8 */ if ( ! function_exists( 'ot_export' ) ) { function ot_export() { /* check and verify export settings file nonce */ if ( isset( $_POST['export_settings_file_nonce'] ) && wp_verify_nonce( $_POST['export_settings_file_nonce'], 'export_settings_file_form' ) ) { ot_export_php_settings_array(); } } } /** * Reusable XMl import helper function. * * @param string $file The path to the file. * @return mixed False or an array of settings. * * @access public * @since 2.0.8 */ if ( ! function_exists( 'ot_import_xml' ) ) { function ot_import_xml( $file ) { if ( $rawdata = @file_get_contents( $file ) ) { $section_count = 0; $settings_count = 0; $section = ''; $settings = array(); $xml = new SimpleXMLElement( $rawdata ); foreach ( $xml->row as $value ) { /* heading is a section now */ if ( $value->item_type == 'heading' ) { /* add section to the sections array */ $settings['sections'][$section_count]['id'] = (string) $value->item_id; $settings['sections'][$section_count]['title'] = (string) $value->item_title; /* save the last section id to use in creating settings */ $section = (string) $value->item_id; /* increment the section count */ $section_count++; } else { /* add setting to the settings array */ $settings['settings'][$settings_count]['id'] = (string) $value->item_id; $settings['settings'][$settings_count]['label'] = (string) $value->item_title; $settings['settings'][$settings_count]['desc'] = (string) $value->item_desc; $settings['settings'][$settings_count]['section'] = $section; $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( (string) $value->item_type ); $settings['settings'][$settings_count]['std'] = ''; $settings['settings'][$settings_count]['class'] = ''; /* textarea rows */ $rows = ''; if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) { if ( (int) $value->item_options > 0 ) { $rows = (int) $value->item_options; } else { $rows = 15; } } $settings['settings'][$settings_count]['rows'] = $rows; /* post type */ $post_type = ''; if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) { if ( '' != (string) $value->item_options ) { $post_type = (string) $value->item_options; } else { $post_type = 'post'; } } $settings['settings'][$settings_count]['post_type'] = $post_type; /* choices */ $choices = array(); if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) { if ( '' != (string) $value->item_options ) { $choices = ot_convert_string_to_array( (string) $value->item_options ); } } $settings['settings'][$settings_count]['choices'] = $choices; $settings_count++; } } /* make sure each setting has a section just incase */ if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { foreach( $settings['settings'] as $k => $setting ) { if ( '' == $setting['section'] ) { $settings['settings'][$k]['section'] = $settings['sections'][0]['id']; } } } return $settings; } return false; } } /** * Export the Theme Mode theme-options.php * * @return attachment * * @access public * @since 2.0.8 */ if ( ! function_exists( 'ot_export_php_settings_array' ) ) { function ot_export_php_settings_array() { $content = ''; $build_settings = ''; $contextual_help = ''; $sections = ''; $settings = ''; $option_tree_settings = get_option( 'option_tree_settings', array() ); header( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); header( "Pragma: no-cache "); header( "Content-Description: File Transfer" ); header( 'Content-Disposition: attachment; filename="theme-options.php"'); header( "Content-Type: application/octet-stream"); header( "Content-Transfer-Encoding: binary" ); /* build contextual help content */ if ( isset( $option_tree_settings['contextual_help']['content'] ) ) { $help = ''; foreach( $option_tree_settings['contextual_help']['content'] as $value ) { $_id = isset( $value['id'] ) ? $value['id'] : ''; $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : ''; $_content = isset( $value['content'] ) ? html_entity_decode( str_replace( "'", "\'", $value['content'] ) ) : ''; $help.= " array( 'id' => '$_id', 'title' => '$_title', 'content' => '$_content' ),"; } $help = substr_replace( $help, '' , -1 ); $contextual_help = "'content' => array( $help ),"; } /* build contextual help sidebar */ if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) { $contextual_help.= " 'sidebar' => '" . html_entity_decode( str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) . "'"; } /* check that $contexual_help has a value and add to $build_settings */ if ( '' != $contextual_help ) { $build_settings.= " 'contextual_help' => array( $contextual_help )"; } /* build sections */ if ( isset( $option_tree_settings['sections'] ) ) { foreach( $option_tree_settings['sections'] as $value ) { $_id = isset( $value['id'] ) ? $value['id'] : ''; $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : ''; $sections.= " array( 'id' => '$_id', 'title' => '$_title' ),"; } $sections = substr_replace( $sections, '' , -1 ); } /* check that $sections has a value and add to $build_settings */ if ( '' != $sections ) { $build_settings.= ", 'sections' => array( $sections )"; } /* build settings */ if ( isset( $option_tree_settings['settings'] ) ) { foreach( $option_tree_settings['settings'] as $value ) { $_id = isset( $value['id'] ) ? $value['id'] : ''; $_label = isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : ''; $_desc = isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : ''; $_std = isset( $value['std'] ) ? $value['std'] : ''; $_type = isset( $value['type'] ) ? $value['type'] : ''; $_section = isset( $value['section'] ) ? $value['section'] : ''; $_rows = isset( $value['rows'] ) ? $value['rows'] : ''; $_post_type = isset( $value['post_type'] ) ? $value['post_type'] : ''; $_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : ''; $_class = isset( $value['class'] ) ? $value['class'] : ''; $choices = ''; if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) { foreach( $value['choices'] as $choice ) { $_choice_value = isset( $choice['value'] ) ? $choice['value'] : ''; $_choice_label = isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : ''; $_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : ''; $choices.= " array( 'value' => '$_choice_value', 'label' => '$_choice_label', 'src' => '$_choice_src' ),"; } $choices = substr_replace( $choices, '' , -1 ); $choices = ", 'choices' => array( $choices ),"; } $setting_settings = ''; if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) { foreach( $value['settings'] as $setting ) { $_setting_id = isset( $setting['id'] ) ? $setting['id'] : ''; $_setting_label = isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : ''; $_setting_desc = isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : ''; $_setting_std = isset( $setting['std'] ) ? $setting['std'] : ''; $_setting_type = isset( $setting['type'] ) ? $setting['type'] : ''; $_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : ''; $_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : ''; $_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : ''; $_setting_class = isset( $setting['class'] ) ? $setting['class'] : ''; $setting_choices = ''; if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) { foreach( $setting['choices'] as $setting_choice ) { $_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : ''; $_setting_choice_label = isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : ''; $_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : ''; $setting_choices.= " array( 'value' => '$_setting_choice_value', 'label' => '$_setting_choice_label', 'src' => '$_setting_choice_src' ),"; } $setting_choices = substr_replace( $setting_choices, '' , -1 ); $setting_choices = ", 'choices' => array( $setting_choices ),"; } $setting_settings.= " array( 'id' => '$_setting_id', 'label' => '$_setting_label', 'desc' => '$_setting_desc', 'std' => '$_setting_std', 'type' => '$_setting_type', 'rows' => '$_setting_rows', 'post_type' => '$_setting_post_type', 'taxonomy' => '$_setting_taxonomy', 'class' => '$_setting_class'$setting_choices ),"; } $setting_settings = substr_replace( $setting_settings, '' , -1 ); $setting_settings = ", 'settings' => array( $setting_settings )"; } $settings.= " array( 'id' => '$_id', 'label' => '$_label', 'desc' => '$_desc', 'std' => '$_std', 'type' => '$_type', 'section' => '$_section', 'rows' => '$_rows', 'post_type' => '$_post_type', 'taxonomy' => '$_taxonomy', 'class' => '$_class'$choices$setting_settings ),"; } $settings = substr_replace( $settings, '' , -1 ); } /* check that $sections has a value and add to $build_settings */ if ( '' != $settings ) { $build_settings.= ", 'settings' => array( $settings )"; } $content.= " $section ) { /* remove from array if missing values */ if ( ! $section['title'] && ! $section['id'] ) { unset( $settings['sections'][$k] ); } else { /* validate label */ if ( '' != $section['title'] ) { $settings['sections'][$k]['title'] = wp_kses_post( $section['title'] ); } /* missing title set to unfiltered ID */ if ( ! $section['title'] ) { $settings['sections'][$k]['title'] = wp_kses_post( $section['id'] ); /* missing ID set to title */ } else if ( ! $section['id'] ) { $section['id'] = wp_kses_post( $section['title'] ); } /* sanitize ID once everything has been checked first */ $settings['sections'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $section['id'] ) ); } } $settings['sections'] = ot_stripslashes( $settings['sections'] ); } /* validate settings by looping over array as many times as it takes */ if ( isset( $settings['settings'] ) ) { $settings['settings'] = ot_validate_settings_array( $settings['settings'] ); } /* validate contextual_help */ if ( isset( $settings['contextual_help']['content'] ) ) { /* fix numeric keys since drag & drop will change them */ $settings['contextual_help']['content'] = array_values( $settings['contextual_help']['content'] ); /* loop through content */ foreach( $settings['contextual_help']['content'] as $k => $content ) { /* remove from array if missing values */ if ( ! $content['title'] && ! $content['id'] ) { unset( $settings['contextual_help']['content'][$k] ); } else { /* validate label */ if ( '' != $content['title'] ) { $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['title'] ); } /* missing title set to unfiltered ID */ if ( ! $content['title'] ) { $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['id'] ); /* missing ID set to title */ } else if ( ! $content['id'] ) { $content['id'] = wp_kses_post( $content['title'] ); } /* sanitize ID once everything has been checked first */ $settings['contextual_help']['content'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $content['id'] ) ); } /* validate textarea description */ if ( isset( $content['content'] ) ) { $settings['contextual_help']['content'][$k]['content'] = wp_kses_post( $content['content'] ); } } } /* validate contextual_help sidebar */ if ( isset( $settings['contextual_help']['sidebar'] ) ) { $settings['contextual_help']['sidebar'] = wp_kses_post( $settings['contextual_help']['sidebar'] ); } $settings['contextual_help'] = ot_stripslashes( $settings['contextual_help'] ); /* default message */ $message = 'failed'; /* is array: save & show success message */ if ( is_array( $settings ) ) { update_option( 'option_tree_settings', $settings ); $message = 'success'; } /* redirect */ wp_redirect( add_query_arg( array( 'action' => 'save-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ); exit; } return false; } } /** * Validate the settings array before save. * * This function will loop over the settings array as many * times as it takes to validate every sub setting. * * @param array $settings The array of settings. * @return array * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_validate_settings_array' ) ) { function ot_validate_settings_array( $settings = array() ) { /* validate settings */ if ( count( $settings ) > 0 ) { /* fix numeric keys since drag & drop will change them */ $settings = array_values( $settings ); /* loop through settings */ foreach( $settings as $k => $setting ) { /* remove from array if missing values */ if ( ! $setting['label'] && ! $setting['id'] ) { unset( $settings[$k] ); } else { /* validate label */ if ( '' != $setting['label'] ) { $settings[$k]['label'] = wp_kses_post( $setting['label'] ); } /* missing label set to unfiltered ID */ if ( ! $setting['label'] ) { $settings[$k]['label'] = $setting['id']; /* missing ID set to label */ } else if ( ! $setting['id'] ) { $setting['id'] = wp_kses_post( $setting['label'] ); } /* sanitize ID once everything has been checked first */ $settings[$k]['id'] = ot_sanitize_option_id( wp_kses_post( $setting['id'] ) ); } /* validate description */ if ( '' != $setting['desc'] ) { $settings[$k]['desc'] = wp_kses_post( $setting['desc'] ); } /* validate choices */ if ( isset( $setting['choices'] ) ) { /* loop through choices */ foreach( $setting['choices'] as $ck => $choice ) { /* remove from array if missing values */ if ( ! $choice['label'] && ! $choice['value'] ) { unset( $setting['choices'][$ck] ); } else { /* missing label set to unfiltered ID */ if ( ! $choice['label'] ) { $setting['choices'][$ck]['label'] = wp_kses_post( $choice['value'] ); /* missing value set to label */ } else if ( ! $choice['value'] ) { $setting['choices'][$ck]['value'] = ot_sanitize_option_id( wp_kses_post( $choice['label'] ) ); } } } /* update keys and push new array values */ $settings[$k]['choices'] = array_values( $setting['choices'] ); } /* validate sub settings */ if ( isset( $setting['settings'] ) ) { $settings[$k]['settings'] = ot_validate_settings_array( $setting['settings'] ); } } } /* return array but strip those damn slashes out first!!! */ return ot_stripslashes( $settings ); } } /** * Save layouts array before the screen is displayed. * * @return void * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_modify_layouts' ) ) { function ot_modify_layouts() { /* check and verify modify layouts nonce */ if ( isset( $_POST['option_tree_modify_layouts_nonce'] ) && wp_verify_nonce( $_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form' ) ) { /* previous layouts value */ $option_tree_layouts = get_option( 'option_tree_layouts' ); /* new layouts value */ $layouts = isset( $_POST['option_tree_layouts'] ) ? $_POST['option_tree_layouts'] : ''; /* rebuild layout array */ $rebuild = array(); /* validate layouts */ if ( is_array( $layouts ) && ! empty( $layouts ) ) { /* setup active layout */ if ( isset( $layouts['active_layout'] ) && '' != $layouts['active_layout'] ) { $rebuild['active_layout'] = $layouts['active_layout']; } /* add new and overwrite active layout */ if ( isset( $layouts['_add_new_layout_'] ) && '' != $layouts['_add_new_layout_'] ) { $rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] ); $rebuild[$rebuild['active_layout']] = base64_encode( serialize( get_option( 'option_tree' ) ) ); } $first_layout = ''; /* loop through layouts */ foreach( $layouts as $key => $layout ) { /* skip over active layout key */ if ( $key == 'active_layout' ) continue; /* check if the key exists then set value */ if ( isset( $option_tree_layouts[$key] ) ) { $rebuild[$key] = $option_tree_layouts[$key]; if ( '' == $first_layout ) { $first_layout = $key; } } } if ( ! isset( $rebuild[$rebuild['active_layout']] ) && '' != $first_layout ) { $rebuild['active_layout'] = $first_layout; } } /* default message */ $message = 'failed'; /* is array: save & show success message */ if ( count( $rebuild ) > 1 ) { /* rebuild the theme options */ $rebuild_option_tree = unserialize( base64_decode( $rebuild[$rebuild['active_layout']] ) ); if ( is_array( $rebuild_option_tree ) ) { update_option( 'option_tree', $rebuild_option_tree ); } /* rebuild the layouts */ update_option( 'option_tree_layouts', $rebuild ); /* change message */ $message = 'success'; } else if ( count( $rebuild ) <= 1 ) { /* delete layouts option */ delete_option( 'option_tree_layouts' ); /* change message */ $message = 'deleted'; } /* redirect */ if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'ot-theme-options' ) { $query_args = add_query_arg( array( 'settings-updated' => 'layout' ), remove_query_arg( array( 'action', 'message' ), $_POST['_wp_http_referer'] ) ); } else { $query_args = add_query_arg( array( 'action' => 'save-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ); } wp_redirect( $query_args ); exit; } return false; } } /** * Helper function to display alert messages. * * @param array Page array * @return mixed * * @access public * @since 2.0 */ if ( ! function_exists( 'ot_alert_message' ) ) { function ot_alert_message( $page = array() ) { if ( empty( $page ) ) return false; $current_page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : ''; $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; $message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : ''; /* theme options messages */ if ( $current_page == 'ot-theme-options' ) { if ( isset( $_POST['action'] ) && $_POST['action'] == 'reset' ) { return '
' . $page['reset_message'] . '
' . $page['updated_message'] . '
' . __( 'Layout activated.', 'option-tree' ) . '
' . __( 'Settings updated.', 'option-tree' ) . '
' . __( 'Settings could not be saved.', 'option-tree' ) . '
' . __( 'Settings Imported.', 'option-tree' ) . '
' . __( 'Settings could not be imported.', 'option-tree' ) . '
' . __( 'Data Imported.', 'option-tree' ) . '
' . __( 'Data could not be imported.', 'option-tree' ) . '
' . __( 'Layouts Imported.', 'option-tree' ) . '
' . __( 'Layouts could not be imported.', 'option-tree' ) . '
' . __( 'Layouts Updated.', 'option-tree' ) . '
' . __( 'Layouts could not be updated.', 'option-tree' ) . '
OptionTree->Documentation
for more information on which ones.', 'option-tree' ) . 'tags */ $string = str_replace( array( "\n", "
" ), "", $string );
/* replace
with \r */
$string = str_replace( array( "
", "
", "
" ), "\r", $string );
/* replace