Advertisement
josenetome

Get options from inactive layouts <OptionTree:Wordpress>

Jan 3rd, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4.         @autor: José Neto <josenetome@gmail.com>
  5.     @description: Get options from inactive layouts <OptionTree:Wordpress>
  6.     @usage: ot_get_option_by_layout($field, $layout, $default)
  7.    
  8. */
  9. if ( ! function_exists( 'ot_get_option_by_layout' ) ) {
  10.  
  11.   function ot_get_option_by_layout( $option_id, $layout, $default = '' ) {
  12.    
  13.     /* get the saved options */
  14.     $layouts = get_option( 'option_tree_layouts' );
  15.    
  16.     /* get options by layout */
  17.     foreach ( $layouts as $layout_name => $fields ) {
  18.    
  19.         if ( $layout_name == 'active_layout') continue;
  20.        
  21.         /* check if layout exists */
  22.         if ( $layout_name == $layout ) {
  23.            
  24.             /* get fields of this layout */
  25.             $fields = unserialize ( base64_decode ( $fields ) );
  26.            
  27.             /* fields loop */
  28.             foreach ( $fields as $option_name => $value) {
  29.                
  30.                 /* look for the saved value */
  31.                 if ( $option_name == $option_id && $value != NULL ) {
  32.                
  33.                     return $value;
  34.                    
  35.                 }
  36.                
  37.             } /* end fields loop */
  38.            
  39.         }
  40.    
  41.     }  
  42.  
  43.   return $default;  
  44.  
  45.   }
  46.  
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement