WordPress.org

Plugin Directory

Changeset 519123


Ignore:
Timestamp:
03/14/12 23:38:16 (2 years ago)
Author:
eddiemoya
Message:

version 2 update, added banner for plugin repo

Location:
simple-hook-widget
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • simple-hook-widget

    • Property svn:ignore set to
      .git
  • simple-hook-widget/trunk/simple-hook-widget.php

    r475014 r519123  
    11<?php 
    22/* 
    3 Plugin Name: Simple Hook Widget 
    4 Description: Creates a custom hook within a sidebar in place of a widget 
    5 Version: 1.1.1 
    6 Author: Eddie Moya 
    7 */ 
     3  Plugin Name: Simple Hook Widget 
     4  Plugin URL: http://wordpress.org/extend/plugins/simple-hook-widget/ 
     5  Description: Creates a custom hook within a sidebar in place of a widget 
     6  Version: 2 
     7  Author: Eddie Moya 
     8  Author URL: http://eddiemoya.com 
     9 */ 
    810 
    911/* 
    10 Copyright (C) 2011 Eddie Moya (eddie.moya+wp[at]gmail.com) 
     12  Copyright (C) 2011 Eddie Moya (eddie.moya+wp[at]gmail.com) 
    1113 
    12 This program is free software; you can redistribute it and/or modify 
    13 it under the terms of the GNU General Public License as published by 
    14 the Free Software Foundation; either version 3 of the License, or 
    15 (at your option) any later version. 
     14  This program is free software; you can redistribute it and/or modify 
     15  it under the terms of the GNU General Public License as published by 
     16  the Free Software Foundation; either version 3 of the License, or 
     17  (at your option) any later version. 
    1618 
    17 This program is distributed in the hope that it will be useful, 
    18 but WITHOUT ANY WARRANTY; without even the implied warranty of 
    19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    20 GNU General Public License for more details. 
     19  This program is distributed in the hope that it will be useful, 
     20  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
     22  GNU General Public License for more details. 
    2123 
    22 You should have received a copy of the GNU General Public License 
    23 along with this program. If not, see <http://www.gnu.org/licenses/>. 
    24 */ 
     24  You should have received a copy of the GNU General Public License 
     25  along with this program. If not, see <http://www.gnu.org/licenses/>. 
     26 */ 
    2527 
    2628class Simple_Hook_Widget extends WP_Widget { 
    27      
     29 
    2830    /** 
    2931     * @author Eddie Moya 
    3032     */ 
    31     function register_widget(){ 
    32         add_action('widgets_init', array( __CLASS__, '_register_widget' ) ); 
     33    function register_widget() { 
     34        add_action('widgets_init', array(__CLASS__, '_register_widget')); 
    3335    } 
    34      
     36 
    3537    /** 
    3638     * @author Eddie Moya 
    3739     */ 
    38     function _register_widget(){ 
    39        register_widget(__CLASS__); 
     40    function _register_widget() { 
     41        register_widget(__CLASS__); 
    4042    } 
    4143 
    42     /** 
    43     * Widget setup. 
    44     */ 
    45     function Simple_Hook_Widget() { 
    46         /* Widget settings. */ 
    47         $widget_ops = array(  
    48             'classname' => 'simple-hook',  
    49             'description' => 'Creates a custom hook within a sidebar in place of a widget' ); 
     44    /** 
     45    * Widget setup. 
     46    */ 
     47    function Simple_Hook_Widget() { 
     48        /* Widget settings. */ 
     49        $widget_ops = array( 
     50            'classname' => 'simple-hook', 
     51            'description' => 'Creates a custom hook within a sidebar in place of a widget'); 
    5052 
    5153        /* Widget control settings. */ 
    52         $control_ops = array( 'width' => 200, 'height' => 350 ); 
     54        //$control_ops = array('width' => 200, 'height' => 350); 
    5355 
    54         /* Create the widget. */ 
    55         parent::WP_Widget( 'simple-hook', 'Simple Hook', $widget_ops, $control_ops ); 
    56     } 
     56        /* Create the widget. */ 
     57        parent::WP_Widget('simple-hook', 'Simple Hook', $widget_ops); 
     58    } 
    5759 
    58     function widget( $args, $instance ) { 
    59         extract( $args ); 
     60    function widget($args, $instance) { 
     61        extract($args); 
    6062 
    61         $hookname = str_replace(' ', '-', strtolower( htmlspecialchars(strip_tags( $instance['hookname'])) )); 
     63        $hook = str_replace(' ', '-', strtolower(htmlspecialchars(strip_tags($instance['hook'])))); 
     64 
     65        //Do the damn thing. 
     66        do_action($hook); 
     67    } 
     68 
     69    /** 
     70     * Update the widget settings. 
     71     */ 
     72    function update($new_instance, $old_instance) { 
     73 
     74        $instance = $old_instance; 
     75        $instance['hook'] = str_replace(' ', '-', strtolower(htmlspecialchars(strip_tags($new_instance['hook']))));         
    6276         
    63         //Do the damn thing. 
    64         do_action($hookname); 
     77        do_action('simplehook_' . $instance['hook']); 
     78 
     79        return $new_instance; 
     80    } 
     81 
     82    function form($instance) { 
     83 
     84        $defaults = array('hook' => apply_filters('simple-hook-default', '')); 
     85        $instance = wp_parse_args((array) $instance, $defaults); 
     86        $hook_list = apply_filters('simple-hook-list', array()); 
    6587         
    66     } 
     88         
     89        if(!empty($hook_list)){ 
     90            $fields = array( 
     91                array( 
     92                    'field_id' => 'hook', 
     93                    'type' => 'select', 
     94                    'label' => 'Select Hook', 
     95                    'options' => $hook_list 
     96                ) 
     97            ); 
     98        } else { 
     99            $fields = array( 
     100                array( 
     101                    'field_id' => 'hook', 
     102                    'type' => 'text', 
     103                    'label' => 'Enter Hook' 
     104                ) 
     105            ); 
     106        } 
    67107 
    68     /** 
    69      * Update the widget settings. 
    70      */ 
    71     function update( $new_instance, $old_instance ) { 
     108        $this->form_fields($fields, $instance); 
     109    } 
     110     
     111     
     112    function form_fields($fields, $instance){ 
     113        foreach($fields as $field){ 
     114            extract($field); 
     115             
     116            $args = array ( 
     117                'style' => (isset($style)) ? $style : '', 
     118                'options' => (isset($options)) ? $options : array() 
     119            ); 
     120            $this->form_field($field_id, $type, $label, $args, $instance); 
     121        } 
     122    } 
     123     
     124    function form_field($field_id, $type, $label, $args, $instance){ 
    72125         
    73         $instance = $old_instance; 
     126        ?><p><?php 
    74127         
    75         $instance['hookname'] = str_replace(' ', '-', strtolower( htmlspecialchars(strip_tags( $new_instance['hookname'])) )); 
    76         do_action('simplehook_' . $instance['hookname']); 
    77        
    78         return $instance; 
    79     } 
    80  
    81     function form( $instance ) { 
    82  
    83         /* Set up some default widget settings. */ 
    84         $defaults = array( 'hookname' => '' ); 
    85         $instance = wp_parse_args( (array) $instance, $defaults ); ?> 
     128        switch ($type){ 
     129            case 'text': 
     130                ?> 
     131                <label for="<?php echo $this->get_field_id( $field_id ); ?>"><?php echo $label; ?>: </label> 
     132                <input id="<?php echo $this->get_field_id( $field_id ); ?>" style="<?php echo $style; ?>" class="widefat" name="<?php echo $this->get_field_name( $field_id ); ?>" value="<?php echo $instance[$field_id]; ?>" /> 
     133                <?php break; 
     134             
     135            case 'select': 
     136                $options = $args['options']; 
     137                $selected_option = $instance[$field_id]; 
     138   
     139                ?> 
     140                    <label for="<?php echo $this->get_field_id( $field_id ); ?>"><?php echo $label; ?>: </label> 
     141                    <select id="<?php echo $this->get_field_id( $field_id ); ?>" class="widefat" name="<?php echo $this->get_field_name($field_id); ?>"> 
     142                        <?php 
     143                            foreach ( $options as $value => $label ) :  
     144                                $selected = ($selected_option == $value) ? 'selected="selected"' : '';  
     145                                ?><option value="<?php echo $value; ?>" <?php echo $selected; ?>><?php echo $label ?></option><?php 
     146                            endforeach;  
     147                        ?> 
     148                    </select> 
     149                     
     150                <?php break; 
     151                 
     152        } 
    86153         
    87         
    88         <p> 
    89             <label for="<?php echo $this->get_field_id( 'hookname' ); ?>">Hook Name: </label> 
    90             <input id="<?php echo $this->get_field_id( 'hookname' ); ?>" name="<?php echo $this->get_field_name( 'hookname' ); ?>" value="<?php echo $instance['hookname']; ?>" style="width:80%;" /> 
    91         </p> 
    92  
    93  
    94     <?php 
    95     } 
     154        ?></p><?php 
     155    } 
    96156} 
    97157 
Note: See TracChangeset for help on using the changeset viewer.