[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-wp-post-type.php (source)

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


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1