Changeset 10751
- Timestamp:
- 03/04/2021 10:43:04 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php
r10356 r10751 13 13 protected $label = ''; 14 14 15 static function caps() { 16 return array( 17 'edit_handbook_pages', 'edit_others_handbook_pages', 15 public static function caps() { 16 return [ 17 'edit_handbook_pages', 18 'edit_others_handbook_pages', 18 19 'edit_published_handbook_pages', 19 );20 } 21 22 static function editor_caps() {23 return array(20 ]; 21 } 22 23 public static function editor_caps() { 24 return [ 24 25 'publish_handbook_pages', 25 'delete_handbook_pages', 'delete_others_handbook_pages', 26 'delete_published_handbook_pages', 'delete_private_handbook_pages', 27 'edit_private_handbook_pages', 'read_private_handbook_pages', 28 ); 26 'delete_handbook_pages', 27 'delete_others_handbook_pages', 28 'delete_published_handbook_pages', 29 'delete_private_handbook_pages', 30 'edit_private_handbook_pages', 31 'read_private_handbook_pages', 32 ]; 29 33 } 30 34 … … 38 42 * @return string 39 43 */ 40 static function get_name( $post_type = 'handbook', $raw = false ) {44 public static function get_name( $post_type = 'handbook', $raw = false ) { 41 45 // Prefer explicitly configured handbook name. 42 46 $name = get_option( $post_type . '_name' ); 43 47 44 48 // If handbook name isn't set, try root relative site path. 45 if ( ! $raw && empty( $name )) {49 if ( ! $raw && ! $name ) { 46 50 if ( is_multisite() ) { 47 51 $name = trim( get_blog_details()->path, '/' ); … … 51 55 52 56 // If no name defined yet, try handbook post type if not standard. 53 if ( empty( $name ) && ( 'handbook' != $post_type ) ) {57 if ( ! $name && ( 'handbook' !== $post_type ) ) { 54 58 $name = ucfirst( substr( $post_type, 0, -9 ) ); 55 59 } … … 61 65 } 62 66 63 function __construct( $type ) {64 if ( 'handbook' != $type ) {67 public function __construct( $type ) { 68 if ( 'handbook' !== $type ) { 65 69 $this->post_type = $type . '-handbook'; 66 70 } else { … … 68 72 } 69 73 70 $this->label = ucwords( str_replace( array( '-', '_' ), ' ', $this->post_type ) );74 $this->label = ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) ); 71 75 $this->label = apply_filters( 'handbook_label', $this->label, $this->post_type ); 72 76 73 77 $this->setting_name = $this->post_type . '_name'; 74 78 75 add_filter( 'user_has_cap', array( $this, 'grant_handbook_caps' ));76 add_action( 'widgets_init', array( $this, 'register_post_type' ));77 add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 );78 add_action( 'template_redirect', array( $this, 'redirect_handbook_root_page' ));79 add_filter( 'template_include', array( $this, 'template_include' ));80 add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ));81 add_action( 'widgets_init', array( $this, 'handbook_sidebar' ), 11 ); // After P282 add_action( 'wporg_email_changes_for_post_types', array( $this, 'wporg_email_changes_for_post_types' ));83 add_action( 'p2_action_links', array( $this, 'disable_p2_resolved_posts_action_links' ));84 add_action( 'admin_init', array( $this, 'add_name_setting' ));85 add_filter( 'body_class', array( $this, 'add_body_class' ));86 add_filter( 'post_class', array( $this, 'add_post_class' ));87 add_filter( 'o2_process_the_content', array( $this, 'disable_o2_processing' ));88 add_filter( 'o2_application_container', array( $this, 'o2_application_container' ));89 add_filter( 'o2_view_type', array( $this, 'o2_view_type' ));90 add_filter( 'o2_post_fragment', array( $this, 'o2_post_fragment' ));91 add_filter( 'comments_open', array( $this, 'comments_open' ), 10, 2 );92 add_filter( 'wp_nav_menu_objects', array( $this, 'highlight_menu_handbook_link' ));93 add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );79 add_filter( 'user_has_cap', [ $this, 'grant_handbook_caps' ] ); 80 add_action( 'widgets_init', [ $this, 'register_post_type' ] ); 81 add_filter( 'post_type_link', [ $this, 'post_type_link' ], 10, 2 ); 82 add_action( 'template_redirect', [ $this, 'redirect_handbook_root_page' ] ); 83 add_filter( 'template_include', [ $this, 'template_include' ] ); 84 add_filter( 'pre_get_posts', [ $this, 'pre_get_posts' ] ); 85 add_action( 'widgets_init', [ $this, 'handbook_sidebar' ], 11 ); // After P2 86 add_action( 'wporg_email_changes_for_post_types', [ $this, 'wporg_email_changes_for_post_types' ] ); 87 add_action( 'p2_action_links', [ $this, 'disable_p2_resolved_posts_action_links' ] ); 88 add_action( 'admin_init', [ $this, 'add_name_setting' ] ); 89 add_filter( 'body_class', [ $this, 'add_body_class' ] ); 90 add_filter( 'post_class', [ $this, 'add_post_class' ] ); 91 add_filter( 'o2_process_the_content', [ $this, 'disable_o2_processing' ] ); 92 add_filter( 'o2_application_container', [ $this, 'o2_application_container' ] ); 93 add_filter( 'o2_view_type', [ $this, 'o2_view_type' ] ); 94 add_filter( 'o2_post_fragment', [ $this, 'o2_post_fragment' ] ); 95 add_filter( 'comments_open', [ $this, 'comments_open' ], 10, 2 ); 96 add_filter( 'wp_nav_menu_objects', [ $this, 'highlight_menu_handbook_link' ] ); 97 add_filter( 'display_post_states', [ $this, 'display_post_states' ], 10, 2 ); 94 98 } 95 99 … … 101 105 * @return string[] 102 106 */ 103 function display_post_states( $post_states, $post ) {107 public function display_post_states( $post_states, $post ) { 104 108 if ( $this->post_is_landing_page( $post ) ) { 105 109 $post_states[] = __( 'Handbook Front Page', 'wporg' ); … … 119 123 * @return array 120 124 */ 121 function add_body_class( $classes ) {125 public function add_body_class( $classes ) { 122 126 if ( is_singular() && wporg_is_handbook( $this->post_type ) ) { 123 127 $classes[] = 'single-handbook'; … … 142 146 * @return array 143 147 */ 144 function add_post_class( $classes ) {148 public function add_post_class( $classes ) { 145 149 if ( $this->post_type === get_post_type() ) { 146 150 $classes[] = 'type-handbook'; … … 150 154 } 151 155 152 function add_name_setting() {156 public function add_name_setting() { 153 157 register_setting( 'general', $this->setting_name, 'esc_attr' ); 154 158 155 $label = ( 'handbook' == $this->post_type ) ?159 $label = ( 'handbook' === $this->post_type ) ? 156 160 __( 'Handbook name', 'wporg' ) : 157 161 sprintf( __( 'Handbook name (%s)', 'wporg' ), substr( $this->post_type, 0, -9 ) ); … … 160 164 $this->setting_name, 161 165 '<label for="' . esc_attr( $this->setting_name ) . '">' . $label . '</label>', 162 array( $this, 'name_setting_html' ),166 [ $this, 'name_setting_html' ], 163 167 'general' 164 168 ); 165 169 } 166 170 167 function name_setting_html() {171 public function name_setting_html() { 168 172 $value = get_option( $this->setting_name, '' ); 169 173 echo '<input type="text" id="' . esc_attr( $this->setting_name ) . '" name="' . esc_attr( $this->setting_name ) . '" value="' . esc_attr( $value ) . '" class="regular-text ltr" />'; 170 174 } 171 175 172 function grant_handbook_caps( $caps ) {176 public function grant_handbook_caps( $caps ) { 173 177 if ( ! is_user_member_of_blog() ) { 174 178 return $caps; … … 188 192 } 189 193 190 function register_post_type() {194 public function register_post_type() { 191 195 if ( 'handbook' != $this->post_type ) { 192 196 $slug = substr( $this->post_type, 0, -9 ); … … 195 199 } 196 200 197 $default_config = array(198 'labels' => array(201 $default_config = [ 202 'labels' => [ 199 203 'name' => $this->label, 200 204 'singular_name' => sprintf( __( '%s Page', 'wporg' ), $this->label ), 201 205 'menu_name' => $this->label, 202 206 'all_items' => sprintf( __( '%s Pages', 'wporg' ), $this->label ), 203 ),207 ], 204 208 'public' => true, 205 209 'show_ui' => true, … … 211 215 'menu_icon' => 'dashicons-book', 212 216 'menu_position' => 11, 213 'rewrite' => array(217 'rewrite' => [ 214 218 'feeds' => false, 215 219 'slug' => $slug, 216 220 'with_front' => false, 217 ),221 ], 218 222 'delete_with_user' => false, 219 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions', 'wpcom-markdown' ),220 );223 'supports' => [ 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions' , 'wpcom-markdown' ], 224 ]; 221 225 // Allow customization of the default post type configuration via filter. 222 $config = apply_filters( 'handbook_post_type_defaults', $default_config, $slug ); 223 226 $config = (array) apply_filters( 'handbook_post_type_defaults', $default_config, $slug ); 227 228 // Override the presumed label with a potentially customized value. 224 229 $this->label = $config['labels']['name']; 225 230 … … 235 240 * handbook's landing page. 236 241 */ 237 p rotectedfunction post_is_landing_page( $post = null ) {242 public function post_is_landing_page( $post = null ) { 238 243 $is_landing_page = false; 239 244 … … 269 274 * @param WP_Post $post The post in question. 270 275 */ 271 function post_type_link( $post_link, $post ) {276 public function post_type_link( $post_link, $post ) { 272 277 $post_type = get_post_type( $post ); 273 278 … … 284 289 * post type archive link for the handbook. 285 290 */ 286 function redirect_handbook_root_page() {291 public function redirect_handbook_root_page() { 287 292 global $wp_query; 288 293 … … 309 314 * @return string 310 315 */ 311 function template_include( $template ) {316 public function template_include( $template ) { 312 317 global $wp_query; 313 318 … … 317 322 } 318 323 319 $handbook_templates = array();324 $handbook_templates = []; 320 325 321 326 // For singular handbook pages not of the 'handbook' post type. 322 327 if ( is_singular( $this->post_type ) && 'handbook' !== $this->post_type ) { 323 $handbook_templates = array( "single-{$this->post_type}.php", 'single-handbook.php' );328 $handbook_templates = [ "single-{$this->post_type}.php", 'single-handbook.php' ]; 324 329 } 325 330 // For handbook landing page. … … 340 345 } 341 346 342 function pre_get_posts( $query ) {347 public function pre_get_posts( $query ) { 343 348 // Bail early if query is not for this handbook's post type. 344 349 if ( get_query_var( 'post_type' ) !== $this->post_type ) { … … 379 384 } 380 385 381 function handbook_sidebar() {382 $sidebar_args = array(383 'id' => $this->post_type,384 'name' => sprintf( __( '%s Sidebar', 'wporg' ), $this->label ),385 'description' => sprintf( __( 'Used on %s pages', 'wporg' ), $this->label ),386 public function handbook_sidebar() { 387 $sidebar_args = [ 388 'id' => $this->post_type, 389 'name' => sprintf( __( '%s Sidebar', 'wporg' ), $this->label ), 390 'description' => sprintf( __( 'Used on %s pages', 'wporg' ), $this->label ), 386 391 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 387 392 'after_widget' => '</aside>', 388 393 'before_title' => '<h2 class="widget-title">', 389 394 'after_title' => '</h2>', 390 );395 ]; 391 396 392 397 $sidebar_args = apply_filters( 'wporg_handbook_sidebar_args', $sidebar_args, $this ); … … 398 403 } 399 404 400 function wporg_email_changes_for_post_types( $post_types ) {405 public function wporg_email_changes_for_post_types( $post_types ) { 401 406 if ( ! in_array( $this->post_type, $post_types ) ) { 402 407 $post_types[] = $this->post_type; … … 410 415 * if that plugin is active. 411 416 */ 412 function disable_p2_resolved_posts_action_links() {413 if ( ( $this->post_type == get_post_type() ) && class_exists( 'P2_Resolved_Posts' ) && isset( $GLOBALS['p2_resolved_posts'] ) && is_object( $GLOBALS['p2_resolved_posts'] ) ) {414 remove_filter( 'p2_action_links', array( P2_Resolved_Posts::instance(), 'p2_action_links' ), 100 );417 public function disable_p2_resolved_posts_action_links() { 418 if ( ( $this->post_type === get_post_type() ) && class_exists( 'P2_Resolved_Posts' ) && isset( $GLOBALS['p2_resolved_posts'] ) && is_object( $GLOBALS['p2_resolved_posts'] ) ) { 419 remove_filter( 'p2_action_links', [ P2_Resolved_Posts::instance(), 'p2_action_links' ], 100 ); 415 420 } 416 421 } … … 422 427 * @return bool 423 428 */ 424 function disable_o2_processing( $process_with_o2 ) {429 public function disable_o2_processing( $process_with_o2 ) { 425 430 return ( is_singular() && $this->post_type === get_post_type() ) ? false : $process_with_o2; 426 431 } … … 432 437 * @return string 433 438 */ 434 function o2_application_container( $container ) {439 public function o2_application_container( $container ) { 435 440 return ( is_singular() && $this->post_type === get_post_type() ) ? '#primary' : $container; 436 441 } … … 443 448 * @return string 444 449 */ 445 function o2_view_type( $view_type ) {450 public function o2_view_type( $view_type ) { 446 451 return ( is_singular() && $this->post_type === get_post_type() ) ? 'single' : $view_type; 447 452 } … … 453 458 * @return array 454 459 */ 455 function o2_post_fragment( $post_fragment ) {460 public function o2_post_fragment( $post_fragment ) { 456 461 $post = get_post( $post_fragment['id'] ); 457 462 if ( ! $post ) { … … 473 478 * @return bool 474 479 */ 475 function comments_open( $open, $post_id ) {480 public function comments_open( $open, $post_id ) { 476 481 $post = get_post( $post_id ); 477 482 if ( ! $post ) { … … 499 504 * @return array 500 505 */ 501 function highlight_menu_handbook_link( $menu_items ) {506 public function highlight_menu_handbook_link( $menu_items ) { 502 507 // Must be on a handbook page that isn't the handbook landing page (which will already be handled). 503 if ( ! is_page( array( 'handbook', 'handbooks' )) && ( ! wporg_is_handbook() || wporg_is_handbook_landing_page() ) ) {508 if ( ! is_page( [ 'handbook', 'handbooks' ] ) && ( ! wporg_is_handbook() || wporg_is_handbook_landing_page() ) ) { 504 509 return $menu_items; 505 510 } 506 511 507 512 // Menu must not have an item that is already noted as being current. 508 $current_menu_item = wp_filter_object_list( $menu_items, array( 'current' => true ));513 $current_menu_item = wp_filter_object_list( $menu_items, [ 'current' => true ] ); 509 514 if ( $current_menu_item ) { 510 515 return $menu_items; … … 512 517 513 518 // Menu must have an item that links to handbook home page. 514 $root_handbook_menu_item = wp_filter_object_list( $menu_items, array( 'url' => wporg_get_current_handbook_home_url() ));519 $root_handbook_menu_item = wp_filter_object_list( $menu_items, [ 'url' => wporg_get_current_handbook_home_url() ] ); 515 520 if ( ! $root_handbook_menu_item ) { 516 521 // Or it must have an item that links to a 'handbook' or 'handbooks' page. … … 518 523 $page = get_page_by_path( $page_slug ); 519 524 if ( $page ) { 520 $root_handbook_menu_item = wp_filter_object_list( $menu_items, array( 'object_id' => $page->ID ));525 $root_handbook_menu_item = wp_filter_object_list( $menu_items, [ 'object_id' => $page->ID ] ); 521 526 } 522 527 }
Note: See TracChangeset
for help on using the changeset viewer.