wp/wp-includes/class-wp-post-type.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    43 	 * @var stdClass $labels
    43 	 * @var stdClass $labels
    44 	 */
    44 	 */
    45 	public $labels;
    45 	public $labels;
    46 
    46 
    47 	/**
    47 	/**
       
    48 	 * Default labels.
       
    49 	 *
       
    50 	 * @since 6.0.0
       
    51 	 * @var (string|null)[][] $default_labels
       
    52 	 */
       
    53 	protected static $default_labels = array();
       
    54 
       
    55 	/**
    48 	 * A short descriptive summary of what the post type is.
    56 	 * A short descriptive summary of what the post type is.
    49 	 *
    57 	 *
    50 	 * Default empty.
    58 	 * Default empty.
    51 	 *
    59 	 *
    52 	 * @since 4.6.0
    60 	 * @since 4.6.0
    90 
    98 
    91 	/**
    99 	/**
    92 	 * Whether queries can be performed on the front end for the post type as part of `parse_request()`.
   100 	 * Whether queries can be performed on the front end for the post type as part of `parse_request()`.
    93 	 *
   101 	 *
    94 	 * Endpoints would include:
   102 	 * Endpoints would include:
       
   103 	 *
    95 	 * - `?post_type={post_type_key}`
   104 	 * - `?post_type={post_type_key}`
    96 	 * - `?{post_type_key}={single_post_slug}`
   105 	 * - `?{post_type_key}={single_post_slug}`
    97 	 * - `?{post_type_query_var}={single_post_slug}`
   106 	 * - `?{post_type_query_var}={single_post_slug}`
    98 	 *
   107 	 *
    99 	 * Default is the value of $public.
   108 	 * Default is the value of $public.
   115 
   124 
   116 	/**
   125 	/**
   117 	 * Where to show the post type in the admin menu.
   126 	 * Where to show the post type in the admin menu.
   118 	 *
   127 	 *
   119 	 * To work, $show_ui must be true. If true, the post type is shown in its own top level menu. If false, no menu is
   128 	 * To work, $show_ui must be true. If true, the post type is shown in its own top level menu. If false, no menu is
   120 	 * shown. If a string of an existing top level menu (eg. 'tools.php' or 'edit.php?post_type=page'), the post type
   129 	 * shown. If a string of an existing top level menu ('tools.php' or 'edit.php?post_type=page', for example), the
   121 	 * will be placed as a sub-menu of that.
   130 	 * post type will be placed as a sub-menu of that.
   122 	 *
   131 	 *
   123 	 * Default is the value of $show_ui.
   132 	 * Default is the value of $show_ui.
   124 	 *
   133 	 *
   125 	 * @since 4.6.0
   134 	 * @since 4.6.0
   126 	 * @var bool|string $show_in_menu
   135 	 * @var bool|string $show_in_menu
   355 	 *
   364 	 *
   356 	 * @since 4.7.4
   365 	 * @since 4.7.4
   357 	 * @var string|bool $rest_base
   366 	 * @var string|bool $rest_base
   358 	 */
   367 	 */
   359 	public $rest_base;
   368 	public $rest_base;
       
   369 
       
   370 	/**
       
   371 	 * The namespace for this post type's REST API endpoints.
       
   372 	 *
       
   373 	 * @since 5.9.0
       
   374 	 * @var string|bool $rest_namespace
       
   375 	 */
       
   376 	public $rest_namespace;
   360 
   377 
   361 	/**
   378 	/**
   362 	 * The controller for this post type's REST API endpoints.
   379 	 * The controller for this post type's REST API endpoints.
   363 	 *
   380 	 *
   364 	 * Custom controllers must extend WP_REST_Controller.
   381 	 * Custom controllers must extend WP_REST_Controller.
   420 		 * @param array  $args      Array of arguments for registering a post type.
   437 		 * @param array  $args      Array of arguments for registering a post type.
   421 		 *                          See the register_post_type() function for accepted arguments.
   438 		 *                          See the register_post_type() function for accepted arguments.
   422 		 * @param string $post_type Post type key.
   439 		 * @param string $post_type Post type key.
   423 		 */
   440 		 */
   424 		$args = apply_filters( 'register_post_type_args', $args, $this->name );
   441 		$args = apply_filters( 'register_post_type_args', $args, $this->name );
       
   442 
       
   443 		$post_type = $this->name;
       
   444 
       
   445 		/**
       
   446 		 * Filters the arguments for registering a specific post type.
       
   447 		 *
       
   448 		 * The dynamic portion of the filter name, `$post_type`, refers to the post type key.
       
   449 		 *
       
   450 		 * Possible hook names include:
       
   451 		 *
       
   452 		 *  - `register_post_post_type_args`
       
   453 		 *  - `register_page_post_type_args`
       
   454 		 *
       
   455 		 * @since 6.0.0
       
   456 		 *
       
   457 		 * @param array  $args      Array of arguments for registering a post type.
       
   458 		 *                          See the register_post_type() function for accepted arguments.
       
   459 		 * @param string $post_type Post type key.
       
   460 		 */
       
   461 		$args = apply_filters( "register_{$post_type}_post_type_args", $args, $this->name );
   425 
   462 
   426 		$has_edit_link = ! empty( $args['_edit_link'] );
   463 		$has_edit_link = ! empty( $args['_edit_link'] );
   427 
   464 
   428 		// Args prefixed with an underscore are reserved for internal use.
   465 		// Args prefixed with an underscore are reserved for internal use.
   429 		$defaults = array(
   466 		$defaults = array(
   450 			'query_var'             => true,
   487 			'query_var'             => true,
   451 			'can_export'            => true,
   488 			'can_export'            => true,
   452 			'delete_with_user'      => null,
   489 			'delete_with_user'      => null,
   453 			'show_in_rest'          => false,
   490 			'show_in_rest'          => false,
   454 			'rest_base'             => false,
   491 			'rest_base'             => false,
       
   492 			'rest_namespace'        => false,
   455 			'rest_controller_class' => false,
   493 			'rest_controller_class' => false,
   456 			'template'              => array(),
   494 			'template'              => array(),
   457 			'template_lock'         => false,
   495 			'template_lock'         => false,
   458 			'_builtin'              => false,
   496 			'_builtin'              => false,
   459 			'_edit_link'            => 'post.php?post=%d',
   497 			'_edit_link'            => 'post.php?post=%d',
   469 		}
   507 		}
   470 
   508 
   471 		// If not set, default to the setting for 'public'.
   509 		// If not set, default to the setting for 'public'.
   472 		if ( null === $args['show_ui'] ) {
   510 		if ( null === $args['show_ui'] ) {
   473 			$args['show_ui'] = $args['public'];
   511 			$args['show_ui'] = $args['public'];
       
   512 		}
       
   513 
       
   514 		// If not set, default rest_namespace to wp/v2 if show_in_rest is true.
       
   515 		if ( false === $args['rest_namespace'] && ! empty( $args['show_in_rest'] ) ) {
       
   516 			$args['rest_namespace'] = 'wp/v2';
   474 		}
   517 		}
   475 
   518 
   476 		// If not set, default to the setting for 'show_ui'.
   519 		// If not set, default to the setting for 'show_ui'.
   477 		if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) {
   520 		if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) {
   478 			$args['show_in_menu'] = $args['show_ui'];
   521 			$args['show_in_menu'] = $args['show_ui'];
   768 			return null;
   811 			return null;
   769 		}
   812 		}
   770 
   813 
   771 		return $this->rest_controller;
   814 		return $this->rest_controller;
   772 	}
   815 	}
       
   816 
       
   817 	/**
       
   818 	 * Returns the default labels for post types.
       
   819 	 *
       
   820 	 * @since 6.0.0
       
   821 	 *
       
   822 	 * @return (string|null)[][] The default labels for post types.
       
   823 	 */
       
   824 	public static function get_default_labels() {
       
   825 		if ( ! empty( self::$default_labels ) ) {
       
   826 			return self::$default_labels;
       
   827 		}
       
   828 
       
   829 		self::$default_labels = array(
       
   830 			'name'                     => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ),
       
   831 			'singular_name'            => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ),
       
   832 			'add_new'                  => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ),
       
   833 			'add_new_item'             => array( __( 'Add New Post' ), __( 'Add New Page' ) ),
       
   834 			'edit_item'                => array( __( 'Edit Post' ), __( 'Edit Page' ) ),
       
   835 			'new_item'                 => array( __( 'New Post' ), __( 'New Page' ) ),
       
   836 			'view_item'                => array( __( 'View Post' ), __( 'View Page' ) ),
       
   837 			'view_items'               => array( __( 'View Posts' ), __( 'View Pages' ) ),
       
   838 			'search_items'             => array( __( 'Search Posts' ), __( 'Search Pages' ) ),
       
   839 			'not_found'                => array( __( 'No posts found.' ), __( 'No pages found.' ) ),
       
   840 			'not_found_in_trash'       => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ),
       
   841 			'parent_item_colon'        => array( null, __( 'Parent Page:' ) ),
       
   842 			'all_items'                => array( __( 'All Posts' ), __( 'All Pages' ) ),
       
   843 			'archives'                 => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
       
   844 			'attributes'               => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
       
   845 			'insert_into_item'         => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
       
   846 			'uploaded_to_this_item'    => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
       
   847 			'featured_image'           => array( _x( 'Featured image', 'post' ), _x( 'Featured image', 'page' ) ),
       
   848 			'set_featured_image'       => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),
       
   849 			'remove_featured_image'    => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ),
       
   850 			'use_featured_image'       => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),
       
   851 			'filter_items_list'        => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
       
   852 			'filter_by_date'           => array( __( 'Filter by date' ), __( 'Filter by date' ) ),
       
   853 			'items_list_navigation'    => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),
       
   854 			'items_list'               => array( __( 'Posts list' ), __( 'Pages list' ) ),
       
   855 			'item_published'           => array( __( 'Post published.' ), __( 'Page published.' ) ),
       
   856 			'item_published_privately' => array( __( 'Post published privately.' ), __( 'Page published privately.' ) ),
       
   857 			'item_reverted_to_draft'   => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ),
       
   858 			'item_scheduled'           => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ),
       
   859 			'item_updated'             => array( __( 'Post updated.' ), __( 'Page updated.' ) ),
       
   860 			'item_link'                => array(
       
   861 				_x( 'Post Link', 'navigation link block title' ),
       
   862 				_x( 'Page Link', 'navigation link block title' ),
       
   863 			),
       
   864 			'item_link_description'    => array(
       
   865 				_x( 'A link to a post.', 'navigation link block description' ),
       
   866 				_x( 'A link to a page.', 'navigation link block description' ),
       
   867 			),
       
   868 		);
       
   869 
       
   870 		return self::$default_labels;
       
   871 	}
       
   872 
       
   873 	/**
       
   874 	 * Resets the cache for the default labels.
       
   875 	 *
       
   876 	 * @since 6.0.0
       
   877 	 */
       
   878 	public static function reset_default_labels() {
       
   879 		self::$default_labels = array();
       
   880 	}
   773 }
   881 }