Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Week 2 Assignment Widget
- Plugin URI: http://p2pu.org/webcraft/wordpress-development
- Description: Week 2 Assignment Widget
- Version: 1.0
- Author: nunomorgadinho
- Author URI: http://p2pu.org/webcraft/wordpress-development
- */
- function widget_assign($args) {
- extract($args);
- ?>
- <?php echo $before_widget; ?>
- <div class="week2assign">
- <span></span><h2>Tribes that I belong:</h2>
- <ul>
- <?php
- $tribes = get_option('widget_assign');
- if (is_serialized($tribes['tribes'])) {
- $tribes['tribes'] = unserialize($tribes['tribes']);
- }
- // you can use this for debugging purposes
- // print_r($tribes['tribes']);
- $tribes_instances = $tribes['tribes'];
- for ($i = 0; $i < count($tribes_instances); $i++)
- {
- $val = $tribes_instances[$i];
- $val = str_replace("\\", "", $val);
- echo '<li class="'.$val.'">'.$val.'</li>';
- }
- ?>
- </ul>
- </div>
- <?php echo $after_widget; ?>
- <?php
- }
- function widget_assign_control() {
- ?>
- Select which tribes do you belong :
- <br/><br/>
- <?php
- $tribes = array("Hackers", "Developers", "Entrepreneurs", "Designers");
- $checked = '';
- foreach ($tribes as $i)
- {
- if (is_tribe_selected($i)) {
- $checked = 'checked';
- }
- echo '<input type="checkbox" name="tribes[]" '.$checked.' value="'.$i.'">'.$i.'</input><br/>';
- $checked = '';
- }
- $data['tribes'] = serialize($_POST['tribes']);
- update_option('widget_assign', $data);
- }
- function is_tribe_selected($tribe)
- {
- $tribes = get_option('widget_assign');
- if (is_serialized($tribes['tribes'])) {
- $tribes['tribes'] = unserialize($tribes['tribes']);
- }
- $tribes_instances = $tribes['tribes'];
- for ($i = 0; $i < count($tribes_instances); $i++)
- {
- $val = $tribes_instances[$i];
- $val = str_replace("\\", "", $val);
- if ($val == $tribe)
- return true;
- }
- return false;
- }
- register_sidebar_widget('Week 2 Assign', 'widget_assign');
- register_widget_control('Week 2 Assign', 'widget_assign_control');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement