Making WordPress.org


Ignore:
Timestamp:
06/17/2014 12:00:42 AM (10 years ago)
Author:
coffee2code
Message:

Handbook plugin: misc fixes and tweaks. Fixes #250

  • Fix to set object post_type variable when post_type is 'handbook'
  • Fix to use get_post_type() instead of referencing no-long-existing object variable
  • Don't append suffix for 'page' post_type (for ToC and widgets)
  • Honor before_widget and after_widget config for widget
  • More succinct and thorough array typecasting
  • Internationalize strings
  • Minor spacing and code formatting tweaks
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php

    r705 r706  
    33class WPorg_Handbook_Widget extends WP_Widget {
    44
    5     protected $post_types = 'handbook';
     5    protected $post_types = array( 'handbook' );
    66
    77    function __construct() {
    8         $this->post_types = apply_filters( 'handbook_post_types', $this->post_types );
    9         if ( ! is_array( $this->post_types ) ) {
    10             $this->post_types = (array) $this->post_types;
    11         }
     8        $this->post_types = (array) apply_filters( 'handbook_post_types', $this->post_types );
    129        $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
    13         parent::__construct( 'handbook', 'Handbook Tools', array( 'classname' => 'widget_wporg_handbook', 'description' => 'Shows watch/unwatch links for handbook pages.' ) );
     10        parent::__construct( 'handbook', __( 'Handbook Tools', 'wporg' ), array( 'classname' => 'widget_wporg_handbook', 'description' => __( 'Shows watch/unwatch links for handbook pages.', 'wporg' ) ) );
    1411    }
    1512
    16     function widget() {
     13    function widget( $args ) {
    1714        if ( ! is_user_logged_in() )
    1815            return;
     
    2118        if ( $post->post_type == 'page' || ( in_array( $post->post_type, $this->post_types ) && ! is_post_type_archive( $this->post_types ) ) ) {
    2219            $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );
     20            if ( isset( $args['before_widget'] ) && $args['before_widget'] ) {
     21                echo $args['before_widget'];
     22            }
     23            echo '<p>';
    2324            if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) {
    24                 printf( '<p>You are watching this page. <a href="%s">Unwatch</a></p>',
     25                printf( __( 'You are watching this page. <a href="%s">Unwatch</a>', 'wporg' ),
    2526                wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ) );
    2627            } else {
    27                 printf( '<p><a href="%s">Watch this page</a></p>',
     28                printf( __( '<a href="%s">Watch this page</a>', 'wporg' ),
    2829                wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ) );
     30            }
     31            echo '</p>';
     32            if ( isset( $args['after_widget'] ) && $args['after_widget'] ) {
     33                echo $args['after_widget'];
    2934            }
    3035        } else {
     
    3540
    3641    function append_suffix( $t ) {
    37         if ( 'handbook' == $t )
     42        if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
    3843            return $t;
     44        }
    3945
    4046        return $t . '-handbook';
     
    4450class WPorg_Handbook_Widget_for_Pages extends WPorg_Handbook_Widget {
    4551
    46     protected $post_type = 'page';
     52    protected $post_types = array( 'page' );
    4753
    4854    function __construct() {
    49         WP_Widget::__construct( 'handbook_for_pages', 'Handbook Tools (for Pages)', array( 'classname' => 'widget_wporg_handbook', 'description' => 'Shows watch/unwatch links for Pages.' ) );
     55        WP_Widget::__construct( 'handbook_for_pages', __( 'Handbook Tools (for Pages)', 'wporg' ), array( 'classname' => 'widget_wporg_handbook', 'description' => __( 'Shows watch/unwatch links for Pages.', 'wporg' ) ) );
    5056    }
    5157}
     
    5359class WPorg_Handbook_Pages_Widget extends WP_Widget_Pages {
    5460
    55     protected $post_types = 'handbook';
     61    protected $post_types = array( 'handbook' );
    5662
    5763    function __construct() {
    58         $widget_ops = array('classname' => 'widget_wporg_handbook_pages', 'description' => __( 'Your site&#8217;s Handbook Pages') );
    59         WP_Widget::__construct('handbook_pages', __('Handbook Pages'), $widget_ops);
     64        $widget_ops = array('classname' => 'widget_wporg_handbook_pages', 'description' => __( 'Your site&#8217;s Handbook Pages', 'wporg' ) );
     65        WP_Widget::__construct( 'handbook_pages', __( 'Handbook Pages', 'wporg' ), $widget_ops );
    6066    }
    6167
     
    6975        $post = get_post();
    7076
    71         $this->post_types = apply_filters( 'handbook_post_types', $this->post_types );
    72         if ( ! is_array( $this->post_types ) ) {
    73             $this->post_types = (array) $this->post_types;
    74         }
     77        $this->post_types = (array) apply_filters( 'handbook_post_types', $this->post_types );
    7578        $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
    7679
     
    8285
    8386    function append_suffix( $t ) {
    84         if ( 'handbook' == $t )
     87        if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
    8588            return $t;
     89        }
    8690
    8791        return $t . '-handbook';
Note: See TracChangeset for help on using the changeset viewer.