Plugin Directory

Changeset 1537473


Ignore:
Timestamp:
11/21/2016 11:23:32 AM (9 years ago)
Author:
Didanix
Message:

Added widget support

Location:
when-is-update/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • when-is-update/trunk/index.js

    r1472164 r1537473  
    3333                longname : "When Is Update",
    3434                author : "Pauli 'Dids' Jokela",
    35                 version : "1.0.6"
     35                version : "1.0.7"
    3636            };
    3737        }
  • when-is-update/trunk/readme.txt

    r1472164 r1537473  
    44Tags: whenisupdate, rust, when, update, game, playrust
    55Requires at least: 3.5.2
    6 Tested up to: 4.5.3
     6Tested up to: 4.6.1
    77Stable tag: trunk
    88License: GPLv2 or later
     
    2929= How do I use this again? =
    3030
    31 There are two ways to add the image banner:
     31There are three ways to add the image banner:
    3232
    33331. Use the `When Is Update` buttons in either the Text or the Visual editor
    34342. Simply include the shortcode `[whenisupdate]` anywhere on your site
     353. Use the included widget
    3536
    3637You can also change the alignment like this:
     
    4950
    5051== Changelog ==
     52
     53= 1.0.7 =
     54* Added a simple widget
    5155
    5256= 1.0.6 =
  • when-is-update/trunk/rust-update-time.php

    r1472379 r1537473  
    44 * Plugin URI: https://whenisupdate.com
    55 * Description: Provides a dynamic image banner for whenisupdate.com.
    6  * Version: 1.0.6
     6 * Version: 1.0.7
    77 * Author: Pauli 'Dids' Jokela
    88 * Author URI: http://paulijokela.com
     
    214214}
    215215
     216// Creating the widget
     217class whenisupdate_widget extends WP_Widget
     218{
     219    function __construct()
     220    {
     221        parent::__construct(
     222            // Base ID of your widget
     223            'whenisupdate_widget',
     224
     225            // Widget name will appear in UI
     226            __('When Is Update', 'whenisupdate_widget_domain'),
     227
     228            // Widget description
     229            array( 'description' => __('Provides a banner image for whenisupdate.com', 'whenisupdate_widget_domain'), )
     230        );
     231    }
     232
     233    // Creating widget front-end
     234    // This is where the action happens
     235    public function widget($args, $instance)
     236    {
     237        $title = apply_filters('widget_title', $instance['title']);
     238
     239        // before and after widget arguments are defined by themes
     240        echo $args['before_widget'];
     241
     242        if (!empty($title)) echo $args['before_title'] . $title . $args['after_title'];
     243
     244        // This is where you run the code and display the output
     245        echo __(whenisupdate_widget_code(), 'whenisupdate_widget_domain');
     246        echo $args['after_widget'];
     247    }
     248           
     249    // Widget Backend
     250    public function form($instance)
     251    {
     252        if (isset($instance['title']))
     253        {
     254            $title = $instance['title'];
     255        }
     256        else
     257        {
     258            $title = __('When Is Update', 'whenisupdate_widget_domain');
     259        }
     260
     261        // Widget admin form
     262        ?>
     263            <p>
     264                <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
     265                <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
     266            </p>
     267        <?php
     268    }
     269       
     270    // Updating widget replacing old instances with new
     271    public function update($new_instance, $old_instance)
     272    {
     273        $instance = array();
     274        $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
     275        return $instance;
     276    }
     277} // Class whenisupdate_widget ends here
     278
     279function whenisupdate_widget_code()
     280{
     281    $options = get_option('when_is_update_option_name', array());
     282    $attribute = isset($options['attribute_link_enabled']) && $options['attribute_link_enabled'];
     283    return getBannerCode($attribute, $align);
     284}
     285
     286// Register and load the widget
     287function whenisupdate_load_widget()
     288{
     289    register_widget('whenisupdate_widget');
     290}
     291add_action('widgets_init', 'whenisupdate_load_widget');
     292
    216293if (is_admin()) $when_is_update_settings_page = new WhenIsUpdateSettingsPage();
Note: See TracChangeset for help on using the changeset viewer.