Changeset 10769 for sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php
- Timestamp:
- 03/05/2021 12:21:47 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php
r10768 r10769 14 14 */ 15 15 public $post_type = ''; 16 17 /** 18 * The handbook's settings. 19 * 20 * @var array 21 */ 22 public $settings = []; 16 23 17 24 /** … … 60 67 61 68 /** 69 * Returns handbook default config. 70 * 71 * @return array 72 */ 73 public static function get_default_handbook_config() { 74 /** 75 * Filters default handbook configuration array. 76 * 77 * @param string $slug The slug for the post type. Default is post type. 78 */ 79 return (array) apply_filters( 'handbook_default_handbook_config', [ 80 'label' => '', 81 'slug' => '', 82 ] ); 83 } 84 85 /** 62 86 * Returns the handbook name. 63 87 * … … 95 119 * 96 120 * @param string $type The post type for the handbook. 97 */ 98 public function __construct( $type ) { 121 * @param array $config The config array for the handbook. 122 */ 123 public function __construct( $type, $config = [] ) { 99 124 $this->post_type = sanitize_title( $type ); 100 125 101 $this->label = ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) ); 102 $this->label = apply_filters( 'handbook_label', $this->label, $this->post_type ); 126 $config = $this->config = wp_parse_args( $config, self::get_default_handbook_config() ); 127 128 $this->label = apply_filters( 129 'handbook_label', 130 $config['label'] ?: ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) ), 131 $this->post_type 132 ); 103 133 104 134 $this->setting_name = $this->post_type . '_name'; … … 127 157 128 158 /** 159 * Returns the configuration array for handbooks. 160 * 161 * @return array 162 */ 163 public function get_config() { 164 return $this->config; 165 } 166 167 /** 129 168 * Adds 'Handbook Front Page' post state indicator for handbook landing pages. 130 169 * … … 235 274 */ 236 275 public function register_post_type() { 237 if ( 'handbook' != $this->post_type ) { 238 $slug = substr( $this->post_type, 0, -9 ); 276 $config = $this->get_config(); 277 278 if ( ! empty( $config['slug'] ) ) { 279 $slug = $config['slug']; 280 } elseif ( 'handbook' !== $this->post_type ) { 281 $slug = str_replace( '-handbook', '', $this->post_type ); 239 282 } else { 240 283 $slug = 'handbook';
Note: See TracChangeset
for help on using the changeset viewer.