Guest User

basic widget

a guest
Feb 15th, 2011
320
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: Week 2 Assignment Widget
  4. Plugin URI: http://p2pu.org/webcraft/wordpress-development
  5. Description: Week 2 Assignment Widget
  6. Version: 1.0
  7. Author: nunomorgadinho
  8. Author URI: http://p2pu.org/webcraft/wordpress-development
  9. */
  10.  
  11. function widget_assign($args) {
  12.     extract($args);
  13. ?>
  14.         <?php echo $before_widget; ?>
  15.        
  16.         <div class="week2assign">
  17.         <span></span><h2>Tribes that I belong:</h2>
  18.         <ul>
  19.          <?php
  20.         $tribes = get_option('widget_assign');
  21.        
  22.         if (is_serialized($tribes['tribes'])) {
  23.             $tribes['tribes'] = unserialize($tribes['tribes']);
  24.         }
  25.  
  26.         // you can use this for debugging purposes
  27.       //  print_r($tribes['tribes']);
  28.        
  29.         $tribes_instances = $tribes['tribes'];
  30.         for ($i = 0; $i < count($tribes_instances); $i++)
  31.         {
  32.             $val = $tribes_instances[$i];
  33.             $val = str_replace("\\", "", $val);
  34.             echo '<li class="'.$val.'">'.$val.'</li>';
  35.         }
  36.        
  37.         ?>
  38.         </ul>
  39.         </div>
  40.        
  41.         <?php echo $after_widget; ?>
  42. <?php
  43. }
  44.  
  45. function widget_assign_control() {
  46.  
  47. ?>
  48.         Select which tribes do you belong :
  49.         <br/><br/>
  50.        
  51.         <?php      
  52.         $tribes = array("Hackers", "Developers", "Entrepreneurs", "Designers");
  53.        
  54.         $checked = '';
  55.         foreach ($tribes as $i)
  56.         {
  57.             if (is_tribe_selected($i)) {
  58.                 $checked = 'checked';
  59.             }
  60.             echo '<input type="checkbox" name="tribes[]" '.$checked.' value="'.$i.'">'.$i.'</input><br/>'; 
  61.             $checked = '';
  62.         }
  63.        
  64.         $data['tribes'] = serialize($_POST['tribes']);
  65.         update_option('widget_assign', $data);
  66. }
  67.  
  68.  
  69. function is_tribe_selected($tribe)
  70. {
  71.     $tribes = get_option('widget_assign');
  72.        
  73.     if (is_serialized($tribes['tribes'])) {
  74.         $tribes['tribes'] = unserialize($tribes['tribes']);
  75.     }
  76.    
  77.     $tribes_instances = $tribes['tribes'];
  78.     for ($i = 0; $i < count($tribes_instances); $i++)
  79.     {
  80.         $val = $tribes_instances[$i];
  81.         $val = str_replace("\\", "", $val);
  82.         if ($val == $tribe)
  83.             return true;
  84.     }
  85.    
  86.     return false;
  87. }
  88.  
  89. register_sidebar_widget('Week 2 Assign', 'widget_assign');
  90. register_widget_control('Week 2 Assign', 'widget_assign_control');
  91.  
  92. ?>
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.

×