Making WordPress.org

Changeset 706


Ignore:
Timestamp:
06/17/2014 12:00:42 AM (9 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
Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook
Files:
3 edited

Legend:

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

    r705 r706  
    2020    static function init() {
    2121
    22         $post_types = 'handbook';
    23 
    24         $post_types = apply_filters( 'handbook_post_types', $post_types );
    25 
    26         if ( ! is_array( $post_types ) ) {
    27             $post_types = (array) $post_types;
    28         }
     22        $post_types = (array) apply_filters( 'handbook_post_types', array( 'handbook' ) );
    2923
    3024        new WPorg_Handbook_TOC( $post_types );
     
    3226        foreach ( $post_types as $type ) {
    3327            new WPorg_Handbook( $type );
    34 
    3528        }
    3629    }
     30
    3731}
     32
    3833add_action( 'after_setup_theme', array( 'WPorg_Handbook_Init', 'init' ) );
    3934
     
    6156
    6257    function __construct( $type ) {
    63         if ( 'handbook' != $type )
     58        if ( 'handbook' != $type ) {
    6459            $this->post_type = $type . '-handbook';
     60        } else {
     61            $this->post_type = $type;
     62        }
    6563
    6664        $this->label = ucwords( str_replace( array( '-', '_' ), ' ', $this->post_type ) );
    67         add_filter( 'user_has_cap', array( $this, 'grant_handbook_caps' ) );
    68         add_filter( 'init', array( $this, 'register_post_type' ) );
    69         add_action( 'admin_page_access_denied', array( $this, 'admin_page_access_denied' ) );
    70         add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 );
    71         add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
    72         add_action( 'widgets_init', array( $this, 'handbook_sidebar' ), 11 ); // After P2
     65
     66        add_filter( 'user_has_cap',                       array( $this, 'grant_handbook_caps' ) );
     67        add_filter( 'init',                               array( $this, 'register_post_type' ) );
     68        add_action( 'admin_page_access_denied',           array( $this, 'admin_page_access_denied' ) );
     69        add_filter( 'post_type_link',                     array( $this, 'post_type_link' ), 10, 2 );
     70        add_filter( 'pre_get_posts',                      array( $this, 'pre_get_posts' ) );
     71        add_action( 'widgets_init',                       array( $this, 'handbook_sidebar' ), 11 ); // After P2
    7372        add_action( 'wporg_email_changes_for_post_types', array( $this, 'wporg_email_changes_for_post_types' ) );
    7473    }
    7574
    7675    function grant_handbook_caps( $caps ) {
    77         if ( ! is_user_member_of_blog() )
     76        if ( ! is_user_member_of_blog() ) {
    7877            return $caps;
     78        }
     79
    7980        foreach ( self::caps() as $cap ) {
    8081            $caps[ $cap ] = true;
    8182        }
     83
    8284        if ( ! empty( $caps['edit_pages'] ) ) {
    8385            foreach ( self::editor_caps() as $cap ) {
     
    8587            }
    8688        }
     89
    8790        return $caps;
    8891    }
     
    9497            $slug = 'handbook';
    9598        }
     99
    96100        register_post_type( $this->post_type, array(
    97101            'labels' => array(
    98                 'name' => "{$this->label} Pages",
    99                 'singular_name' => "{$this->label} Page",
    100                 'menu_name' => "{$this->label}",
    101                 'all_items' => "{$this->label} Pages",
     102                'name'          => sprintf( __( '%s Pages', 'wporg' ), $this->label ),
     103                'singular_name' => sprintf( __( '%s Page', 'wporg' ), $this->label ),
     104                'menu_name'     => $this->label,
     105                'all_items'     => sprintf( __( '%s Pages', 'wporg' ), $this->label ),
    102106            ),
    103             'public' => true,
    104             'show_ui' => true,
    105             'capability_type' => 'handbook_page',
    106             'map_meta_cap' => true,
    107             'has_archive' => true,
    108             'hierarchical' => true,
    109             'menu_position' => 11,
    110             'rewrite'     => array(
    111                 'feeds'      => false,
    112                 'slug'       => $slug,
    113                 'with_front' => false,
     107            'public'            => true,
     108            'show_ui'           => true,
     109            'capability_type'   => 'handbook_page',
     110            'map_meta_cap'      => true,
     111            'has_archive'       => true,
     112            'hierarchical'      => true,
     113            'menu_position'     => 11,
     114            'rewrite' => array(
     115                'feeds'         => false,
     116                'slug'          => $slug,
     117                'with_front'    => false,
    114118            ),
    115             'delete_with_user' => false,
    116             'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
     119            'delete_with_user'  => false,
     120            'supports'          => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
    117121        ) );
    118122    }
     
    126130
    127131    function post_type_link( $link, $post ) {
    128         if ( $post->post_type === $this->post_type && $post->post_name === $this->post_type )
     132        if ( $post->post_type === $this->post_type && $post->post_name === $this->post_type ) {
    129133            return get_post_type_archive_link( $this->post_type );
     134        }
     135
    130136        return $link;
    131137    }
     
    138144
    139145    function handbook_sidebar() {
    140         register_sidebar( array( 'id' => $this->post_type, 'name' => $this->label, 'description' => "Used on {$this->label} pages" ) );
     146        register_sidebar( array(
     147            'id'          => $this->post_type,
     148            'name'        => $this->label,
     149            'description' => sprintf( __( 'Used on %s pages', 'wporg' ), $this->label ),
     150        ) );
    141151        require_once dirname( __FILE__ ) . '/inc/widgets.php';
    142152        register_widget( 'WPorg_Handbook_Pages_Widget' );
     
    144154
    145155    function wporg_email_changes_for_post_types( $post_types ) {
    146         if ( ! in_array( $this->post_type, $post_types ) )
     156        if ( ! in_array( $this->post_type, $post_types ) ) {
    147157            $post_types[] = $this->post_type;
     158        }
     159
    148160        return $post_types;
    149161    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/table-of-contents.php

    r705 r706  
    1111
    1212    function __construct( $post_types ) {
    13         $this->post_types = $post_types;
     13        $this->post_types = (array) $post_types;
    1414        add_action( 'template_redirect', array( $this, 'load_filters' ) );
    1515    }
     
    2323
    2424    function append_suffix( $t ) {
    25         if ( 'handbook' == $t )
     25        if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
    2626            return $t;
     27        }
    2728
    2829        return $t . '-handbook';
     
    4243            $pages_header = 'h3';
    4344
    44         if ( $pages = wp_list_pages( array( 'child_of' => get_the_ID(), 'echo' => false, 'title_li' => false, 'post_type' => $this->post_type ) ) )
     45        if ( $pages = wp_list_pages( array( 'child_of' => get_the_ID(), 'echo' => false, 'title_li' => false, 'post_type' => get_post_type() ) ) )
    4546            $toc .= "<$pages_header>Pages</$pages_header><ul class=\"items\">$pages</ul>";
    4647
     
    4849            $toc .= $this->styles;
    4950            $toc .= '<div class="table-of-contents">';
    50             $toc .= "<$contents_header>Contents</$contents_header><ul class=\"items\">";
     51            $toc .= "<$contents_header>" . __( 'Topics', 'wporg' ) . "</$contents_header><ul class=\"items\">";
    5152            $last_item = false;
    5253            foreach ( $items as $item ) {
     
    7980
    8081            if ( ! $first ) {
    81                 $replacement .= '<p class="toc-jump"><a href="#top">Top &uarr;</a></p>';
     82                $replacement .= '<p class="toc-jump"><a href="#top">' . __( 'Top &uarr;', 'wporg' ) . '</a></p>';
    8283            } else {
    8384                $first = false;
  • 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.