Changeset 706
- Timestamp:
- 06/17/2014 12:00:42 AM (9 years ago)
- 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 20 20 static function init() { 21 21 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' ) ); 29 23 30 24 new WPorg_Handbook_TOC( $post_types ); … … 32 26 foreach ( $post_types as $type ) { 33 27 new WPorg_Handbook( $type ); 34 35 28 } 36 29 } 30 37 31 } 32 38 33 add_action( 'after_setup_theme', array( 'WPorg_Handbook_Init', 'init' ) ); 39 34 … … 61 56 62 57 function __construct( $type ) { 63 if ( 'handbook' != $type ) 58 if ( 'handbook' != $type ) { 64 59 $this->post_type = $type . '-handbook'; 60 } else { 61 $this->post_type = $type; 62 } 65 63 66 64 $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 73 72 add_action( 'wporg_email_changes_for_post_types', array( $this, 'wporg_email_changes_for_post_types' ) ); 74 73 } 75 74 76 75 function grant_handbook_caps( $caps ) { 77 if ( ! is_user_member_of_blog() ) 76 if ( ! is_user_member_of_blog() ) { 78 77 return $caps; 78 } 79 79 80 foreach ( self::caps() as $cap ) { 80 81 $caps[ $cap ] = true; 81 82 } 83 82 84 if ( ! empty( $caps['edit_pages'] ) ) { 83 85 foreach ( self::editor_caps() as $cap ) { … … 85 87 } 86 88 } 89 87 90 return $caps; 88 91 } … … 94 97 $slug = 'handbook'; 95 98 } 99 96 100 register_post_type( $this->post_type, array( 97 101 '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 ), 102 106 ), 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' 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, 114 118 ), 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' ), 117 121 ) ); 118 122 } … … 126 130 127 131 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 ) { 129 133 return get_post_type_archive_link( $this->post_type ); 134 } 135 130 136 return $link; 131 137 } … … 138 144 139 145 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 ) ); 141 151 require_once dirname( __FILE__ ) . '/inc/widgets.php'; 142 152 register_widget( 'WPorg_Handbook_Pages_Widget' ); … … 144 154 145 155 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 ) ) { 147 157 $post_types[] = $this->post_type; 158 } 159 148 160 return $post_types; 149 161 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/table-of-contents.php
r705 r706 11 11 12 12 function __construct( $post_types ) { 13 $this->post_types = $post_types;13 $this->post_types = (array) $post_types; 14 14 add_action( 'template_redirect', array( $this, 'load_filters' ) ); 15 15 } … … 23 23 24 24 function append_suffix( $t ) { 25 if ( 'handbook' == $t )25 if ( in_array( $t, array( 'handbook', 'page' ) ) ) { 26 26 return $t; 27 } 27 28 28 29 return $t . '-handbook'; … … 42 43 $pages_header = 'h3'; 43 44 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() ) ) ) 45 46 $toc .= "<$pages_header>Pages</$pages_header><ul class=\"items\">$pages</ul>"; 46 47 … … 48 49 $toc .= $this->styles; 49 50 $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\">"; 51 52 $last_item = false; 52 53 foreach ( $items as $item ) { … … 79 80 80 81 if ( ! $first ) { 81 $replacement .= '<p class="toc-jump"><a href="#top"> Top ↑</a></p>';82 $replacement .= '<p class="toc-jump"><a href="#top">' . __( 'Top ↑', 'wporg' ) . '</a></p>'; 82 83 } else { 83 84 $first = false; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php
r705 r706 3 3 class WPorg_Handbook_Widget extends WP_Widget { 4 4 5 protected $post_types = 'handbook';5 protected $post_types = array( 'handbook' ); 6 6 7 7 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 ); 12 9 $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' ) ) ); 14 11 } 15 12 16 function widget( ) {13 function widget( $args ) { 17 14 if ( ! is_user_logged_in() ) 18 15 return; … … 21 18 if ( $post->post_type == 'page' || ( in_array( $post->post_type, $this->post_types ) && ! is_post_type_archive( $this->post_types ) ) ) { 22 19 $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>'; 23 24 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' ), 25 26 wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ) ); 26 27 } else { 27 printf( '<p><a href="%s">Watch this page</a></p>',28 printf( __( '<a href="%s">Watch this page</a>', 'wporg' ), 28 29 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']; 29 34 } 30 35 } else { … … 35 40 36 41 function append_suffix( $t ) { 37 if ( 'handbook' == $t )42 if ( in_array( $t, array( 'handbook', 'page' ) ) ) { 38 43 return $t; 44 } 39 45 40 46 return $t . '-handbook'; … … 44 50 class WPorg_Handbook_Widget_for_Pages extends WPorg_Handbook_Widget { 45 51 46 protected $post_type = 'page';52 protected $post_types = array( 'page' ); 47 53 48 54 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' ) ) ); 50 56 } 51 57 } … … 53 59 class WPorg_Handbook_Pages_Widget extends WP_Widget_Pages { 54 60 55 protected $post_types = 'handbook';61 protected $post_types = array( 'handbook' ); 56 62 57 63 function __construct() { 58 $widget_ops = array('classname' => 'widget_wporg_handbook_pages', 'description' => __( 'Your site’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’s Handbook Pages', 'wporg' ) ); 65 WP_Widget::__construct( 'handbook_pages', __( 'Handbook Pages', 'wporg' ), $widget_ops ); 60 66 } 61 67 … … 69 75 $post = get_post(); 70 76 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 ); 75 78 $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types ); 76 79 … … 82 85 83 86 function append_suffix( $t ) { 84 if ( 'handbook' == $t )87 if ( in_array( $t, array( 'handbook', 'page' ) ) ) { 85 88 return $t; 89 } 86 90 87 91 return $t . '-handbook';
Note: See TracChangeset
for help on using the changeset viewer.