Changeset 37890
- Timestamp:
- 06/28/2016 04:40:33 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-form-advanced.php
r37674 r37890 12 12 13 13 /** 14 * @global string $post_type15 * @global object$post_type_object16 * @global WP_Post $post14 * @global string $post_type 15 * @global WP_Post_Type $post_type_object 16 * @global WP_Post $post 17 17 */ 18 18 global $post_type, $post_type_object, $post; -
trunk/src/wp-admin/edit.php
r37680 r37890 24 24 25 25 /** 26 * @global string $post_type27 * @global object$post_type_object26 * @global string $post_type 27 * @global WP_Post_Type $post_type_object 28 28 */ 29 29 global $post_type, $post_type_object; -
trunk/src/wp-admin/includes/class-wp-posts-list-table.php
r37856 r37890 73 73 * @see WP_List_Table::__construct() for more information on default arguments. 74 74 * 75 * @global object$post_type_object76 * @global wpdb $wpdb75 * @global WP_Post_Type $post_type_object 76 * @global wpdb $wpdb 77 77 * 78 78 * @param array $args An associative array of arguments. -
trunk/src/wp-admin/includes/nav-menu.php
r37881 r37890 523 523 * @see WP_Query::query() 524 524 * 525 * @param array $posts The posts for the current post type.526 * @param array $args An array of WP_Query arguments.527 * @param object$post_type The current post type object for this menu item meta box.525 * @param array $posts The posts for the current post type. 526 * @param array $args An array of WP_Query arguments. 527 * @param WP_Post_Type $post_type The current post type object for this menu item meta box. 528 528 */ 529 529 $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); -
trunk/src/wp-includes/class-wp-xmlrpc-server.php
r37674 r37890 884 884 * @access protected 885 885 * 886 * @param object$post_type Post type object.887 * @param array $fields The subset of post fields to return.886 * @param WP_Post_Type $post_type Post type object. 887 * @param array $fields The subset of post fields to return. 888 888 * @return array The prepared post type data. 889 889 */ … … 923 923 * @since 3.4.0 924 924 * 925 * @param array $_post_type An array of post type data.926 * @param object$post_type Post type object.925 * @param array $_post_type An array of post type data. 926 * @param WP_Post_Type $post_type Post type object. 927 927 */ 928 928 return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); -
trunk/src/wp-includes/post.php
r37886 r37890 820 820 821 821 /** 822 * Retrieve the post type of the current post or of a given post.822 * Retrieves the post type of the current post or of a given post. 823 823 * 824 824 * @since 2.1.0 … … 835 835 836 836 /** 837 * Retrieve a post type object by name.837 * Retrieves a post type object by name. 838 838 * 839 839 * @since 3.0.0 … … 844 844 * 845 845 * @param string $post_type The name of a registered post type. 846 * @return object|null A post type object.846 * @return WP_Post_Type|null WP_Post_Type object if it exists, null otherwise. 847 847 */ 848 848 function get_post_type_object( $post_type ) { … … 900 900 * @since 4.4.0 The `show_ui` argument is now enforced on the post type listing 901 901 * screen and post editing screen. 902 * 903 * @global array $wp_post_types List of post types. 904 * @global WP_Rewrite $wp_rewrite Used for default feeds. 905 * @global WP $wp Used to add query vars. 902 * @since 4.6.0 Converted to use `WP_Post_Type`. 903 * 904 * @global array $wp_post_types List of post types. 906 905 * 907 906 * @param string $post_type Post type key. Must not exceed 20 characters and may … … 1012 1011 * this post type. Default 'post.php?post=%d'. 1013 1012 * } 1014 * @return object|WP_Error The registered post type object, or an error object.1013 * @return WP_Post_Type|WP_Error The registered post type object, or an error object. 1015 1014 */ 1016 1015 function register_post_type( $post_type, $args = array() ) { 1017 global $wp_post_types , $wp_rewrite, $wp;1016 global $wp_post_types; 1018 1017 1019 1018 if ( ! is_array( $wp_post_types ) ) { … … 1023 1022 // Sanitize post type name 1024 1023 $post_type = sanitize_key( $post_type ); 1025 $args = wp_parse_args( $args );1026 1027 /**1028 * Filters the arguments for registering a post type.1029 *1030 * @since 4.4.01031 *1032 * @param array $args Array of arguments for registering a post type.1033 * @param string $post_type Post type key.1034 */1035 $args = apply_filters( 'register_post_type_args', $args, $post_type );1036 1037 $has_edit_link = ! empty( $args['_edit_link'] );1038 1039 // Args prefixed with an underscore are reserved for internal use.1040 $defaults = array(1041 'labels' => array(),1042 'description' => '',1043 'public' => false,1044 'hierarchical' => false,1045 'exclude_from_search' => null,1046 'publicly_queryable' => null,1047 'show_ui' => null,1048 'show_in_menu' => null,1049 'show_in_nav_menus' => null,1050 'show_in_admin_bar' => null,1051 'menu_position' => null,1052 'menu_icon' => null,1053 'capability_type' => 'post',1054 'capabilities' => array(),1055 'map_meta_cap' => null,1056 'supports' => array(),1057 'register_meta_box_cb' => null,1058 'taxonomies' => array(),1059 'has_archive' => false,1060 'rewrite' => true,1061 'query_var' => true,1062 'can_export' => true,1063 'delete_with_user' => null,1064 '_builtin' => false,1065 '_edit_link' => 'post.php?post=%d',1066 );1067 $args = array_merge( $defaults, $args );1068 $args = (object) $args;1069 1070 $args->name = $post_type;1071 1024 1072 1025 if ( empty( $post_type ) || strlen( $post_type ) > 20 ) { … … 1075 1028 } 1076 1029 1077 // If not set, default to the setting for public. 1078 if ( null === $args->publicly_queryable ) 1079 $args->publicly_queryable = $args->public; 1080 1081 // If not set, default to the setting for public. 1082 if ( null === $args->show_ui ) 1083 $args->show_ui = $args->public; 1084 1085 // If not set, default to the setting for show_ui. 1086 if ( null === $args->show_in_menu || ! $args->show_ui ) 1087 $args->show_in_menu = $args->show_ui; 1088 1089 // If not set, default to the whether the full UI is shown. 1090 if ( null === $args->show_in_admin_bar ) 1091 $args->show_in_admin_bar = (bool) $args->show_in_menu; 1092 1093 // If not set, default to the setting for public. 1094 if ( null === $args->show_in_nav_menus ) 1095 $args->show_in_nav_menus = $args->public; 1096 1097 // If not set, default to true if not public, false if public. 1098 if ( null === $args->exclude_from_search ) 1099 $args->exclude_from_search = !$args->public; 1100 1101 // Back compat with quirky handling in version 3.0. #14122. 1102 if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) ) 1103 $args->map_meta_cap = true; 1104 1105 // If not set, default to false. 1106 if ( null === $args->map_meta_cap ) 1107 $args->map_meta_cap = false; 1108 1109 // If there's no specified edit link and no UI, remove the edit link. 1110 if ( ! $args->show_ui && ! $has_edit_link ) { 1111 $args->_edit_link = ''; 1112 } 1113 1114 $args->cap = get_post_type_capabilities( $args ); 1115 unset( $args->capabilities ); 1116 1117 if ( is_array( $args->capability_type ) ) 1118 $args->capability_type = $args->capability_type[0]; 1119 1120 if ( ! empty( $args->supports ) ) { 1121 add_post_type_support( $post_type, $args->supports ); 1122 unset( $args->supports ); 1123 } elseif ( false !== $args->supports ) { 1124 // Add default features 1125 add_post_type_support( $post_type, array( 'title', 'editor' ) ); 1126 } 1127 1128 if ( false !== $args->query_var ) { 1129 if ( true === $args->query_var ) 1130 $args->query_var = $post_type; 1131 else 1132 $args->query_var = sanitize_title_with_dashes( $args->query_var ); 1133 1134 if ( $wp && is_post_type_viewable( $args ) ) { 1135 $wp->add_query_var( $args->query_var ); 1136 } 1137 } 1138 1139 if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { 1140 if ( ! is_array( $args->rewrite ) ) 1141 $args->rewrite = array(); 1142 if ( empty( $args->rewrite['slug'] ) ) 1143 $args->rewrite['slug'] = $post_type; 1144 if ( ! isset( $args->rewrite['with_front'] ) ) 1145 $args->rewrite['with_front'] = true; 1146 if ( ! isset( $args->rewrite['pages'] ) ) 1147 $args->rewrite['pages'] = true; 1148 if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive ) 1149 $args->rewrite['feeds'] = (bool) $args->has_archive; 1150 if ( ! isset( $args->rewrite['ep_mask'] ) ) { 1151 if ( isset( $args->permalink_epmask ) ) 1152 $args->rewrite['ep_mask'] = $args->permalink_epmask; 1153 else 1154 $args->rewrite['ep_mask'] = EP_PERMALINK; 1155 } 1156 1157 if ( $args->hierarchical ) 1158 add_rewrite_tag( "%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&pagename=" ); 1159 else 1160 add_rewrite_tag( "%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" ); 1161 1162 if ( $args->has_archive ) { 1163 $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive; 1164 if ( $args->rewrite['with_front'] ) 1165 $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; 1166 else 1167 $archive_slug = $wp_rewrite->root . $archive_slug; 1168 1169 add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' ); 1170 if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) { 1171 $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; 1172 add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); 1173 add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); 1174 } 1175 if ( $args->rewrite['pages'] ) 1176 add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' ); 1177 } 1178 1179 $permastruct_args = $args->rewrite; 1180 $permastruct_args['feed'] = $permastruct_args['feeds']; 1181 add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args ); 1182 } 1183 1184 // Register the post type meta box if a custom callback was specified. 1185 if ( $args->register_meta_box_cb ) 1186 add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 ); 1187 1188 $args->labels = get_post_type_labels( $args ); 1189 $args->label = $args->labels->name; 1190 1191 $wp_post_types[ $post_type ] = $args; 1192 1193 add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 ); 1194 1195 foreach ( $args->taxonomies as $taxonomy ) { 1196 register_taxonomy_for_object_type( $taxonomy, $post_type ); 1197 } 1030 $post_type_object = new WP_Post_Type( $post_type, $args ); 1031 $post_type_object->add_supports(); 1032 $post_type_object->add_rewrite_rules(); 1033 $post_type_object->register_meta_boxes(); 1034 1035 $wp_post_types[ $post_type ] = $post_type_object; 1036 1037 $post_type_object->add_hooks(); 1038 $post_type_object->register_taxonomies(); 1198 1039 1199 1040 /** … … 1202 1043 * @since 3.3.0 1203 1044 * 1204 * @param string $post_typePost type.1205 * @param object $argsArguments used to register the post type.1045 * @param string $post_type Post type. 1046 * @param WP_Post_Type $post_type_object Arguments used to register the post type. 1206 1047 */ 1207 do_action( 'registered_post_type', $post_type, $ args);1208 1209 return $ args;1048 do_action( 'registered_post_type', $post_type, $post_type_object ); 1049 1050 return $post_type_object; 1210 1051 } 1211 1052 … … 1216 1057 * 1217 1058 * @since 4.5.0 1218 * 1219 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 1220 * @global WP $wp Current WordPress environment instance. 1221 * @global array $_wp_post_type_features Used to remove post type features. 1222 * @global array $post_type_meta_caps Used to remove meta capabilities. 1223 * @global array $wp_post_types List of post types. 1059 * @since 4.6.0 Converted to use `WP_Post_Type`. 1060 * 1061 * @global array $wp_post_types List of post types. 1224 1062 * 1225 1063 * @param string $post_type Post type to unregister. … … 1227 1065 */ 1228 1066 function unregister_post_type( $post_type ) { 1067 global $wp_post_types; 1068 1229 1069 if ( ! post_type_exists( $post_type ) ) { 1230 1070 return new WP_Error( 'invalid_post_type', __( 'Invalid post type' ) ); 1231 1071 } 1232 1072 1233 $post_type_ args= get_post_type_object( $post_type );1073 $post_type_object = get_post_type_object( $post_type ); 1234 1074 1235 1075 // Do not allow unregistering internal post types. 1236 if ( $post_type_ args->_builtin ) {1076 if ( $post_type_object->_builtin ) { 1237 1077 return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); 1238 1078 } 1239 1079 1240 global $wp, $wp_rewrite, $_wp_post_type_features, $post_type_meta_caps, $wp_post_types; 1241 1242 // Remove query var. 1243 if ( false !== $post_type_args->query_var ) { 1244 $wp->remove_query_var( $post_type_args->query_var ); 1245 } 1246 1247 // Remove any rewrite rules, permastructs, and rules. 1248 if ( false !== $post_type_args->rewrite ) { 1249 remove_rewrite_tag( "%$post_type%" ); 1250 remove_permastruct( $post_type ); 1251 foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) { 1252 if ( false !== strpos( $query, "index.php?post_type=$post_type" ) ) { 1253 unset( $wp_rewrite->extra_rules_top[ $regex ] ); 1254 } 1255 } 1256 } 1257 1258 // Remove registered custom meta capabilities. 1259 foreach ( $post_type_args->cap as $cap ) { 1260 unset( $post_type_meta_caps[ $cap ] ); 1261 } 1262 1263 // Remove all post type support. 1264 unset( $_wp_post_type_features[ $post_type ] ); 1265 1266 // Unregister the post type meta box if a custom callback was specified. 1267 if ( $post_type_args->register_meta_box_cb ) { 1268 remove_action( 'add_meta_boxes_' . $post_type, $post_type_args->register_meta_box_cb ); 1269 } 1270 1271 // Remove the post type from all taxonomies. 1272 foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) { 1273 unregister_taxonomy_for_object_type( $taxonomy, $post_type ); 1274 } 1275 1276 // Remove the future post hook action. 1277 remove_action( 'future_' . $post_type, '_future_post_hook', 5 ); 1278 1279 // Remove the post type. 1080 $post_type_object->remove_supports(); 1081 $post_type_object->remove_rewrite_rules(); 1082 $post_type_object->unregister_meta_boxes(); 1083 $post_type_object->remove_hooks(); 1084 $post_type_object->unregister_taxonomies(); 1085 1280 1086 unset( $wp_post_types[ $post_type ] ); 1281 1087 … … 1463 1269 * @access private 1464 1270 * 1465 * @param object $post_type_object Post type object.1271 * @param object|WP_Post_Type $post_type_object Post type object. 1466 1272 * @return object Object with all the labels as member variables. 1467 1273 */ … … 1718 1524 * @since 4.5.0 Added the ability to pass a post type name in addition to object. 1719 1525 * 1720 * @param object$post_type Post type name or object.1526 * @param string|WP_Post_Type $post_type Post type name or object. 1721 1527 * @return bool Whether the post type should be considered viewable. 1722 1528 */ -
trunk/src/wp-settings.php
r37864 r37890 159 159 require( ABSPATH . WPINC . '/class-walker-page.php' ); 160 160 require( ABSPATH . WPINC . '/class-walker-page-dropdown.php' ); 161 require( ABSPATH . WPINC . '/class-wp-post-type.php' ); 161 162 require( ABSPATH . WPINC . '/class-wp-post.php' ); 162 163 require( ABSPATH . WPINC . '/post-template.php' ); -
trunk/tests/phpunit/tests/post/types.php
r37459 r37890 30 30 31 31 $pobj = get_post_type_object( 'foo' ); 32 $this->assertInstanceOf( ' stdClass', $pobj );32 $this->assertInstanceOf( 'WP_Post_Type', $pobj ); 33 33 $this->assertEquals( 'foo', $pobj->name ); 34 34 … … 555 555 * 556 556 * @param array $args register_post_type() arguments. 557 * @return stdClassPost type object for `$this->post_type`.557 * @return WP_Post_Type Post type object for `$this->post_type`. 558 558 */ 559 559 public function register_post_type( $args = array() ) {
Note: See TracChangeset
for help on using the changeset viewer.