wp/wp-content/plugins/option-tree/includes/ot-settings-api.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    47      *
    47      *
    48      * @access    public
    48      * @access    public
    49      * @since     2.0
    49      * @since     2.0
    50      */
    50      */
    51     public function hooks() {
    51     public function hooks() {
    52       
    52 
       
    53       /**
       
    54        * Filter the `admin_menu` action hook priority.
       
    55        *
       
    56        * @since 2.5.0
       
    57        *
       
    58        * @param int $priority The priority. Default '10'.
       
    59        */
       
    60       $priority = apply_filters( 'ot_admin_menu_priority', 10 );
       
    61 
    53       /* add pages & menu items */
    62       /* add pages & menu items */
    54       add_action( 'admin_menu', array( $this, 'add_page' ) );
    63       add_action( 'admin_menu', array( $this, 'add_page' ), $priority );
    55       
    64       
    56       /* register sections */
    65       /* register sections */
    57       add_action( 'admin_init', array( $this, 'add_sections' ) );
    66       add_action( 'admin_init', array( $this, 'add_sections' ) );
    58       
    67       
    59       /* register settings */
    68       /* register settings */
   231             $show_buttons = isset( $page['show_buttons'] ) && $page['show_buttons'] == false ? false : true;
   240             $show_buttons = isset( $page['show_buttons'] ) && $page['show_buttons'] == false ? false : true;
   232 
   241 
   233             /* update active layout content */
   242             /* update active layout content */
   234             if ( isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ) {
   243             if ( isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ) {
   235   
   244   
   236               $layouts = get_option( 'option_tree_layouts' );
   245               $layouts = get_option( ot_layouts_id() );
   237               
   246               
   238               /* has active layout */
   247               /* has active layout */
   239               if ( isset( $layouts['active_layout'] ) ) {
   248               if ( isset( $layouts['active_layout'] ) ) {
   240                 $option_tree = get_option( $option['id'] );
   249                 $option_tree = get_option( $option['id'] );
   241                 $layouts[$layouts['active_layout']] = ot_encode( serialize( $option_tree ) );
   250                 $layouts[$layouts['active_layout']] = ot_encode( serialize( $option_tree ) );
   242                 update_option( 'option_tree_layouts', $layouts );
   251                 update_option( ot_layouts_id(), $layouts );
   243               }
   252               }
   244               
   253               
   245             }
   254             }
   246             
   255             
   247             echo '<div class="wrap settings-wrap" id ="page-' . $page['id'] . '">';
   256             echo '<div class="wrap settings-wrap" id ="page-' . $page['id'] . '">';
   248   
   257   
   249               screen_icon( ( isset( $page['screen_icon'] ) ? $page['screen_icon'] : 'options-general' ) );
       
   250               echo '<h2>' . $page['page_title'] . '</h2>';
   258               echo '<h2>' . $page['page_title'] . '</h2>';
   251               
   259               
   252               echo ot_alert_message( $page );
   260               echo ot_alert_message( $page );
   253               
   261               
   254               settings_errors( 'option-tree' );
   262               settings_errors( 'option-tree' );
   256               /* Header */
   264               /* Header */
   257               echo '<div id="option-tree-header-wrap">';
   265               echo '<div id="option-tree-header-wrap">';
   258               
   266               
   259                 echo '<ul id="option-tree-header">';
   267                 echo '<ul id="option-tree-header">';
   260                   
   268                   
   261                   echo '<li id="option-tree-logo"><a href="http://wordpress.org/extend/plugins/option-tree/" target="_blank">OptionTree</a></li>';
   269                   echo '<li id="option-tree-logo">' . apply_filters( 'ot_header_logo_link', '<a href="http://wordpress.org/extend/plugins/option-tree/" target="_blank">OptionTree</a>', $page['id'] ) . '</li>';
   262                   
   270                   
   263                   echo '<li id="option-tree-version"><span>Version ' . OT_VERSION . '</span></li>';
   271                   echo '<li id="option-tree-version"><span>' . apply_filters( 'ot_header_version_text', 'OptionTree ' . OT_VERSION, $page['id'] ) . '</span></li>';
       
   272                   
       
   273                   // Add additional theme specific links here.
       
   274                   do_action( 'ot_header_list', $page['id'] );
   264                 
   275                 
   265                 echo '</ul>';
   276                 echo '</ul>';
   266                 
   277                 
   267                 /* layouts form */
   278                 /* layouts form */
   268                 if ( $page['id'] == 'ot_theme_options' && OT_SHOW_NEW_LAYOUT == true )
   279                 if ( $page['id'] == 'ot_theme_options' && OT_SHOW_NEW_LAYOUT == true )
   285                 
   296                 
   286                 /* Sub Header */
   297                 /* Sub Header */
   287                 echo '<div id="option-tree-sub-header">';
   298                 echo '<div id="option-tree-sub-header">';
   288                   
   299                   
   289                 if ( $show_buttons )
   300                 if ( $show_buttons )
   290                   echo '<button class="option-tree-ui-button blue right">' . $page['button_text'] . '</button>';
   301                   echo '<button class="option-tree-ui-button button button-primary right">' . $page['button_text'] . '</button>';
   291                   
   302                   
   292                 echo '</div>';
   303                 echo '</div>';
   293                 
   304                 
   294                 /* Navigation */
   305                 /* Navigation */
   295                 echo '<div class="ui-tabs">';
   306                 echo '<div class="ui-tabs">';
   330               /* buttons */
   341               /* buttons */
   331               if ( $show_buttons ) {
   342               if ( $show_buttons ) {
   332               
   343               
   333                 echo '<div class="option-tree-ui-buttons">';
   344                 echo '<div class="option-tree-ui-buttons">';
   334                 
   345                 
   335                   echo '<button class="option-tree-ui-button blue right">' . $page['button_text'] . '</button>';
   346                   echo '<button class="option-tree-ui-button button button-primary right">' . $page['button_text'] . '</button>';
   336                   
   347                   
   337                 echo '</div>';
   348                 echo '</div>';
   338                 
   349                 
   339               }
   350               }
   340               
   351               
   348                   /* form nonce */
   359                   /* form nonce */
   349                   wp_nonce_field( 'option_tree_reset_form', 'option_tree_reset_nonce' );
   360                   wp_nonce_field( 'option_tree_reset_form', 'option_tree_reset_nonce' );
   350         
   361         
   351                   echo '<input type="hidden" name="action" value="reset" />';
   362                   echo '<input type="hidden" name="action" value="reset" />';
   352                   
   363                   
   353                   echo '<button type="submit" class="option-tree-ui-button red left reset-settings" title="' . __( 'Reset Options', 'option-tree' ) . '">' . __( 'Reset Options', 'option-tree' ) . '</button>';
   364                   echo '<button type="submit" class="option-tree-ui-button button button-secondary left reset-settings" title="' . __( 'Reset Options', 'option-tree' ) . '">' . __( 'Reset Options', 'option-tree' ) . '</button>';
   354                 
   365                 
   355                 echo '</form>';
   366                 echo '</form>';
   356                 
   367                 
   357               }
   368               }
   358                           
   369                           
   470      *
   481      *
   471      * @access    public
   482      * @access    public
   472      * @since     2.0
   483      * @since     2.0
   473      */
   484      */
   474     public function display_setting( $args = array() ) {
   485     public function display_setting( $args = array() ) {
       
   486 
   475       extract( $args );
   487       extract( $args );
   476       
   488       
   477       /* get current saved data */
   489       /* get current saved data */
   478       $options = get_option( $get_option, false );
   490       $options = get_option( $get_option, false );
   479       
   491       
   482       
   494       
   483       /* set standard value */
   495       /* set standard value */
   484       if ( isset( $std ) ) {  
   496       if ( isset( $std ) ) {  
   485         $field_value = ot_filter_std_value( $field_value, $std );
   497         $field_value = ot_filter_std_value( $field_value, $std );
   486       }
   498       }
       
   499       
       
   500       // Allow the descriptions to be filtered before being displayed
       
   501       $desc = apply_filters( 'ot_filter_description', ( isset( $desc ) ? $desc : '' ), $id );
   487 
   502 
   488       /* build the arguments array */
   503       /* build the arguments array */
   489       $_args = array(
   504       $_args = array(
   490         'type'              => $type,
   505         'type'              => $type,
   491         'field_id'          => $id,
   506         'field_id'          => $id,
   492         'field_name'        => $get_option . '[' . $id . ']',
   507         'field_name'        => $get_option . '[' . $id . ']',
   493         'field_value'       => $field_value,
   508         'field_value'       => $field_value,
   494         'field_desc'        => isset( $desc ) ? $desc : '',
   509         'field_desc'        => $desc,
   495         'field_std'         => isset( $std ) ? $std : '',
   510         'field_std'         => isset( $std ) ? $std : '',
   496         'field_rows'        => isset( $rows ) && ! empty( $rows ) ? $rows : 15,
   511         'field_rows'        => isset( $rows ) && ! empty( $rows ) ? $rows : 15,
   497         'field_post_type'   => isset( $post_type ) && ! empty( $post_type ) ? $post_type : 'post',
   512         'field_post_type'   => isset( $post_type ) && ! empty( $post_type ) ? $post_type : 'post',
   498         'field_taxonomy'    => isset( $taxonomy ) && ! empty( $taxonomy ) ? $taxonomy : 'category',
   513         'field_taxonomy'    => isset( $taxonomy ) && ! empty( $taxonomy ) ? $taxonomy : 'category',
   499         'field_min_max_step'=> isset( $min_max_step ) && ! empty( $min_max_step ) ? $min_max_step : '0,100,1',
   514         'field_min_max_step'=> isset( $min_max_step ) && ! empty( $min_max_step ) ? $min_max_step : '0,100,1',
       
   515         'field_condition'   => isset( $condition ) && ! empty( $condition ) ? $condition : '',
       
   516         'field_operator'    => isset( $operator ) && ! empty( $operator ) ? $operator : 'and',
   500         'field_class'       => isset( $class ) ? $class : '',
   517         'field_class'       => isset( $class ) ? $class : '',
   501         'field_choices'     => isset( $choices ) && ! empty( $choices ) ? $choices : array(),
   518         'field_choices'     => isset( $choices ) && ! empty( $choices ) ? $choices : array(),
   502         'field_settings'    => isset( $settings ) && ! empty( $settings ) ? $settings : array(),
   519         'field_settings'    => isset( $settings ) && ! empty( $settings ) ? $settings : array(),
   503         'post_id'           => ot_get_media_post_ID(),
   520         'post_id'           => ot_get_media_post_ID(),
   504         'get_option'        => $get_option,
   521         'get_option'        => $get_option,
   505       );
   522       );
   506       
   523       
       
   524       // Limit DB queries for Google Fonts.
       
   525       if ( $type == 'google-fonts' ) {
       
   526         ot_fetch_google_fonts();
       
   527         ot_set_google_fonts( $id, $field_value );
       
   528       }
       
   529       
   507       /* get the option HTML */
   530       /* get the option HTML */
   508       echo ot_display_by_type( $_args );
   531       echo ot_display_by_type( $_args );
   509     }
   532     }
   510     
   533     
   511     /**
   534     /**
   572 
   595 
   573             /* verify setting has a type & value */
   596             /* verify setting has a type & value */
   574             if ( isset( $setting['type'] ) && isset( $input[$setting['id']] ) ) {
   597             if ( isset( $setting['type'] ) && isset( $input[$setting['id']] ) ) {
   575               
   598               
   576               /* get the defaults */
   599               /* get the defaults */
   577               $current_settings = get_option( 'option_tree_settings' );
   600               $current_settings = get_option( ot_settings_id() );
   578               $current_options = get_option( $option['id'] );
   601               $current_options = get_option( $option['id'] );
   579                 
   602                 
   580               /* validate setting */
   603               /* validate setting */
   581               if ( is_array( $input[$setting['id']] ) && in_array( $setting['type'], array( 'list-item', 'slider' ) ) ) {
   604               if ( is_array( $input[$setting['id']] ) && in_array( $setting['type'], array( 'list-item', 'slider' ) ) ) {
   582 
   605 
   630                     }
   653                     }
   631                     
   654                     
   632                   }
   655                   }
   633                 
   656                 
   634                 }
   657                 }
       
   658               
       
   659               } else if ( is_array( $input[$setting['id']] ) && $setting['type'] == 'social-links' ) {
       
   660                 
       
   661                 /* get the settings array */
       
   662                 $settings = isset( $_POST[$setting['id'] . '_settings_array'] ) ? unserialize( ot_decode( $_POST[$setting['id'] . '_settings_array'] ) ) : array();
       
   663                 
       
   664                 /* settings are empty get the defaults */
       
   665                 if ( empty( $settings ) ) {
       
   666                   $settings = ot_social_links_settings( $setting['id'] );
       
   667                 }
       
   668                 
       
   669                 /* create an empty WPML id array */
       
   670                 $wpml_ids = array();
       
   671                 
       
   672                 foreach( $input[$setting['id']] as $k => $setting_array ) {
       
   673 
       
   674                   foreach( $settings as $sub_setting ) {
       
   675                     
       
   676                     /* setup the WPML ID */
       
   677                     $wpml_id = $setting['id'] . '_' . $sub_setting['id'] . '_' . $k;
       
   678                     
       
   679                     /* add id to array */
       
   680                     $wpml_ids[] = $wpml_id;
       
   681                       
       
   682                     /* verify sub setting has a type & value */
       
   683                     if ( isset( $sub_setting['type'] ) && isset( $input[$setting['id']][$k][$sub_setting['id']] ) ) {
       
   684 
       
   685                       /* validate setting */
       
   686                       $input[$setting['id']][$k][$sub_setting['id']] = ot_validate_setting( $input[$setting['id']][$k][$sub_setting['id']], $sub_setting['type'], $sub_setting['id'], $wpml_id );
       
   687                       
       
   688                     }
       
   689                     
       
   690                   }
       
   691                 
       
   692                 }
   635 
   693 
   636               } else {
   694               } else {
   637                 
   695                 
   638                 $input[$setting['id']] = ot_validate_setting( $input[$setting['id']], $setting['type'], $setting['id'], $setting['id'] );
   696                 $input[$setting['id']] = ot_validate_setting( $input[$setting['id']], $setting['type'], $setting['id'], $setting['id'] );
   639                  
   697                  
   670                 }
   728                 }
   671                 
   729                 
   672               }
   730               }
   673               
   731               
   674             }
   732             }
       
   733             
       
   734             /* unregister WPML strings that were deleted from social links */
       
   735             if ( isset( $current_settings['settings'] ) && isset( $setting['type'] ) && $setting['type'] == 'social-links' ) {
       
   736               
       
   737               if ( ! isset( $wpml_ids ) )
       
   738                 $wpml_ids = array();
       
   739                 
       
   740               foreach( $current_settings['settings'] as $check_setting ) {
       
   741               
       
   742                 if ( $setting['id'] == $check_setting['id'] && ! empty( $current_options[$setting['id']] ) ) {
       
   743                 
       
   744                   foreach( $current_options[$setting['id']] as $key => $value ) {
       
   745                 
       
   746                     foreach( $value as $ckey => $cvalue ) {
       
   747                       
       
   748                       $id = $setting['id'] . '_' . $ckey . '_' . $key;
       
   749                       
       
   750                       if ( ! in_array( $id, $wpml_ids ) ) {
       
   751                       
       
   752                         ot_wpml_unregister_string( $id );
       
   753                         
       
   754                       }
       
   755                       
       
   756                     }
       
   757                   
       
   758                   }
       
   759                 
       
   760                 }
       
   761                 
       
   762               }
       
   763               
       
   764             }
   675       
   765       
   676           }
   766           }
   677         
   767         
   678         }
   768         }
   679         
   769         
   818     
   908     
   819       if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
   909       if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
   820         return;
   910         return;
   821     
   911     
   822       foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
   912       foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
   823         
   913 
   824         echo '<div id="setting_' . $field['id'] . '" class="format-settings">';
   914         $conditions = '';
       
   915 
       
   916         if ( isset( $field['args']['condition'] ) && ! empty( $field['args']['condition'] ) ) {
       
   917 
       
   918           $conditions = ' data-condition="' . $field['args']['condition'] . '"';
       
   919           $conditions.= isset( $field['args']['operator'] ) && in_array( $field['args']['operator'], array( 'and', 'AND', 'or', 'OR' ) ) ? ' data-operator="' . $field['args']['operator'] . '"' : '';
       
   920 
       
   921         }
       
   922         
       
   923         // Build the setting CSS class
       
   924         if ( isset( $field['args']['class'] ) && ! empty( $field['args']['class'] ) ) {
       
   925           
       
   926           $classes = explode( ' ', $field['args']['class'] );
       
   927           
       
   928           foreach( $classes as $key => $value ) {
       
   929           
       
   930             $classes[$key] = $value . '-wrap';
       
   931             
       
   932           }
       
   933           
       
   934           $class = 'format-settings ' . implode( ' ', $classes );
       
   935           
       
   936         } else {
       
   937         
       
   938           $class = 'format-settings';
       
   939           
       
   940         }
       
   941         
       
   942         echo '<div id="setting_' . $field['id'] . '" class="' . $class . '"' . $conditions . '>';
   825           
   943           
   826           echo '<div class="format-setting-wrap">';
   944           echo '<div class="format-setting-wrap">';
   827           
   945           
   828             if ( $field['args']['type'] != 'textblock' && ! empty( $field['title'] ) ) {
   946             if ( $field['args']['type'] != 'textblock' && ! empty( $field['title'] ) ) {
   829             
   947