Changeset 10768
- Timestamp:
- 03/05/2021 12:05:23 AM (4 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php
r10764 r10768 93 93 /** 94 94 * Constructor 95 * 96 * @param string $type The post type for the handbook. 95 97 */ 96 98 public function __construct( $type ) { 97 if ( 'handbook' !== $type ) { 98 $this->post_type = $type . '-handbook'; 99 } else { 100 $this->post_type = $type; 101 } 99 $this->post_type = sanitize_title( $type ); 102 100 103 101 $this->label = ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/init.php
r10767 r10768 47 47 * @param array $handbooks Array of handbook post types. Default 'handbook'. 48 48 */ 49 return (array) apply_filters( 'handbook_post_types', array( 'handbook' ) ); 49 $post_types = (array) apply_filters( 'handbook_post_types', [ 'handbook' ] ); 50 return array_map( 51 function( $pt ) { 52 $pt = sanitize_title( $pt ); 53 return ( in_array( $pt, [ 'handbook', 'page' ] ) || false !== strpos( $pt, '-handbook' ) ) ? $pt : $pt . '-handbook'; 54 }, 55 $post_types 56 ); 50 57 } 51 58 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/table-of-contents.php
r8899 r10768 40 40 41 41 function load_filters() { 42 $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );43 44 42 if ( is_singular( $this->post_types ) && ! is_embed() ) { 45 43 add_filter( 'the_content', array( $this, 'add_toc' ) ); 46 44 } 47 }48 49 function append_suffix( $t ) {50 if ( in_array( $t, array( 'handbook', 'page' ) ) ) {51 return $t;52 }53 54 return $t . '-handbook';55 45 } 56 46 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/template-tags.php
r10763 r10768 6 6 * Wrapper function for WPorg_Handbook_Init::get_post_types(). 7 7 * 8 * @return array Array with full handbook post type names {post-type}-handbook.8 * @return array Array of handbook post types. 9 9 */ 10 10 function wporg_get_handbook_post_types() { … … 13 13 } 14 14 15 $post_types = WPorg_Handbook_Init::get_post_types(); 16 17 foreach ( $post_types as $key => $post_type ) { 18 if ( 'handbook' !== $post_type ) { 19 $post_types[ $key ] = $post_type . '-handbook'; 20 } 21 } 22 23 return $post_types; 15 return WPorg_Handbook_Init::get_post_types(); 24 16 } 25 17 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php
r10187 r10768 3 3 class WPorg_Handbook_Watchlist { 4 4 5 private static $post_types = array( 'handbook' );5 private static $post_types; 6 6 7 7 public static function init() { … … 10 10 11 11 public static function on_init() { 12 self::$post_types = (array) apply_filters( 'handbook_post_types', self::$post_types ); 13 self::$post_types = array_map( array( __CLASS__, 'append_suffix' ), self::$post_types ); 12 self::$post_types = WPorg_Handbook_Init::get_post_types(); 14 13 15 14 add_action( 'p2_action_links', array(__CLASS__, 'display_action_link'), 100 ); 16 15 add_filter( 'o2_filter_post_actions', array( __CLASS__, 'add_o2_action_link' ) ); 17 16 add_filter( 'o2_filter_post_action_html', array( __CLASS__, 'get_o2_action_link' ), 10, 2 ); 18 }19 20 /**21 * Appends '-handbook' to the dynamic post type, if not already 'handbook'.22 *23 * @param string $t Hanbook post type name.24 * @return string25 */26 private static function append_suffix( $t ) {27 if ( in_array( $t, array( 'handbook', 'page' ) ) ) {28 return $t;29 }30 31 return $t . '-handbook';32 17 } 33 18 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php
r8942 r10768 11 11 protected static $widget_id_base = 'handbook_pages'; 12 12 13 protected $post_types = array( 'handbook' );13 protected $post_types; 14 14 15 15 /** … … 72 72 } 73 73 74 $this->post_types = (array) apply_filters( 'handbook_post_types', $this->post_types ); 75 $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types ); 74 $this->post_types = WPorg_Handbook_Init::get_post_types(); 76 75 77 76 $post_type = ''; … … 94 93 95 94 // Exclude root handbook page from the table of contents. 96 $page = get_page_by_path( $ this->append_suffix( $post_type ), OBJECT, $post_type );95 $page = get_page_by_path( $post_type, OBJECT, $post_type ); 97 96 if ( ! $page ) { 98 97 $slug = substr( $post_type, 0, -9 ); … … 108 107 109 108 return $args; 110 }111 112 public function append_suffix( $t ) {113 if ( in_array( $t, array( 'handbook', 'page' ) ) ) {114 return $t;115 }116 117 return $t . '-handbook';118 109 } 119 110 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/init.php
r10765 r10768 101 101 } 102 102 103 public function test_get_post_types_custom() { 104 reinit_handbooks( [ 'plugins-handbook', 'themes' ], 'post_types' ); 105 106 // Note: The automatic appending of '-handbook' is for back-compat. 107 $this->assertEquals( ['plugins-handbook', 'themes-handbook'], WPorg_Handbook_Init::get_post_types() ); 108 } 109 103 110 public function test_get_post_types_filtered() { 111 add_filter( 'handbook_post_types', function ( $post_types ) { 112 $post_types[] = 'example'; 113 return $post_types; 114 }, 11 ); 104 115 reinit_handbooks( [ 'plugins', 'themes' ], 'post_types' ); 105 116 106 117 // Note: The automatic appending of '-handbook' is for back-compat. 107 $this->assertEquals( [ 'plugins-handbook', 'themes-handbook'], WPorg_Handbook_Init::get_post_types() );118 $this->assertEquals( [ 'plugins-handbook', 'themes-handbook', 'example-handbook' ], WPorg_Handbook_Init::get_post_types() ); 108 119 } 109 120
Note: See TracChangeset
for help on using the changeset viewer.