qlstudio

wp widget check and return function

Oct 17th, 2012
996
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×