wp/wp-content/plugins/option-tree/includes/ot-functions.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  * OptionTree functions
       
     4  *
       
     5  * @package   OptionTree
       
     6  * @author    Derek Herman <derek@valendesigns.com>
       
     7  * @copyright Copyright (c) 2013, Derek Herman
       
     8  * @since     2.0
       
     9  */
       
    10       
       
    11 /**
       
    12  * Get Option.
       
    13  *
       
    14  * Helper function to return the option value.
       
    15  * If no value has been saved, it returns $default.
       
    16  *
       
    17  * @param     string    The option ID.
       
    18  * @param     string    The default option value.
       
    19  * @return    mixed
       
    20  *
       
    21  * @access    public
       
    22  * @since     2.0
       
    23  */
       
    24 if ( ! function_exists( 'ot_get_option' ) ) {
       
    25 
       
    26   function ot_get_option( $option_id, $default = '' ) {
       
    27     
       
    28     /* get the saved options */ 
       
    29     $options = get_option( 'option_tree' );
       
    30     
       
    31     /* look for the saved value */
       
    32     if ( isset( $options[$option_id] ) && '' != $options[$option_id] ) {
       
    33         
       
    34       return ot_wpml_filter( $options, $option_id );
       
    35       
       
    36     }
       
    37     
       
    38     return $default;
       
    39     
       
    40   }
       
    41   
       
    42 }
       
    43 
       
    44 /**
       
    45  * Filter the return values through WPML
       
    46  *
       
    47  * @param     array     $options The current options    
       
    48  * @param     string    $option_id The option ID
       
    49  * @return    mixed
       
    50  *
       
    51  * @access    public
       
    52  * @since     2.1
       
    53  */
       
    54 if ( ! function_exists( 'ot_wpml_filter' ) ) {
       
    55 
       
    56   function ot_wpml_filter( $options, $option_id ) {
       
    57       
       
    58     // Return translated strings using WMPL
       
    59     if ( function_exists('icl_t') ) {
       
    60       
       
    61       $settings = get_option( 'option_tree_settings' );
       
    62       
       
    63       if ( isset( $settings['settings'] ) ) {
       
    64       
       
    65         foreach( $settings['settings'] as $setting ) {
       
    66           
       
    67           // List Item & Slider
       
    68           if ( $option_id == $setting['id'] && in_array( $setting['type'], array( 'list-item', 'slider' ) ) ) {
       
    69           
       
    70             foreach( $options[$option_id] as $key => $value ) {
       
    71           
       
    72               foreach( $value as $ckey => $cvalue ) {
       
    73                 
       
    74                 $id = $option_id . '_' . $ckey . '_' . $key;
       
    75                 $_string = icl_t( 'Theme Options', $id, $cvalue );
       
    76                 
       
    77                 if ( ! empty( $_string ) ) {
       
    78                 
       
    79                   $options[$option_id][$key][$ckey] = $_string;
       
    80                   
       
    81                 }
       
    82                 
       
    83               }
       
    84             
       
    85             }
       
    86           
       
    87           // All other acceptable option types
       
    88           } else if ( $option_id == $setting['id'] && in_array( $setting['type'], apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ) ) ) {
       
    89           
       
    90             $_string = icl_t( 'Theme Options', $option_id, $options[$option_id] );
       
    91             
       
    92             if ( ! empty( $_string ) ) {
       
    93             
       
    94               $options[$option_id] = $_string;
       
    95               
       
    96             }
       
    97             
       
    98           }
       
    99           
       
   100         }
       
   101       
       
   102       }
       
   103     
       
   104     }
       
   105     
       
   106     return $options[$option_id];
       
   107   
       
   108   }
       
   109 
       
   110 }
       
   111 
       
   112 /**
       
   113  * Enqueue the dynamic CSS.
       
   114  *
       
   115  * @return    void
       
   116  *
       
   117  * @access    public
       
   118  * @since     2.0
       
   119  */
       
   120 if ( ! function_exists( 'ot_load_dynamic_css' ) ) {
       
   121 
       
   122   function ot_load_dynamic_css() {
       
   123     
       
   124     /* don't load in the admin */
       
   125     if ( is_admin() )
       
   126       return;
       
   127     
       
   128     /* grab a copy of the paths */
       
   129     $ot_css_file_paths = get_option( 'ot_css_file_paths', array() );
       
   130     
       
   131     if ( ! empty( $ot_css_file_paths ) ) {
       
   132       
       
   133       $last_css = '';
       
   134       
       
   135       /* loop through paths */
       
   136       foreach( $ot_css_file_paths as $key => $path ) {
       
   137         
       
   138         if ( '' != $path && file_exists( $path ) ) {
       
   139         
       
   140           $parts = explode( '/wp-content', $path );
       
   141           
       
   142           if ( isset( $parts[1] ) ) {
       
   143             
       
   144             $css = home_url( '/wp-content' . $parts[1] );
       
   145             
       
   146             if ( $last_css !== $css ) {
       
   147               
       
   148               /* enqueue filtered file */
       
   149               wp_enqueue_style( 'ot-dynamic-' . $key, $css, false, OT_VERSION );
       
   150               
       
   151               $last_css = $css;
       
   152               
       
   153             }
       
   154             
       
   155           }
       
   156       
       
   157         }
       
   158         
       
   159       }
       
   160     
       
   161     }
       
   162     
       
   163   }
       
   164   
       
   165 }
       
   166 
       
   167 /**
       
   168  * Registers the Theme Option page link for the admin bar.
       
   169  *
       
   170  * @uses      ot_register_settings()
       
   171  *
       
   172  * @return    void
       
   173  *
       
   174  * @access    public
       
   175  * @since     2.1
       
   176  */
       
   177 if ( ! function_exists( 'ot_register_theme_options_admin_bar_menu' ) ) {
       
   178 
       
   179   function ot_register_theme_options_admin_bar_menu( $wp_admin_bar ) {
       
   180     
       
   181     if ( ! current_user_can( apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ) ) || ! is_admin_bar_showing() )
       
   182       return;
       
   183     
       
   184     $wp_admin_bar->add_node( array(
       
   185       'parent'  => 'appearance',
       
   186       'id'      => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ),
       
   187       'title'   => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ),
       
   188       'href'    => admin_url( apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ) . '?page=' . apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) )
       
   189     ) );
       
   190     
       
   191   }
       
   192   
       
   193 }
       
   194 
       
   195 /* End of file ot-functions.php */
       
   196 /* Location: ./includes/ot-functions.php */