[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Post API: WP_Post_Type class 4 * 5 * @package WordPress 6 * @subpackage Post 7 * @since 4.6.0 8 */ 9 10 /** 11 * Core class used for interacting with post types. 12 * 13 * @since 4.6.0 14 * 15 * @see register_post_type() 16 */ 17 #[AllowDynamicProperties] 18 final class WP_Post_Type { 19 /** 20 * Post type key. 21 * 22 * @since 4.6.0 23 * @var string $name 24 */ 25 public $name; 26 27 /** 28 * Name of the post type shown in the menu. Usually plural. 29 * 30 * @since 4.6.0 31 * @var string $label 32 */ 33 public $label; 34 35 /** 36 * Labels object for this post type. 37 * 38 * If not set, post labels are inherited for non-hierarchical types 39 * and page labels for hierarchical ones. 40 * 41 * @see get_post_type_labels() 42 * 43 * @since 4.6.0 44 * @var stdClass $labels 45 */ 46 public $labels; 47 48 /** 49 * Default labels. 50 * 51 * @since 6.0.0 52 * @var (string|null)[][] $default_labels 53 */ 54 protected static $default_labels = array(); 55 56 /** 57 * A short descriptive summary of what the post type is. 58 * 59 * Default empty. 60 * 61 * @since 4.6.0 62 * @var string $description 63 */ 64 public $description = ''; 65 66 /** 67 * Whether a post type is intended for use publicly either via the admin interface or by front-end users. 68 * 69 * While the default settings of $exclude_from_search, $publicly_queryable, $show_ui, and $show_in_nav_menus 70 * are inherited from public, each does not rely on this relationship and controls a very specific intention. 71 * 72 * Default false. 73 * 74 * @since 4.6.0 75 * @var bool $public 76 */ 77 public $public = false; 78 79 /** 80 * Whether the post type is hierarchical (e.g. page). 81 * 82 * Default false. 83 * 84 * @since 4.6.0 85 * @var bool $hierarchical 86 */ 87 public $hierarchical = false; 88 89 /** 90 * Whether to exclude posts with this post type from front end search 91 * results. 92 * 93 * Default is the opposite value of $public. 94 * 95 * @since 4.6.0 96 * @var bool $exclude_from_search 97 */ 98 public $exclude_from_search = null; 99 100 /** 101 * Whether queries can be performed on the front end for the post type as part of `parse_request()`. 102 * 103 * Endpoints would include: 104 * 105 * - `?post_type={post_type_key}` 106 * - `?{post_type_key}={single_post_slug}` 107 * - `?{post_type_query_var}={single_post_slug}` 108 * 109 * Default is the value of $public. 110 * 111 * @since 4.6.0 112 * @var bool $publicly_queryable 113 */ 114 public $publicly_queryable = null; 115 116 /** 117 * Whether to generate and allow a UI for managing this post type in the admin. 118 * 119 * Default is the value of $public. 120 * 121 * @since 4.6.0 122 * @var bool $show_ui 123 */ 124 public $show_ui = null; 125 126 /** 127 * Where to show the post type in the admin menu. 128 * 129 * 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 130 * shown. If a string of an existing top level menu ('tools.php' or 'edit.php?post_type=page', for example), the 131 * post type will be placed as a sub-menu of that. 132 * 133 * Default is the value of $show_ui. 134 * 135 * @since 4.6.0 136 * @var bool|string $show_in_menu 137 */ 138 public $show_in_menu = null; 139 140 /** 141 * Makes this post type available for selection in navigation menus. 142 * 143 * Default is the value $public. 144 * 145 * @since 4.6.0 146 * @var bool $show_in_nav_menus 147 */ 148 public $show_in_nav_menus = null; 149 150 /** 151 * Makes this post type available via the admin bar. 152 * 153 * Default is the value of $show_in_menu. 154 * 155 * @since 4.6.0 156 * @var bool $show_in_admin_bar 157 */ 158 public $show_in_admin_bar = null; 159 160 /** 161 * The position in the menu order the post type should appear. 162 * 163 * To work, $show_in_menu must be true. Default null (at the bottom). 164 * 165 * @since 4.6.0 166 * @var int $menu_position 167 */ 168 public $menu_position = null; 169 170 /** 171 * The URL or reference to the icon to be used for this menu. 172 * 173 * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme. 174 * This should begin with 'data:image/svg+xml;base64,'. Pass the name of a Dashicons helper class 175 * to use a font icon, e.g. 'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty 176 * so an icon can be added via CSS. 177 * 178 * Defaults to use the posts icon. 179 * 180 * @since 4.6.0 181 * @var string $menu_icon 182 */ 183 public $menu_icon = null; 184 185 /** 186 * The string to use to build the read, edit, and delete capabilities. 187 * 188 * May be passed as an array to allow for alternative plurals when using 189 * this argument as a base to construct the capabilities, e.g. 190 * array( 'story', 'stories' ). Default 'post'. 191 * 192 * @since 4.6.0 193 * @var string $capability_type 194 */ 195 public $capability_type = 'post'; 196 197 /** 198 * Whether to use the internal default meta capability handling. 199 * 200 * Default false. 201 * 202 * @since 4.6.0 203 * @var bool $map_meta_cap 204 */ 205 public $map_meta_cap = false; 206 207 /** 208 * Provide a callback function that sets up the meta boxes for the edit form. 209 * 210 * Do `remove_meta_box()` and `add_meta_box()` calls in the callback. Default null. 211 * 212 * @since 4.6.0 213 * @var callable $register_meta_box_cb 214 */ 215 public $register_meta_box_cb = null; 216 217 /** 218 * An array of taxonomy identifiers that will be registered for the post type. 219 * 220 * Taxonomies can be registered later with `register_taxonomy()` or `register_taxonomy_for_object_type()`. 221 * 222 * Default empty array. 223 * 224 * @since 4.6.0 225 * @var string[] $taxonomies 226 */ 227 public $taxonomies = array(); 228 229 /** 230 * Whether there should be post type archives, or if a string, the archive slug to use. 231 * 232 * Will generate the proper rewrite rules if $rewrite is enabled. Default false. 233 * 234 * @since 4.6.0 235 * @var bool|string $has_archive 236 */ 237 public $has_archive = false; 238 239 /** 240 * Sets the query_var key for this post type. 241 * 242 * Defaults to $post_type key. If false, a post type cannot be loaded at `?{query_var}={post_slug}`. 243 * If specified as a string, the query `?{query_var_string}={post_slug}` will be valid. 244 * 245 * @since 4.6.0 246 * @var string|bool $query_var 247 */ 248 public $query_var; 249 250 /** 251 * Whether to allow this post type to be exported. 252 * 253 * Default true. 254 * 255 * @since 4.6.0 256 * @var bool $can_export 257 */ 258 public $can_export = true; 259 260 /** 261 * Whether to delete posts of this type when deleting a user. 262 * 263 * - If true, posts of this type belonging to the user will be moved to Trash when the user is deleted. 264 * - If false, posts of this type belonging to the user will *not* be trashed or deleted. 265 * - If not set (the default), posts are trashed if post type supports the 'author' feature. 266 * Otherwise posts are not trashed or deleted. 267 * 268 * Default null. 269 * 270 * @since 4.6.0 271 * @var bool $delete_with_user 272 */ 273 public $delete_with_user = null; 274 275 /** 276 * Array of blocks to use as the default initial state for an editor session. 277 * 278 * Each item should be an array containing block name and optional attributes. 279 * 280 * Default empty array. 281 * 282 * @link https://developer.wordpress.org/block-editor/developers/block-api/block-templates/ 283 * 284 * @since 5.0.0 285 * @var array[] $template 286 */ 287 public $template = array(); 288 289 /** 290 * Whether the block template should be locked if $template is set. 291 * 292 * - If set to 'all', the user is unable to insert new blocks, move existing blocks 293 * and delete blocks. 294 * - If set to 'insert', the user is able to move existing blocks but is unable to insert 295 * new blocks and delete blocks. 296 * 297 * Default false. 298 * 299 * @link https://developer.wordpress.org/block-editor/developers/block-api/block-templates/ 300 * 301 * @since 5.0.0 302 * @var string|false $template_lock 303 */ 304 public $template_lock = false; 305 306 /** 307 * Whether this post type is a native or "built-in" post_type. 308 * 309 * Default false. 310 * 311 * @since 4.6.0 312 * @var bool $_builtin 313 */ 314 public $_builtin = false; 315 316 /** 317 * URL segment to use for edit link of this post type. 318 * 319 * Default 'post.php?post=%d'. 320 * 321 * @since 4.6.0 322 * @var string $_edit_link 323 */ 324 public $_edit_link = 'post.php?post=%d'; 325 326 /** 327 * Post type capabilities. 328 * 329 * @since 4.6.0 330 * @var stdClass $cap 331 */ 332 public $cap; 333 334 /** 335 * Triggers the handling of rewrites for this post type. 336 * 337 * Defaults to true, using $post_type as slug. 338 * 339 * @since 4.6.0 340 * @var array|false $rewrite 341 */ 342 public $rewrite; 343 344 /** 345 * The features supported by the post type. 346 * 347 * @since 4.6.0 348 * @var array|bool $supports 349 */ 350 public $supports; 351 352 /** 353 * Whether this post type should appear in the REST API. 354 * 355 * Default false. If true, standard endpoints will be registered with 356 * respect to $rest_base and $rest_controller_class. 357 * 358 * @since 4.7.4 359 * @var bool $show_in_rest 360 */ 361 public $show_in_rest; 362 363 /** 364 * The base path for this post type's REST API endpoints. 365 * 366 * @since 4.7.4 367 * @var string|bool $rest_base 368 */ 369 public $rest_base; 370 371 /** 372 * The namespace for this post type's REST API endpoints. 373 * 374 * @since 5.9.0 375 * @var string|bool $rest_namespace 376 */ 377 public $rest_namespace; 378 379 /** 380 * The controller for this post type's REST API endpoints. 381 * 382 * Custom controllers must extend WP_REST_Controller. 383 * 384 * @since 4.7.4 385 * @var string|bool $rest_controller_class 386 */ 387 public $rest_controller_class; 388 389 /** 390 * The controller instance for this post type's REST API endpoints. 391 * 392 * Lazily computed. Should be accessed using {@see WP_Post_Type::get_rest_controller()}. 393 * 394 * @since 5.3.0 395 * @var WP_REST_Controller $rest_controller 396 */ 397 public $rest_controller; 398 399 /** 400 * Constructor. 401 * 402 * See the register_post_type() function for accepted arguments for `$args`. 403 * 404 * Will populate object properties from the provided arguments and assign other 405 * default properties based on that information. 406 * 407 * @since 4.6.0 408 * 409 * @see register_post_type() 410 * 411 * @param string $post_type Post type key. 412 * @param array|string $args Optional. Array or string of arguments for registering a post type. 413 * See register_post_type() for information on accepted arguments. 414 * Default empty array. 415 */ 416 public function __construct( $post_type, $args = array() ) { 417 $this->name = $post_type; 418 419 $this->set_props( $args ); 420 } 421 422 /** 423 * Sets post type properties. 424 * 425 * See the register_post_type() function for accepted arguments for `$args`. 426 * 427 * @since 4.6.0 428 * 429 * @param array|string $args Array or string of arguments for registering a post type. 430 */ 431 public function set_props( $args ) { 432 $args = wp_parse_args( $args ); 433 434 /** 435 * Filters the arguments for registering a post type. 436 * 437 * @since 4.4.0 438 * 439 * @param array $args Array of arguments for registering a post type. 440 * See the register_post_type() function for accepted arguments. 441 * @param string $post_type Post type key. 442 */ 443 $args = apply_filters( 'register_post_type_args', $args, $this->name ); 444 445 $post_type = $this->name; 446 447 /** 448 * Filters the arguments for registering a specific post type. 449 * 450 * The dynamic portion of the filter name, `$post_type`, refers to the post type key. 451 * 452 * Possible hook names include: 453 * 454 * - `register_post_post_type_args` 455 * - `register_page_post_type_args` 456 * 457 * @since 6.0.0 458 * 459 * @param array $args Array of arguments for registering a post type. 460 * See the register_post_type() function for accepted arguments. 461 * @param string $post_type Post type key. 462 */ 463 $args = apply_filters( "register_{$post_type}_post_type_args", $args, $this->name ); 464 465 $has_edit_link = ! empty( $args['_edit_link'] ); 466 467 // Args prefixed with an underscore are reserved for internal use. 468 $defaults = array( 469 'labels' => array(), 470 'description' => '', 471 'public' => false, 472 'hierarchical' => false, 473 'exclude_from_search' => null, 474 'publicly_queryable' => null, 475 'show_ui' => null, 476 'show_in_menu' => null, 477 'show_in_nav_menus' => null, 478 'show_in_admin_bar' => null, 479 'menu_position' => null, 480 'menu_icon' => null, 481 'capability_type' => 'post', 482 'capabilities' => array(), 483 'map_meta_cap' => null, 484 'supports' => array(), 485 'register_meta_box_cb' => null, 486 'taxonomies' => array(), 487 'has_archive' => false, 488 'rewrite' => true, 489 'query_var' => true, 490 'can_export' => true, 491 'delete_with_user' => null, 492 'show_in_rest' => false, 493 'rest_base' => false, 494 'rest_namespace' => false, 495 'rest_controller_class' => false, 496 'template' => array(), 497 'template_lock' => false, 498 '_builtin' => false, 499 '_edit_link' => 'post.php?post=%d', 500 ); 501 502 $args = array_merge( $defaults, $args ); 503 504 $args['name'] = $this->name; 505 506 // If not set, default to the setting for 'public'. 507 if ( null === $args['publicly_queryable'] ) { 508 $args['publicly_queryable'] = $args['public']; 509 } 510 511 // If not set, default to the setting for 'public'. 512 if ( null === $args['show_ui'] ) { 513 $args['show_ui'] = $args['public']; 514 } 515 516 // If not set, default rest_namespace to wp/v2 if show_in_rest is true. 517 if ( false === $args['rest_namespace'] && ! empty( $args['show_in_rest'] ) ) { 518 $args['rest_namespace'] = 'wp/v2'; 519 } 520 521 // If not set, default to the setting for 'show_ui'. 522 if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) { 523 $args['show_in_menu'] = $args['show_ui']; 524 } 525 526 // If not set, default to the setting for 'show_in_menu'. 527 if ( null === $args['show_in_admin_bar'] ) { 528 $args['show_in_admin_bar'] = (bool) $args['show_in_menu']; 529 } 530 531 // If not set, default to the setting for 'public'. 532 if ( null === $args['show_in_nav_menus'] ) { 533 $args['show_in_nav_menus'] = $args['public']; 534 } 535 536 // If not set, default to true if not public, false if public. 537 if ( null === $args['exclude_from_search'] ) { 538 $args['exclude_from_search'] = ! $args['public']; 539 } 540 541 // Back compat with quirky handling in version 3.0. #14122. 542 if ( empty( $args['capabilities'] ) 543 && null === $args['map_meta_cap'] && in_array( $args['capability_type'], array( 'post', 'page' ), true ) 544 ) { 545 $args['map_meta_cap'] = true; 546 } 547 548 // If not set, default to false. 549 if ( null === $args['map_meta_cap'] ) { 550 $args['map_meta_cap'] = false; 551 } 552 553 // If there's no specified edit link and no UI, remove the edit link. 554 if ( ! $args['show_ui'] && ! $has_edit_link ) { 555 $args['_edit_link'] = ''; 556 } 557 558 $this->cap = get_post_type_capabilities( (object) $args ); 559 unset( $args['capabilities'] ); 560 561 if ( is_array( $args['capability_type'] ) ) { 562 $args['capability_type'] = $args['capability_type'][0]; 563 } 564 565 if ( false !== $args['query_var'] ) { 566 if ( true === $args['query_var'] ) { 567 $args['query_var'] = $this->name; 568 } else { 569 $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); 570 } 571 } 572 573 if ( false !== $args['rewrite'] && ( is_admin() || get_option( 'permalink_structure' ) ) ) { 574 if ( ! is_array( $args['rewrite'] ) ) { 575 $args['rewrite'] = array(); 576 } 577 if ( empty( $args['rewrite']['slug'] ) ) { 578 $args['rewrite']['slug'] = $this->name; 579 } 580 if ( ! isset( $args['rewrite']['with_front'] ) ) { 581 $args['rewrite']['with_front'] = true; 582 } 583 if ( ! isset( $args['rewrite']['pages'] ) ) { 584 $args['rewrite']['pages'] = true; 585 } 586 if ( ! isset( $args['rewrite']['feeds'] ) || ! $args['has_archive'] ) { 587 $args['rewrite']['feeds'] = (bool) $args['has_archive']; 588 } 589 if ( ! isset( $args['rewrite']['ep_mask'] ) ) { 590 if ( isset( $args['permalink_epmask'] ) ) { 591 $args['rewrite']['ep_mask'] = $args['permalink_epmask']; 592 } else { 593 $args['rewrite']['ep_mask'] = EP_PERMALINK; 594 } 595 } 596 } 597 598 foreach ( $args as $property_name => $property_value ) { 599 $this->$property_name = $property_value; 600 } 601 602 $this->labels = get_post_type_labels( $this ); 603 $this->label = $this->labels->name; 604 } 605 606 /** 607 * Sets the features support for the post type. 608 * 609 * @since 4.6.0 610 */ 611 public function add_supports() { 612 if ( ! empty( $this->supports ) ) { 613 foreach ( $this->supports as $feature => $args ) { 614 if ( is_array( $args ) ) { 615 add_post_type_support( $this->name, $feature, $args ); 616 } else { 617 add_post_type_support( $this->name, $args ); 618 } 619 } 620 unset( $this->supports ); 621 } elseif ( false !== $this->supports ) { 622 // Add default features. 623 add_post_type_support( $this->name, array( 'title', 'editor' ) ); 624 } 625 } 626 627 /** 628 * Adds the necessary rewrite rules for the post type. 629 * 630 * @since 4.6.0 631 * 632 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 633 * @global WP $wp Current WordPress environment instance. 634 */ 635 public function add_rewrite_rules() { 636 global $wp_rewrite, $wp; 637 638 if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) { 639 $wp->add_query_var( $this->query_var ); 640 } 641 642 if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) { 643 if ( $this->hierarchical ) { 644 add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" ); 645 } else { 646 add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" ); 647 } 648 649 if ( $this->has_archive ) { 650 $archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive; 651 if ( $this->rewrite['with_front'] ) { 652 $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; 653 } else { 654 $archive_slug = $wp_rewrite->root . $archive_slug; 655 } 656 657 add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$this->name", 'top' ); 658 if ( $this->rewrite['feeds'] && $wp_rewrite->feeds ) { 659 $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; 660 add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' ); 661 add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' ); 662 } 663 if ( $this->rewrite['pages'] ) { 664 add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$this->name" . '&paged=$matches[1]', 'top' ); 665 } 666 } 667 668 $permastruct_args = $this->rewrite; 669 $permastruct_args['feed'] = $permastruct_args['feeds']; 670 add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $permastruct_args ); 671 } 672 } 673 674 /** 675 * Registers the post type meta box if a custom callback was specified. 676 * 677 * @since 4.6.0 678 */ 679 public function register_meta_boxes() { 680 if ( $this->register_meta_box_cb ) { 681 add_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10, 1 ); 682 } 683 } 684 685 /** 686 * Adds the future post hook action for the post type. 687 * 688 * @since 4.6.0 689 */ 690 public function add_hooks() { 691 add_action( 'future_' . $this->name, '_future_post_hook', 5, 2 ); 692 } 693 694 /** 695 * Registers the taxonomies for the post type. 696 * 697 * @since 4.6.0 698 */ 699 public function register_taxonomies() { 700 foreach ( $this->taxonomies as $taxonomy ) { 701 register_taxonomy_for_object_type( $taxonomy, $this->name ); 702 } 703 } 704 705 /** 706 * Removes the features support for the post type. 707 * 708 * @since 4.6.0 709 * 710 * @global array $_wp_post_type_features Post type features. 711 */ 712 public function remove_supports() { 713 global $_wp_post_type_features; 714 715 unset( $_wp_post_type_features[ $this->name ] ); 716 } 717 718 /** 719 * Removes any rewrite rules, permastructs, and rules for the post type. 720 * 721 * @since 4.6.0 722 * 723 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 724 * @global WP $wp Current WordPress environment instance. 725 * @global array $post_type_meta_caps Used to remove meta capabilities. 726 */ 727 public function remove_rewrite_rules() { 728 global $wp, $wp_rewrite, $post_type_meta_caps; 729 730 // Remove query var. 731 if ( false !== $this->query_var ) { 732 $wp->remove_query_var( $this->query_var ); 733 } 734 735 // Remove any rewrite rules, permastructs, and rules. 736 if ( false !== $this->rewrite ) { 737 remove_rewrite_tag( "%$this->name%" ); 738 remove_permastruct( $this->name ); 739 foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) { 740 if ( false !== strpos( $query, "index.php?post_type=$this->name" ) ) { 741 unset( $wp_rewrite->extra_rules_top[ $regex ] ); 742 } 743 } 744 } 745 746 // Remove registered custom meta capabilities. 747 foreach ( $this->cap as $cap ) { 748 unset( $post_type_meta_caps[ $cap ] ); 749 } 750 } 751 752 /** 753 * Unregisters the post type meta box if a custom callback was specified. 754 * 755 * @since 4.6.0 756 */ 757 public function unregister_meta_boxes() { 758 if ( $this->register_meta_box_cb ) { 759 remove_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10 ); 760 } 761 } 762 763 /** 764 * Removes the post type from all taxonomies. 765 * 766 * @since 4.6.0 767 */ 768 public function unregister_taxonomies() { 769 foreach ( get_object_taxonomies( $this->name ) as $taxonomy ) { 770 unregister_taxonomy_for_object_type( $taxonomy, $this->name ); 771 } 772 } 773 774 /** 775 * Removes the future post hook action for the post type. 776 * 777 * @since 4.6.0 778 */ 779 public function remove_hooks() { 780 remove_action( 'future_' . $this->name, '_future_post_hook', 5 ); 781 } 782 783 /** 784 * Gets the REST API controller for this post type. 785 * 786 * Will only instantiate the controller class once per request. 787 * 788 * @since 5.3.0 789 * 790 * @return WP_REST_Controller|null The controller instance, or null if the post type 791 * is set not to show in rest. 792 */ 793 public function get_rest_controller() { 794 if ( ! $this->show_in_rest ) { 795 return null; 796 } 797 798 $class = $this->rest_controller_class ? $this->rest_controller_class : WP_REST_Posts_Controller::class; 799 800 if ( ! class_exists( $class ) ) { 801 return null; 802 } 803 804 if ( ! is_subclass_of( $class, WP_REST_Controller::class ) ) { 805 return null; 806 } 807 808 if ( ! $this->rest_controller ) { 809 $this->rest_controller = new $class( $this->name ); 810 } 811 812 if ( ! ( $this->rest_controller instanceof $class ) ) { 813 return null; 814 } 815 816 return $this->rest_controller; 817 } 818 819 /** 820 * Returns the default labels for post types. 821 * 822 * @since 6.0.0 823 * 824 * @return (string|null)[][] The default labels for post types. 825 */ 826 public static function get_default_labels() { 827 if ( ! empty( self::$default_labels ) ) { 828 return self::$default_labels; 829 } 830 831 self::$default_labels = array( 832 'name' => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ), 833 'singular_name' => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ), 834 'add_new' => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ), 835 'add_new_item' => array( __( 'Add New Post' ), __( 'Add New Page' ) ), 836 'edit_item' => array( __( 'Edit Post' ), __( 'Edit Page' ) ), 837 'new_item' => array( __( 'New Post' ), __( 'New Page' ) ), 838 'view_item' => array( __( 'View Post' ), __( 'View Page' ) ), 839 'view_items' => array( __( 'View Posts' ), __( 'View Pages' ) ), 840 'search_items' => array( __( 'Search Posts' ), __( 'Search Pages' ) ), 841 'not_found' => array( __( 'No posts found.' ), __( 'No pages found.' ) ), 842 'not_found_in_trash' => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ), 843 'parent_item_colon' => array( null, __( 'Parent Page:' ) ), 844 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), 845 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), 846 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ), 847 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), 848 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), 849 'featured_image' => array( _x( 'Featured image', 'post' ), _x( 'Featured image', 'page' ) ), 850 'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ), 851 'remove_featured_image' => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ), 852 'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ), 853 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ), 854 'filter_by_date' => array( __( 'Filter by date' ), __( 'Filter by date' ) ), 855 'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ), 856 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ), 857 'item_published' => array( __( 'Post published.' ), __( 'Page published.' ) ), 858 'item_published_privately' => array( __( 'Post published privately.' ), __( 'Page published privately.' ) ), 859 'item_reverted_to_draft' => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ), 860 'item_scheduled' => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ), 861 'item_updated' => array( __( 'Post updated.' ), __( 'Page updated.' ) ), 862 'item_link' => array( 863 _x( 'Post Link', 'navigation link block title' ), 864 _x( 'Page Link', 'navigation link block title' ), 865 ), 866 'item_link_description' => array( 867 _x( 'A link to a post.', 'navigation link block description' ), 868 _x( 'A link to a page.', 'navigation link block description' ), 869 ), 870 ); 871 872 return self::$default_labels; 873 } 874 875 /** 876 * Resets the cache for the default labels. 877 * 878 * @since 6.0.0 879 */ 880 public static function reset_default_labels() { 881 self::$default_labels = array(); 882 } 883 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sun Jun 4 08:20:02 2023 | Cross-referenced by PHPXref |