• R/O
  • HTTP
  • SSH
  • HTTPS

magic3: コミット

Cloud computing platform


コミットメタ情報

リビジョンf60ad03b422da2a585bcd1c4a4c7f539adeffb78 (tree)
日時2017-09-03 22:21:16
作者naoki hirata <naoki@magi...>
コミッターnaoki hirata

ログメッセージ

WordPressテンプレート機能更新。

変更サマリ

差分

--- /dev/null
+++ b/include/wp/wp-includes/class-wp-post-type.php
@@ -0,0 +1,721 @@
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+ * @access public
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+ * @access public
32+ * @var string $label
33+ */
34+ public $label;
35+
36+ /**
37+ * Labels object for this post type.
38+ *
39+ * If not set, post labels are inherited for non-hierarchical types
40+ * and page labels for hierarchical ones.
41+ *
42+ * @see get_post_type_labels()
43+ *
44+ * @since 4.6.0
45+ * @access public
46+ * @var object $labels
47+ */
48+ public $labels;
49+
50+ /**
51+ * A short descriptive summary of what the post type is.
52+ *
53+ * Default empty.
54+ *
55+ * @since 4.6.0
56+ * @access public
57+ * @var string $description
58+ */
59+ public $description = '';
60+
61+ /**
62+ * Whether a post type is intended for use publicly either via the admin interface or by front-end users.
63+ *
64+ * While the default settings of $exclude_from_search, $publicly_queryable, $show_ui, and $show_in_nav_menus
65+ * are inherited from public, each does not rely on this relationship and controls a very specific intention.
66+ *
67+ * Default false.
68+ *
69+ * @since 4.6.0
70+ * @access public
71+ * @var bool $public
72+ */
73+ public $public = false;
74+
75+ /**
76+ * Whether the post type is hierarchical (e.g. page).
77+ *
78+ * Default false.
79+ *
80+ * @since 4.6.0
81+ * @access public
82+ * @var bool $hierarchical
83+ */
84+ public $hierarchical = false;
85+
86+ /**
87+ * Whether to exclude posts with this post type from front end search
88+ * results.
89+ *
90+ * Default is the opposite value of $public.
91+ *
92+ * @since 4.6.0
93+ * @access public
94+ * @var bool $exclude_from_search
95+ */
96+ public $exclude_from_search = null;
97+
98+ /**
99+ * Whether queries can be performed on the front end for the post type as part of `parse_request()`.
100+ *
101+ * Endpoints would include:
102+ * - `?post_type={post_type_key}`
103+ * - `?{post_type_key}={single_post_slug}`
104+ * - `?{post_type_query_var}={single_post_slug}`
105+ *
106+ * Default is the value of $public.
107+ *
108+ * @since 4.6.0
109+ * @access public
110+ * @var bool $publicly_queryable
111+ */
112+ public $publicly_queryable = null;
113+
114+ /**
115+ * Whether to generate and allow a UI for managing this post type in the admin.
116+ *
117+ * Default is the value of $public.
118+ *
119+ * @since 4.6.0
120+ * @access public
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 (eg. 'tools.php' or 'edit.php?post_type=page'), the post type
130+ * 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+ * @access public
136+ * @var bool $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+ * @access public
147+ * @var bool $show_in_nav_menus
148+ */
149+ public $show_in_nav_menus = null;
150+
151+ /**
152+ * Makes this post type available via the admin bar.
153+ *
154+ * Default is the value of $show_in_menu.
155+ *
156+ * @since 4.6.0
157+ * @access public
158+ * @var bool $show_in_admin_bar
159+ */
160+ public $show_in_admin_bar = null;
161+
162+ /**
163+ * The position in the menu order the post type should appear.
164+ *
165+ * To work, $show_in_menu must be true. Default null (at the bottom).
166+ *
167+ * @since 4.6.0
168+ * @access public
169+ * @var int $menu_position
170+ */
171+ public $menu_position = null;
172+
173+ /**
174+ * The URL to the icon to be used for this menu.
175+ *
176+ * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme.
177+ * This should begin with 'data:image/svg+xml;base64,'. Pass the name of a Dashicons helper class
178+ * to use a font icon, e.g. 'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty
179+ * so an icon can be added via CSS.
180+ *
181+ * Defaults to use the posts icon.
182+ *
183+ * @since 4.6.0
184+ * @access public
185+ * @var string $menu_icon
186+ */
187+ public $menu_icon = null;
188+
189+ /**
190+ * The string to use to build the read, edit, and delete capabilities.
191+ *
192+ * May be passed as an array to allow for alternative plurals when using
193+ * this argument as a base to construct the capabilities, e.g.
194+ * array( 'story', 'stories' ). Default 'post'.
195+ *
196+ * @since 4.6.0
197+ * @access public
198+ * @var string $capability_type
199+ */
200+ public $capability_type = 'post';
201+
202+ /**
203+ * Whether to use the internal default meta capability handling.
204+ *
205+ * Default false.
206+ *
207+ * @since 4.6.0
208+ * @access public
209+ * @var bool $map_meta_cap
210+ */
211+ public $map_meta_cap = false;
212+
213+ /**
214+ * Provide a callback function that sets up the meta boxes for the edit form.
215+ *
216+ * Do `remove_meta_box()` and `add_meta_box()` calls in the callback. Default null.
217+ *
218+ * @since 4.6.0
219+ * @access public
220+ * @var string $register_meta_box_cb
221+ */
222+ public $register_meta_box_cb = null;
223+
224+ /**
225+ * An array of taxonomy identifiers that will be registered for the post type.
226+ *
227+ * Taxonomies can be registered later with `register_taxonomy()` or `register_taxonomy_for_object_type()`.
228+ *
229+ * Default empty array.
230+ *
231+ * @since 4.6.0
232+ * @access public
233+ * @var array $taxonomies
234+ */
235+ public $taxonomies = array();
236+
237+ /**
238+ * Whether there should be post type archives, or if a string, the archive slug to use.
239+ *
240+ * Will generate the proper rewrite rules if $rewrite is enabled. Default false.
241+ *
242+ * @since 4.6.0
243+ * @access public
244+ * @var bool|string $has_archive
245+ */
246+ public $has_archive = false;
247+
248+ /**
249+ * Sets the query_var key for this post type.
250+ *
251+ * Defaults to $post_type key. If false, a post type cannot be loaded at `?{query_var}={post_slug}`.
252+ * If specified as a string, the query `?{query_var_string}={post_slug}` will be valid.
253+ *
254+ * @since 4.6.0
255+ * @access public
256+ * @var string|bool $query_var
257+ */
258+ public $query_var;
259+
260+ /**
261+ * Whether to allow this post type to be exported.
262+ *
263+ * Default true.
264+ *
265+ * @since 4.6.0
266+ * @access public
267+ * @var bool $can_export
268+ */
269+ public $can_export = true;
270+
271+ /**
272+ * Whether to delete posts of this type when deleting a user.
273+ *
274+ * If true, posts of this type belonging to the user will be moved to trash when then user is deleted.
275+ * If false, posts of this type belonging to the user will *not* be trashed or deleted.
276+ * If not set (the default), posts are trashed if post_type_supports( 'author' ).
277+ * Otherwise posts are not trashed or deleted. Default null.
278+ *
279+ * @since 4.6.0
280+ * @access public
281+ * @var bool $delete_with_user
282+ */
283+ public $delete_with_user = null;
284+
285+ /**
286+ * Whether this post type is a native or "built-in" post_type.
287+ *
288+ * Default false.
289+ *
290+ * @since 4.6.0
291+ * @access public
292+ * @var bool $_builtin
293+ */
294+ public $_builtin = false;
295+
296+ /**
297+ * URL segment to use for edit link of this post type.
298+ *
299+ * Default 'post.php?post=%d'.
300+ *
301+ * @since 4.6.0
302+ * @access public
303+ * @var string $_edit_link
304+ */
305+ public $_edit_link = 'post.php?post=%d';
306+
307+ /**
308+ * Post type capabilities.
309+ *
310+ * @since 4.6.0
311+ * @access public
312+ * @var object $cap
313+ */
314+ public $cap;
315+
316+ /**
317+ * Triggers the handling of rewrites for this post type.
318+ *
319+ * Defaults to true, using $post_type as slug.
320+ *
321+ * @since 4.6.0
322+ * @access public
323+ * @var array|false $rewrite
324+ */
325+ public $rewrite;
326+
327+ /**
328+ * The features supported by the post type.
329+ *
330+ * @since 4.6.0
331+ * @access public
332+ * @var array|bool $supports
333+ */
334+ public $supports;
335+
336+ /**
337+ * Whether this post type should appear in the REST API.
338+ *
339+ * Default false. If true, standard endpoints will be registered with
340+ * respect to $rest_base and $rest_controller_class.
341+ *
342+ * @since 4.7.4
343+ * @access public
344+ * @var bool $show_in_rest
345+ */
346+ public $show_in_rest;
347+
348+ /**
349+ * The base path for this post type's REST API endpoints.
350+ *
351+ * @since 4.7.4
352+ * @access public
353+ * @var string|bool $rest_base
354+ */
355+ public $rest_base;
356+
357+ /**
358+ * The controller for this post type's REST API endpoints.
359+ *
360+ * Custom controllers must extend WP_REST_Controller.
361+ *
362+ * @since 4.7.4
363+ * @access public
364+ * @var string|bool $rest_controller_class
365+ */
366+ public $rest_controller_class;
367+
368+ /**
369+ * Constructor.
370+ *
371+ * Will populate object properties from the provided arguments and assign other
372+ * default properties based on that information.
373+ *
374+ * @since 4.6.0
375+ * @access public
376+ *
377+ * @see register_post_type()
378+ *
379+ * @param string $post_type Post type key.
380+ * @param array|string $args Optional. Array or string of arguments for registering a post type.
381+ * Default empty array.
382+ */
383+ public function __construct( $post_type, $args = array() ) {
384+ $this->name = $post_type;
385+
386+ $this->set_props( $args );
387+ }
388+
389+ /**
390+ * Sets post type properties.
391+ *
392+ * @since 4.6.0
393+ * @access public
394+ *
395+ * @param array|string $args Array or string of arguments for registering a post type.
396+ */
397+ public function set_props( $args ) {
398+ $args = wp_parse_args( $args );
399+
400+ /**
401+ * Filters the arguments for registering a post type.
402+ *
403+ * @since 4.4.0
404+ *
405+ * @param array $args Array of arguments for registering a post type.
406+ * @param string $post_type Post type key.
407+ */
408+ $args = apply_filters( 'register_post_type_args', $args, $this->name );
409+
410+ $has_edit_link = ! empty( $args['_edit_link'] );
411+
412+ // Args prefixed with an underscore are reserved for internal use.
413+ $defaults = array(
414+ 'labels' => array(),
415+ 'description' => '',
416+ 'public' => false,
417+ 'hierarchical' => false,
418+ 'exclude_from_search' => null,
419+ 'publicly_queryable' => null,
420+ 'show_ui' => null,
421+ 'show_in_menu' => null,
422+ 'show_in_nav_menus' => null,
423+ 'show_in_admin_bar' => null,
424+ 'menu_position' => null,
425+ 'menu_icon' => null,
426+ 'capability_type' => 'post',
427+ 'capabilities' => array(),
428+ 'map_meta_cap' => null,
429+ 'supports' => array(),
430+ 'register_meta_box_cb' => null,
431+ 'taxonomies' => array(),
432+ 'has_archive' => false,
433+ 'rewrite' => true,
434+ 'query_var' => true,
435+ 'can_export' => true,
436+ 'delete_with_user' => null,
437+ 'show_in_rest' => false,
438+ 'rest_base' => false,
439+ 'rest_controller_class' => false,
440+ '_builtin' => false,
441+ '_edit_link' => 'post.php?post=%d',
442+ );
443+
444+ $args = array_merge( $defaults, $args );
445+
446+ $args['name'] = $this->name;
447+
448+ // If not set, default to the setting for public.
449+ if ( null === $args['publicly_queryable'] ) {
450+ $args['publicly_queryable'] = $args['public'];
451+ }
452+
453+ // If not set, default to the setting for public.
454+ if ( null === $args['show_ui'] ) {
455+ $args['show_ui'] = $args['public'];
456+ }
457+
458+ // If not set, default to the setting for show_ui.
459+ if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) {
460+ $args['show_in_menu'] = $args['show_ui'];
461+ }
462+
463+ // If not set, default to the whether the full UI is shown.
464+ if ( null === $args['show_in_admin_bar'] ) {
465+ $args['show_in_admin_bar'] = (bool) $args['show_in_menu'];
466+ }
467+
468+ // If not set, default to the setting for public.
469+ if ( null === $args['show_in_nav_menus'] ) {
470+ $args['show_in_nav_menus'] = $args['public'];
471+ }
472+
473+ // If not set, default to true if not public, false if public.
474+ if ( null === $args['exclude_from_search'] ) {
475+ $args['exclude_from_search'] = ! $args['public'];
476+ }
477+
478+ // Back compat with quirky handling in version 3.0. #14122.
479+ if ( empty( $args['capabilities'] ) && null === $args['map_meta_cap'] && in_array( $args['capability_type'], array( 'post', 'page' ) ) ) {
480+ $args['map_meta_cap'] = true;
481+ }
482+
483+ // If not set, default to false.
484+ if ( null === $args['map_meta_cap'] ) {
485+ $args['map_meta_cap'] = false;
486+ }
487+
488+ // If there's no specified edit link and no UI, remove the edit link.
489+ if ( ! $args['show_ui'] && ! $has_edit_link ) {
490+ $args['_edit_link'] = '';
491+ }
492+
493+ $this->cap = get_post_type_capabilities( (object) $args );
494+ unset( $args['capabilities'] );
495+
496+ if ( is_array( $args['capability_type'] ) ) {
497+ $args['capability_type'] = $args['capability_type'][0];
498+ }
499+
500+ if ( false !== $args['query_var'] ) {
501+ if ( true === $args['query_var'] ) {
502+ $args['query_var'] = $this->name;
503+ } else {
504+ $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
505+ }
506+ }
507+
508+ if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
509+ if ( ! is_array( $args['rewrite'] ) ) {
510+ $args['rewrite'] = array();
511+ }
512+ if ( empty( $args['rewrite']['slug'] ) ) {
513+ $args['rewrite']['slug'] = $this->name;
514+ }
515+ if ( ! isset( $args['rewrite']['with_front'] ) ) {
516+ $args['rewrite']['with_front'] = true;
517+ }
518+ if ( ! isset( $args['rewrite']['pages'] ) ) {
519+ $args['rewrite']['pages'] = true;
520+ }
521+ if ( ! isset( $args['rewrite']['feeds'] ) || ! $args['has_archive'] ) {
522+ $args['rewrite']['feeds'] = (bool) $args['has_archive'];
523+ }
524+ if ( ! isset( $args['rewrite']['ep_mask'] ) ) {
525+ if ( isset( $args['permalink_epmask'] ) ) {
526+ $args['rewrite']['ep_mask'] = $args['permalink_epmask'];
527+ } else {
528+ $args['rewrite']['ep_mask'] = EP_PERMALINK;
529+ }
530+ }
531+ }
532+
533+ foreach ( $args as $property_name => $property_value ) {
534+ $this->$property_name = $property_value;
535+ }
536+
537+ $this->labels = get_post_type_labels( $this );
538+ $this->label = $this->labels->name;
539+ }
540+
541+ /**
542+ * Sets the features support for the post type.
543+ *
544+ * @since 4.6.0
545+ * @access public
546+ */
547+ public function add_supports() {
548+ if ( ! empty( $this->supports ) ) {
549+ add_post_type_support( $this->name, $this->supports );
550+ unset( $this->supports );
551+ } elseif ( false !== $this->supports ) {
552+ // Add default features.
553+ add_post_type_support( $this->name, array( 'title', 'editor' ) );
554+ }
555+ }
556+
557+ /**
558+ * Adds the necessary rewrite rules for the post type.
559+ *
560+ * @since 4.6.0
561+ * @access public
562+ *
563+ * @global WP_Rewrite $wp_rewrite WordPress Rewrite Component.
564+ * @global WP $wp Current WordPress environment instance.
565+ */
566+ public function add_rewrite_rules() {
567+ global $wp_rewrite, $wp;
568+
569+ if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) {
570+ $wp->add_query_var( $this->query_var );
571+ }
572+
573+ if ( false !== $this->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
574+ if ( $this->hierarchical ) {
575+ add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
576+ } else {
577+ add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
578+ }
579+
580+ if ( $this->has_archive ) {
581+ $archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive;
582+ if ( $this->rewrite['with_front'] ) {
583+ $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
584+ } else {
585+ $archive_slug = $wp_rewrite->root . $archive_slug;
586+ }
587+
588+ add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$this->name", 'top' );
589+ if ( $this->rewrite['feeds'] && $wp_rewrite->feeds ) {
590+ $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
591+ add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
592+ add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
593+ }
594+ if ( $this->rewrite['pages'] ) {
595+ add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$this->name" . '&paged=$matches[1]', 'top' );
596+ }
597+ }
598+
599+ $permastruct_args = $this->rewrite;
600+ $permastruct_args['feed'] = $permastruct_args['feeds'];
601+ add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $permastruct_args );
602+ }
603+ }
604+
605+ /**
606+ * Registers the post type meta box if a custom callback was specified.
607+ *
608+ * @since 4.6.0
609+ * @access public
610+ */
611+ public function register_meta_boxes() {
612+ if ( $this->register_meta_box_cb ) {
613+ add_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10, 1 );
614+ }
615+ }
616+
617+ /**
618+ * Adds the future post hook action for the post type.
619+ *
620+ * @since 4.6.0
621+ * @access public
622+ */
623+ public function add_hooks() {
624+ add_action( 'future_' . $this->name, '_future_post_hook', 5, 2 );
625+ }
626+
627+ /**
628+ * Registers the taxonomies for the post type.
629+ *
630+ * @since 4.6.0
631+ * @access public
632+ */
633+ public function register_taxonomies() {
634+ foreach ( $this->taxonomies as $taxonomy ) {
635+ register_taxonomy_for_object_type( $taxonomy, $this->name );
636+ }
637+ }
638+
639+ /**
640+ * Removes the features support for the post type.
641+ *
642+ * @since 4.6.0
643+ * @access public
644+ *
645+ * @global array $_wp_post_type_features Post type features.
646+ */
647+ public function remove_supports() {
648+ global $_wp_post_type_features;
649+
650+ unset( $_wp_post_type_features[ $this->name ] );
651+ }
652+
653+ /**
654+ * Removes any rewrite rules, permastructs, and rules for the post type.
655+ *
656+ * @since 4.6.0
657+ * @access public
658+ *
659+ * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
660+ * @global WP $wp Current WordPress environment instance.
661+ * @global array $post_type_meta_caps Used to remove meta capabilities.
662+ */
663+ public function remove_rewrite_rules() {
664+ global $wp, $wp_rewrite, $post_type_meta_caps;
665+
666+ // Remove query var.
667+ if ( false !== $this->query_var ) {
668+ $wp->remove_query_var( $this->query_var );
669+ }
670+
671+ // Remove any rewrite rules, permastructs, and rules.
672+ if ( false !== $this->rewrite ) {
673+ remove_rewrite_tag( "%$this->name%" );
674+ remove_permastruct( $this->name );
675+ foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) {
676+ if ( false !== strpos( $query, "index.php?post_type=$this->name" ) ) {
677+ unset( $wp_rewrite->extra_rules_top[ $regex ] );
678+ }
679+ }
680+ }
681+
682+ // Remove registered custom meta capabilities.
683+ foreach ( $this->cap as $cap ) {
684+ unset( $post_type_meta_caps[ $cap ] );
685+ }
686+ }
687+
688+ /**
689+ * Unregisters the post type meta box if a custom callback was specified.
690+ *
691+ * @since 4.6.0
692+ * @access public
693+ */
694+ public function unregister_meta_boxes() {
695+ if ( $this->register_meta_box_cb ) {
696+ remove_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10 );
697+ }
698+ }
699+
700+ /**
701+ * Removes the post type from all taxonomies.
702+ *
703+ * @since 4.6.0
704+ * @access public
705+ */
706+ public function unregister_taxonomies() {
707+ foreach ( get_object_taxonomies( $this->name ) as $taxonomy ) {
708+ unregister_taxonomy_for_object_type( $taxonomy, $this->name );
709+ }
710+ }
711+
712+ /**
713+ * Removes the future post hook action for the post type.
714+ *
715+ * @since 4.6.0
716+ * @access public
717+ */
718+ public function remove_hooks() {
719+ remove_action( 'future_' . $this->name, '_future_post_hook', 5 );
720+ }
721+}
旧リポジトリブラウザで表示