Advertisement
qlstudio

wp widget check and return function

Oct 17th, 2012
1,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. /**
  2.  * widget function ##
  3.  * reduce code redundancy ##
  4.  */
  5. function ql_widget( $widget, $widget_name, $element = 'sider' ){
  6.    
  7.     if ( $widget ) { // widget ID passed ##
  8.        
  9.         // get all widgets ##
  10.         $widgets = wp_get_sidebars_widgets();
  11.        
  12.         if ( is_active_sidebar( $widget ) ) {
  13.            
  14. ?>
  15.                 <div class="<?php echo $element; ?>">
  16.                     <?php
  17.                    
  18.                     dynamic_sidebar( $widget );
  19.                    
  20.                     ?>
  21.                 </div>
  22. <?php
  23.            
  24.         } else {
  25.    
  26.             // issue error to admin if requested widget does not exist or is empty ##
  27.             if ( ql_user_is_administator() ) { // user is admin ##
  28.                
  29.                 $message = ( array_key_exists( $widget, $widgets ) )? 'empty' : 'error' ;
  30.                
  31. ?>
  32.                 <div class="error">
  33.             <strong>Widget <?php echo $message; ?>:</strong> <?php echo $widget_name ? $widget_name : $widget ; ?>
  34.         </div>
  35. <?php  
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement