wp/wp-content/plugins/option-tree/includes/ot-functions-admin.php
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php if ( ! defined( 'OT_VERSION' ) ) exit( 'No direct script access allowed' );
       
     2 /**
       
     3  * Functions used only while viewing the admin UI.
       
     4  *
       
     5  * Limit loading these function only when needed 
       
     6  * and not in the front end.
       
     7  *
       
     8  * @package   OptionTree
       
     9  * @author    Derek Herman <derek@valendesigns.com>
       
    10  * @copyright Copyright (c) 2013, Derek Herman
       
    11  * @since     2.0
       
    12  */
       
    13 
       
    14 /**
       
    15  * Registers the Theme Option page
       
    16  *
       
    17  * @uses      ot_register_settings()
       
    18  *
       
    19  * @return    void
       
    20  *
       
    21  * @access    public
       
    22  * @since     2.1
       
    23  */
       
    24 if ( ! function_exists( 'ot_register_theme_options_page' ) ) {
       
    25 
       
    26   function ot_register_theme_options_page() {
       
    27   
       
    28     /* get the settings array */
       
    29     $get_settings = get_option( 'option_tree_settings' );
       
    30     
       
    31     /* sections array */
       
    32     $sections = isset( $get_settings['sections'] ) ? $get_settings['sections'] : array();
       
    33     
       
    34     /* settings array */
       
    35     $settings = isset( $get_settings['settings'] ) ? $get_settings['settings'] : array();
       
    36     
       
    37     /* contexual_help array */
       
    38     $contextual_help = isset( $get_settings['contextual_help'] ) ? $get_settings['contextual_help'] : array();
       
    39     
       
    40     /* build the Theme Options */
       
    41     if ( function_exists( 'ot_register_settings' ) && OT_USE_THEME_OPTIONS ) {
       
    42       
       
    43       ot_register_settings( array(
       
    44           array(
       
    45             'id'                  => 'option_tree',
       
    46             'pages'               => array( 
       
    47               array(
       
    48                 'id'              => 'ot_theme_options',
       
    49                 'parent_slug'     => apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ),
       
    50                 'page_title'      => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ),
       
    51                 'menu_title'      => apply_filters( 'ot_theme_options_menu_title', __( 'Theme Options', 'option-tree' ) ),
       
    52                 'capability'      => $caps = apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ),
       
    53                 'menu_slug'       => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ),
       
    54                 'icon_url'        => apply_filters( 'ot_theme_options_icon_url', null ),
       
    55                 'position'        => apply_filters( 'ot_theme_options_position', null ),
       
    56                 'updated_message' => apply_filters( 'ot_theme_options_updated_message', __( 'Theme Options updated.', 'option-tree' ) ),
       
    57                 'reset_message'   => apply_filters( 'ot_theme_options_reset_message', __( 'Theme Options reset.', 'option-tree' ) ),
       
    58                 'button_text'     => apply_filters( 'ot_theme_options_button_text', __( 'Save Changes', 'option-tree' ) ),
       
    59                 'screen_icon'     => 'themes',
       
    60                 'contextual_help' => $contextual_help,
       
    61                 'sections'        => $sections,
       
    62                 'settings'        => $settings
       
    63               )
       
    64             )
       
    65           )
       
    66         ) 
       
    67       );
       
    68       
       
    69       // Filters the options.php to add the minimum user capabilities.
       
    70       add_filter( 'option_page_capability_option_tree', create_function( '$caps', "return '$caps';" ), 999 );
       
    71     
       
    72     }
       
    73   
       
    74   }
       
    75 
       
    76 }
       
    77 
       
    78 /**
       
    79  * Registers the Settings page
       
    80  *
       
    81  * @uses      ot_register_settings()
       
    82  *
       
    83  * @return    void
       
    84  *
       
    85  * @access    public
       
    86  * @since     2.1
       
    87  */
       
    88 if ( ! function_exists( 'ot_register_settings_page' ) ) {
       
    89 
       
    90   function ot_register_settings_page() {
       
    91   
       
    92     // Create the filterable pages array
       
    93     $ot_register_pages_array =  array( 
       
    94       array( 
       
    95         'id'              => 'ot',
       
    96         'page_title'      => __( 'OptionTree', 'option-tree' ),
       
    97         'menu_title'      => __( 'OptionTree', 'option-tree' ),
       
    98         'capability'      => 'edit_theme_options',
       
    99         'menu_slug'       => 'ot-settings',
       
   100         'icon_url'        => OT_URL . '/assets/images/ot-logo-mini.png',
       
   101         'position'        => 61,
       
   102         'hidden_page'     => true
       
   103       ),
       
   104       array(
       
   105         'id'              => 'settings',
       
   106         'parent_slug'     => 'ot-settings',
       
   107         'page_title'      => __( 'Settings', 'option-tree' ),
       
   108         'menu_title'      => __( 'Settings', 'option-tree' ),
       
   109         'capability'      => 'edit_theme_options',
       
   110         'menu_slug'       => 'ot-settings',
       
   111         'icon_url'        => null,
       
   112         'position'        => null,
       
   113         'updated_message' => __( 'Theme Options updated.', 'option-tree' ),
       
   114         'reset_message'   => __( 'Theme Options reset.', 'option-tree' ),
       
   115         'button_text'     => __( 'Save Settings', 'option-tree' ),
       
   116         'show_buttons'    => false,
       
   117         'screen_icon'     => 'themes',
       
   118         'sections'        => array(
       
   119           array(
       
   120             'id'          => 'create_setting',
       
   121             'title'       => __( 'Theme Options UI', 'option-tree' )
       
   122           ),
       
   123           array(
       
   124             'id'          => 'import',
       
   125             'title'       => __( 'Import', 'option-tree' )
       
   126           ),
       
   127           array(
       
   128             'id'          => 'export',
       
   129             'title'       => __( 'Export', 'option-tree' )
       
   130           ),
       
   131           array(
       
   132             'id'          => 'layouts',
       
   133             'title'       => __( 'Layouts', 'option-tree' )
       
   134           )
       
   135         ),
       
   136         'settings'        => array(
       
   137           array(
       
   138             'id'          => 'theme_options_ui_text',
       
   139             'label'       => __( 'Theme Options UI Builder', 'option-tree' ),
       
   140             'type'        => 'theme_options_ui',
       
   141             'section'     => 'create_setting'
       
   142           ),
       
   143           array(
       
   144             'id'          => 'import_xml_text',
       
   145             'label'       => __( 'Settings XML', 'option-tree' ),
       
   146             'type'        => 'import-xml',
       
   147             'section'     => 'import'
       
   148           ),
       
   149           array(
       
   150             'id'          => 'import_settings_text',
       
   151             'label'       => __( 'Settings', 'option-tree' ),
       
   152             'type'        => 'import-settings',
       
   153             'section'     => 'import'
       
   154           ),
       
   155           array(
       
   156             'id'          => 'import_data_text',
       
   157             'label'       => __( 'Theme Options', 'option-tree' ),
       
   158             'type'        => 'import-data',
       
   159             'section'     => 'import'
       
   160           ),
       
   161           array(
       
   162             'id'          => 'import_layouts_text',
       
   163             'label'       => __( 'Layouts', 'option-tree' ),
       
   164             'type'        => 'import-layouts',
       
   165             'section'     => 'import'
       
   166           ),
       
   167           array(
       
   168             'id'          => 'export_settings_file_text',
       
   169             'label'       => __( 'Settings PHP File', 'option-tree' ),
       
   170             'type'        => 'export-settings-file',
       
   171             'section'     => 'export'
       
   172           ),
       
   173           array(
       
   174             'id'          => 'export_settings_text',
       
   175             'label'       => __( 'Settings', 'option-tree' ),
       
   176             'type'        => 'export-settings',
       
   177             'section'     => 'export'
       
   178           ),
       
   179           array(
       
   180             'id'          => 'export_data_text',
       
   181             'label'       => __( 'Theme Options', 'option-tree' ),
       
   182             'type'        => 'export-data',
       
   183             'section'     => 'export'
       
   184           ),
       
   185           array(
       
   186             'id'          => 'export_layout_text',
       
   187             'label'       => __( 'Layouts', 'option-tree' ),
       
   188             'type'        => 'export-layouts',
       
   189             'section'     => 'export'
       
   190           ),
       
   191           array(
       
   192             'id'          => 'modify_layouts_text',
       
   193             'label'       => __( 'Layout Management', 'option-tree' ),
       
   194             'type'        => 'modify-layouts',
       
   195             'section'     => 'layouts'
       
   196           )
       
   197         )
       
   198       ),
       
   199       array(
       
   200         'id'              => 'documentation',
       
   201         'parent_slug'     => 'ot-settings',
       
   202         'page_title'      => __( 'Documentation', 'option-tree' ),
       
   203         'menu_title'      => __( 'Documentation', 'option-tree' ),
       
   204         'capability'      => 'edit_theme_options',
       
   205         'menu_slug'       => 'ot-documentation',
       
   206         'icon_url'        => null,
       
   207         'position'        => null,
       
   208         'updated_message' => __( 'Theme Options updated.', 'option-tree' ),
       
   209         'reset_message'   => __( 'Theme Options reset.', 'option-tree' ),
       
   210         'button_text'     => __( 'Save Settings', 'option-tree' ),
       
   211         'show_buttons'    => false,
       
   212         'screen_icon'     => 'themes',
       
   213         'sections'        => array(
       
   214           array(
       
   215             'id'          => 'creating_options',
       
   216             'title'       => __( 'Creating Options', 'option-tree' )
       
   217           ),
       
   218           array(
       
   219             'id'          => 'option_types',
       
   220             'title'       => __( 'Option Types', 'option-tree' )
       
   221           ),
       
   222           array(
       
   223             'id'          => 'functions',
       
   224             'title'       => __( 'Function References', 'option-tree' )
       
   225           ),
       
   226           array(
       
   227             'id'          => 'theme_mode',
       
   228             'title'       => __( 'Theme Mode', 'option-tree' )
       
   229           ),
       
   230           array(
       
   231             'id'          => 'meta_boxes',
       
   232             'title'       => __( 'Meta Boxes', 'option-tree' )
       
   233           ),
       
   234           array(
       
   235             'id'          => 'examples',
       
   236             'title'       => __( 'Code Examples', 'option-tree' )
       
   237           ),
       
   238           array(
       
   239             'id'          => 'layouts_overview',
       
   240             'title'       => __( 'Layouts Overview', 'option-tree' )
       
   241           )
       
   242         ),
       
   243         'settings'        => array(
       
   244           array(
       
   245             'id'          => 'creating_options_text',
       
   246             'label'       => __( 'Overview of available Theme Option fields.', 'option-tree' ),
       
   247             'type'        => 'creating-options',
       
   248             'section'     => 'creating_options'
       
   249           ),
       
   250           array(
       
   251             'id'          => 'option_types_text',
       
   252             'label'       => __( 'Option types in alphabetical order & hooks to filter them.', 'option-tree' ),
       
   253             'type'        => 'option-types',
       
   254             'section'     => 'option_types'
       
   255           ),
       
   256           array(
       
   257             'id'          => 'functions_ot_get_option',
       
   258             'label'       => __( 'Function Reference:ot_get_option()', 'option-tree' ),
       
   259             'type'        => 'ot-get-option',
       
   260             'section'     => 'functions'
       
   261           ),
       
   262           array(
       
   263             'id'          => 'functions_get_option_tree',
       
   264             'label'       => __( 'Function Reference:get_option_tree()', 'option-tree' ),
       
   265             'type'        => 'get-option-tree',
       
   266             'section'     => 'functions'
       
   267           ),
       
   268           array(
       
   269             'id'          => 'theme_mode_text',
       
   270             'label'       => __( 'Theme Mode', 'option-tree' ),
       
   271             'type'        => 'theme-mode',
       
   272             'section'     => 'theme_mode'
       
   273           ),
       
   274           array(
       
   275             'id'          => 'meta_boxes_text',
       
   276             'label'       => __( 'Meta Boxes', 'option-tree' ),
       
   277             'type'        => 'meta-boxes',
       
   278             'section'     => 'meta_boxes'
       
   279           ),
       
   280           array(
       
   281             'id'          => 'example_text',
       
   282             'label'       => __( 'Code examples for front-end development.', 'option-tree' ),
       
   283             'type'        => 'examples',
       
   284             'section'     => 'examples'
       
   285           ),
       
   286           array(
       
   287             'id'          => 'layouts_overview_text',
       
   288             'label'       => __( 'What\'s a layout anyhow?', 'option-tree' ),
       
   289             'type'        => 'layouts-overview',
       
   290             'section'     => 'layouts_overview'
       
   291           )
       
   292         )
       
   293       )
       
   294     );
       
   295     
       
   296     // Loop over the settings and remove as needed.
       
   297     foreach( $ot_register_pages_array as $key => $page ) {
       
   298       
       
   299       // Remove various options from the Settings UI.
       
   300       if ( $page['id'] == 'settings' ) {
       
   301         
       
   302         // Remove the Theme Options UI
       
   303         if ( OT_SHOW_OPTIONS_UI == false ) {
       
   304         
       
   305           foreach( $page['sections'] as $section_key => $section ) {
       
   306             if ( $section['id'] == 'create_setting' ) {
       
   307               unset($ot_register_pages_array[$key]['sections'][$section_key]);
       
   308             }
       
   309           }
       
   310           
       
   311           foreach( $page['settings'] as $setting_key => $setting ) {
       
   312             if ( $setting['section'] == 'create_setting' ) {
       
   313               unset($ot_register_pages_array[$key]['settings'][$setting_key]);
       
   314             }
       
   315           }
       
   316         
       
   317         }
       
   318         
       
   319         // Remove parts of the Imports UI
       
   320         if ( OT_SHOW_SETTINGS_IMPORT == false ) {
       
   321           
       
   322           foreach( $page['settings'] as $setting_key => $setting ) {
       
   323             if ( $setting['section'] == 'import' && in_array( $setting['id'], array('import_xml_text', 'import_settings_text' ) ) ) {
       
   324               unset($ot_register_pages_array[$key]['settings'][$setting_key]);
       
   325             }
       
   326           }
       
   327         
       
   328         }
       
   329         
       
   330         // Remove parts of the Export UI
       
   331         if ( OT_SHOW_SETTINGS_EXPORT == false ) {
       
   332           
       
   333           foreach( $page['settings'] as $setting_key => $setting ) {
       
   334             if ( $setting['section'] == 'export' && in_array( $setting['id'], array('export_settings_file_text', 'export_settings_text' ) ) ) {
       
   335               unset($ot_register_pages_array[$key]['settings'][$setting_key]);
       
   336             }
       
   337           }
       
   338         
       
   339         }
       
   340         
       
   341         // Remove the Layouts UI
       
   342         if ( OT_SHOW_NEW_LAYOUT == false ) {
       
   343   
       
   344           foreach( $page['sections'] as $section_key => $section ) {
       
   345             if ( $section['id'] == 'layouts' ) {
       
   346               unset($ot_register_pages_array[$key]['sections'][$section_key]);
       
   347             }
       
   348           }
       
   349           
       
   350           foreach( $page['settings'] as $setting_key => $setting ) {
       
   351             if ( $setting['section'] == 'layouts' ) {
       
   352               unset($ot_register_pages_array[$key]['settings'][$setting_key]);
       
   353             }
       
   354           }
       
   355         
       
   356         }
       
   357       
       
   358       }
       
   359       
       
   360       // Remove the Documentation UI.
       
   361       if ( OT_SHOW_DOCS == false && $page['id'] == 'documentation' ) {
       
   362         
       
   363         unset( $ot_register_pages_array[$key] );
       
   364       
       
   365       }
       
   366     
       
   367     }
       
   368     
       
   369     $ot_register_pages_array = apply_filters( 'ot_register_pages_array', $ot_register_pages_array );
       
   370     
       
   371     // Register the pages.
       
   372     ot_register_settings( array(
       
   373         array(
       
   374           'id'              => 'option_tree_settings',
       
   375           'pages'           => $ot_register_pages_array
       
   376         )
       
   377       )
       
   378     );
       
   379   
       
   380   }
       
   381 
       
   382 }
       
   383 
       
   384 /**
       
   385  * Runs directly after the Theme Options are save.
       
   386  *
       
   387  * @return    void
       
   388  *
       
   389  * @access    public
       
   390  * @since     2.0
       
   391  */
       
   392 if ( ! function_exists( 'ot_after_theme_options_save' ) ) {
       
   393 
       
   394   function ot_after_theme_options_save() {
       
   395   
       
   396     $page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
       
   397     $updated = isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ? true : false;
       
   398     
       
   399     /* only execute after the theme options are saved */
       
   400     if ( apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) == $page && $updated ) {
       
   401       
       
   402       /* grab a copy of the theme options */
       
   403       $options = get_option( 'option_tree' );
       
   404       
       
   405       /* execute the action hook and pass the theme options to it */
       
   406       do_action( 'ot_after_theme_options_save', $options );
       
   407       
       
   408     }
       
   409   
       
   410   }
       
   411 
       
   412 }
       
   413 
       
   414 /**
       
   415  * Validate the options by type before saving.
       
   416  *
       
   417  * This function will run on only some of the option types
       
   418  * as all of them don't need to be validated, just the
       
   419  * ones users are going to input data into; because they
       
   420  * can't be trusted.
       
   421  *
       
   422  * @param     mixed     Setting value
       
   423  * @param     string    Setting type
       
   424  * @param     string    Setting field ID
       
   425  * @param     string    WPML field ID
       
   426  * @return    mixed
       
   427  *
       
   428  * @access    public
       
   429  * @since     2.0
       
   430  */
       
   431 if ( ! function_exists( 'ot_validate_setting' ) ) {
       
   432 
       
   433   function ot_validate_setting( $input, $type, $field_id, $wmpl_id = '' ) {
       
   434     
       
   435     /* exit early if missing data */
       
   436     if ( ! $input || ! $type || ! $field_id )
       
   437       return $input;
       
   438     
       
   439     $input = apply_filters( 'ot_validate_setting', $input, $type, $field_id );
       
   440     
       
   441     /* WPML Register and Unregister strings */
       
   442     if ( ! empty( $wmpl_id ) ) {
       
   443     
       
   444       /* Allow filtering on the WPML option types */
       
   445       $single_string_types = apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) );
       
   446               
       
   447       if ( in_array( $type, $single_string_types ) ) {
       
   448       
       
   449         if ( ! empty( $input ) ) {
       
   450         
       
   451           ot_wpml_register_string( $wmpl_id, $input );
       
   452           
       
   453         } else {
       
   454         
       
   455           ot_wpml_unregister_string( $wmpl_id );
       
   456           
       
   457         }
       
   458       
       
   459       }
       
   460     
       
   461     }
       
   462             
       
   463     if ( 'background' == $type ) {
       
   464 
       
   465       $input['background-color'] = ot_validate_setting( $input['background-color'], 'colorpicker', $field_id );
       
   466       
       
   467       $input['background-image'] = ot_validate_setting( $input['background-image'], 'upload', $field_id );
       
   468       
       
   469     } else if ( 'colorpicker' == $type ) {
       
   470 
       
   471       /* return empty & set error */
       
   472       if ( 0 === preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $input ) ) {
       
   473         
       
   474         $input = '';
       
   475         
       
   476         add_settings_error( 'option-tree', 'invalid_hex', __( 'The Colorpicker only allows valid hexadecimal values.', 'option-tree' ), 'error' );
       
   477       
       
   478       }
       
   479     
       
   480     } else if ( in_array( $type, array( 'css', 'text', 'textarea', 'textarea-simple' ) ) ) {
       
   481       
       
   482       if ( ! current_user_can( 'unfiltered_html' ) && OT_ALLOW_UNFILTERED_HTML == false ) {
       
   483       
       
   484         $input = wp_kses_post( $input );
       
   485         
       
   486       }
       
   487             
       
   488     } else if ( 'measurement' == $type ) {
       
   489     
       
   490       $input[0] = sanitize_text_field( $input[0] );
       
   491       
       
   492     } else if ( 'typography' == $type && isset( $input['font-color'] ) ) {
       
   493       
       
   494       $input['font-color'] = ot_validate_setting( $input['font-color'], 'colorpicker', $field_id );
       
   495     
       
   496     } else if ( 'upload' == $type ) {
       
   497 
       
   498       $input = sanitize_text_field( $input );
       
   499          
       
   500     }
       
   501     
       
   502     $input = apply_filters( 'ot_after_validate_setting', $input, $type, $field_id );
       
   503  
       
   504     return $input;
       
   505     
       
   506   }
       
   507 
       
   508 }
       
   509   
       
   510 /**
       
   511  * Setup the default admin styles
       
   512  *
       
   513  * @return    void
       
   514  *
       
   515  * @access    public
       
   516  * @since     2.0
       
   517  */
       
   518 if ( ! function_exists( 'ot_admin_styles' ) ) {
       
   519 
       
   520   function ot_admin_styles() {
       
   521   
       
   522     wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION );
       
   523     
       
   524   }
       
   525   
       
   526 }
       
   527 
       
   528 /**
       
   529  * Setup the default admin scripts
       
   530  *
       
   531  * @uses      add_thickbox()          Include Thickbox for file uploads
       
   532  * @uses      wp_enqueue_script()     Add OptionTree scripts
       
   533  * @uses      wp_localize_script()    Used to include arbitrary Javascript data
       
   534  *
       
   535  * @return    void
       
   536  *
       
   537  * @access    public
       
   538  * @since     2.0
       
   539  */
       
   540 if ( ! function_exists( 'ot_admin_scripts' ) ) {
       
   541 
       
   542   function ot_admin_scripts() {
       
   543 
       
   544     if ( function_exists( 'wp_enqueue_media' ) ) {
       
   545       /* WP 3.5 Media Uploader */
       
   546       wp_enqueue_media();
       
   547     } else {
       
   548       /* Legacy Thickbox */
       
   549       add_thickbox();
       
   550     }
       
   551     
       
   552     /* load the colorpicker */
       
   553     wp_enqueue_script( 'ot-colorpicker-js', OT_URL . 'assets/js/ot-colorpicker.js', array( 'jquery' ), OT_VERSION );
       
   554     
       
   555     /* load jQuery-ui slider */
       
   556     wp_enqueue_script( 'jquery-ui-slider' );
       
   557     
       
   558     /* load all the required scripts */
       
   559     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 );
       
   560     
       
   561     /* create localized JS array */
       
   562     $localized_array = array( 
       
   563       'ajax'                  => admin_url( 'admin-ajax.php' ),
       
   564       'upload_text'           => __( 'Send to OptionTree', 'option-tree' ),
       
   565       'remove_media_text'     => __( 'Remove Media', 'option-tree' ),
       
   566       'reset_agree'           => __( 'Are you sure you want to reset back to the defaults?', 'option-tree' ),
       
   567       'remove_no'             => __( 'You can\'t remove this! But you can edit the values.', 'option-tree' ),
       
   568       'remove_agree'          => __( 'Are you sure you want to remove this?', 'option-tree' ),
       
   569       'activate_layout_agree' => __( 'Are you sure you want to activate this layout?', 'option-tree' ),
       
   570       'setting_limit'         => __( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' )
       
   571     );
       
   572     
       
   573     /* localized script attached to 'option_tree' */
       
   574     wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array );
       
   575 
       
   576   }
       
   577   
       
   578 }
       
   579 
       
   580 /**
       
   581  * Returns the ID of a custom post type by post_name.
       
   582  *
       
   583  * @uses        get_results()
       
   584  *
       
   585  * @return      int
       
   586  *
       
   587  * @access      public
       
   588  * @since       2.0
       
   589  */
       
   590 if ( ! function_exists( 'ot_get_media_post_ID' ) ) {
       
   591 
       
   592   function ot_get_media_post_ID() {
       
   593     global $wpdb;
       
   594     
       
   595     return $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE `post_name` = 'media' AND `post_type` = 'option-tree' AND `post_status` = 'private'" );
       
   596     
       
   597   }
       
   598 
       
   599 }
       
   600 
       
   601 /**
       
   602  * Register custom post type & create the media post used to attach images.
       
   603  *
       
   604  * @uses        get_results()
       
   605  *
       
   606  * @return      void
       
   607  *
       
   608  * @access      public
       
   609  * @since       2.0
       
   610  */
       
   611 if ( ! function_exists( 'ot_create_media_post' ) ) {
       
   612   
       
   613   function ot_create_media_post() {
       
   614     
       
   615     register_post_type( 'option-tree', array(
       
   616       'labels'              => array( 'name' => __( 'Option Tree', 'option-tree' ) ),
       
   617       'public'              => false,
       
   618       'show_ui'             => false,
       
   619       'capability_type'     => 'post',
       
   620       'exclude_from_search' => true,
       
   621       'hierarchical'        => false,
       
   622       'rewrite'             => false,
       
   623       'supports'            => array( 'title', 'editor' ),
       
   624       'can_export'          => false,
       
   625       'show_in_nav_menus'   => false
       
   626     ) );
       
   627   
       
   628     /* look for custom page */
       
   629     $post_id = ot_get_media_post_ID();
       
   630       
       
   631     /* no post exists */
       
   632     if ( $post_id == 0 ) {
       
   633       
       
   634       /* create post object */
       
   635       $_p = array();
       
   636       $_p['post_title']     = 'Media';
       
   637       $_p['post_status']    = 'private';
       
   638       $_p['post_type']      = 'option-tree';
       
   639       $_p['comment_status'] = 'closed';
       
   640       $_p['ping_status']    = 'closed';
       
   641       
       
   642       /* insert the post into the database */
       
   643       wp_insert_post( $_p );
       
   644       
       
   645     }
       
   646   
       
   647   }
       
   648 
       
   649 }
       
   650 
       
   651 /**
       
   652  * Setup default settings array.
       
   653  *
       
   654  * @return    void
       
   655  *
       
   656  * @access    public
       
   657  * @since     2.0
       
   658  */
       
   659 if ( ! function_exists( 'ot_default_settings' ) ) {
       
   660 
       
   661   function ot_default_settings() {
       
   662     global $wpdb, $table_prefix;
       
   663     
       
   664     if ( ! get_option( 'option_tree_settings' ) ) {
       
   665       
       
   666       $section_count = 0;
       
   667       $settings_count = 0;
       
   668       $settings = array();
       
   669       
       
   670       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" ) ) {
       
   671         
       
   672         foreach ( $old_settings as $setting ) {
       
   673           
       
   674           /* heading is a section now */
       
   675           if ( $setting->item_type == 'heading' ) {
       
   676             
       
   677             /* add section to the sections array */
       
   678             $settings['sections'][$section_count]['id'] = $setting->item_id;
       
   679             $settings['sections'][$section_count]['title'] = $setting->item_title;
       
   680             
       
   681             /* save the last section id to use in creating settings */
       
   682             $section = $setting->item_id;
       
   683             
       
   684             /* increment the section count */
       
   685             $section_count++;
       
   686             
       
   687           } else {
       
   688             
       
   689             /* add setting to the settings array */
       
   690             $settings['settings'][$settings_count]['id'] = $setting->item_id;
       
   691             $settings['settings'][$settings_count]['label'] = $setting->item_title;
       
   692             $settings['settings'][$settings_count]['desc'] = $setting->item_desc;
       
   693             $settings['settings'][$settings_count]['section'] = $section;
       
   694             $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( $setting->item_type );
       
   695             $settings['settings'][$settings_count]['std'] = '';
       
   696             $settings['settings'][$settings_count]['class'] = '';
       
   697             
       
   698             /* textarea rows */
       
   699             $rows = '';
       
   700             if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) {
       
   701               if ( (int) $setting->item_options > 0 ) {
       
   702                 $rows = (int) $setting->item_options;
       
   703               } else {
       
   704                 $rows = 15;
       
   705               }
       
   706             }
       
   707             $settings['settings'][$settings_count]['rows'] = $rows;
       
   708             
       
   709             /* post type */
       
   710             $post_type = '';
       
   711             if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) {
       
   712               if ( '' != $setting->item_options ) {
       
   713                 $post_type = $setting->item_options;
       
   714               } else {
       
   715                 $post_type = 'post';
       
   716               }
       
   717             }
       
   718             $settings['settings'][$settings_count]['post_type'] = $post_type;
       
   719             
       
   720             /* choices */
       
   721             $choices = array();
       
   722             if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) {
       
   723               if ( '' != $setting->item_options ) {
       
   724                 $choices = ot_convert_string_to_array( $setting->item_options );
       
   725               }
       
   726             }
       
   727             $settings['settings'][$settings_count]['choices'] = $choices;
       
   728             
       
   729             $settings_count++;
       
   730           }
       
   731         
       
   732         }
       
   733         
       
   734         /* make sure each setting has a section just incase */
       
   735         if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) {
       
   736           foreach( $settings['settings'] as $k => $setting ) {
       
   737             if ( '' == $setting['section'] ) {
       
   738               $settings['settings'][$k]['section'] = $settings['sections'][0]['id'];
       
   739             }
       
   740           }
       
   741         }
       
   742           
       
   743       }
       
   744       
       
   745       /* if array if not properly formed create fallback settings array */
       
   746       if ( ! isset( $settings['sections'] ) || ! isset( $settings['settings'] ) ) {
       
   747         
       
   748         $settings = array(
       
   749           'sections' => array(
       
   750             array(
       
   751               'id'        => 'general',
       
   752               'title'     => __( 'General', 'option-tree' )
       
   753             )
       
   754           ),
       
   755           'settings' => array(
       
   756             array(
       
   757               'id'        => 'sample_text',
       
   758               'label'     => __( 'Sample Text Field Label', 'option-tree' ),
       
   759               'desc'      => __( 'Description for the sample text field.', 'option-tree' ),
       
   760               'section'   => 'general',
       
   761               'type'      => 'text',
       
   762               'std'       => '',
       
   763               'class'     => '',
       
   764               'rows'      => '',
       
   765               'post_type' => '',
       
   766               'choices'   => array()
       
   767             )
       
   768           )
       
   769         );
       
   770         
       
   771       }
       
   772       
       
   773       /* update the settings array */
       
   774       update_option( 'option_tree_settings', $settings );
       
   775       
       
   776       /* get option tree array */
       
   777       $options = get_option( 'option_tree' );
       
   778       
       
   779       /* validate options */
       
   780       if ( is_array( $options ) ) {
       
   781 
       
   782         foreach( $settings['settings'] as $setting ) {
       
   783         
       
   784           if ( isset( $options[$setting['id']] ) ) {
       
   785             
       
   786             $content = ot_stripslashes( $options[$setting['id']] );
       
   787             
       
   788             $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] );
       
   789             
       
   790           }
       
   791         
       
   792         }
       
   793         
       
   794         /* execute the action hook and pass the theme options to it */
       
   795         do_action( 'ot_before_theme_options_save', $options );
       
   796         
       
   797         /* update the option tree array */
       
   798         update_option( 'option_tree', $options );
       
   799         
       
   800       }
       
   801       
       
   802     }
       
   803     
       
   804   }
       
   805 
       
   806 }
       
   807 
       
   808 /**
       
   809  * Helper function to update the CSS option type after save.
       
   810  *
       
   811  * @return    void
       
   812  *
       
   813  * @access    public
       
   814  * @since     2.0
       
   815  */
       
   816 if ( ! function_exists( 'ot_save_css' ) ) {
       
   817 
       
   818   function ot_save_css( $options ) {
       
   819     
       
   820     /* grab a copy of the settings */
       
   821     $settings = get_option( 'option_tree_settings' );
       
   822       
       
   823     /* has settings */
       
   824     if ( isset( $settings['settings'] ) ) {
       
   825         
       
   826       /* loop through sections and insert CSS when needed */
       
   827       foreach( $settings['settings'] as $k => $setting ) {
       
   828         
       
   829         /* is the CSS option type */
       
   830         if ( isset( $setting['type'] ) && 'css' == $setting['type'] ) {
       
   831 
       
   832           /* insert CSS into dynamic.css */
       
   833           if ( isset( $options[$setting['id']] ) && '' !== $options[$setting['id']] ) {
       
   834             
       
   835             ot_insert_css_with_markers( $setting['id'], $options[$setting['id']] );
       
   836           
       
   837           /* remove old CSS from dynamic.css */
       
   838           } else {
       
   839           
       
   840             ot_remove_old_css( $setting['id'] );
       
   841             
       
   842           }
       
   843           
       
   844         }
       
   845       
       
   846       }
       
   847       
       
   848     }
       
   849     
       
   850   }
       
   851 
       
   852 }
       
   853  
       
   854 /**
       
   855  * Helper function to load filters for XML mime type.
       
   856  *
       
   857  * @return    void
       
   858  *
       
   859  * @access    public
       
   860  * @since     2.0
       
   861  */
       
   862 if ( ! function_exists( 'ot_add_xml_to_upload_filetypes' ) ) {
       
   863 
       
   864   function ot_add_xml_to_upload_filetypes() {
       
   865     
       
   866     add_filter( 'upload_mimes', 'ot_upload_mimes' );
       
   867     add_filter( 'wp_mime_type_icon', 'ot_xml_mime_type_icon', 10, 2 );
       
   868   
       
   869   }
       
   870 
       
   871 }
       
   872 
       
   873 /**
       
   874  * Filter 'upload_mimes' and add xml. 
       
   875  *
       
   876  * @param     array     $mimes An array of valid upload mime types
       
   877  * @return    array
       
   878  *
       
   879  * @access    public
       
   880  * @since     2.0
       
   881  */
       
   882 if ( ! function_exists( 'ot_upload_mimes' ) ) {
       
   883 
       
   884   function ot_upload_mimes( $mimes ) {
       
   885   
       
   886     $mimes['xml'] = 'application/xml';
       
   887     
       
   888     return $mimes;
       
   889     
       
   890   }
       
   891 
       
   892 }
       
   893 
       
   894 /**
       
   895  * Filters 'wp_mime_type_icon' and have xml display as a document.
       
   896  *
       
   897  * @param     string    $icon The mime icon
       
   898  * @param     string    $mime The mime type
       
   899  * @return    string
       
   900  *
       
   901  * @access    public
       
   902  * @since     2.0
       
   903  */
       
   904 if ( ! function_exists( 'ot_xml_mime_type_icon' ) ) {
       
   905 
       
   906   function ot_xml_mime_type_icon( $icon, $mime ) {
       
   907   
       
   908     if ( $mime == 'application/xml' || $mime == 'text/xml' )
       
   909       return wp_mime_type_icon( 'document' );
       
   910       
       
   911     return $icon;
       
   912     
       
   913   }
       
   914 
       
   915 }
       
   916 
       
   917 /**
       
   918  * Import before the screen is displayed.
       
   919  *
       
   920  * @return    void
       
   921  *
       
   922  * @access    public
       
   923  * @since     2.0
       
   924  */
       
   925 if ( ! function_exists( 'ot_import' ) ) {
       
   926 
       
   927   function ot_import() {
       
   928     
       
   929     /* check and verify import xml nonce */
       
   930     if ( isset( $_POST['import_xml_nonce'] ) && wp_verify_nonce( $_POST['import_xml_nonce'], 'import_xml_form' ) ) {
       
   931 
       
   932       /* import input value */
       
   933       $file = isset( $_POST['import_xml'] ) ? esc_url( $_POST['import_xml'] ) : '';
       
   934       
       
   935       /* validate xml file */
       
   936       if ( preg_match( "/(.xml)$/i", $file ) && class_exists( 'SimpleXMLElement' ) ) {
       
   937       
       
   938         $settings = ot_import_xml( $file );
       
   939         
       
   940       }
       
   941       
       
   942       /* default message */
       
   943       $message = 'failed';
       
   944       
       
   945       /* cleanup, save, & show success message */
       
   946       if ( isset( $settings ) && ! empty( $settings ) ) {
       
   947         
       
   948         /* delete file */
       
   949         if ( $file ) {
       
   950           global $wpdb;
       
   951           $attachmentid = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$file'" );
       
   952           wp_delete_attachment( $attachmentid, true );
       
   953         }
       
   954         
       
   955         /* update settings */
       
   956         update_option( 'option_tree_settings', $settings );
       
   957         
       
   958         /* set message */
       
   959         $message = 'success';
       
   960         
       
   961       }
       
   962       
       
   963       /* redirect */
       
   964       wp_redirect( add_query_arg( array( 'action' => 'import-xml', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
   965       exit;
       
   966       
       
   967     }
       
   968     
       
   969     /* check and verify import settings nonce */
       
   970     if ( isset( $_POST['import_settings_nonce'] ) && wp_verify_nonce( $_POST['import_settings_nonce'], 'import_settings_form' ) ) {
       
   971 
       
   972       /* textarea value */
       
   973       $textarea = isset( $_POST['import_settings'] ) ? unserialize( ot_decode( $_POST['import_settings'] ) ) : '';
       
   974       
       
   975       /* default message */
       
   976       $message = 'failed';
       
   977       
       
   978       /* is array: save & show success message */
       
   979       if ( is_array( $textarea ) ) {
       
   980         update_option( 'option_tree_settings', $textarea );
       
   981         $message = 'success';
       
   982       }
       
   983       
       
   984       /* redirect */
       
   985       wp_redirect( add_query_arg( array( 'action' => 'import-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
   986       exit;
       
   987       
       
   988     }
       
   989     
       
   990     /* check and verify import theme options data nonce */
       
   991     if ( isset( $_POST['import_data_nonce'] ) && wp_verify_nonce( $_POST['import_data_nonce'], 'import_data_form' ) ) {
       
   992       
       
   993       /* default message */
       
   994       $message = 'failed';
       
   995       
       
   996       /* textarea value */
       
   997       $options = isset( $_POST['import_data'] ) ? unserialize( ot_decode( $_POST['import_data'] ) ) : '';
       
   998       
       
   999       /* get settings array */
       
  1000       $settings = get_option( 'option_tree_settings' );
       
  1001       
       
  1002       /* has options */
       
  1003       if ( is_array( $options ) ) {
       
  1004         
       
  1005         /* validate options */
       
  1006         if ( is_array( $settings ) ) {
       
  1007         
       
  1008           foreach( $settings['settings'] as $setting ) {
       
  1009           
       
  1010             if ( isset( $options[$setting['id']] ) ) {
       
  1011               
       
  1012               $content = ot_stripslashes( $options[$setting['id']] );
       
  1013               
       
  1014               $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] );
       
  1015               
       
  1016             }
       
  1017           
       
  1018           }
       
  1019         
       
  1020         }
       
  1021         
       
  1022         /* execute the action hook and pass the theme options to it */
       
  1023         do_action( 'ot_before_theme_options_save', $options );
       
  1024       
       
  1025         /* update the option tree array */
       
  1026         update_option( 'option_tree', $options );
       
  1027         
       
  1028         $message = 'success';
       
  1029         
       
  1030       }
       
  1031       
       
  1032       /* redirect accordingly */
       
  1033       wp_redirect( add_query_arg( array( 'action' => 'import-data', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
  1034       exit;
       
  1035       
       
  1036     }
       
  1037     
       
  1038     /* check and verify import layouts nonce */
       
  1039     if ( isset( $_POST['import_layouts_nonce'] ) && wp_verify_nonce( $_POST['import_layouts_nonce'], 'import_layouts_form' ) ) {
       
  1040       
       
  1041       /* default message */
       
  1042       $message = 'failed';
       
  1043       
       
  1044       /* textarea value */
       
  1045       $layouts = isset( $_POST['import_layouts'] ) ? unserialize( ot_decode( $_POST['import_layouts'] ) ) : '';
       
  1046       
       
  1047       /* get settings array */
       
  1048       $settings = get_option( 'option_tree_settings' );
       
  1049       
       
  1050       /* has layouts */
       
  1051       if ( is_array( $layouts ) ) {
       
  1052         
       
  1053         /* validate options */
       
  1054         if ( is_array( $settings ) ) {
       
  1055           
       
  1056           foreach( $layouts as $key => $value ) {
       
  1057             
       
  1058             if ( $key == 'active_layout' )
       
  1059               continue;
       
  1060               
       
  1061             $options = unserialize( ot_decode( $value ) );
       
  1062             
       
  1063             foreach( $settings['settings'] as $setting ) {
       
  1064 
       
  1065               if ( isset( $options[$setting['id']] ) ) {
       
  1066                 
       
  1067                 $content = ot_stripslashes( $options[$setting['id']] );
       
  1068                 
       
  1069                 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] );
       
  1070                 
       
  1071               }
       
  1072             
       
  1073             }
       
  1074 
       
  1075             $layouts[$key] = ot_encode( serialize( $options ) );
       
  1076           
       
  1077           }
       
  1078         
       
  1079         }
       
  1080         
       
  1081         /* update the option tree array */
       
  1082         if ( isset( $layouts['active_layout'] ) ) {
       
  1083           
       
  1084           $new_options = unserialize( ot_decode( $layouts[$layouts['active_layout']] ) );
       
  1085           
       
  1086           /* execute the action hook and pass the theme options to it */
       
  1087           do_action( 'ot_before_theme_options_save', $new_options );
       
  1088         
       
  1089           update_option( 'option_tree', $new_options );
       
  1090           
       
  1091         }
       
  1092         
       
  1093         /* update the option tree layouts array */
       
  1094         update_option( 'option_tree_layouts', $layouts );
       
  1095         
       
  1096         $message = 'success';
       
  1097         
       
  1098       }
       
  1099         
       
  1100       /* redirect accordingly */
       
  1101       wp_redirect( add_query_arg( array( 'action' => 'import-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
  1102       exit;
       
  1103       
       
  1104     }
       
  1105     
       
  1106     return false;
       
  1107 
       
  1108   }
       
  1109   
       
  1110 }
       
  1111 
       
  1112 /**
       
  1113  * Export before the screen is displayed.
       
  1114  *
       
  1115  * @return    void
       
  1116  *
       
  1117  * @access    public
       
  1118  * @since     2.0.8
       
  1119  */
       
  1120 if ( ! function_exists( 'ot_export' ) ) {
       
  1121 
       
  1122   function ot_export() {
       
  1123     
       
  1124     /* check and verify export settings file nonce */
       
  1125     if ( isset( $_POST['export_settings_file_nonce'] ) && wp_verify_nonce( $_POST['export_settings_file_nonce'], 'export_settings_file_form' ) ) {
       
  1126 
       
  1127       ot_export_php_settings_array();
       
  1128       
       
  1129     }
       
  1130     
       
  1131   }
       
  1132   
       
  1133 }
       
  1134 
       
  1135 /**
       
  1136  * Reusable XMl import helper function.
       
  1137  *
       
  1138  * @param     string    $file The path to the file.
       
  1139  * @return    mixed     False or an array of settings.
       
  1140  *
       
  1141  * @access    public
       
  1142  * @since     2.0.8
       
  1143  */
       
  1144 if ( ! function_exists( 'ot_import_xml' ) ) {
       
  1145 
       
  1146   function ot_import_xml( $file ) {
       
  1147     
       
  1148     $get_data = wp_remote_get( $file );
       
  1149     
       
  1150     if ( is_wp_error( $get_data ) )
       
  1151       return false;
       
  1152         
       
  1153     $rawdata = isset( $get_data['body'] ) ? $get_data['body'] : false;
       
  1154 
       
  1155     if ( $rawdata ) {
       
  1156       
       
  1157       $section_count = 0;
       
  1158       $settings_count = 0;
       
  1159       
       
  1160       $section = '';
       
  1161       
       
  1162       $settings = array();
       
  1163       $xml = new SimpleXMLElement( $rawdata );
       
  1164   
       
  1165       foreach ( $xml->row as $value ) {
       
  1166         
       
  1167         /* heading is a section now */
       
  1168         if ( $value->item_type == 'heading' ) {
       
  1169           
       
  1170           /* add section to the sections array */
       
  1171           $settings['sections'][$section_count]['id'] = (string) $value->item_id;
       
  1172           $settings['sections'][$section_count]['title'] = (string) $value->item_title;
       
  1173           
       
  1174           /* save the last section id to use in creating settings */
       
  1175           $section = (string) $value->item_id;
       
  1176           
       
  1177           /* increment the section count */
       
  1178           $section_count++;
       
  1179           
       
  1180         } else {
       
  1181           
       
  1182           /* add setting to the settings array */
       
  1183           $settings['settings'][$settings_count]['id'] = (string) $value->item_id;
       
  1184           $settings['settings'][$settings_count]['label'] = (string) $value->item_title;
       
  1185           $settings['settings'][$settings_count]['desc'] = (string) $value->item_desc;
       
  1186           $settings['settings'][$settings_count]['section'] = $section;
       
  1187           $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( (string) $value->item_type );
       
  1188           $settings['settings'][$settings_count]['std'] = '';
       
  1189           $settings['settings'][$settings_count]['class'] = '';
       
  1190           
       
  1191           /* textarea rows */
       
  1192           $rows = '';
       
  1193           if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) {
       
  1194             if ( (int) $value->item_options > 0 ) {
       
  1195               $rows = (int) $value->item_options;
       
  1196             } else {
       
  1197               $rows = 15;
       
  1198             }
       
  1199           }
       
  1200           $settings['settings'][$settings_count]['rows'] = $rows;
       
  1201           
       
  1202           /* post type */
       
  1203           $post_type = '';
       
  1204           if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) {
       
  1205             if ( '' != (string) $value->item_options ) {
       
  1206               $post_type = (string) $value->item_options;
       
  1207             } else {
       
  1208               $post_type = 'post';
       
  1209             }
       
  1210           }
       
  1211           $settings['settings'][$settings_count]['post_type'] = $post_type;
       
  1212           
       
  1213           /* choices */
       
  1214           $choices = array();
       
  1215           if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) {
       
  1216             if ( '' != (string) $value->item_options ) {
       
  1217               $choices = ot_convert_string_to_array( (string) $value->item_options );
       
  1218             }
       
  1219           }
       
  1220           $settings['settings'][$settings_count]['choices'] = $choices;
       
  1221           
       
  1222           $settings_count++;
       
  1223         }
       
  1224   
       
  1225       }
       
  1226       
       
  1227       /* make sure each setting has a section just incase */
       
  1228       if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) {
       
  1229         foreach( $settings['settings'] as $k => $setting ) {
       
  1230           if ( '' == $setting['section'] ) {
       
  1231             $settings['settings'][$k]['section'] = $settings['sections'][0]['id'];
       
  1232           }
       
  1233         }
       
  1234       }
       
  1235       
       
  1236       return $settings;
       
  1237       
       
  1238     }
       
  1239     
       
  1240     return false;
       
  1241   }
       
  1242 
       
  1243 }
       
  1244 
       
  1245 /**
       
  1246  * Export the Theme Mode theme-options.php
       
  1247  *
       
  1248  * @return    attachment
       
  1249  *
       
  1250  * @access    public
       
  1251  * @since     2.0.8
       
  1252  */
       
  1253 if ( ! function_exists( 'ot_export_php_settings_array' ) ) {
       
  1254 
       
  1255   function ot_export_php_settings_array() {
       
  1256     
       
  1257     $content              = '';
       
  1258     $build_settings       = '';
       
  1259     $contextual_help      = '';
       
  1260     $sections             = '';
       
  1261     $settings             = '';
       
  1262     $option_tree_settings = get_option( 'option_tree_settings', array() );
       
  1263     
       
  1264     header( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
       
  1265     header( "Pragma: no-cache ");
       
  1266     header( "Content-Description: File Transfer" );
       
  1267     header( 'Content-Disposition: attachment; filename="theme-options.php"');
       
  1268     header( "Content-Type: application/octet-stream");
       
  1269     header( "Content-Transfer-Encoding: binary" );
       
  1270     
       
  1271     /* build contextual help content */
       
  1272     if ( isset( $option_tree_settings['contextual_help']['content'] ) ) {
       
  1273       $help = '';
       
  1274       foreach( $option_tree_settings['contextual_help']['content'] as $value ) {
       
  1275         $_id = isset( $value['id'] ) ? $value['id'] : '';
       
  1276         $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '';
       
  1277         $_content = isset( $value['content'] ) ? html_entity_decode(  str_replace( "'", "\'", $value['content'] ) ) : '';
       
  1278         $help.= "
       
  1279         array(
       
  1280           'id'        => '$_id',
       
  1281           'title'     => '$_title',
       
  1282           'content'   => '$_content'
       
  1283         ),";
       
  1284       }
       
  1285       $help = substr_replace( $help, '' , -1 );
       
  1286       $contextual_help = "
       
  1287       'content'       => array( $help
       
  1288       ),";
       
  1289     }
       
  1290     
       
  1291     /* build contextual help sidebar */
       
  1292     if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) {
       
  1293       $contextual_help.= "
       
  1294       'sidebar'       => '" . html_entity_decode(  str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) . "'";
       
  1295     }
       
  1296     
       
  1297     /* check that $contexual_help has a value and add to $build_settings */
       
  1298     if ( '' != $contextual_help ) {
       
  1299       $build_settings.= "
       
  1300     'contextual_help' => array( $contextual_help
       
  1301     ),";
       
  1302     }
       
  1303     
       
  1304     /* build sections */
       
  1305     if ( isset( $option_tree_settings['sections'] ) ) {
       
  1306       foreach( $option_tree_settings['sections'] as $value ) {
       
  1307         $_id = isset( $value['id'] ) ? $value['id'] : '';
       
  1308         $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '';
       
  1309         $sections.= "
       
  1310       array(
       
  1311         'id'          => '$_id',
       
  1312         'title'       => '$_title'
       
  1313       ),";
       
  1314       }
       
  1315       $sections = substr_replace( $sections, '' , -1 );
       
  1316     }
       
  1317     
       
  1318     /* check that $sections has a value and add to $build_settings */
       
  1319     if ( '' != $sections ) {
       
  1320       $build_settings.= "
       
  1321     'sections'        => array( $sections
       
  1322     )";
       
  1323     }
       
  1324     
       
  1325     /* build settings */
       
  1326     if ( isset( $option_tree_settings['settings'] ) ) {
       
  1327       foreach( $option_tree_settings['settings'] as $value ) {
       
  1328         $_id = isset( $value['id'] ) ? $value['id'] : '';
       
  1329         $_label = isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : '';
       
  1330         $_desc = isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : '';
       
  1331         $_std = isset( $value['std'] ) ? str_replace( "'", "\'", $value['std'] ) : '';
       
  1332         $_type = isset( $value['type'] ) ? $value['type'] : '';
       
  1333         $_section = isset( $value['section'] ) ? $value['section'] : '';
       
  1334         $_rows = isset( $value['rows'] ) ? $value['rows'] : '';
       
  1335         $_post_type = isset( $value['post_type'] ) ? $value['post_type'] : '';
       
  1336         $_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : '';
       
  1337         $_min_max_step = isset( $value['min_max_step'] ) ? $value['min_max_step'] : '';
       
  1338         $_class = isset( $value['class'] ) ? $value['class'] : '';
       
  1339         
       
  1340         $choices = '';
       
  1341         if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) {
       
  1342           foreach( $value['choices'] as $choice ) {
       
  1343             $_choice_value = isset( $choice['value'] ) ? str_replace( "'", "\'", $choice['value'] ) : '';
       
  1344             $_choice_label = isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : '';
       
  1345             $_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : '';
       
  1346             $choices.= "
       
  1347           array(
       
  1348             'value'       => '$_choice_value',
       
  1349             'label'       => '$_choice_label',
       
  1350             'src'         => '$_choice_src'
       
  1351           ),";
       
  1352           }
       
  1353           $choices = substr_replace( $choices, '' , -1 );
       
  1354           $choices = ",
       
  1355         'choices'     => array( $choices
       
  1356         ),";
       
  1357         }
       
  1358         
       
  1359         $std = "'$_std'";
       
  1360         if ( is_array( $_std ) ) {
       
  1361           $std_array = array();
       
  1362           foreach( $_std as $_sk => $_sv ) {
       
  1363             $std_array[] = "'$_sk' => '$_sv'";
       
  1364           }
       
  1365           $std = 'array(
       
  1366 ' . implode( ",\n", $std_array ) . '
       
  1367           )';
       
  1368         }
       
  1369         
       
  1370         $setting_settings = '';
       
  1371         if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) {
       
  1372           foreach( $value['settings'] as $setting ) {
       
  1373             $_setting_id = isset( $setting['id'] ) ? $setting['id'] : '';
       
  1374             $_setting_label = isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : '';
       
  1375             $_setting_desc = isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : '';
       
  1376             $_setting_std = isset( $setting['std'] ) ? $setting['std'] : '';
       
  1377             $_setting_type = isset( $setting['type'] ) ? $setting['type'] : '';
       
  1378             $_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : '';
       
  1379             $_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : '';
       
  1380             $_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : '';
       
  1381             $_setting_min_max_step = isset( $setting['min_max_step'] ) ? $setting['min_max_step'] : '';
       
  1382             $_setting_class = isset( $setting['class'] ) ? $setting['class'] : '';
       
  1383             
       
  1384             $setting_choices = '';
       
  1385             if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) {
       
  1386               foreach( $setting['choices'] as $setting_choice ) {
       
  1387                 $_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : '';
       
  1388                 $_setting_choice_label = isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : '';
       
  1389                 $_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : '';
       
  1390                 $setting_choices.= "
       
  1391               array(
       
  1392                 'value'       => '$_setting_choice_value',
       
  1393                 'label'       => '$_setting_choice_label',
       
  1394                 'src'         => '$_setting_choice_src'
       
  1395               ),";
       
  1396               }
       
  1397               $setting_choices = substr_replace( $setting_choices, '' , -1 );
       
  1398               $setting_choices = ",
       
  1399             'choices'     => array( $setting_choices
       
  1400             ),";
       
  1401             }
       
  1402             
       
  1403             $setting_std = "'$_setting_std'";
       
  1404             if ( is_array( $_setting_std ) ) {
       
  1405               $setting_std_array = array();
       
  1406               foreach( $_setting_std as $_ssk => $_ssv ) {
       
  1407                 $setting_std_array[] = "'$_ssk' => '$_ssv'";
       
  1408               }
       
  1409               $setting_std = 'array(
       
  1410 ' . implode( ",\n", $setting_std_array ) . '
       
  1411               )';
       
  1412             }
       
  1413         
       
  1414             $setting_settings.= "
       
  1415           array(
       
  1416             'id'          => '$_setting_id',
       
  1417             'label'       => '$_setting_label',
       
  1418             'desc'        => '$_setting_desc',
       
  1419             'std'         => $setting_std,
       
  1420             'type'        => '$_setting_type',
       
  1421             'rows'        => '$_setting_rows',
       
  1422             'post_type'   => '$_setting_post_type',
       
  1423             'taxonomy'    => '$_setting_taxonomy',
       
  1424             'min_max_step'=> '$_setting_min_max_step',
       
  1425             'class'       => '$_setting_class'$setting_choices
       
  1426           ),";
       
  1427           }
       
  1428           $setting_settings = substr_replace( $setting_settings, '' , -1 );
       
  1429           $setting_settings = ",
       
  1430         'settings'    => array( $setting_settings
       
  1431         )";
       
  1432         }
       
  1433         
       
  1434         $settings.= "
       
  1435       array(
       
  1436         'id'          => '$_id',
       
  1437         'label'       => '$_label',
       
  1438         'desc'        => '$_desc',
       
  1439         'std'         => $std,
       
  1440         'type'        => '$_type',
       
  1441         'section'     => '$_section',
       
  1442         'rows'        => '$_rows',
       
  1443         'post_type'   => '$_post_type',
       
  1444         'taxonomy'    => '$_taxonomy',
       
  1445         'min_max_step'=> '$_min_max_step',
       
  1446         'class'       => '$_class'$choices$setting_settings
       
  1447       ),";
       
  1448       }
       
  1449       $settings = substr_replace( $settings, '' , -1 );
       
  1450     }
       
  1451     
       
  1452     /* check that $sections has a value and add to $build_settings */
       
  1453     if ( '' != $settings ) {
       
  1454       $build_settings.= ",
       
  1455     'settings'        => array( $settings
       
  1456     )";
       
  1457     }
       
  1458     
       
  1459     $content.= "<?php
       
  1460 /**
       
  1461  * Initialize the custom theme options.
       
  1462  */
       
  1463 add_action( 'admin_init', 'custom_theme_options' );
       
  1464 
       
  1465 /**
       
  1466  * Build the custom settings & update OptionTree.
       
  1467  */
       
  1468 function custom_theme_options() {
       
  1469   /**
       
  1470    * Get a copy of the saved settings array. 
       
  1471    */
       
  1472   \$saved_settings = get_option( 'option_tree_settings', array() );
       
  1473   
       
  1474   /**
       
  1475    * Custom settings array that will eventually be 
       
  1476    * passes to the OptionTree Settings API Class.
       
  1477    */
       
  1478   \$custom_settings = array( $build_settings
       
  1479   );
       
  1480   
       
  1481   /* allow settings to be filtered before saving */
       
  1482   \$custom_settings = apply_filters( 'option_tree_settings_args', \$custom_settings );
       
  1483   
       
  1484   /* settings are not the same update the DB */
       
  1485   if ( \$saved_settings !== \$custom_settings ) {
       
  1486     update_option( 'option_tree_settings', \$custom_settings ); 
       
  1487   }
       
  1488   
       
  1489 }";
       
  1490 
       
  1491     echo $content;
       
  1492     die();
       
  1493   }
       
  1494 
       
  1495 }
       
  1496 
       
  1497 /**
       
  1498  * Save settings array before the screen is displayed.
       
  1499  *
       
  1500  * @return    void
       
  1501  *
       
  1502  * @access    public
       
  1503  * @since     2.0
       
  1504  */
       
  1505 if ( ! function_exists( 'ot_save_settings' ) ) {
       
  1506 
       
  1507   function ot_save_settings() {
       
  1508 
       
  1509     /* check and verify import settings nonce */
       
  1510     if ( isset( $_POST['option_tree_settings_nonce'] ) && wp_verify_nonce( $_POST['option_tree_settings_nonce'], 'option_tree_settings_form' ) ) {
       
  1511 
       
  1512       /* settings value */
       
  1513       $settings = isset( $_POST['option_tree_settings'] ) ? $_POST['option_tree_settings'] : '';
       
  1514       
       
  1515       /* validate sections */
       
  1516       if ( isset( $settings['sections'] ) ) {
       
  1517         
       
  1518         /* fix numeric keys since drag & drop will change them */
       
  1519         $settings['sections'] = array_values( $settings['sections'] );
       
  1520         
       
  1521         /* loop through sections */
       
  1522         foreach( $settings['sections'] as $k => $section ) {
       
  1523           
       
  1524           /* remove from array if missing values */
       
  1525           if ( ( ! isset( $section['title'] ) && ! isset( $section['id'] ) ) || ( '' == $section['title'] && '' == $section['id'] ) ) {
       
  1526           
       
  1527             unset( $settings['sections'][$k] );
       
  1528             
       
  1529           } else {
       
  1530             
       
  1531             /* validate label */
       
  1532             if ( '' != $section['title'] ) {
       
  1533             
       
  1534              $settings['sections'][$k]['title'] = wp_kses_post( $section['title'] );
       
  1535               
       
  1536             }
       
  1537             
       
  1538             /* missing title set to unfiltered ID */
       
  1539             if ( ! isset( $section['title'] ) || '' == $section['title'] ) {
       
  1540               
       
  1541               $settings['sections'][$k]['title'] = wp_kses_post( $section['id'] );
       
  1542             
       
  1543             /* missing ID set to title */ 
       
  1544             } else if ( ! isset( $section['id'] ) || '' == $section['id'] ) {
       
  1545               
       
  1546               $section['id'] = wp_kses_post( $section['title'] );
       
  1547               
       
  1548             }
       
  1549             
       
  1550             /* sanitize ID once everything has been checked first */
       
  1551             $settings['sections'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $section['id'] ) );
       
  1552             
       
  1553           }
       
  1554           
       
  1555         }
       
  1556         
       
  1557         $settings['sections'] = ot_stripslashes( $settings['sections'] );
       
  1558       
       
  1559       }
       
  1560       
       
  1561       /* validate settings by looping over array as many times as it takes */
       
  1562       if ( isset( $settings['settings'] ) ) {
       
  1563         
       
  1564         $settings['settings'] = ot_validate_settings_array( $settings['settings'] );
       
  1565         
       
  1566       }
       
  1567       
       
  1568       /* validate contextual_help */
       
  1569       if ( isset( $settings['contextual_help']['content'] ) ) {
       
  1570         
       
  1571         /* fix numeric keys since drag & drop will change them */
       
  1572         $settings['contextual_help']['content'] = array_values( $settings['contextual_help']['content'] );
       
  1573         
       
  1574         /* loop through content */
       
  1575         foreach( $settings['contextual_help']['content'] as $k => $content ) {
       
  1576           
       
  1577           /* remove from array if missing values */
       
  1578           if ( ( ! isset( $content['title'] ) && ! isset( $content['id'] ) ) || ( '' == $content['title'] && '' == $content['id'] ) ) {
       
  1579           
       
  1580             unset( $settings['contextual_help']['content'][$k] );
       
  1581             
       
  1582           } else {
       
  1583             
       
  1584             /* validate label */
       
  1585             if ( '' != $content['title'] ) {
       
  1586             
       
  1587              $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['title'] );
       
  1588               
       
  1589             }
       
  1590           
       
  1591             /* missing title set to unfiltered ID */
       
  1592             if ( ! isset( $content['title'] ) || '' == $content['title'] ) {
       
  1593               
       
  1594               $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['id'] );
       
  1595             
       
  1596             /* missing ID set to title */ 
       
  1597             } else if ( ! isset( $content['id'] ) || '' == $content['id'] ) {
       
  1598               
       
  1599               $content['id'] = wp_kses_post( $content['title'] );
       
  1600               
       
  1601             }
       
  1602             
       
  1603             /* sanitize ID once everything has been checked first */
       
  1604             $settings['contextual_help']['content'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $content['id'] ) );
       
  1605             
       
  1606           }
       
  1607           
       
  1608           /* validate textarea description */
       
  1609           if ( isset( $content['content'] ) ) {
       
  1610           
       
  1611             $settings['contextual_help']['content'][$k]['content'] = wp_kses_post( $content['content'] );
       
  1612             
       
  1613           }
       
  1614           
       
  1615         }
       
  1616       
       
  1617       }
       
  1618       
       
  1619       /* validate contextual_help sidebar */
       
  1620       if ( isset( $settings['contextual_help']['sidebar'] ) ) {
       
  1621       
       
  1622         $settings['contextual_help']['sidebar'] = wp_kses_post( $settings['contextual_help']['sidebar'] );
       
  1623         
       
  1624       }
       
  1625       
       
  1626       $settings['contextual_help'] = ot_stripslashes( $settings['contextual_help'] );
       
  1627       
       
  1628       /* default message */
       
  1629       $message = 'failed';
       
  1630       
       
  1631       /* is array: save & show success message */
       
  1632       if ( is_array( $settings ) ) {
       
  1633         
       
  1634         /* WPML unregister ID's that have been removed */
       
  1635         if ( function_exists( 'icl_unregister_string' ) ) {
       
  1636           
       
  1637           $current = get_option( 'option_tree_settings' );
       
  1638           $options = get_option( 'option_tree' );
       
  1639           
       
  1640           if ( isset( $current['settings'] ) ) {
       
  1641             
       
  1642             /* Empty ID array */
       
  1643             $new_ids = array();
       
  1644             
       
  1645             /* Build the WPML IDs array */
       
  1646             foreach( $settings['settings'] as $setting ) {
       
  1647             
       
  1648               if ( $setting['id'] ) {
       
  1649                 
       
  1650                 $new_ids[] = $setting['id'];
       
  1651 
       
  1652               }
       
  1653               
       
  1654             }
       
  1655             
       
  1656             /* Remove missing IDs from WPML */
       
  1657             foreach( $current['settings'] as $current_setting ) {
       
  1658               
       
  1659               if ( ! in_array( $current_setting['id'], $new_ids ) ) {
       
  1660               
       
  1661                 if ( ! empty( $options[$current_setting['id']] ) && in_array( $current_setting['type'], array( 'list-item', 'slider' ) ) ) {
       
  1662                   
       
  1663                   foreach( $options[$current_setting['id']] as $key => $value ) {
       
  1664           
       
  1665                     foreach( $value as $ckey => $cvalue ) {
       
  1666                       
       
  1667                       ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key );
       
  1668                       
       
  1669                     }
       
  1670                   
       
  1671                   }
       
  1672                   
       
  1673                 } else {
       
  1674                 
       
  1675                   ot_wpml_unregister_string( $current_setting['id'] );
       
  1676                   
       
  1677                 }
       
  1678               
       
  1679               }
       
  1680               
       
  1681             }
       
  1682 
       
  1683           }
       
  1684           
       
  1685         }
       
  1686         
       
  1687         update_option( 'option_tree_settings', $settings );
       
  1688         $message = 'success';
       
  1689         
       
  1690       }
       
  1691       
       
  1692       /* redirect */
       
  1693       wp_redirect( add_query_arg( array( 'action' => 'save-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
  1694       exit;
       
  1695       
       
  1696     }
       
  1697     
       
  1698     return false;
       
  1699 
       
  1700   }
       
  1701   
       
  1702 }
       
  1703 
       
  1704 /**
       
  1705  * Validate the settings array before save.
       
  1706  *
       
  1707  * This function will loop over the settings array as many 
       
  1708  * times as it takes to validate every sub setting.
       
  1709  *
       
  1710  * @param     array     $settings The array of settings.
       
  1711  * @return    array
       
  1712  *
       
  1713  * @access    public
       
  1714  * @since     2.0
       
  1715  */
       
  1716 if ( ! function_exists( 'ot_validate_settings_array' ) ) {
       
  1717 
       
  1718   function ot_validate_settings_array( $settings = array() ) {
       
  1719     
       
  1720     /* validate settings */
       
  1721     if ( count( $settings ) > 0 ) {
       
  1722       
       
  1723       /* fix numeric keys since drag & drop will change them */
       
  1724       $settings = array_values( $settings );
       
  1725       
       
  1726       /* loop through settings */
       
  1727       foreach( $settings as $k => $setting ) {
       
  1728         
       
  1729         
       
  1730         /* remove from array if missing values */
       
  1731         if ( ( ! isset( $setting['label'] ) && ! isset( $setting['id'] ) ) || ( '' == $setting['label'] && '' == $setting['id'] ) ) {
       
  1732         
       
  1733           unset( $settings[$k] );
       
  1734           
       
  1735         } else {
       
  1736           
       
  1737           /* validate label */
       
  1738           if ( '' != $setting['label'] ) {
       
  1739           
       
  1740             $settings[$k]['label'] = wp_kses_post( $setting['label'] );
       
  1741             
       
  1742           }
       
  1743           
       
  1744           /* missing label set to unfiltered ID */
       
  1745           if ( ! isset( $setting['label'] ) || '' == $setting['label'] ) {
       
  1746             
       
  1747             $settings[$k]['label'] = $setting['id'];
       
  1748           
       
  1749           /* missing ID set to label */ 
       
  1750           } else if ( ! isset( $setting['id'] ) || '' == $setting['id'] ) {
       
  1751             
       
  1752             $setting['id'] = wp_kses_post( $setting['label'] );
       
  1753             
       
  1754           }
       
  1755           
       
  1756           /* sanitize ID once everything has been checked first */
       
  1757           $settings[$k]['id'] = ot_sanitize_option_id( wp_kses_post( $setting['id'] ) );
       
  1758           
       
  1759         }
       
  1760         
       
  1761         /* validate description */
       
  1762         if ( '' != $setting['desc']  ) {
       
  1763         
       
  1764           $settings[$k]['desc'] = wp_kses_post( $setting['desc'] );
       
  1765           
       
  1766         }
       
  1767         
       
  1768         /* validate choices */
       
  1769         if ( isset( $setting['choices'] ) ) {
       
  1770           
       
  1771           /* loop through choices */
       
  1772           foreach( $setting['choices'] as $ck => $choice ) {
       
  1773             
       
  1774             /* remove from array if missing values */
       
  1775             if ( ( ! isset( $choice['label'] ) && ! isset( $choice['value'] ) ) || ( '' == $choice['label'] && '' == $choice['value'] ) ) {
       
  1776         
       
  1777               unset( $setting['choices'][$ck] );
       
  1778               
       
  1779             } else {
       
  1780               
       
  1781               /* missing label set to unfiltered ID */
       
  1782               if ( ! isset( $choice['label'] ) || '' == $choice['label'] ) {
       
  1783                 
       
  1784                 $setting['choices'][$ck]['label'] = wp_kses_post( $choice['value'] );
       
  1785               
       
  1786               /* missing value set to label */ 
       
  1787               } else if ( ! isset( $choice['value'] ) || '' == $choice['value'] ) {
       
  1788                 
       
  1789                 $setting['choices'][$ck]['value'] = ot_sanitize_option_id( wp_kses_post( $choice['label'] ) );
       
  1790                 
       
  1791               }
       
  1792               
       
  1793             }
       
  1794             
       
  1795           }
       
  1796           
       
  1797           /* update keys and push new array values */
       
  1798           $settings[$k]['choices'] = array_values( $setting['choices'] );
       
  1799           
       
  1800         }
       
  1801         
       
  1802         /* validate sub settings */
       
  1803         if ( isset( $setting['settings'] ) ) {
       
  1804 
       
  1805           $settings[$k]['settings'] = ot_validate_settings_array( $setting['settings'] );
       
  1806           
       
  1807         }
       
  1808 
       
  1809       }
       
  1810     
       
  1811     }
       
  1812     
       
  1813     /* return array but strip those damn slashes out first!!! */
       
  1814     return ot_stripslashes( $settings );
       
  1815     
       
  1816   }
       
  1817 
       
  1818 }
       
  1819 
       
  1820 /**
       
  1821  * Save layouts array before the screen is displayed.
       
  1822  *
       
  1823  * @return    void
       
  1824  *
       
  1825  * @access    public
       
  1826  * @since     2.0
       
  1827  */
       
  1828 if ( ! function_exists( 'ot_modify_layouts' ) ) {
       
  1829 
       
  1830   function ot_modify_layouts() {
       
  1831 
       
  1832     /* check and verify modify layouts nonce */
       
  1833     if ( isset( $_POST['option_tree_modify_layouts_nonce'] ) && wp_verify_nonce( $_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form' ) ) {
       
  1834       
       
  1835       /* previous layouts value */
       
  1836       $option_tree_layouts = get_option( 'option_tree_layouts' );
       
  1837       
       
  1838       /* new layouts value */
       
  1839       $layouts = isset( $_POST['option_tree_layouts'] ) ? $_POST['option_tree_layouts'] : '';
       
  1840       
       
  1841       /* rebuild layout array */
       
  1842       $rebuild = array();
       
  1843       
       
  1844       /* validate layouts */
       
  1845       if ( is_array( $layouts ) && ! empty( $layouts ) ) {
       
  1846         
       
  1847         /* setup active layout */
       
  1848         if ( isset( $layouts['active_layout'] ) && ! empty( $layouts['active_layout'] ) ) {
       
  1849           $rebuild['active_layout'] = $layouts['active_layout'];
       
  1850         }
       
  1851         
       
  1852         /* add new and overwrite active layout */
       
  1853         if ( isset( $layouts['_add_new_layout_'] ) && ! empty( $layouts['_add_new_layout_'] ) ) {
       
  1854           $rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] );
       
  1855           $rebuild[$rebuild['active_layout']] = ot_encode( serialize( get_option( 'option_tree' ) ) );
       
  1856         }
       
  1857         
       
  1858         $first_layout = '';
       
  1859         
       
  1860         /* loop through layouts */
       
  1861         foreach( $layouts as $key => $layout ) {
       
  1862           
       
  1863           /* skip over active layout key */
       
  1864           if ( $key == 'active_layout' )
       
  1865             continue;
       
  1866           
       
  1867           /* check if the key exists then set value */
       
  1868           if ( isset( $option_tree_layouts[$key] ) && ! empty( $option_tree_layouts[$key] ) ) {
       
  1869             $rebuild[$key] = $option_tree_layouts[$key];
       
  1870             if ( '' == $first_layout ) {
       
  1871               $first_layout = $key;
       
  1872             }
       
  1873           }
       
  1874           
       
  1875         }
       
  1876         
       
  1877         if ( isset( $rebuild['active_layout'] ) && ! isset( $rebuild[$rebuild['active_layout']] ) && ! empty( $first_layout ) ) {
       
  1878           $rebuild['active_layout'] = $first_layout;
       
  1879         }
       
  1880         
       
  1881       }
       
  1882       
       
  1883       /* default message */
       
  1884       $message = 'failed';
       
  1885       
       
  1886       /* is array: save & show success message */
       
  1887       if ( count( $rebuild ) > 1 ) {
       
  1888 
       
  1889         /* rebuild the theme options */
       
  1890         $rebuild_option_tree = unserialize( ot_decode( $rebuild[$rebuild['active_layout']] ) );
       
  1891         if ( is_array( $rebuild_option_tree ) ) {
       
  1892           
       
  1893           /* execute the action hook and pass the theme options to it */
       
  1894           do_action( 'ot_before_theme_options_save', $rebuild_option_tree );
       
  1895           
       
  1896           update_option( 'option_tree', $rebuild_option_tree );
       
  1897           
       
  1898         }
       
  1899         
       
  1900         /* rebuild the layouts */
       
  1901         update_option( 'option_tree_layouts', $rebuild );
       
  1902         
       
  1903         /* change message */
       
  1904         $message = 'success';
       
  1905         
       
  1906       } else if ( count( $rebuild ) <= 1 ) {
       
  1907 
       
  1908         /* delete layouts option */
       
  1909         delete_option( 'option_tree_layouts' );
       
  1910         
       
  1911         /* change message */
       
  1912         $message = 'deleted';
       
  1913         
       
  1914       }
       
  1915       
       
  1916       /* redirect */
       
  1917       if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ) {
       
  1918         $query_args = add_query_arg( array( 'settings-updated' => 'layout' ), remove_query_arg( array( 'action', 'message' ), $_POST['_wp_http_referer'] ) );
       
  1919       } else {
       
  1920         $query_args = add_query_arg( array( 'action' => 'save-layouts', 'message' => $message ), $_POST['_wp_http_referer'] );
       
  1921       }
       
  1922       wp_redirect( $query_args );
       
  1923       exit;
       
  1924       
       
  1925     }
       
  1926     
       
  1927     return false;
       
  1928 
       
  1929   }
       
  1930   
       
  1931 }
       
  1932 
       
  1933 /**
       
  1934  * Helper function to display alert messages.
       
  1935  *
       
  1936  * @param     array     Page array
       
  1937  * @return    mixed
       
  1938  *
       
  1939  * @access    public
       
  1940  * @since     2.0
       
  1941  */
       
  1942 if ( ! function_exists( 'ot_alert_message' ) ) {
       
  1943 
       
  1944   function ot_alert_message( $page = array() ) {
       
  1945     
       
  1946     if ( empty( $page ) )
       
  1947       return false;
       
  1948     
       
  1949     $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
       
  1950     $message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : '';
       
  1951     $updated = isset( $_REQUEST['settings-updated'] ) ? $_REQUEST['settings-updated'] : '';
       
  1952     
       
  1953     if ( $action == 'save-settings' ) {
       
  1954     
       
  1955       if ( $message == 'success' ) {
       
  1956         
       
  1957         return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings updated.', 'option-tree' ) . '</p></div>';
       
  1958         
       
  1959       } else if ( $message == 'failed' ) {
       
  1960         
       
  1961         return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be saved.', 'option-tree' ) . '</p></div>';
       
  1962         
       
  1963       }
       
  1964       
       
  1965     } else if ( $action == 'import-xml' || $action == 'import-settings' ) {
       
  1966       
       
  1967       if ( $message == 'success' ) {
       
  1968         
       
  1969         return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings Imported.', 'option-tree' ) . '</p></div>';
       
  1970         
       
  1971       } else if ( $message == 'failed' ) {
       
  1972         
       
  1973         return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be imported.', 'option-tree' ) . '</p></div>';
       
  1974         
       
  1975       }
       
  1976     } else if ( $action == 'import-data' ) {
       
  1977       
       
  1978       if ( $message == 'success' ) {
       
  1979         
       
  1980         return '<div id="message" class="updated fade below-h2"><p>' . __( 'Data Imported.', 'option-tree' ) . '</p></div>';
       
  1981         
       
  1982       } else if ( $message == 'failed' ) {
       
  1983         
       
  1984         return '<div id="message" class="error fade below-h2"><p>' . __( 'Data could not be imported.', 'option-tree' ) . '</p></div>';
       
  1985         
       
  1986       }
       
  1987     
       
  1988     } else if ( $action == 'import-layouts' ) {
       
  1989       
       
  1990       if ( $message == 'success' ) {
       
  1991         
       
  1992         return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Imported.', 'option-tree' ) . '</p></div>';
       
  1993         
       
  1994       } else if ( $message == 'failed' ) {
       
  1995         
       
  1996         return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be imported.', 'option-tree' ) . '</p></div>';
       
  1997         
       
  1998       }
       
  1999            
       
  2000     } else if ( $action == 'save-layouts' ) {
       
  2001       
       
  2002       if ( $message == 'success' ) {
       
  2003         
       
  2004         return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Updated.', 'option-tree' ) . '</p></div>';
       
  2005         
       
  2006       } else if ( $message == 'failed' ) {
       
  2007         
       
  2008         return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be updated.', 'option-tree' ) . '</p></div>';
       
  2009         
       
  2010       } else if ( $message == 'deleted' ) {
       
  2011         
       
  2012         return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts have been deleted.', 'option-tree' ) . '</p></div>';
       
  2013         
       
  2014       }
       
  2015     
       
  2016     } else if ( $updated == 'layout' ) {  
       
  2017        
       
  2018       return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layout activated.', 'option-tree' ) . '</p></div>';
       
  2019         
       
  2020     } else if ( $action == 'reset' ) {
       
  2021       
       
  2022       return '<div id="message" class="updated fade below-h2"><p>' . $page['reset_message'] . '</p></div>';
       
  2023         
       
  2024     }
       
  2025     
       
  2026     do_action( 'ot_custom_page_messages' );
       
  2027     
       
  2028     if ( $updated == 'true' ) {  
       
  2029        
       
  2030       return '<div id="message" class="updated fade below-h2"><p>' . $page['updated_message'] . '</p></div>';
       
  2031         
       
  2032     } 
       
  2033     
       
  2034     return false;
       
  2035     
       
  2036   }
       
  2037   
       
  2038 }
       
  2039 
       
  2040 /**
       
  2041  * Setup the default option types.
       
  2042  *
       
  2043  * The returned option types are filterable so you can add your own.
       
  2044  * This is not a task for a beginner as you'll need to add the function
       
  2045  * that displays the option to the user and validate the saved data.
       
  2046  *
       
  2047  * @return    array
       
  2048  *
       
  2049  * @access    public
       
  2050  * @since     2.0
       
  2051  */
       
  2052 if ( ! function_exists( 'ot_option_types_array' ) ) {
       
  2053 
       
  2054   function ot_option_types_array() {
       
  2055   
       
  2056     return apply_filters( 'ot_option_types_array', array( 
       
  2057       'background'                => 'Background',
       
  2058       'category-checkbox'         => 'Category Checkbox',
       
  2059       'category-select'           => 'Category Select',
       
  2060       'checkbox'                  => 'Checkbox',
       
  2061       'colorpicker'               => 'Colorpicker',
       
  2062       'css'                       => 'CSS',
       
  2063       'custom-post-type-checkbox' => 'Custom Post Type Checkbox',
       
  2064       'custom-post-type-select'   => 'Custom Post Type Select',
       
  2065       'list-item'                 => 'List Item',
       
  2066       'measurement'               => 'Measurement',
       
  2067       'numeric-slider'            => 'Numeric Slider',
       
  2068       'page-checkbox'             => 'Page Checkbox',
       
  2069       'page-select'               => 'Page Select',
       
  2070       'post-checkbox'             => 'Post Checkbox',
       
  2071       'post-select'               => 'Post Select',
       
  2072       'radio'                     => 'Radio',
       
  2073       'radio-image'               => 'Radio Image',
       
  2074       'select'                    => 'Select',
       
  2075       'sidebar-select'            => 'Sidebar Select', 
       
  2076       'slider'                    => 'Slider',
       
  2077       'tag-checkbox'              => 'Tag Checkbox',
       
  2078       'tag-select'                => 'Tag Select',
       
  2079       'taxonomy-checkbox'         => 'Taxonomy Checkbox',
       
  2080       'taxonomy-select'           => 'Taxonomy Select',
       
  2081       'text'                      => 'Text',
       
  2082       'textarea'                  => 'Textarea',
       
  2083       'textarea-simple'           => 'Textarea Simple',
       
  2084       'textblock'                 => 'Textblock',
       
  2085       'textblock-titled'          => 'Textblock Titled',
       
  2086       'typography'                => 'Typography',
       
  2087       'upload'                    => 'Upload'
       
  2088     ) );
       
  2089     
       
  2090   }
       
  2091 }
       
  2092 
       
  2093 /**
       
  2094  * Map old option types for rebuilding XML and Table data.
       
  2095  *
       
  2096  * @param     string      $type The old option type
       
  2097  * @return    string      The new option type
       
  2098  *
       
  2099  * @access    public
       
  2100  * @since     2.0
       
  2101  */
       
  2102 if ( ! function_exists( 'ot_map_old_option_types' ) ) {
       
  2103 
       
  2104   function ot_map_old_option_types( $type = '' ) {
       
  2105     
       
  2106     if ( ! $type ) 
       
  2107       return 'text';
       
  2108       
       
  2109     $types = array(
       
  2110       'background'        => 'background',
       
  2111       'category'          => 'category-select',
       
  2112       'categories'        => 'category-checkbox',
       
  2113       'checkbox'          => 'checkbox',
       
  2114       'colorpicker'       => 'colorpicker',
       
  2115       'css'               => 'css',
       
  2116       'custom_post'       => 'custom-post-type-select',
       
  2117       'custom_posts'      => 'custom-post-type-checkbox',                     
       
  2118       'input'             => 'text',
       
  2119       'image'             => 'upload',
       
  2120       'measurement'       => 'measurement',
       
  2121       'page'              => 'page-select',
       
  2122       'pages'             => 'page-checkbox',
       
  2123       'post'              => 'post-select',
       
  2124       'posts'             => 'post-checkbox',
       
  2125       'radio'             => 'radio',
       
  2126       'select'            => 'select',
       
  2127       'slider'            => 'slider',
       
  2128       'tag'               => 'tag-select',
       
  2129       'tags'              => 'tag-checkbox',
       
  2130       'textarea'          => 'textarea',
       
  2131       'textblock'         => 'textblock',
       
  2132       'typography'        => 'typography',
       
  2133       'upload'            => 'upload'
       
  2134     );
       
  2135     
       
  2136     if ( isset( $types[$type] ) )
       
  2137       return $types[$type];
       
  2138     
       
  2139     return false;
       
  2140     
       
  2141   }
       
  2142 }
       
  2143 
       
  2144 /**
       
  2145  * Recognized font families
       
  2146  *
       
  2147  * Returns an array of all recognized font families.
       
  2148  * Keys are intended to be stored in the database
       
  2149  * while values are ready for display in html.
       
  2150  * Renamed in version 2.0 to avoid name collisions.
       
  2151  *
       
  2152  * @uses      apply_filters()
       
  2153  *
       
  2154  * @return    array
       
  2155  *
       
  2156  * @access    public
       
  2157  * @since     1.1.8
       
  2158  * @updated   2.0
       
  2159  */
       
  2160 if ( ! function_exists( 'ot_recognized_font_families' ) ) {
       
  2161 
       
  2162   function ot_recognized_font_families( $field_id = '' ) {
       
  2163   
       
  2164     return apply_filters( 'ot_recognized_font_families', array(
       
  2165       'arial'     => 'Arial',
       
  2166       'georgia'   => 'Georgia',
       
  2167       'helvetica' => 'Helvetica',
       
  2168       'palatino'  => 'Palatino',
       
  2169       'tahoma'    => 'Tahoma',
       
  2170       'times'     => '"Times New Roman", sans-serif',
       
  2171       'trebuchet' => 'Trebuchet',
       
  2172       'verdana'   => 'Verdana'
       
  2173     ), $field_id );
       
  2174     
       
  2175   }
       
  2176 
       
  2177 }
       
  2178 
       
  2179 /**
       
  2180  * Recognized font sizes
       
  2181  *
       
  2182  * Returns an array of all recognized font sizes.
       
  2183  *
       
  2184  * @uses      apply_filters()
       
  2185  *
       
  2186  * @param     string  $field_id ID that's passed to the filters.
       
  2187  * @return    array
       
  2188  *
       
  2189  * @access    public
       
  2190  * @since     2.0.12
       
  2191  */
       
  2192 if ( ! function_exists( 'ot_recognized_font_sizes' ) ) {
       
  2193 
       
  2194   function ot_recognized_font_sizes( $field_id ) {
       
  2195   
       
  2196     $range = ot_range( 
       
  2197       apply_filters( 'ot_font_size_low_range', 0, $field_id ), 
       
  2198       apply_filters( 'ot_font_size_high_range', 150, $field_id ), 
       
  2199       apply_filters( 'ot_font_size_range_interval', 1, $field_id )
       
  2200     );
       
  2201     
       
  2202     $unit = apply_filters( 'ot_font_size_unit_type', 'px', $field_id );
       
  2203     
       
  2204     foreach( $range as $k => $v ) {
       
  2205       $range[$k] = $v . $unit;
       
  2206     }
       
  2207     
       
  2208     return $range;
       
  2209   }
       
  2210 
       
  2211 }
       
  2212 
       
  2213 /**
       
  2214  * Recognized font styles
       
  2215  *
       
  2216  * Returns an array of all recognized font styles.
       
  2217  * Renamed in version 2.0 to avoid name collisions.
       
  2218  *
       
  2219  * @uses      apply_filters()
       
  2220  *
       
  2221  * @return    array
       
  2222  *
       
  2223  * @access    public
       
  2224  * @since     1.1.8
       
  2225  * @updated   2.0
       
  2226  */
       
  2227 if ( ! function_exists( 'ot_recognized_font_styles' ) ) {
       
  2228 
       
  2229   function ot_recognized_font_styles( $field_id = '' ) {
       
  2230   
       
  2231     return apply_filters( 'ot_recognized_font_styles', array(
       
  2232       'normal'  => 'Normal',
       
  2233       'italic'  => 'Italic',
       
  2234       'oblique' => 'Oblique',
       
  2235       'inherit' => 'Inherit'
       
  2236     ), $field_id );
       
  2237     
       
  2238   }
       
  2239 
       
  2240 }
       
  2241 
       
  2242 /**
       
  2243  * Recognized font variants
       
  2244  *
       
  2245  * Returns an array of all recognized font variants.
       
  2246  * Renamed in version 2.0 to avoid name collisions.
       
  2247  *
       
  2248  * @uses      apply_filters()
       
  2249  *
       
  2250  * @return    array
       
  2251  *
       
  2252  * @access    public
       
  2253  * @since     1.1.8
       
  2254  * @updated   2.0
       
  2255  */
       
  2256 if ( ! function_exists( 'ot_recognized_font_variants' ) ) {
       
  2257 
       
  2258   function ot_recognized_font_variants( $field_id = '' ) {
       
  2259   
       
  2260     return apply_filters( 'ot_recognized_font_variants', array(
       
  2261       'normal'      => 'Normal',
       
  2262       'small-caps'  => 'Small Caps',
       
  2263       'inherit'     => 'Inherit'
       
  2264     ), $field_id );
       
  2265   
       
  2266   }
       
  2267   
       
  2268 }
       
  2269 
       
  2270 /**
       
  2271  * Recognized font weights
       
  2272  *
       
  2273  * Returns an array of all recognized font weights.
       
  2274  * Renamed in version 2.0 to avoid name collisions.
       
  2275  *
       
  2276  * @uses      apply_filters()
       
  2277  *
       
  2278  * @return    array
       
  2279  *
       
  2280  * @access    public
       
  2281  * @since     1.1.8
       
  2282  * @updated   2.0
       
  2283  */
       
  2284 if ( ! function_exists( 'ot_recognized_font_weights' ) ) {
       
  2285 
       
  2286   function ot_recognized_font_weights( $field_id = '' ) {
       
  2287     
       
  2288     return apply_filters( 'ot_recognized_font_weights', array(
       
  2289       'normal'    => 'Normal',
       
  2290       'bold'      => 'Bold',
       
  2291       'bolder'    => 'Bolder',
       
  2292       'lighter'   => 'Lighter',
       
  2293       '100'       => '100',
       
  2294       '200'       => '200',
       
  2295       '300'       => '300',
       
  2296       '400'       => '400',
       
  2297       '500'       => '500',
       
  2298       '600'       => '600',
       
  2299       '700'       => '700',
       
  2300       '800'       => '800',
       
  2301       '900'       => '900',
       
  2302       'inherit'   => 'Inherit'
       
  2303     ), $field_id );
       
  2304   
       
  2305   }
       
  2306   
       
  2307 }
       
  2308 
       
  2309 /**
       
  2310  * Recognized letter spacing
       
  2311  *
       
  2312  * Returns an array of all recognized line heights.
       
  2313  *
       
  2314  * @uses      apply_filters()
       
  2315  *
       
  2316  * @param     string  $field_id ID that's passed to the filters.
       
  2317  * @return    array
       
  2318  *
       
  2319  * @access    public
       
  2320  * @since     2.0.12
       
  2321  */
       
  2322 if ( ! function_exists( 'ot_recognized_letter_spacing' ) ) {
       
  2323 
       
  2324   function ot_recognized_letter_spacing( $field_id ) {
       
  2325   
       
  2326     $range = ot_range( 
       
  2327       apply_filters( 'ot_letter_spacing_low_range', -0.1, $field_id ), 
       
  2328       apply_filters( 'ot_letter_spacing_high_range', 0.1, $field_id ), 
       
  2329       apply_filters( 'ot_letter_spacing_range_interval', 0.01, $field_id )
       
  2330     );
       
  2331     
       
  2332     $unit = apply_filters( 'ot_letter_spacing_unit_type', 'em', $field_id );
       
  2333     
       
  2334     foreach( $range as $k => $v ) {
       
  2335       $range[$k] = $v . $unit;
       
  2336     }
       
  2337     
       
  2338     return $range;
       
  2339   }
       
  2340 
       
  2341 }
       
  2342 
       
  2343 /**
       
  2344  * Recognized line heights
       
  2345  *
       
  2346  * Returns an array of all recognized line heights.
       
  2347  *
       
  2348  * @uses      apply_filters()
       
  2349  *
       
  2350  * @param     string  $field_id ID that's passed to the filters.
       
  2351  * @return    array
       
  2352  *
       
  2353  * @access    public
       
  2354  * @since     2.0.12
       
  2355  */
       
  2356 if ( ! function_exists( 'ot_recognized_line_heights' ) ) {
       
  2357 
       
  2358   function ot_recognized_line_heights( $field_id ) {
       
  2359   
       
  2360     $range = ot_range( 
       
  2361       apply_filters( 'ot_line_height_low_range', 0, $field_id ), 
       
  2362       apply_filters( 'ot_line_height_high_range', 150, $field_id ), 
       
  2363       apply_filters( 'ot_line_height_unit_type', 1, $field_id )
       
  2364     );
       
  2365     
       
  2366     $unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id );
       
  2367     
       
  2368     foreach( $range as $k => $v ) {
       
  2369       $range[$k] = $v . $unit;
       
  2370     }
       
  2371     
       
  2372     return $range;
       
  2373   }
       
  2374 
       
  2375 }
       
  2376 
       
  2377 /**
       
  2378  * Recognized text decorations
       
  2379  *
       
  2380  * Returns an array of all recognized text decorations.
       
  2381  * Keys are intended to be stored in the database
       
  2382  * while values are ready for display in html.
       
  2383  *
       
  2384  * @uses      apply_filters()
       
  2385  *
       
  2386  * @return    array
       
  2387  *
       
  2388  * @access    public
       
  2389  * @since     2.0.10
       
  2390  */
       
  2391 if ( ! function_exists( 'ot_recognized_text_decorations' ) ) {
       
  2392   
       
  2393   function ot_recognized_text_decorations( $field_id = '' ) {
       
  2394   
       
  2395     return apply_filters( 'ot_recognized_text_decorations', array(
       
  2396       'blink'         => 'Blink',
       
  2397       'inherit'       => 'Inherit',
       
  2398       'line-through'  => 'Line Through',
       
  2399       'none'          => 'None',
       
  2400       'overline'      => 'Overline',
       
  2401       'underline'     => 'Underline'
       
  2402     ), $field_id );
       
  2403     
       
  2404   }
       
  2405 
       
  2406 }
       
  2407 
       
  2408 /**
       
  2409  * Recognized text transformations
       
  2410  *
       
  2411  * Returns an array of all recognized text transformations.
       
  2412  * Keys are intended to be stored in the database
       
  2413  * while values are ready for display in html.
       
  2414  *
       
  2415  * @uses      apply_filters()
       
  2416  *
       
  2417  * @return    array
       
  2418  *
       
  2419  * @access    public
       
  2420  * @since     2.0.10
       
  2421  */
       
  2422 if ( ! function_exists( 'ot_recognized_text_transformations' ) ) {
       
  2423   
       
  2424   function ot_recognized_text_transformations( $field_id = '' ) {
       
  2425   
       
  2426     return apply_filters( 'ot_recognized_text_transformations', array(
       
  2427       'capitalize'  => 'Capitalize',
       
  2428       'inherit'     => 'Inherit',
       
  2429       'lowercase'   => 'Lowercase',
       
  2430       'none'        => 'None',
       
  2431       'uppercase'   => 'Uppercase'
       
  2432     ), $field_id );
       
  2433     
       
  2434   }
       
  2435 
       
  2436 }
       
  2437 
       
  2438 /**
       
  2439  * Recognized background repeat
       
  2440  *
       
  2441  * Returns an array of all recognized background repeat values.
       
  2442  * Renamed in version 2.0 to avoid name collisions.
       
  2443  *
       
  2444  * @uses      apply_filters()
       
  2445  *
       
  2446  * @return    array
       
  2447  *
       
  2448  * @access    public
       
  2449  * @since     1.1.8
       
  2450  * @updated   2.0
       
  2451  */
       
  2452 if ( ! function_exists( 'ot_recognized_background_repeat' ) ) {
       
  2453   
       
  2454   function ot_recognized_background_repeat( $field_id = '' ) {
       
  2455   
       
  2456     return apply_filters( 'ot_recognized_background_repeat', array(
       
  2457       'no-repeat' => 'No Repeat',
       
  2458       'repeat'    => 'Repeat All',
       
  2459       'repeat-x'  => 'Repeat Horizontally',
       
  2460       'repeat-y'  => 'Repeat Vertically',
       
  2461       'inherit'   => 'Inherit'
       
  2462     ), $field_id );
       
  2463     
       
  2464   }
       
  2465   
       
  2466 }
       
  2467 
       
  2468 /**
       
  2469  * Recognized background attachment
       
  2470  *
       
  2471  * Returns an array of all recognized background attachment values.
       
  2472  * Renamed in version 2.0 to avoid name collisions.
       
  2473  *
       
  2474  * @uses      apply_filters()
       
  2475  *
       
  2476  * @return    array
       
  2477  *
       
  2478  * @access    public
       
  2479  * @since     1.1.8
       
  2480  * @updated   2.0
       
  2481  */
       
  2482 if ( ! function_exists( 'ot_recognized_background_attachment' ) ) {
       
  2483 
       
  2484   function ot_recognized_background_attachment( $field_id = '' ) {
       
  2485   
       
  2486     return apply_filters( 'ot_recognized_background_attachment', array(
       
  2487       "fixed"   => "Fixed",
       
  2488       "scroll"  => "Scroll",
       
  2489       "inherit" => "Inherit"
       
  2490     ), $field_id );
       
  2491     
       
  2492   }
       
  2493 
       
  2494 }
       
  2495 
       
  2496 /**
       
  2497  * Recognized background position
       
  2498  *
       
  2499  * Returns an array of all recognized background position values.
       
  2500  * Renamed in version 2.0 to avoid name collisions.
       
  2501  *
       
  2502  * @uses      apply_filters()
       
  2503  *
       
  2504  * @return    array
       
  2505  *
       
  2506  * @access    public
       
  2507  * @since     1.1.8
       
  2508  * @updated   2.0
       
  2509  */
       
  2510 if ( ! function_exists( 'ot_recognized_background_position' ) ) {
       
  2511 
       
  2512   function ot_recognized_background_position( $field_id = '' ) {
       
  2513   
       
  2514     return apply_filters( 'ot_recognized_background_position', array(
       
  2515       "left top"      => "Left Top",
       
  2516       "left center"   => "Left Center",
       
  2517       "left bottom"   => "Left Bottom",
       
  2518       "center top"    => "Center Top",
       
  2519       "center center" => "Center Center",
       
  2520       "center bottom" => "Center Bottom",
       
  2521       "right top"     => "Right Top",
       
  2522       "right center"  => "Right Center",
       
  2523       "right bottom"  => "Right Bottom"
       
  2524     ), $field_id );
       
  2525     
       
  2526   }
       
  2527 
       
  2528 }
       
  2529 
       
  2530 /**
       
  2531  * Measurement Units
       
  2532  *
       
  2533  * Returns an array of all available unit types.
       
  2534  * Renamed in version 2.0 to avoid name collisions.
       
  2535  *
       
  2536  * @uses      apply_filters()
       
  2537  *
       
  2538  * @return    array
       
  2539  *
       
  2540  * @access    public
       
  2541  * @since     1.1.8
       
  2542  * @updated   2.0
       
  2543  */
       
  2544 if ( ! function_exists( 'ot_measurement_unit_types' ) ) {
       
  2545   
       
  2546   function ot_measurement_unit_types( $field_id = '' ) {
       
  2547   
       
  2548     return apply_filters( 'ot_measurement_unit_types', array(
       
  2549       'px' => 'px',
       
  2550       '%'  => '%',
       
  2551       'em' => 'em',
       
  2552       'pt' => 'pt'
       
  2553     ), $field_id );
       
  2554     
       
  2555   }
       
  2556 
       
  2557 }
       
  2558 
       
  2559 /**
       
  2560  * Radio Images default array.
       
  2561  *
       
  2562  * Returns an array of all available radio images.
       
  2563  * You can filter this function to change the images
       
  2564  * on a per option basis.
       
  2565  *
       
  2566  * @uses      apply_filters()
       
  2567  *
       
  2568  * @return    array
       
  2569  *
       
  2570  * @access    public
       
  2571  * @since     2.0
       
  2572  */
       
  2573 if ( ! function_exists( 'ot_radio_images' ) ) {
       
  2574   
       
  2575   function ot_radio_images( $field_id = '' ) {
       
  2576   
       
  2577     return apply_filters( 'ot_radio_images', array(
       
  2578       array(
       
  2579         'value'   => 'left-sidebar',
       
  2580         'label'   => __( 'Left Sidebar', 'option-tree' ),
       
  2581         'src'     => OT_URL . 'assets/images/layout/left-sidebar.png'
       
  2582       ),
       
  2583       array(
       
  2584         'value'   => 'right-sidebar',
       
  2585         'label'   => __( 'Right Sidebar', 'option-tree' ),
       
  2586         'src'     => OT_URL . 'assets/images/layout/right-sidebar.png'
       
  2587       ),
       
  2588       array(
       
  2589         'value'   => 'full-width',
       
  2590         'label'   => __( 'Full Width (no sidebar)', 'option-tree' ),
       
  2591         'src'     => OT_URL . 'assets/images/layout/full-width.png'
       
  2592       ),
       
  2593       array(
       
  2594         'value'   => 'dual-sidebar',
       
  2595         'label'   => __( 'Dual Sidebar', 'option-tree' ),
       
  2596         'src'     => OT_URL . 'assets/images/layout/dual-sidebar.png'
       
  2597       ),
       
  2598       array(
       
  2599         'value'   => 'left-dual-sidebar',
       
  2600         'label'   => __( 'Left Dual Sidebar', 'option-tree' ),
       
  2601         'src'     => OT_URL . 'assets/images/layout/left-dual-sidebar.png'
       
  2602       ),
       
  2603       array(
       
  2604         'value'   => 'right-dual-sidebar',
       
  2605         'label'   => __( 'Right Dual Sidebar', 'option-tree' ),
       
  2606         'src'     => OT_URL . 'assets/images/layout/right-dual-sidebar.png'
       
  2607       )
       
  2608     ), $field_id );
       
  2609     
       
  2610   }
       
  2611 
       
  2612 }
       
  2613 
       
  2614 /**
       
  2615  * Default List Item Settings array.
       
  2616  *
       
  2617  * Returns an array of the default list item settings.
       
  2618  * You can filter this function to change the settings
       
  2619  * on a per option basis.
       
  2620  *
       
  2621  * @uses      apply_filters()
       
  2622  *
       
  2623  * @return    array
       
  2624  *
       
  2625  * @access    public
       
  2626  * @since     2.0
       
  2627  */
       
  2628 if ( ! function_exists( 'ot_list_item_settings' ) ) {
       
  2629 
       
  2630   function ot_list_item_settings( $id ) {
       
  2631     
       
  2632     $settings = apply_filters( 'ot_list_item_settings', array(
       
  2633       array(
       
  2634         'id'        => 'image',
       
  2635         'label'     => __( 'Image', 'option-tree' ),
       
  2636         'desc'      => '',
       
  2637         'std'       => '',
       
  2638         'type'      => 'upload',
       
  2639         'rows'      => '',
       
  2640         'class'     => '',
       
  2641         'post_type' => '',
       
  2642         'choices'   => array()
       
  2643       ),
       
  2644       array(
       
  2645         'id'        => 'link',
       
  2646         'label'     => __( 'Link', 'option-tree' ),
       
  2647         'desc'      => '',
       
  2648         'std'       => '',
       
  2649         'type'      => 'text',
       
  2650         'rows'      => '',
       
  2651         'class'     => '',
       
  2652         'post_type' => '',
       
  2653         'choices'   => array()
       
  2654       ),
       
  2655       array(
       
  2656         'id'        => 'description',
       
  2657         'label'     => __( 'Description', 'option-tree' ),
       
  2658         'desc'      => '',
       
  2659         'std'       => '',
       
  2660         'type'      => 'textarea-simple',
       
  2661         'rows'      => 10,
       
  2662         'class'     => '',
       
  2663         'post_type' => '',
       
  2664         'choices'   => array()
       
  2665       )
       
  2666     ), $id );
       
  2667     
       
  2668     return $settings;
       
  2669   
       
  2670   }
       
  2671 
       
  2672 }
       
  2673 
       
  2674 /**
       
  2675  * Default Slider Settings array.
       
  2676  *
       
  2677  * Returns an array of the default slider settings.
       
  2678  * You can filter this function to change the settings
       
  2679  * on a per option basis.
       
  2680  *
       
  2681  * @uses      apply_filters()
       
  2682  *
       
  2683  * @return    array
       
  2684  *
       
  2685  * @access    public
       
  2686  * @since     2.0
       
  2687  */
       
  2688 if ( ! function_exists( 'ot_slider_settings' ) ) {
       
  2689 
       
  2690   function ot_slider_settings( $id ) {
       
  2691     
       
  2692     $settings = apply_filters( 'image_slider_fields', array(
       
  2693       array(
       
  2694         'name'      => 'image',
       
  2695         'type'      => 'image',
       
  2696         'label'     => __( 'Image', 'option-tree' ),
       
  2697         'class'     => ''
       
  2698       ),
       
  2699       array(
       
  2700         'name'      => 'link',
       
  2701         'type'      => 'text',
       
  2702         'label'     => __( 'Link', 'option-tree' ),
       
  2703         'class'     => ''
       
  2704       ),
       
  2705       array(
       
  2706         'name'      => 'description',
       
  2707         'type'      => 'textarea',
       
  2708         'label'     => __( 'Description', 'option-tree' ),
       
  2709         'class'     => ''
       
  2710       )
       
  2711     ), $id );
       
  2712     
       
  2713     /* fix the array keys, values, and just get it 2.0 ready */
       
  2714     foreach( $settings as $_k => $setting ) {
       
  2715     
       
  2716       foreach( $setting as $s_key => $s_value ) {
       
  2717         
       
  2718         if ( 'name' == $s_key ) {
       
  2719         
       
  2720           $settings[$_k]['id'] = $s_value;
       
  2721           unset($settings[$_k]['name']);
       
  2722           
       
  2723         } else if ( 'type' == $s_key ) {
       
  2724           
       
  2725           if ( 'input' == $s_value ) {
       
  2726           
       
  2727             $settings[$_k]['type'] = 'text';
       
  2728             
       
  2729           } else if ( 'textarea' == $s_value ) {
       
  2730           
       
  2731             $settings[$_k]['type'] = 'textarea-simple';
       
  2732             
       
  2733           } else if ( 'image' == $s_value ) {
       
  2734           
       
  2735             $settings[$_k]['type'] = 'upload';
       
  2736             
       
  2737           }
       
  2738           
       
  2739         }
       
  2740         
       
  2741       } 
       
  2742       
       
  2743     }
       
  2744     
       
  2745     return $settings;
       
  2746     
       
  2747   }
       
  2748 
       
  2749 }
       
  2750 
       
  2751 /**
       
  2752  * Inserts CSS with field_id markers.
       
  2753  *
       
  2754  * Inserts CSS into a dynamic.css file, placing it between
       
  2755  * BEGIN and END field_id markers. Replaces existing marked info, 
       
  2756  * but still retains surrounding data.
       
  2757  *
       
  2758  * @param     string  $field_id The CSS option field ID.
       
  2759  * @param     array   $options The current option_tree array.
       
  2760  * @return    bool    True on write success, false on failure.
       
  2761  *
       
  2762  * @access    public
       
  2763  * @since     1.1.8
       
  2764  * @updated   2.0.12
       
  2765  */
       
  2766 if ( ! function_exists( 'ot_insert_css_with_markers' ) ) {
       
  2767 
       
  2768   function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) {
       
  2769     
       
  2770     /* missing $field_id or $insertion exit early */
       
  2771     if ( '' == $field_id || '' == $insertion )
       
  2772       return;
       
  2773 
       
  2774     /* path to the dynamic.css file */
       
  2775     $filepath = get_stylesheet_directory() . '/dynamic.css';
       
  2776     
       
  2777     /* allow filter on path */
       
  2778     $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id );
       
  2779     
       
  2780     /* grab a copy of the paths array */
       
  2781     $ot_css_file_paths = get_option( 'ot_css_file_paths', array() );
       
  2782     
       
  2783     /* set the path for this field */
       
  2784     $ot_css_file_paths[$field_id] = $filepath;
       
  2785     
       
  2786     /* update the paths */
       
  2787     update_option( 'ot_css_file_paths', $ot_css_file_paths );
       
  2788     
       
  2789     /* insert CSS into file */
       
  2790     if ( file_exists( $filepath ) ) {
       
  2791       
       
  2792       $insertion   = ot_normalize_css( $insertion );
       
  2793       $regex       = "/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/";
       
  2794       $marker      = $field_id;
       
  2795       
       
  2796       /* Match custom CSS */
       
  2797       preg_match_all( $regex, $insertion, $matches );
       
  2798       
       
  2799       /* Loop through CSS */
       
  2800       foreach( $matches[0] as $option ) {
       
  2801 
       
  2802         $value        = '';
       
  2803         $option_id    = str_replace( array( '{{', '}}' ), '', $option );
       
  2804         $option_array = explode( '|', $option_id );
       
  2805         
       
  2806         /* get the array value */
       
  2807         if ( $meta ) {
       
  2808           global $post;
       
  2809           
       
  2810           $value = get_post_meta( $post->ID, $option_array[0], true );
       
  2811           
       
  2812         } else {
       
  2813         
       
  2814           $options = get_option( 'option_tree' );
       
  2815           
       
  2816           if ( isset( $options[$option_array[0]] ) ) {
       
  2817             
       
  2818             $value = $options[$option_array[0]];
       
  2819   
       
  2820           }
       
  2821           
       
  2822         }
       
  2823         
       
  2824         if ( is_array( $value ) ) {
       
  2825           
       
  2826           if ( ! isset( $option_array[1] ) ) {
       
  2827           
       
  2828             /* Measurement */
       
  2829             if ( isset( $value[0] ) && isset( $value[1] ) ) {
       
  2830               
       
  2831               /* set $value with measurement properties */
       
  2832               $value = $value[0].$value[1];
       
  2833               
       
  2834             /* typography */
       
  2835             } else if ( ot_array_keys_exists( $value, array( 'font-color', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'letter-spacing', 'line-height', 'text-decoration', 'text-transform' ) ) ) {
       
  2836               $font = array();
       
  2837               
       
  2838               if ( ! empty( $value['font-color'] ) )
       
  2839                 $font[] = "color: " . $value['font-color'] . ";";
       
  2840               
       
  2841               if ( ! empty( $value['font-family'] ) ) {
       
  2842                 foreach ( ot_recognized_font_families( $marker ) as $key => $v ) {
       
  2843                   if ( $key == $value['font-family'] ) {
       
  2844                     $font[] = "font-family: " . $v . ";";
       
  2845                   }
       
  2846                 }
       
  2847               }
       
  2848               
       
  2849               if ( ! empty( $value['font-size'] ) )
       
  2850                 $font[] = "font-size: " . $value['font-size'] . ";";
       
  2851               
       
  2852               if ( ! empty( $value['font-style'] ) )
       
  2853                 $font[] = "font-style: " . $value['font-style'] . ";";
       
  2854               
       
  2855               if ( ! empty( $value['font-variant'] ) )
       
  2856                 $font[] = "font-variant: " . $value['font-variant'] . ";";
       
  2857               
       
  2858               if ( ! empty( $value['font-weight'] ) )
       
  2859                 $font[] = "font-weight: " . $value['font-weight'] . ";";
       
  2860                 
       
  2861               if ( ! empty( $value['letter-spacing'] ) )
       
  2862                 $font[] = "letter-spacing: " . $value['letter-spacing'] . ";";
       
  2863               
       
  2864               if ( ! empty( $value['line-height'] ) )
       
  2865                 $font[] = "line-height: " . $value['line-height'] . ";";
       
  2866               
       
  2867               if ( ! empty( $value['text-decoration'] ) )
       
  2868                 $font[] = "text-decoration: " . $value['text-decoration'] . ";";
       
  2869               
       
  2870               if ( ! empty( $value['text-transform'] ) )
       
  2871                 $font[] = "text-transform: " . $value['text-transform'] . ";";
       
  2872               
       
  2873               /* set $value with font properties or empty string */
       
  2874               $value = ! empty( $font ) ? implode( "\n", $font ) : '';
       
  2875               
       
  2876             /* background */
       
  2877             } else if ( ot_array_keys_exists( $value, array( 'background-color', 'background-image', 'background-repeat', 'background-attachment', 'background-position' ) ) ) {
       
  2878               $bg = array();
       
  2879               
       
  2880               if ( ! empty( $value['background-color'] ) )
       
  2881                 $bg[] = $value['background-color'];
       
  2882                 
       
  2883               if ( ! empty( $value['background-image'] ) )
       
  2884                 $bg[] = 'url("' . $value['background-image'] . '")';
       
  2885                 
       
  2886               if ( ! empty( $value['background-repeat'] ) )
       
  2887                 $bg[] = $value['background-repeat'];
       
  2888                 
       
  2889               if ( ! empty( $value['background-attachment'] ) )
       
  2890                 $bg[] = $value['background-attachment'];
       
  2891                 
       
  2892               if ( ! empty( $value['background-position'] ) )
       
  2893                 $bg[] = $value['background-position'];
       
  2894               
       
  2895               /* set $value with background properties or empty string */
       
  2896               $value = ! empty( $bg ) ? 'background: ' . implode( " ", $bg ) . ';' : '';
       
  2897             }
       
  2898           
       
  2899           } else {
       
  2900           
       
  2901             $value = $value[$option_array[1]];
       
  2902             
       
  2903           }
       
  2904          
       
  2905         }
       
  2906         
       
  2907         // Filter the CSS
       
  2908          $value = apply_filters( 'ot_insert_css_with_markers_value', $value, $option_id );
       
  2909          
       
  2910         /* insert CSS, even if the value is empty */
       
  2911          $insertion = stripslashes( str_replace( $option, $value, $insertion ) );
       
  2912          
       
  2913       }
       
  2914     
       
  2915       /* create array from the lines of code */
       
  2916       $markerdata = explode( "\n", implode( '', file( $filepath ) ) );
       
  2917       
       
  2918       /* can't write to the file return false */
       
  2919       if ( ! $f = ot_file_open( $filepath, 'w' ) )
       
  2920         return false;
       
  2921       
       
  2922       $searching = true;
       
  2923       $foundit = false;
       
  2924       
       
  2925       /* has array of lines */
       
  2926       if ( ! empty( $markerdata ) ) {
       
  2927         
       
  2928         /* foreach line of code */
       
  2929         foreach( $markerdata as $n => $markerline ) {
       
  2930           
       
  2931           /* found begining of marker, set $searching to false  */
       
  2932           if ( $markerline == "/* BEGIN {$marker} */" )
       
  2933             $searching = false;
       
  2934           
       
  2935           /* keep rewrite each line of CSS  */
       
  2936           if ( $searching == true ) {
       
  2937             if ( $n + 1 < count( $markerdata ) )
       
  2938               ot_file_write( $f, "{$markerline}\n" );
       
  2939             else
       
  2940               ot_file_write( $f, "{$markerline}" );
       
  2941           }
       
  2942           
       
  2943           /* found end marker write code */
       
  2944           if ( $markerline == "/* END {$marker} */" ) {
       
  2945             ot_file_write( $f, "/* BEGIN {$marker} */\n" );
       
  2946             ot_file_write( $f, "{$insertion}\n" );
       
  2947             ot_file_write( $f, "/* END {$marker} */\n" );
       
  2948             $searching = true;
       
  2949             $foundit = true;
       
  2950           }
       
  2951           
       
  2952         }
       
  2953         
       
  2954       }
       
  2955       
       
  2956       /* nothing inserted, write code. DO IT, DO IT! */
       
  2957       if ( ! $foundit ) {
       
  2958         ot_file_write( $f, "/* BEGIN {$marker} */\n" );
       
  2959         ot_file_write( $f, "{$insertion}\n" );
       
  2960         ot_file_write( $f, "/* END {$marker} */\n" );
       
  2961       }
       
  2962       
       
  2963       /* close file */
       
  2964       ot_file_close( $f );
       
  2965       return true;
       
  2966     }
       
  2967     
       
  2968     return false;
       
  2969 
       
  2970   }
       
  2971 
       
  2972 }
       
  2973 
       
  2974 /**
       
  2975  * Remove old CSS.
       
  2976  *
       
  2977  * Removes CSS when the textarea is empty, but still retains surrounding styles.
       
  2978  *
       
  2979  * @param     string  $field_id The CSS option field ID.
       
  2980  * @return    bool    True on write success, false on failure.
       
  2981  *
       
  2982  * @access    public
       
  2983  * @since     2.0
       
  2984  */
       
  2985 if ( ! function_exists( 'ot_remove_old_css' ) ) {
       
  2986 
       
  2987   function ot_remove_old_css( $field_id = '' ) {
       
  2988     
       
  2989     /* missing $field_id string */
       
  2990     if ( '' == $field_id )
       
  2991       return false;
       
  2992     
       
  2993     /* path to the dynamic.css file */
       
  2994     $filepath = get_stylesheet_directory() . '/dynamic.css';
       
  2995     
       
  2996     /* allow filter on path */
       
  2997     $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id );
       
  2998     
       
  2999     /* remove CSS from file */
       
  3000     if ( is_writeable( $filepath ) ) {
       
  3001       
       
  3002       /* get each line in the file */
       
  3003       $markerdata = explode( "\n", implode( '', file( $filepath ) ) );
       
  3004       
       
  3005       /* can't write to the file return false */
       
  3006       if ( ! $f = ot_file_open( $filepath, 'w' ) )
       
  3007         return false;
       
  3008       
       
  3009       $searching = true;
       
  3010       
       
  3011       /* has array of lines */
       
  3012       if ( ! empty( $markerdata ) ) {
       
  3013         
       
  3014         /* foreach line of code */
       
  3015         foreach ( $markerdata as $n => $markerline ) {
       
  3016           
       
  3017           /* found begining of marker, set $searching to false  */
       
  3018           if ( $markerline == "/* BEGIN {$field_id} */" )
       
  3019             $searching = false;
       
  3020           
       
  3021           /* $searching is true, keep rewrite each line of CSS  */
       
  3022           if ( $searching == true ) {
       
  3023             if ( $n + 1 < count( $markerdata ) )
       
  3024               ot_file_write( $f, "{$markerline}\n" );
       
  3025             else
       
  3026               ot_file_write( $f, "{$markerline}" );
       
  3027           }
       
  3028           
       
  3029           /* found end marker delete old CSS */
       
  3030           if ( $markerline == "/* END {$field_id} */" ) {
       
  3031             ot_file_write( $f, "" );
       
  3032             $searching = true;
       
  3033           }
       
  3034           
       
  3035         }
       
  3036         
       
  3037       }
       
  3038       
       
  3039       /* close file */
       
  3040       ot_file_close( $f );
       
  3041       return true;
       
  3042       
       
  3043     }
       
  3044     
       
  3045     return false;
       
  3046     
       
  3047   }
       
  3048   
       
  3049 }
       
  3050 
       
  3051 /**
       
  3052  * Normalize CSS
       
  3053  *
       
  3054  * Normalize & Convert all line-endings to UNIX format.
       
  3055  *
       
  3056  * @param     string    $css
       
  3057  * @return    string
       
  3058  *
       
  3059  * @access    public
       
  3060  * @since     1.1.8
       
  3061  * @updated   2.0
       
  3062  */
       
  3063 if ( ! function_exists( 'ot_normalize_css' ) ) {
       
  3064 
       
  3065   function ot_normalize_css( $css ) {
       
  3066     
       
  3067     /* Normalize & Convert */
       
  3068     $css = str_replace( "\r\n", "\n", $css );
       
  3069     $css = str_replace( "\r", "\n", $css );
       
  3070     
       
  3071     /* Don't allow out-of-control blank lines */
       
  3072     $css = preg_replace( "/\n{2,}/", "\n\n", $css );
       
  3073     
       
  3074     return $css;
       
  3075   }
       
  3076   
       
  3077 }
       
  3078 
       
  3079 /**
       
  3080  * Helper function to loop over the option types.
       
  3081  *
       
  3082  * @param    array    $type The current option type.
       
  3083  *
       
  3084  * @return   string
       
  3085  *
       
  3086  * @access   public
       
  3087  * @since    2.0
       
  3088  */
       
  3089 if ( ! function_exists( 'ot_loop_through_option_types' ) ) {
       
  3090 
       
  3091   function ot_loop_through_option_types( $type = '', $child = false ) {
       
  3092   
       
  3093     $content = '';
       
  3094     $types = ot_option_types_array();
       
  3095     
       
  3096     if ( $child )
       
  3097       unset($types['list-item']);
       
  3098     
       
  3099     foreach( $types as $key => $value )
       
  3100       $content.= '<option value="' . $key . '" ' . selected( $type, $key, false ) . '>'  . $value . '</option>';
       
  3101     
       
  3102     return $content;
       
  3103     
       
  3104   }
       
  3105   
       
  3106 }
       
  3107 
       
  3108 /**
       
  3109  * Helper function to loop over choices.
       
  3110  *
       
  3111  * @param    string     $name The form element name.
       
  3112  * @param    array      $choices The array of choices.
       
  3113  *
       
  3114  * @return   string
       
  3115  *
       
  3116  * @access   public
       
  3117  * @since    2.0
       
  3118  */
       
  3119 if ( ! function_exists( 'ot_loop_through_choices' ) ) {
       
  3120 
       
  3121   function ot_loop_through_choices( $name, $choices = array() ) {
       
  3122     
       
  3123     $content = '';
       
  3124     
       
  3125     foreach( $choices as $key => $choice )
       
  3126       $content.= '<li class="ui-state-default list-choice">' . ot_choices_view( $name, $key, $choice ) . '</li>';
       
  3127     
       
  3128     return $content;
       
  3129   }
       
  3130   
       
  3131 }
       
  3132 
       
  3133 /**
       
  3134  * Helper function to loop over sub settings.
       
  3135  *
       
  3136  * @param    string     $name The form element name.
       
  3137  * @param    array      $settings The array of settings.
       
  3138  *
       
  3139  * @return   string
       
  3140  *
       
  3141  * @access   public
       
  3142  * @since    2.0
       
  3143  */
       
  3144 if ( ! function_exists( 'ot_loop_through_sub_settings' ) ) {
       
  3145 
       
  3146   function ot_loop_through_sub_settings( $name, $settings = array() ) {
       
  3147     
       
  3148     $content = '';
       
  3149     
       
  3150     foreach( $settings as $key => $setting )
       
  3151       $content.= '<li class="ui-state-default list-sub-setting">' . ot_settings_view( $name, $key, $setting ) . '</li>';
       
  3152     
       
  3153     return $content;
       
  3154   }
       
  3155   
       
  3156 }
       
  3157 
       
  3158 /**
       
  3159  * Helper function to display sections.
       
  3160  *
       
  3161  * This function is used in AJAX to add a new section
       
  3162  * and when section have already been added and saved.
       
  3163  *
       
  3164  * @param    int      $key The array key for the current element.
       
  3165  * @param    array    An array of values for the current section.
       
  3166  *
       
  3167  * @return   void
       
  3168  *
       
  3169  * @access   public
       
  3170  * @since    2.0
       
  3171  */
       
  3172 if ( ! function_exists( 'ot_sections_view' ) ) {
       
  3173 
       
  3174   function ot_sections_view( $name, $key, $section = array() ) {
       
  3175   
       
  3176     return '
       
  3177     <div class="option-tree-setting is-section">
       
  3178       <div class="open">' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : 'Section ' . ( $key + 1 ) ) . '</div>
       
  3179       <div class="button-section">
       
  3180         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'edit', 'option-tree' ) . '">
       
  3181           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span> 
       
  3182         </a>
       
  3183         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  3184           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  3185         </a>
       
  3186       </div>
       
  3187       <div class="option-tree-setting-body">
       
  3188         <div class="format-settings">
       
  3189           <div class="format-setting type-text">
       
  3190             <div class="description">' . __( '<strong>Section Title</strong>: Displayed as a menu item on the Theme Options page.', 'option-tree' ) . '</div>
       
  3191             <div class="format-setting-inner">
       
  3192               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title section-title" autocomplete="off" />
       
  3193             </div>
       
  3194           </div>
       
  3195         </div>
       
  3196         <div class="format-settings">
       
  3197           <div class="format-setting type-text">
       
  3198             <div class="description">' . __( '<strong>Section ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div>
       
  3199             <div class="format-setting-inner">
       
  3200               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $section['id'] ) ? esc_attr( $section['id'] ) : '' ) . '" class="widefat option-tree-ui-input section-id" autocomplete="off" />
       
  3201             </div>
       
  3202           </div>
       
  3203         </div>
       
  3204       </div>
       
  3205     </div>';
       
  3206     
       
  3207   }
       
  3208 
       
  3209 }
       
  3210 
       
  3211 /**
       
  3212  * Helper function to display settings.
       
  3213  *
       
  3214  * This function is used in AJAX to add a new setting
       
  3215  * and when settings have already been added and saved.
       
  3216  *
       
  3217  * @param    int      $key The array key for the current element.
       
  3218  * @param    array    An array of values for the current section.
       
  3219  *
       
  3220  * @return   void
       
  3221  *
       
  3222  * @access   public
       
  3223  * @since    2.0
       
  3224  */
       
  3225 if ( ! function_exists( 'ot_settings_view' ) ) {
       
  3226 
       
  3227   function ot_settings_view( $name, $key, $setting = array() ) {
       
  3228     
       
  3229     $child = ( strpos( $name, '][settings]') !== false ) ? true : false;
       
  3230     $type = isset( $setting['type'] ) ? $setting['type'] : '';
       
  3231     $std = isset( $setting['std'] ) ? $setting['std'] : '';
       
  3232     
       
  3233     // Serialize the standard value just incase
       
  3234     if ( is_array( $std ) ) {
       
  3235       $std = maybe_serialize( $std );
       
  3236     }
       
  3237     
       
  3238     if ( in_array( $type, array( 'textarea', 'textarea-simple', 'css' ) ) ) {
       
  3239       $std_form_element = '<textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]">' . esc_html( $std ) . '</textarea>';
       
  3240     } else {
       
  3241       $std_form_element = '<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]" value="' . esc_attr( $std ) . '" class="widefat option-tree-ui-input" autocomplete="off" />';
       
  3242     }
       
  3243     
       
  3244     return '
       
  3245     <div class="option-tree-setting">
       
  3246       <div class="open">' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : 'Setting ' . ( $key + 1 ) ) . '</div>
       
  3247       <div class="button-section">
       
  3248         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  3249           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  3250         </a>
       
  3251         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  3252           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  3253         </a>
       
  3254       </div>
       
  3255       <div class="option-tree-setting-body">
       
  3256         <div class="format-settings">
       
  3257           <div class="format-setting type-text wide-desc">
       
  3258             <div class="description">' . __( '<strong>Label</strong>: Displayed as the label of a form element on the Theme Options page.', 'option-tree' ) . '</div>
       
  3259             <div class="format-setting-inner">
       
  3260               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][label]" value="' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" />
       
  3261             </div>
       
  3262           </div>
       
  3263         </div>
       
  3264         <div class="format-settings">
       
  3265           <div class="format-setting type-text wide-desc">
       
  3266             <div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div>
       
  3267             <div class="format-setting-inner">
       
  3268               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $setting['id'] ) ? esc_attr( $setting['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3269             </div>
       
  3270           </div>
       
  3271         </div>
       
  3272         <div class="format-settings">
       
  3273           <div class="format-setting type-select wide-desc">
       
  3274             <div class="description">' . __( '<strong>Type</strong>: Choose one of the available option types from the dropdown.', 'option-tree' ) . '</div>
       
  3275             <div class="format-setting-inner">
       
  3276               <select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][type]" value="' . esc_attr( $type ) . '" class="option-tree-ui-select">
       
  3277               ' . ot_loop_through_option_types( $type, $child ) . '                     
       
  3278                
       
  3279               </select>
       
  3280             </div>
       
  3281           </div>
       
  3282         </div>
       
  3283         <div class="format-settings">
       
  3284           <div class="format-setting type-textarea wide-desc">
       
  3285             <div class="description">' . __( '<strong>Description</strong>: Enter a detailed description for the users to read on the Theme Options page, HTML is allowed. This is also where you enter content for both the Textblock & Textblock Titled option types.', 'option-tree' ) . '</div>
       
  3286             <div class="format-setting-inner">
       
  3287               <textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][desc]">' . ( isset( $setting['desc'] ) ? esc_html( $setting['desc'] ) : '' ) . '</textarea>
       
  3288             </div>
       
  3289           </div>
       
  3290         </div>
       
  3291         <div class="format-settings">
       
  3292           <div class="format-setting type-textblock wide-desc">
       
  3293             <div class="description">' . __( '<strong>Choices</strong>: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ) . '</div>
       
  3294             <div class="format-setting-inner">
       
  3295               <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']">
       
  3296                 ' . ( isset( $setting['choices'] ) ? ot_loop_through_choices( $name . '[' . $key . ']', $setting['choices'] ) : '' ) . '
       
  3297               </ul>
       
  3298               <a href="javascript:void(0);" class="option-tree-choice-add option-tree-ui-button hug-left">' . __( 'Add Choice', 'option-tree' ) . '</a>
       
  3299             </div>
       
  3300           </div>
       
  3301         </div>
       
  3302         <div class="format-settings">
       
  3303           <div class="format-setting type-textblock wide-desc">
       
  3304             <div class="description">' . __( '<strong>Settings</strong>: This will only affect the List Item option type.', 'option-tree' ) . '</div>
       
  3305             <div class="format-setting-inner">
       
  3306               <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']">
       
  3307                 ' . ( isset( $setting['settings'] ) ? ot_loop_through_sub_settings( $name . '[' . $key . '][settings]', $setting['settings'] ) : '' ) . '
       
  3308               </ul>
       
  3309               <a href="javascript:void(0);" class="option-tree-list-item-setting-add option-tree-ui-button hug-left">' . __( 'Add Setting', 'option-tree' ) . '</a>
       
  3310             </div>
       
  3311           </div>
       
  3312         </div>
       
  3313         <div class="format-settings">
       
  3314           <div class="format-setting type-text wide-desc">
       
  3315             <div class="description">' . __( '<strong>Standard</strong>: Setting the standard value for your option only works for some option types. Read the <code>OptionTree->Documentation</code> for more information on which ones.', 'option-tree' ) . '</div>
       
  3316             <div class="format-setting-inner">
       
  3317               ' . $std_form_element . '
       
  3318             </div>
       
  3319           </div>
       
  3320         </div>
       
  3321         <div class="format-settings">
       
  3322           <div class="format-setting type-text wide-desc">
       
  3323             <div class="description">' . __( '<strong>Rows</strong>: Enter a numeric value for the number of rows in your textarea. This will only affect the following option types: CSS, Textarea, & Textarea Simple.', 'option-tree' ) . '</div>
       
  3324             <div class="format-setting-inner">
       
  3325               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][rows]" value="' . ( isset( $setting['rows'] ) ? esc_attr( $setting['rows'] ) : '' ) . '" class="widefat option-tree-ui-input" />
       
  3326             </div>
       
  3327           </div>
       
  3328         </div>
       
  3329         <div class="format-settings">
       
  3330           <div class="format-setting type-text wide-desc">
       
  3331             <div class="description">' . __( '<strong>Post Type</strong>: Add a comma separated list of post type like \'post,page\'. This will only affect the following option types: Custom Post Type Checkbox, & Custom Post Type Select.', 'option-tree' ) . '</div>
       
  3332             <div class="format-setting-inner">
       
  3333               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][post_type]" value="' . ( isset( $setting['post_type'] ) ? esc_attr( $setting['post_type'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3334             </div>
       
  3335           </div>
       
  3336         </div>
       
  3337         <div class="format-settings">
       
  3338           <div class="format-setting type-text wide-desc">
       
  3339             <div class="description">' . __( '<strong>Taxonomy</strong>: Add a comma separated list of any registered taxonomy like \'category,post_tag\'. This will only affect the following option types: Taxonomy Checkbox, & Taxonomy Select.', 'option-tree' ) . '</div>
       
  3340             <div class="format-setting-inner">
       
  3341               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][taxonomy]" value="' . ( isset( $setting['taxonomy'] ) ? esc_attr( $setting['taxonomy'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3342             </div>
       
  3343           </div>
       
  3344         </div>
       
  3345         <div class="format-settings">
       
  3346           <div class="format-setting type-text wide-desc">
       
  3347             <div class="description">' . __( '<strong>Min, Max, & Step</strong>: Add a comma separated list of options in the following format <code>0,100,1</code> (slide from <code>0-100</code> in intervals of <code>1</code>). The three values represent the minimum, maximum, and step options and will only affect the Numeric Slider option type.', 'option-tree' ) . '</div>
       
  3348             <div class="format-setting-inner">
       
  3349               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][min_max_step]" value="' . ( isset( $setting['min_max_step'] ) ? esc_attr( $setting['min_max_step'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3350             </div>
       
  3351           </div>
       
  3352         </div>
       
  3353         <div class="format-settings">
       
  3354           <div class="format-setting type-text wide-desc">
       
  3355             <div class="description">' . __( '<strong>CSS Class</strong>: Add and optional class to this option type.', 'option-tree' ) . '</div>
       
  3356             <div class="format-setting-inner">
       
  3357               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][class]" value="' . ( isset( $setting['class'] ) ? esc_attr( $setting['class'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3358             </div>
       
  3359           </div>
       
  3360         </div>
       
  3361       </div>
       
  3362     </div>
       
  3363     ' . ( ! $child ? '<input type="hidden" class="hidden-section" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][section]" value="' . ( isset( $setting['section'] ) ? esc_attr( $setting['section'] ) : '' ) . '" />' : '' );
       
  3364   
       
  3365   }
       
  3366 
       
  3367 }
       
  3368 
       
  3369 /**
       
  3370  * Helper function to display setting choices.
       
  3371  *
       
  3372  * This function is used in AJAX to add a new choice
       
  3373  * and when choices have already been added and saved.
       
  3374  *
       
  3375  * @param    string   $name The form element name.
       
  3376  * @param    array    $key The array key for the current element.
       
  3377  * @param    array    An array of values for the current choice.
       
  3378  *
       
  3379  * @return   void
       
  3380  *
       
  3381  * @access   public
       
  3382  * @since    2.0
       
  3383  */
       
  3384 if ( ! function_exists( 'ot_choices_view' ) ) {
       
  3385 
       
  3386   function ot_choices_view( $name, $key, $choice = array() ) {
       
  3387   
       
  3388     return '
       
  3389     <div class="option-tree-setting">
       
  3390       <div class="open">' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : 'Choice ' . ( $key + 1 ) ) . '</div>
       
  3391       <div class="button-section">
       
  3392         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  3393           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  3394         </a>
       
  3395         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  3396           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  3397         </a>
       
  3398       </div>
       
  3399       <div class="option-tree-setting-body">
       
  3400         <div class="format-settings">
       
  3401           <div class="format-setting-label">
       
  3402             <h5>' . __( 'Label', 'option-tree' ) . '</h5>
       
  3403           </div>
       
  3404           <div class="format-setting type-text wide-desc">
       
  3405             <div class="format-setting-inner">
       
  3406               <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][label]" value="' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" />
       
  3407             </div>
       
  3408           </div>
       
  3409         </div>
       
  3410         <div class="format-settings">
       
  3411           <div class="format-setting-label">
       
  3412             <h5>' . __( 'Value', 'option-tree' ) . '</h5>
       
  3413           </div>
       
  3414           <div class="format-setting type-text wide-desc">
       
  3415             <div class="format-setting-inner">
       
  3416               <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][value]" value="' . ( isset( $choice['value'] ) ? esc_attr( $choice['value'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3417             </div>
       
  3418           </div>
       
  3419         </div>
       
  3420         <div class="format-settings">
       
  3421           <div class="format-setting-label">
       
  3422             <h5>' . __( 'Image Source (Radio Image only)', 'option-tree' ) . '</h5>
       
  3423           </div>
       
  3424           <div class="format-setting type-text wide-desc">
       
  3425             <div class="format-setting-inner">
       
  3426               <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][src]" value="' . ( isset( $choice['src'] ) ? esc_attr( $choice['src'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3427             </div>
       
  3428           </div>
       
  3429         </div>
       
  3430     </div>';
       
  3431     
       
  3432   }
       
  3433 
       
  3434 }
       
  3435 
       
  3436 /**
       
  3437  * Helper function to display sections.
       
  3438  *
       
  3439  * This function is used in AJAX to add a new section
       
  3440  * and when section have already been added and saved.
       
  3441  *
       
  3442  * @param    int      $key The array key for the current element.
       
  3443  * @param    array    An array of values for the current section.
       
  3444  *
       
  3445  * @return   void
       
  3446  *
       
  3447  * @access   public
       
  3448  * @since    2.0
       
  3449  */
       
  3450 if ( ! function_exists( 'ot_contextual_help_view' ) ) {
       
  3451 
       
  3452   function ot_contextual_help_view( $name, $key, $content = array() ) {
       
  3453   
       
  3454     return '
       
  3455     <div class="option-tree-setting">
       
  3456       <div class="open">' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : 'Content ' . ( $key + 1 ) ) . '</div>
       
  3457       <div class="button-section">
       
  3458         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  3459           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  3460         </a>
       
  3461         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  3462           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  3463         </a>
       
  3464       </div>
       
  3465       <div class="option-tree-setting-body">
       
  3466         <div class="format-settings">
       
  3467           <div class="format-setting type-text no-desc">
       
  3468             <div class="description">' . __( '<strong>Title</strong>: Displayed as a contextual help menu item on the Theme Options page.', 'option-tree' ) . '</div>
       
  3469             <div class="format-setting-inner">
       
  3470               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" />
       
  3471             </div>
       
  3472           </div>
       
  3473         </div>
       
  3474         <div class="format-settings">
       
  3475           <div class="format-setting type-text no-desc">
       
  3476             <div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div>
       
  3477             <div class="format-setting-inner">
       
  3478               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $content['id'] ) ? esc_attr( $content['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  3479             </div>
       
  3480           </div>
       
  3481         </div>
       
  3482         <div class="format-settings">
       
  3483           <div class="format-setting type-textarea no-desc">
       
  3484             <div class="description">' . __( '<strong>Content</strong>: Enter the HTML content about this contextual help item displayed on the Theme Option page for end users to read.', 'option-tree' ) . '</div>
       
  3485             <div class="format-setting-inner">
       
  3486               <textarea class="textarea" rows="15" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][content]">' . ( isset( $content['content'] ) ? esc_html( $content['content'] ) : '' ) . '</textarea>
       
  3487             </div>
       
  3488           </div>
       
  3489         </div>
       
  3490       </div>
       
  3491     </div>';
       
  3492     
       
  3493   }
       
  3494 
       
  3495 }
       
  3496 
       
  3497 /**
       
  3498  * Helper function to display sections.
       
  3499  *
       
  3500  * @param     string      $key
       
  3501  * @param     string      $data
       
  3502  * @param     string      $active_layout
       
  3503  *
       
  3504  * @return    void
       
  3505  *
       
  3506  * @access    public
       
  3507  * @since     2.0
       
  3508  */
       
  3509 if ( ! function_exists( 'ot_layouts_view' ) ) {
       
  3510 
       
  3511   function ot_layout_view( $key, $data = '', $active_layout = '' ) {
       
  3512   
       
  3513     return '
       
  3514     <div class="option-tree-setting">
       
  3515       <div class="open">' . ( isset( $key ) ? esc_attr( $key ) : __( 'Layout', 'option-tree' ) ) . '</div>
       
  3516       <div class="button-section">
       
  3517         <a href="javascript:void(0);" class="option-tree-layout-activate option-tree-ui-button left-item' . ( $active_layout == $key ? ' active' : '' ) . '" title="' . __( 'Activate', 'option-tree' ) . '">
       
  3518           <span class="icon check">' . __( 'Activate', 'option-tree' ) . '</span>
       
  3519         </a>
       
  3520         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="'. __( 'Delete', 'option-tree' ) . '">
       
  3521           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  3522         </a>
       
  3523       </div>
       
  3524       <input type="hidden" name="option_tree_layouts[' . esc_attr( $key ) . ']" value="' . $data . '" />
       
  3525     </div>';
       
  3526     
       
  3527   }
       
  3528 
       
  3529 }
       
  3530 
       
  3531 /**
       
  3532  * Helper function to display list items.
       
  3533  *
       
  3534  * This function is used in AJAX to add a new list items
       
  3535  * and when they have already been added and saved.
       
  3536  *
       
  3537  * @param     string    $name The form field name.
       
  3538  * @param     int       $key The array key for the current element.
       
  3539  * @param     array     An array of values for the current list item.
       
  3540  *
       
  3541  * @return   void
       
  3542  *
       
  3543  * @access   public
       
  3544  * @since    2.0
       
  3545  */
       
  3546 if ( ! function_exists( 'ot_list_item_view' ) ) {
       
  3547 
       
  3548   function ot_list_item_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) {
       
  3549     
       
  3550     /* required title setting */
       
  3551     $required_setting = array(
       
  3552       array(
       
  3553         'id'        => 'title',
       
  3554         'label'     => __( 'Title', 'option-tree' ),
       
  3555         'desc'      => '',
       
  3556         'std'       => '',
       
  3557         'type'      => 'text',
       
  3558         'rows'      => '',
       
  3559         'class'     => 'option-tree-setting-title',
       
  3560         'post_type' => '',
       
  3561         'choices'   => array()
       
  3562       )
       
  3563     );
       
  3564     
       
  3565     /* load the old filterable slider settings */
       
  3566     if ( 'slider' == $type ) {
       
  3567       
       
  3568       $settings = ot_slider_settings( $name );
       
  3569     
       
  3570     }
       
  3571       
       
  3572     /* if no settings array load the filterable list item settings */
       
  3573     if ( empty( $settings ) ) {
       
  3574       
       
  3575       $settings = ot_list_item_settings( $name );
       
  3576       
       
  3577     }
       
  3578     
       
  3579     /* merge the two settings array */
       
  3580     $settings = array_merge( $required_setting, $settings );
       
  3581     
       
  3582     echo '
       
  3583     <div class="option-tree-setting">
       
  3584       <div class="open">' . ( isset( $list_item['title'] ) ? esc_attr( $list_item['title'] ) : '' ) . '</div>
       
  3585       <div class="button-section">
       
  3586         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  3587           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  3588         </a>
       
  3589         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button red light right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  3590           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  3591         </a>
       
  3592       </div>
       
  3593       <div class="option-tree-setting-body">';
       
  3594         
       
  3595       foreach( $settings as $field ) {
       
  3596         
       
  3597         // Set field value
       
  3598         $field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : '';
       
  3599         
       
  3600         /* set default to standard value */
       
  3601         if ( isset( $field['std'] ) ) {  
       
  3602           $field_value = ot_filter_std_value( $field_value, $field['std'] );
       
  3603         }
       
  3604           
       
  3605         /* make life easier */
       
  3606         $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name;
       
  3607              
       
  3608         /* build the arguments array */
       
  3609         $_args = array(
       
  3610           'type'              => $field['type'],
       
  3611           'field_id'          => $name . '_' . $field['id'] . '_' . $key,
       
  3612           'field_name'        => $_field_name . '[' . $key . '][' . $field['id'] . ']',
       
  3613           'field_value'       => $field_value,
       
  3614           'field_desc'        => isset( $field['desc'] ) ? $field['desc'] : '',
       
  3615           'field_std'         => isset( $field['std'] ) ? $field['std'] : '',
       
  3616           'field_rows'        => isset( $field['rows'] ) ? $field['rows'] : 10,
       
  3617           'field_post_type'   => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post',
       
  3618           'field_taxonomy'    => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category',
       
  3619           'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1',
       
  3620           'field_class'       => isset( $field['class'] ) ? $field['class'] : '',
       
  3621           'field_choices'     => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(),
       
  3622           'field_settings'    => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(),
       
  3623           'post_id'           => $post_id,
       
  3624           'get_option'        => $get_option
       
  3625         );
       
  3626           
       
  3627         /* option label */
       
  3628         echo '<div class="format-settings">';
       
  3629           
       
  3630         /* don't show title with textblocks */
       
  3631         if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) {
       
  3632           echo '<div class="format-setting-label">';
       
  3633             echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>';
       
  3634           echo '</div>';
       
  3635         }
       
  3636         
       
  3637         /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */
       
  3638         if ( $_args['type'] == 'textarea' )
       
  3639           $_args['type'] = 'textarea-simple';
       
  3640           
       
  3641         /* option body, list-item is not allowed inside another list-item */
       
  3642         if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' ) {
       
  3643           echo ot_display_by_type( $_args );
       
  3644         }
       
  3645         
       
  3646         echo '</div>';
       
  3647       
       
  3648       }
       
  3649         
       
  3650     echo
       
  3651       '</div>
       
  3652     </div>';
       
  3653     
       
  3654   }
       
  3655   
       
  3656 }
       
  3657 
       
  3658 /**
       
  3659  * Helper function to display Theme Options layouts form.
       
  3660  *
       
  3661  * @return    string
       
  3662  *
       
  3663  * @access    public
       
  3664  * @since     2.0
       
  3665  */
       
  3666 if ( ! function_exists( 'ot_theme_options_layouts_form' ) ) {
       
  3667 
       
  3668   function ot_theme_options_layouts_form( $active = false ) {
       
  3669     
       
  3670     echo '<form method="post" id="option-tree-options-layouts-form">';
       
  3671         
       
  3672       /* form nonce */
       
  3673       wp_nonce_field( 'option_tree_modify_layouts_form', 'option_tree_modify_layouts_nonce' );
       
  3674         
       
  3675       /* get the saved layouts */
       
  3676       $layouts = get_option( 'option_tree_layouts' );
       
  3677       
       
  3678       /* set active layout */
       
  3679       $active_layout = isset( $layouts['active_layout'] ) ? $layouts['active_layout'] : '';
       
  3680 
       
  3681       if ( is_array( $layouts ) && count( $layouts ) > 1 ) {
       
  3682         
       
  3683         $active_layout = esc_attr( $layouts['active_layout'] );
       
  3684         
       
  3685         echo '<input type="hidden" id="the_current_layout" value="' . $active_layout . '" />';
       
  3686         
       
  3687         echo '<div class="option-tree-active-layout">';
       
  3688         
       
  3689           echo '<select name="option_tree_layouts[active_layout]" class="option-tree-ui-select">';
       
  3690       
       
  3691             foreach( $layouts as $key => $data ) { 
       
  3692               
       
  3693               if ( $key == 'active_layout' )
       
  3694                 continue;
       
  3695               
       
  3696               echo '<option' . selected( $key, $active_layout, false ) . ' value="' . esc_attr( $key ) . '">' . esc_attr( $key ) . '</option>';
       
  3697             }
       
  3698            
       
  3699           echo '</select>';
       
  3700         
       
  3701         echo '</div>';
       
  3702          
       
  3703         foreach( $layouts as $key => $data ) {
       
  3704           
       
  3705           if ( $key == 'active_layout' )
       
  3706               continue;
       
  3707               
       
  3708           echo '<input type="hidden" name="option_tree_layouts[' . $key . ']" value="' . ( isset( $data ) ? $data : '' ) . '" />';
       
  3709           
       
  3710         }
       
  3711        
       
  3712       }
       
  3713       
       
  3714       /* new layout wrapper */
       
  3715       echo '<div class="option-tree-save-layout' . ( ! empty( $active_layout ) ? ' active-layout' : '' ) . '">';
       
  3716         
       
  3717         /* add new layout */
       
  3718         echo '<input type="text" name="option_tree_layouts[_add_new_layout_]" value="" class="widefat option-tree-ui-input" autocomplete="off" />';
       
  3719         
       
  3720         echo '<button type="submit" class="option-tree-ui-button blue save-layout" title="' . __( 'New Layout', 'option-tree' ) . '">' . __( 'New Layout', 'option-tree' ) . '</button>';
       
  3721       
       
  3722       echo '</div>';
       
  3723       
       
  3724     echo '</form>';
       
  3725     
       
  3726   }
       
  3727 
       
  3728 }
       
  3729 
       
  3730 /**
       
  3731  * Helper function to validate option ID's
       
  3732  *
       
  3733  * @param     string      $input The string to sanitize.
       
  3734  * @return    string
       
  3735  *
       
  3736  * @access    public
       
  3737  * @since     2.0
       
  3738  */
       
  3739 if ( ! function_exists( 'ot_sanitize_option_id' ) ) {
       
  3740 
       
  3741   function ot_sanitize_option_id( $input ) {
       
  3742   
       
  3743     return preg_replace( '/[^a-z0-9]/', '_', trim( strtolower( $input ) ) );
       
  3744       
       
  3745   }
       
  3746 
       
  3747 }
       
  3748 
       
  3749 /**
       
  3750  * Helper function to validate layout ID's
       
  3751  *
       
  3752  * @param     string      $input The string to sanitize.
       
  3753  * @return    string
       
  3754  *
       
  3755  * @access    public
       
  3756  * @since     2.0
       
  3757  */
       
  3758 if ( ! function_exists( 'ot_sanitize_layout_id' ) ) {
       
  3759 
       
  3760   function ot_sanitize_layout_id( $input ) {
       
  3761   
       
  3762     return preg_replace( '/[^a-z0-9]/', '-', trim( strtolower( $input ) ) );
       
  3763       
       
  3764   }
       
  3765 
       
  3766 }
       
  3767 
       
  3768 /**
       
  3769  * Convert choices array to string
       
  3770  *
       
  3771  * @return    string
       
  3772  *
       
  3773  * @access    public
       
  3774  * @since     2.0
       
  3775  */
       
  3776 if ( ! function_exists( 'ot_convert_array_to_string' ) ) {
       
  3777 
       
  3778   function ot_convert_array_to_string( $input ) {
       
  3779 
       
  3780     if ( is_array( $input ) ) {
       
  3781 
       
  3782       foreach( $input as $k => $choice ) {
       
  3783         $choices[$k] = $choice['value'] . '|' . $choice['label'];
       
  3784         
       
  3785         if ( isset( $choice['src'] ) )
       
  3786           $choices[$k].= '|' . $choice['src'];
       
  3787           
       
  3788       }
       
  3789       
       
  3790       return implode( ',', $choices );
       
  3791     }
       
  3792     
       
  3793     return false;
       
  3794   }
       
  3795 }
       
  3796 
       
  3797 /**
       
  3798  * Convert choices string to array
       
  3799  *
       
  3800  * @return    array
       
  3801  *
       
  3802  * @access    public
       
  3803  * @since     2.0
       
  3804  */
       
  3805 if ( ! function_exists( 'ot_convert_string_to_array' ) ) {
       
  3806 
       
  3807   function ot_convert_string_to_array( $input ) {
       
  3808     
       
  3809     if ( '' !== $input ) {
       
  3810     
       
  3811       /* empty choices array */
       
  3812       $choices = array();
       
  3813       
       
  3814       /* exlode the string into an array */
       
  3815       foreach( explode( ',', $input ) as $k => $choice ) {
       
  3816         
       
  3817         /* if ":" is splitting the string go deeper */
       
  3818         if ( preg_match( '/\|/', $choice ) ) {
       
  3819           $split = explode( '|', $choice );
       
  3820           $choices[$k]['value'] = trim( $split[0] );
       
  3821           $choices[$k]['label'] = trim( $split[1] );
       
  3822           
       
  3823           /* if radio image there are three values */
       
  3824           if ( isset( $split[2] ) )
       
  3825             $choices[$k]['src'] = trim( $split[2] );
       
  3826             
       
  3827         } else {
       
  3828           $choices[$k]['value'] = trim( $choice );
       
  3829           $choices[$k]['label'] = trim( $choice );
       
  3830         }
       
  3831         
       
  3832       }
       
  3833       
       
  3834       /* return a formated choices array */
       
  3835       return $choices;
       
  3836     
       
  3837     }
       
  3838     
       
  3839     return false;
       
  3840     
       
  3841   }
       
  3842 }
       
  3843 
       
  3844 /**
       
  3845  * Helper function - strpos() with arrays.
       
  3846  *
       
  3847  * @param     string    $haystack
       
  3848  * @param     array     $needles
       
  3849  * @return    bool
       
  3850  *
       
  3851  * @access    public
       
  3852  * @since     2.0
       
  3853  */
       
  3854 if ( ! function_exists( 'ot_strpos_array' ) ) {
       
  3855 
       
  3856   function ot_strpos_array( $haystack, $needles = array() ) {
       
  3857   
       
  3858     foreach( $needles as $needle ) {
       
  3859       $pos = strpos( $haystack, $needle );
       
  3860       if ( $pos !== false ) {
       
  3861         return true;
       
  3862       }
       
  3863     }
       
  3864     
       
  3865     return false;
       
  3866   }
       
  3867 
       
  3868 }
       
  3869 
       
  3870 /**
       
  3871  * Helper function - strpos() with arrays.
       
  3872  *
       
  3873  * @param     string    $haystack
       
  3874  * @param     array     $needles
       
  3875  * @return    bool
       
  3876  *
       
  3877  * @access    public
       
  3878  * @since     2.0
       
  3879  */
       
  3880 if ( ! function_exists( 'ot_array_keys_exists' ) ) {
       
  3881   
       
  3882   function ot_array_keys_exists( $array, $keys ) {
       
  3883     
       
  3884     foreach($keys as $k) {
       
  3885       if ( isset($array[$k]) ) {
       
  3886         return true;
       
  3887       }
       
  3888     }
       
  3889     
       
  3890     return false;
       
  3891   }
       
  3892   
       
  3893 }
       
  3894 
       
  3895 /**
       
  3896  * Custom stripslashes from single value or array.
       
  3897  *
       
  3898  * @param       mixed   $input
       
  3899  * @return      mixed
       
  3900  *
       
  3901  * @access      public
       
  3902  * @since       2.0
       
  3903  */
       
  3904 if ( ! function_exists( 'ot_stripslashes' ) ) {
       
  3905 
       
  3906   function ot_stripslashes( $input ) {
       
  3907   
       
  3908     if ( is_array( $input ) ) {
       
  3909     
       
  3910       foreach( $input as &$val ) {
       
  3911       
       
  3912         if ( is_array( $val ) ) {
       
  3913         
       
  3914           $val = ot_stripslashes( $val );
       
  3915           
       
  3916         } else {
       
  3917         
       
  3918           $val = stripslashes( trim( $val ) );
       
  3919           
       
  3920         }
       
  3921         
       
  3922       }
       
  3923       
       
  3924     } else {
       
  3925     
       
  3926       $input = stripslashes( trim( $input ) );
       
  3927       
       
  3928     }
       
  3929     
       
  3930     return $input;
       
  3931     
       
  3932   }
       
  3933 
       
  3934 }
       
  3935 
       
  3936 /**
       
  3937  * Reverse wpautop.
       
  3938  *
       
  3939  * @param     string    $string The string to be filtered
       
  3940  * @return    string
       
  3941  *
       
  3942  * @access    public
       
  3943  * @since     2.0.9
       
  3944  */
       
  3945 if ( ! function_exists( 'ot_reverse_wpautop' ) ) {
       
  3946 
       
  3947   function ot_reverse_wpautop( $string = '' ) {
       
  3948     
       
  3949     /* return if string is empty */
       
  3950     if ( trim( $string ) === '' )
       
  3951       return '';
       
  3952       
       
  3953     /* remove all new lines & <p> tags */
       
  3954     $string = str_replace( array( "\n", "<p>" ), "", $string );
       
  3955   
       
  3956     /* replace <br /> with \r */
       
  3957     $string = str_replace( array( "<br />", "<br>", "<br/>" ), "\r", $string );
       
  3958   
       
  3959     /* replace </p> with \r\n */
       
  3960     $string = str_replace( "</p>", "\r\n", $string );
       
  3961     
       
  3962     /* return clean string */
       
  3963     return trim( $string );
       
  3964                 
       
  3965   }
       
  3966 
       
  3967 }
       
  3968 
       
  3969 /**
       
  3970  * Returns an array of elements from start to limit, inclusive.
       
  3971  *
       
  3972  * Occasionally zero will be some impossibly large number to 
       
  3973  * the "E" power when creating a range from negative to positive.
       
  3974  * This function attempts to fix that by setting that number back to "0".
       
  3975  *
       
  3976  * @param     string    $start First value of the sequence.
       
  3977  * @param     string    $limit The sequence is ended upon reaching the limit value.
       
  3978  * @param     string    $step If a step value is given, it will be used as the increment 
       
  3979  *                      between elements in the sequence. step should be given as a 
       
  3980  *                      positive number. If not specified, step will default to 1.
       
  3981  * @return    array
       
  3982  *
       
  3983  * @access    public
       
  3984  * @since     2.0.12
       
  3985  */
       
  3986 function ot_range( $start, $limit, $step = 1 ) {
       
  3987   
       
  3988   if ( $step < 0 )
       
  3989     $step = 1;
       
  3990     
       
  3991   $range = range( $start, $limit, $step );
       
  3992   
       
  3993   foreach( $range as $k => $v ) {
       
  3994     if ( strpos( $v, 'E' ) ) {
       
  3995       $range[$k] = 0;
       
  3996     }
       
  3997   }
       
  3998   
       
  3999   return $range;
       
  4000 }
       
  4001 
       
  4002 /**
       
  4003  * Helper function to return encoded strings
       
  4004  *
       
  4005  * @return    string
       
  4006  *
       
  4007  * @access    public
       
  4008  * @since     2.0.13
       
  4009  */
       
  4010 function ot_encode( $value ) {
       
  4011 
       
  4012   $func = 'base64' . '_encode';
       
  4013   return $func( $value );
       
  4014   
       
  4015 }
       
  4016 
       
  4017 /**
       
  4018  * Helper function to return decoded strings
       
  4019  *
       
  4020  * @return    string
       
  4021  *
       
  4022  * @access    public
       
  4023  * @since     2.0.13
       
  4024  */
       
  4025 function ot_decode( $value ) {
       
  4026 
       
  4027   $func = 'base64' . '_decode';
       
  4028   return $func( $value );
       
  4029   
       
  4030 }
       
  4031 
       
  4032 /**
       
  4033  * Helper function to open a file
       
  4034  *
       
  4035  * @access    public
       
  4036  * @since     2.0.13
       
  4037  */
       
  4038 function ot_file_open( $handle, $mode ) {
       
  4039 
       
  4040   $func = 'f' . 'open';
       
  4041   return @$func( $handle, $mode );
       
  4042   
       
  4043 }
       
  4044 
       
  4045 /**
       
  4046  * Helper function to close a file
       
  4047  *
       
  4048  * @access    public
       
  4049  * @since     2.0.13
       
  4050  */
       
  4051 function ot_file_close( $handle ) {
       
  4052 
       
  4053   $func = 'f' . 'close';
       
  4054   return $func( $handle );
       
  4055   
       
  4056 }
       
  4057 
       
  4058 /**
       
  4059  * Helper function to write to an open file
       
  4060  *
       
  4061  * @access    public
       
  4062  * @since     2.0.13
       
  4063  */
       
  4064 function ot_file_write( $handle, $string ) {
       
  4065 
       
  4066   $func = 'f' . 'write';
       
  4067   return $func( $handle, $string );
       
  4068   
       
  4069 }
       
  4070 
       
  4071 /**
       
  4072  * Helper function to filter standard option values.
       
  4073  *
       
  4074  * @param     mixed     $value Saved string or array value
       
  4075  * @param     mixed     $std Standard string or array value
       
  4076  * @return    mixed     String or array
       
  4077  *
       
  4078  * @access    public
       
  4079  * @since     2.0.15
       
  4080  */
       
  4081 function ot_filter_std_value( $value = '', $std = '' ) {
       
  4082   
       
  4083   $std = maybe_unserialize( $std );
       
  4084   
       
  4085   if ( is_array( $value ) && is_array( $std ) ) {
       
  4086   
       
  4087     foreach( $value as $k => $v ) {
       
  4088       
       
  4089       if ( '' == $value[$k] && isset( $std[$k] ) ) {
       
  4090       
       
  4091         $value[$k] = $std[$k];
       
  4092         
       
  4093       }
       
  4094       
       
  4095     }
       
  4096   
       
  4097   } else if ( '' == $value && ! empty( $std ) ) {
       
  4098   
       
  4099     $value = $std;
       
  4100     
       
  4101   }
       
  4102 
       
  4103   return $value;
       
  4104   
       
  4105 }
       
  4106 
       
  4107 /**
       
  4108  * Helper function to register a WPML string
       
  4109  *
       
  4110  * @access    public
       
  4111  * @since     2.1
       
  4112  */
       
  4113 function ot_wpml_register_string( $id, $value ) {
       
  4114 
       
  4115   if ( function_exists( 'icl_register_string' ) ) {
       
  4116       
       
  4117     icl_register_string( 'Theme Options', $id, $value );
       
  4118       
       
  4119   }
       
  4120   
       
  4121 }
       
  4122 
       
  4123 /**
       
  4124  * Helper function to unregister a WPML string
       
  4125  *
       
  4126  * @access    public
       
  4127  * @since     2.1
       
  4128  */
       
  4129 function ot_wpml_unregister_string( $id ) {
       
  4130 
       
  4131   if ( function_exists( 'icl_unregister_string' ) ) {
       
  4132       
       
  4133     icl_unregister_string( 'Theme Options', $id );
       
  4134       
       
  4135   }
       
  4136   
       
  4137 }
       
  4138 
       
  4139 /* End of file ot-functions-admin.php */
       
  4140 /* Location: ./includes/ot-functions-admin.php */