Changeset 8961 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php
- Timestamp:
- 06/19/2019 05:04:11 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php
r8869 r8961 20 20 21 21 /** 22 * Hidden handbook post types. 23 * 24 * Note: Hidden only from users who aren't logged in. 25 * 26 * @var array 27 * @access public 28 */ 29 public static $hidden_handbooks = [ 'apis-handbook' ]; 30 31 /** 22 32 * Initializer 23 33 * … … 25 35 */ 26 36 public static function init() { 37 add_filter( 'handbook_label', array( __CLASS__, 'change_handbook_label' ), 10, 2 ); 27 38 add_filter( 'handbook_post_type_defaults', array( __CLASS__, 'filter_handbook_post_type_defaults' ), 10, 2 ); 28 39 add_filter( 'handbook_post_types', array( __CLASS__, 'filter_handbook_post_types' ) ); … … 37 48 public static function do_init() { 38 49 add_filter( 'query_vars', array( __CLASS__, 'add_query_vars' ) ); 50 51 add_action( 'template_redirect', array( __CLASS__, 'redirect_hidden_handbooks' ), 1 ); 39 52 40 53 add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ), 9 ); … … 70 83 71 84 /** 85 * Redirects handbooks that should be inaccessible to visitors who aren't logged in. 86 */ 87 public static function redirect_hidden_handbooks() { 88 if ( ! self::$hidden_handbooks || get_current_user_id() || ! function_exists( 'wporg_is_handbook' ) || ! wporg_is_handbook() ) { 89 return; 90 } 91 92 if ( in_array( wporg_get_current_handbook(), self::$hidden_handbooks ) ) { 93 wp_safe_redirect( home_url() ); 94 exit(); 95 } 96 } 97 98 /** 72 99 * Add handbook query vars to the current query. 73 100 * … … 88 115 89 116 /** 90 * Filter handbook post types to create handbooks for: plugins, themes.117 * Filter handbook post types to create handbooks for: apis, plugins, themes. 91 118 * 92 119 * @access public … … 97 124 public static function filter_handbook_post_types( $types ) { 98 125 if ( ! self::$post_types ) { 99 self::$post_types = apply_filters( 'devhub_handbook_post_types', [ ' plugin', 'theme' ] );126 self::$post_types = apply_filters( 'devhub_handbook_post_types', [ 'apis', 'plugin', 'theme' ] ); 100 127 } 101 128 … … 241 268 } 242 269 270 /** 271 * Overrides the default handbook label when post type name does not directly 272 * translate to post type label. 273 * 274 * @param string $label The default label, which is merely a sanitized 275 * version of the handbook name. 276 * @param string $post_type The handbook post type. 277 * @return string 278 */ 279 public static function change_handbook_label( $label, $post_type ) { 280 if ( 'apis-handbook' === $post_type ) { 281 $label = __( 'Common APIs Handbook', 'wporg' ); 282 } 283 284 return $label; 285 } 286 243 287 } // Devhub_Handbooks 244 288
Note: See TracChangeset
for help on using the changeset viewer.