wp/wp-includes/post.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    16  * See {@see 'init'}.
    16  * See {@see 'init'}.
    17  *
    17  *
    18  * @since 2.9.0
    18  * @since 2.9.0
    19  */
    19  */
    20 function create_initial_post_types() {
    20 function create_initial_post_types() {
       
    21 	WP_Post_Type::reset_default_labels();
       
    22 
    21 	register_post_type(
    23 	register_post_type(
    22 		'post',
    24 		'post',
    23 		array(
    25 		array(
    24 			'labels'                => array(
    26 			'labels'                => array(
    25 				'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
    27 				'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
   124 	);
   126 	);
   125 
   127 
   126 	register_post_type(
   128 	register_post_type(
   127 		'nav_menu_item',
   129 		'nav_menu_item',
   128 		array(
   130 		array(
   129 			'labels'           => array(
   131 			'labels'                => array(
   130 				'name'          => __( 'Navigation Menu Items' ),
   132 				'name'          => __( 'Navigation Menu Items' ),
   131 				'singular_name' => __( 'Navigation Menu Item' ),
   133 				'singular_name' => __( 'Navigation Menu Item' ),
   132 			),
   134 			),
   133 			'public'           => false,
   135 			'public'                => false,
   134 			'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
   136 			'_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
   135 			'hierarchical'     => false,
   137 			'hierarchical'          => false,
   136 			'rewrite'          => false,
   138 			'rewrite'               => false,
   137 			'delete_with_user' => false,
   139 			'delete_with_user'      => false,
   138 			'query_var'        => false,
   140 			'query_var'             => false,
       
   141 			'map_meta_cap'          => true,
       
   142 			'capability_type'       => array( 'edit_theme_options', 'edit_theme_options' ),
       
   143 			'capabilities'          => array(
       
   144 				// Meta Capabilities.
       
   145 				'edit_post'              => 'edit_post',
       
   146 				'read_post'              => 'read_post',
       
   147 				'delete_post'            => 'delete_post',
       
   148 				// Primitive Capabilities.
       
   149 				'edit_posts'             => 'edit_theme_options',
       
   150 				'edit_others_posts'      => 'edit_theme_options',
       
   151 				'delete_posts'           => 'edit_theme_options',
       
   152 				'publish_posts'          => 'edit_theme_options',
       
   153 				'read_private_posts'     => 'edit_theme_options',
       
   154 				'read'                   => 'read',
       
   155 				'delete_private_posts'   => 'edit_theme_options',
       
   156 				'delete_published_posts' => 'edit_theme_options',
       
   157 				'delete_others_posts'    => 'edit_theme_options',
       
   158 				'edit_private_posts'     => 'edit_theme_options',
       
   159 				'edit_published_posts'   => 'edit_theme_options',
       
   160 			),
       
   161 			'show_in_rest'          => true,
       
   162 			'rest_base'             => 'menu-items',
       
   163 			'rest_controller_class' => 'WP_REST_Menu_Items_Controller',
   139 		)
   164 		)
   140 	);
   165 	);
   141 
   166 
   142 	register_post_type(
   167 	register_post_type(
   143 		'custom_css',
   168 		'custom_css',
   308 
   333 
   309 	register_post_type(
   334 	register_post_type(
   310 		'wp_template',
   335 		'wp_template',
   311 		array(
   336 		array(
   312 			'labels'                => array(
   337 			'labels'                => array(
   313 				'name'                  => __( 'Templates' ),
   338 				'name'                  => _x( 'Templates', 'post type general name' ),
   314 				'singular_name'         => __( 'Template' ),
   339 				'singular_name'         => _x( 'Template', 'post type singular name' ),
   315 				'add_new'               => _x( 'Add New', 'Template' ),
   340 				'add_new'               => _x( 'Add New', 'Template' ),
   316 				'add_new_item'          => __( 'Add New Template' ),
   341 				'add_new_item'          => __( 'Add New Template' ),
   317 				'new_item'              => __( 'New Template' ),
   342 				'new_item'              => __( 'New Template' ),
   318 				'edit_item'             => __( 'Edit Template' ),
   343 				'edit_item'             => __( 'Edit Template' ),
   319 				'view_item'             => __( 'View Template' ),
   344 				'view_item'             => __( 'View Template' ),
   320 				'all_items'             => __( 'All Templates' ),
   345 				'all_items'             => __( 'Templates' ),
   321 				'search_items'          => __( 'Search Templates' ),
   346 				'search_items'          => __( 'Search Templates' ),
   322 				'parent_item_colon'     => __( 'Parent Template:' ),
   347 				'parent_item_colon'     => __( 'Parent Template:' ),
   323 				'not_found'             => __( 'No templates found.' ),
   348 				'not_found'             => __( 'No templates found.' ),
   324 				'not_found_in_trash'    => __( 'No templates found in Trash.' ),
   349 				'not_found_in_trash'    => __( 'No templates found in Trash.' ),
   325 				'archives'              => __( 'Template archives' ),
   350 				'archives'              => __( 'Template archives' ),
   359 				'title',
   384 				'title',
   360 				'slug',
   385 				'slug',
   361 				'excerpt',
   386 				'excerpt',
   362 				'editor',
   387 				'editor',
   363 				'revisions',
   388 				'revisions',
       
   389 				'author',
       
   390 			),
       
   391 		)
       
   392 	);
       
   393 
       
   394 	register_post_type(
       
   395 		'wp_template_part',
       
   396 		array(
       
   397 			'labels'                => array(
       
   398 				'name'                  => _x( 'Template Parts', 'post type general name' ),
       
   399 				'singular_name'         => _x( 'Template Part', 'post type singular name' ),
       
   400 				'add_new'               => _x( 'Add New', 'Template Part' ),
       
   401 				'add_new_item'          => __( 'Add New Template Part' ),
       
   402 				'new_item'              => __( 'New Template Part' ),
       
   403 				'edit_item'             => __( 'Edit Template Part' ),
       
   404 				'view_item'             => __( 'View Template Part' ),
       
   405 				'all_items'             => __( 'Template Parts' ),
       
   406 				'search_items'          => __( 'Search Template Parts' ),
       
   407 				'parent_item_colon'     => __( 'Parent Template Part:' ),
       
   408 				'not_found'             => __( 'No template parts found.' ),
       
   409 				'not_found_in_trash'    => __( 'No template parts found in Trash.' ),
       
   410 				'archives'              => __( 'Template part archives' ),
       
   411 				'insert_into_item'      => __( 'Insert into template part' ),
       
   412 				'uploaded_to_this_item' => __( 'Uploaded to this template part' ),
       
   413 				'filter_items_list'     => __( 'Filter template parts list' ),
       
   414 				'items_list_navigation' => __( 'Template parts list navigation' ),
       
   415 				'items_list'            => __( 'Template parts list' ),
       
   416 			),
       
   417 			'description'           => __( 'Template parts to include in your templates.' ),
       
   418 			'public'                => false,
       
   419 			'_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
       
   420 			'has_archive'           => false,
       
   421 			'show_ui'               => false,
       
   422 			'show_in_menu'          => false,
       
   423 			'show_in_rest'          => true,
       
   424 			'rewrite'               => false,
       
   425 			'rest_base'             => 'template-parts',
       
   426 			'rest_controller_class' => 'WP_REST_Templates_Controller',
       
   427 			'map_meta_cap'          => true,
       
   428 			'capabilities'          => array(
       
   429 				'create_posts'           => 'edit_theme_options',
       
   430 				'delete_posts'           => 'edit_theme_options',
       
   431 				'delete_others_posts'    => 'edit_theme_options',
       
   432 				'delete_private_posts'   => 'edit_theme_options',
       
   433 				'delete_published_posts' => 'edit_theme_options',
       
   434 				'edit_posts'             => 'edit_theme_options',
       
   435 				'edit_others_posts'      => 'edit_theme_options',
       
   436 				'edit_private_posts'     => 'edit_theme_options',
       
   437 				'edit_published_posts'   => 'edit_theme_options',
       
   438 				'publish_posts'          => 'edit_theme_options',
       
   439 				'read'                   => 'edit_theme_options',
       
   440 				'read_private_posts'     => 'edit_theme_options',
       
   441 			),
       
   442 			'supports'              => array(
       
   443 				'title',
       
   444 				'slug',
       
   445 				'excerpt',
       
   446 				'editor',
       
   447 				'revisions',
       
   448 				'author',
       
   449 			),
       
   450 		)
       
   451 	);
       
   452 
       
   453 	register_post_type(
       
   454 		'wp_global_styles',
       
   455 		array(
       
   456 			'label'        => _x( 'Global Styles', 'post type general name' ),
       
   457 			'description'  => __( 'Global styles to include in themes.' ),
       
   458 			'public'       => false,
       
   459 			'_builtin'     => true, /* internal use only. don't use this when registering your own post type. */
       
   460 			'show_ui'      => false,
       
   461 			'show_in_rest' => false,
       
   462 			'rewrite'      => false,
       
   463 			'capabilities' => array(
       
   464 				'read'                   => 'edit_theme_options',
       
   465 				'create_posts'           => 'edit_theme_options',
       
   466 				'edit_posts'             => 'edit_theme_options',
       
   467 				'edit_published_posts'   => 'edit_theme_options',
       
   468 				'delete_published_posts' => 'edit_theme_options',
       
   469 				'edit_others_posts'      => 'edit_theme_options',
       
   470 				'delete_others_posts'    => 'edit_theme_options',
       
   471 			),
       
   472 			'map_meta_cap' => true,
       
   473 			'supports'     => array(
       
   474 				'title',
       
   475 				'editor',
       
   476 				'revisions',
       
   477 			),
       
   478 		)
       
   479 	);
       
   480 
       
   481 	register_post_type(
       
   482 		'wp_navigation',
       
   483 		array(
       
   484 			'labels'                => array(
       
   485 				'name'                  => _x( 'Navigation Menus', 'post type general name' ),
       
   486 				'singular_name'         => _x( 'Navigation Menu', 'post type singular name' ),
       
   487 				'add_new'               => _x( 'Add New', 'Navigation Menu' ),
       
   488 				'add_new_item'          => __( 'Add New Navigation Menu' ),
       
   489 				'new_item'              => __( 'New Navigation Menu' ),
       
   490 				'edit_item'             => __( 'Edit Navigation Menu' ),
       
   491 				'view_item'             => __( 'View Navigation Menu' ),
       
   492 				'all_items'             => __( 'Navigation Menus' ),
       
   493 				'search_items'          => __( 'Search Navigation Menus' ),
       
   494 				'parent_item_colon'     => __( 'Parent Navigation Menu:' ),
       
   495 				'not_found'             => __( 'No Navigation Menu found.' ),
       
   496 				'not_found_in_trash'    => __( 'No Navigation Menu found in Trash.' ),
       
   497 				'archives'              => __( 'Navigation Menu archives' ),
       
   498 				'insert_into_item'      => __( 'Insert into Navigation Menu' ),
       
   499 				'uploaded_to_this_item' => __( 'Uploaded to this Navigation Menu' ),
       
   500 				'filter_items_list'     => __( 'Filter Navigation Menu list' ),
       
   501 				'items_list_navigation' => __( 'Navigation Menus list navigation' ),
       
   502 				'items_list'            => __( 'Navigation Menus list' ),
       
   503 			),
       
   504 			'description'           => __( 'Navigation menus that can be inserted into your site.' ),
       
   505 			'public'                => false,
       
   506 			'_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
       
   507 			'has_archive'           => false,
       
   508 			'show_ui'               => true,
       
   509 			'show_in_menu'          => false,
       
   510 			'show_in_admin_bar'     => false,
       
   511 			'show_in_rest'          => true,
       
   512 			'rewrite'               => false,
       
   513 			'map_meta_cap'          => true,
       
   514 			'capabilities'          => array(
       
   515 				'edit_others_posts'      => 'edit_theme_options',
       
   516 				'delete_posts'           => 'edit_theme_options',
       
   517 				'publish_posts'          => 'edit_theme_options',
       
   518 				'create_posts'           => 'edit_theme_options',
       
   519 				'read_private_posts'     => 'edit_theme_options',
       
   520 				'delete_private_posts'   => 'edit_theme_options',
       
   521 				'delete_published_posts' => 'edit_theme_options',
       
   522 				'delete_others_posts'    => 'edit_theme_options',
       
   523 				'edit_private_posts'     => 'edit_theme_options',
       
   524 				'edit_published_posts'   => 'edit_theme_options',
       
   525 				'edit_posts'             => 'edit_theme_options',
       
   526 			),
       
   527 			'rest_base'             => 'navigation',
       
   528 			'rest_controller_class' => 'WP_REST_Posts_Controller',
       
   529 			'supports'              => array(
       
   530 				'title',
       
   531 				'editor',
       
   532 				'revisions',
   364 			),
   533 			),
   365 		)
   534 		)
   366 	);
   535 	);
   367 
   536 
   368 	register_post_status(
   537 	register_post_status(
   805  *
   974  *
   806  * @since 1.5.1
   975  * @since 1.5.1
   807  *
   976  *
   808  * @global WP_Post $post Global post object.
   977  * @global WP_Post $post Global post object.
   809  *
   978  *
   810  * @param int|WP_Post|null $post   Optional. Post ID or post object. `null`, `false`, `0` and other PHP falsey
   979  * @param int|WP_Post|null $post   Optional. Post ID or post object. `null`, `false`, `0` and other PHP falsey values
   811  *                                 values return the current global post inside the loop. A numerically valid post
   980  *                                 return the current global post inside the loop. A numerically valid post ID that
   812  *                                 ID that points to a non-existent post returns `null`. Defaults to global $post.
   981  *                                 points to a non-existent post returns `null`. Defaults to global $post.
   813  * @param string           $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
   982  * @param string           $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
   814  *                                 correspond to a WP_Post object, an associative array, or a numeric array,
   983  *                                 correspond to a WP_Post object, an associative array, or a numeric array,
   815  *                                 respectively. Default OBJECT.
   984  *                                 respectively. Default OBJECT.
   816  * @param string           $filter Optional. Type of filter to apply. Accepts 'raw', 'edit', 'db',
   985  * @param string           $filter Optional. Type of filter to apply. Accepts 'raw', 'edit', 'db',
   817  *                                 or 'display'. Default 'raw'.
   986  *                                 or 'display'. Default 'raw'.
   947  * If the post ID is of an attachment, then the parent post status will be given
  1116  * If the post ID is of an attachment, then the parent post status will be given
   948  * instead.
  1117  * instead.
   949  *
  1118  *
   950  * @since 2.0.0
  1119  * @since 2.0.0
   951  *
  1120  *
   952  * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post..
  1121  * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
   953  * @return string|false Post status on success, false on failure.
  1122  * @return string|false Post status on success, false on failure.
   954  */
  1123  */
   955 function get_post_status( $post = null ) {
  1124 function get_post_status( $post = null ) {
   956 	$post = get_post( $post );
  1125 	$post = get_post( $post );
   957 
  1126 
  1075  *
  1244  *
  1076  * Arguments prefixed with an _underscore shouldn't be used by plugins and themes.
  1245  * Arguments prefixed with an _underscore shouldn't be used by plugins and themes.
  1077  *
  1246  *
  1078  * @since 3.0.0
  1247  * @since 3.0.0
  1079  *
  1248  *
  1080  * @global array $wp_post_statuses Inserts new post status object into the list
  1249  * @global stdClass[] $wp_post_statuses Inserts new post status object into the list
  1081  *
  1250  *
  1082  * @param string       $post_status Name of the post status.
  1251  * @param string       $post_status Name of the post status.
  1083  * @param array|string $args {
  1252  * @param array|string $args {
  1084  *     Optional. Array or string of post status arguments.
  1253  *     Optional. Array or string of post status arguments.
  1085  *
  1254  *
  1199 /**
  1368 /**
  1200  * Retrieve a post status object by name.
  1369  * Retrieve a post status object by name.
  1201  *
  1370  *
  1202  * @since 3.0.0
  1371  * @since 3.0.0
  1203  *
  1372  *
  1204  * @global array $wp_post_statuses List of post statuses.
  1373  * @global stdClass[] $wp_post_statuses List of post statuses.
  1205  *
  1374  *
  1206  * @see register_post_status()
  1375  * @see register_post_status()
  1207  *
  1376  *
  1208  * @param string $post_status The name of a registered post status.
  1377  * @param string $post_status The name of a registered post status.
  1209  * @return object|null A post status object.
  1378  * @return stdClass|null A post status object.
  1210  */
  1379  */
  1211 function get_post_status_object( $post_status ) {
  1380 function get_post_status_object( $post_status ) {
  1212 	global $wp_post_statuses;
  1381 	global $wp_post_statuses;
  1213 
  1382 
  1214 	if ( empty( $wp_post_statuses[ $post_status ] ) ) {
  1383 	if ( empty( $wp_post_statuses[ $post_status ] ) ) {
  1221 /**
  1390 /**
  1222  * Get a list of post statuses.
  1391  * Get a list of post statuses.
  1223  *
  1392  *
  1224  * @since 3.0.0
  1393  * @since 3.0.0
  1225  *
  1394  *
  1226  * @global array $wp_post_statuses List of post statuses.
  1395  * @global stdClass[] $wp_post_statuses List of post statuses.
  1227  *
  1396  *
  1228  * @see register_post_status()
  1397  * @see register_post_status()
  1229  *
  1398  *
  1230  * @param array|string $args     Optional. Array or string of post status arguments to compare against
  1399  * @param array|string $args     Optional. Array or string of post status arguments to compare against
  1231  *                               properties of the global `$wp_post_statuses objects`. Default empty array.
  1400  *                               properties of the global `$wp_post_statuses objects`. Default empty array.
  1232  * @param string       $output   Optional. The type of output to return, either 'names' or 'objects'. Default 'names'.
  1401  * @param string       $output   Optional. The type of output to return, either 'names' or 'objects'. Default 'names'.
  1233  * @param string       $operator Optional. The logical operation to perform. 'or' means only one element
  1402  * @param string       $operator Optional. The logical operation to perform. 'or' means only one element
  1234  *                               from the array needs to match; 'and' means all elements must match.
  1403  *                               from the array needs to match; 'and' means all elements must match.
  1235  *                               Default 'and'.
  1404  *                               Default 'and'.
  1236  * @return array A list of post status names or objects.
  1405  * @return string[]|stdClass[] A list of post status names or objects.
  1237  */
  1406  */
  1238 function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {
  1407 function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {
  1239 	global $wp_post_statuses;
  1408 	global $wp_post_statuses;
  1240 
  1409 
  1241 	$field = ( 'names' === $output ) ? 'name' : false;
  1410 	$field = ( 'names' === $output ) ? 'name' : false;
  1369  * @since 4.6.0 Post type object returned is now an instance of `WP_Post_Type`.
  1538  * @since 4.6.0 Post type object returned is now an instance of `WP_Post_Type`.
  1370  * @since 4.7.0 Introduced `show_in_rest`, `rest_base` and `rest_controller_class`
  1539  * @since 4.7.0 Introduced `show_in_rest`, `rest_base` and `rest_controller_class`
  1371  *              arguments to register the post type in REST API.
  1540  *              arguments to register the post type in REST API.
  1372  * @since 5.0.0 The `template` and `template_lock` arguments were added.
  1541  * @since 5.0.0 The `template` and `template_lock` arguments were added.
  1373  * @since 5.3.0 The `supports` argument will now accept an array of arguments for a feature.
  1542  * @since 5.3.0 The `supports` argument will now accept an array of arguments for a feature.
       
  1543  * @since 5.9.0 The `rest_namespace` argument was added.
  1374  *
  1544  *
  1375  * @global array $wp_post_types List of post types.
  1545  * @global array $wp_post_types List of post types.
  1376  *
  1546  *
  1377  * @param string       $post_type Post type key. Must not exceed 20 characters and may
  1547  * @param string       $post_type Post type key. Must not exceed 20 characters and may
  1378  *                                only contain lowercase alphanumeric characters, dashes,
  1548  *                                only contain lowercase alphanumeric characters, dashes,
  1389  *     @type string       $description           A short descriptive summary of what the post type is.
  1559  *     @type string       $description           A short descriptive summary of what the post type is.
  1390  *                                               Default empty.
  1560  *                                               Default empty.
  1391  *     @type bool         $public                Whether a post type is intended for use publicly either via
  1561  *     @type bool         $public                Whether a post type is intended for use publicly either via
  1392  *                                               the admin interface or by front-end users. While the default
  1562  *                                               the admin interface or by front-end users. While the default
  1393  *                                               settings of $exclude_from_search, $publicly_queryable, $show_ui,
  1563  *                                               settings of $exclude_from_search, $publicly_queryable, $show_ui,
  1394  *                                               and $show_in_nav_menus are inherited from public, each does not
  1564  *                                               and $show_in_nav_menus are inherited from $public, each does not
  1395  *                                               rely on this relationship and controls a very specific intention.
  1565  *                                               rely on this relationship and controls a very specific intention.
  1396  *                                               Default false.
  1566  *                                               Default false.
  1397  *     @type bool         $hierarchical          Whether the post type is hierarchical (e.g. page). Default false.
  1567  *     @type bool         $hierarchical          Whether the post type is hierarchical (e.g. page). Default false.
  1398  *     @type bool         $exclude_from_search   Whether to exclude posts with this post type from front end search
  1568  *     @type bool         $exclude_from_search   Whether to exclude posts with this post type from front end search
  1399  *                                               results. Default is the opposite value of $public.
  1569  *                                               results. Default is the opposite value of $public.
  1406  *     @type bool         $show_ui               Whether to generate and allow a UI for managing this post type in the
  1576  *     @type bool         $show_ui               Whether to generate and allow a UI for managing this post type in the
  1407  *                                               admin. Default is value of $public.
  1577  *                                               admin. Default is value of $public.
  1408  *     @type bool|string  $show_in_menu          Where to show the post type in the admin menu. To work, $show_ui
  1578  *     @type bool|string  $show_in_menu          Where to show the post type in the admin menu. To work, $show_ui
  1409  *                                               must be true. If true, the post type is shown in its own top level
  1579  *                                               must be true. If true, the post type is shown in its own top level
  1410  *                                               menu. If false, no menu is shown. If a string of an existing top
  1580  *                                               menu. If false, no menu is shown. If a string of an existing top
  1411  *                                               level menu (eg. 'tools.php' or 'edit.php?post_type=page'), the post
  1581  *                                               level menu ('tools.php' or 'edit.php?post_type=page', for example), the
  1412  *                                               type will be placed as a sub-menu of that.
  1582  *                                               post type will be placed as a sub-menu of that.
  1413  *                                               Default is value of $show_ui.
  1583  *                                               Default is value of $show_ui.
  1414  *     @type bool         $show_in_nav_menus     Makes this post type available for selection in navigation menus.
  1584  *     @type bool         $show_in_nav_menus     Makes this post type available for selection in navigation menus.
  1415  *                                               Default is value of $public.
  1585  *                                               Default is value of $public.
  1416  *     @type bool         $show_in_admin_bar     Makes this post type available via the admin bar. Default is value
  1586  *     @type bool         $show_in_admin_bar     Makes this post type available via the admin bar. Default is value
  1417  *                                               of $show_in_menu.
  1587  *                                               of $show_in_menu.
  1418  *     @type bool         $show_in_rest          Whether to include the post type in the REST API. Set this to true
  1588  *     @type bool         $show_in_rest          Whether to include the post type in the REST API. Set this to true
  1419  *                                               for the post type to be available in the block editor.
  1589  *                                               for the post type to be available in the block editor.
  1420  *     @type string       $rest_base             To change the base url of REST API route. Default is $post_type.
  1590  *     @type string       $rest_base             To change the base URL of REST API route. Default is $post_type.
  1421  *     @type string       $rest_controller_class REST API Controller class name. Default is 'WP_REST_Posts_Controller'.
  1591  *     @type string       $rest_namespace        To change the namespace URL of REST API route. Default is wp/v2.
       
  1592  *     @type string       $rest_controller_class REST API controller class name. Default is 'WP_REST_Posts_Controller'.
  1422  *     @type int          $menu_position         The position in the menu order the post type should appear. To work,
  1593  *     @type int          $menu_position         The position in the menu order the post type should appear. To work,
  1423  *                                               $show_in_menu must be true. Default null (at the bottom).
  1594  *                                               $show_in_menu must be true. Default null (at the bottom).
  1424  *     @type string       $menu_icon             The url to the icon to be used for this menu. Pass a base64-encoded
  1595  *     @type string       $menu_icon             The URL to the icon to be used for this menu. Pass a base64-encoded
  1425  *                                               SVG using a data URI, which will be colored to match the color scheme
  1596  *                                               SVG using a data URI, which will be colored to match the color scheme
  1426  *                                               -- this should begin with 'data:image/svg+xml;base64,'. Pass the name
  1597  *                                               -- this should begin with 'data:image/svg+xml;base64,'. Pass the name
  1427  *                                               of a Dashicons helper class to use a font icon, e.g.
  1598  *                                               of a Dashicons helper class to use a font icon, e.g.
  1428  *                                               'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty
  1599  *                                               'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty
  1429  *                                               so an icon can be added via CSS. Defaults to use the posts icon.
  1600  *                                               so an icon can be added via CSS. Defaults to use the posts icon.
  1430  *     @type string       $capability_type       The string to use to build the read, edit, and delete capabilities.
  1601  *     @type string|array $capability_type       The string to use to build the read, edit, and delete capabilities.
  1431  *                                               May be passed as an array to allow for alternative plurals when using
  1602  *                                               May be passed as an array to allow for alternative plurals when using
  1432  *                                               this argument as a base to construct the capabilities, e.g.
  1603  *                                               this argument as a base to construct the capabilities, e.g.
  1433  *                                               array('story', 'stories'). Default 'post'.
  1604  *                                               array('story', 'stories'). Default 'post'.
  1434  *     @type string[]     $capabilities          Array of capabilities for this post type. $capability_type is used
  1605  *     @type string[]     $capabilities          Array of capabilities for this post type. $capability_type is used
  1435  *                                               as a base to construct capabilities by default.
  1606  *                                               as a base to construct capabilities by default.
  1536 	 * @param string       $post_type        Post type.
  1707 	 * @param string       $post_type        Post type.
  1537 	 * @param WP_Post_Type $post_type_object Arguments used to register the post type.
  1708 	 * @param WP_Post_Type $post_type_object Arguments used to register the post type.
  1538 	 */
  1709 	 */
  1539 	do_action( 'registered_post_type', $post_type, $post_type_object );
  1710 	do_action( 'registered_post_type', $post_type, $post_type_object );
  1540 
  1711 
       
  1712 	/**
       
  1713 	 * Fires after a specific post type is registered.
       
  1714 	 *
       
  1715 	 * The dynamic portion of the filter name, `$post_type`, refers to the post type key.
       
  1716 	 *
       
  1717 	 * Possible hook names include:
       
  1718 	 *
       
  1719 	 *  - `registered_post_type_post`
       
  1720 	 *  - `registered_post_type_page`
       
  1721 	 *
       
  1722 	 * @since 6.0.0
       
  1723 	 *
       
  1724 	 * @param string       $post_type        Post type.
       
  1725 	 * @param WP_Post_Type $post_type_object Arguments used to register the post type.
       
  1726 	 */
       
  1727 	do_action( "registered_post_type_{$post_type}", $post_type, $post_type_object );
       
  1728 
  1541 	return $post_type_object;
  1729 	return $post_type_object;
  1542 }
  1730 }
  1543 
  1731 
  1544 /**
  1732 /**
  1545  * Unregisters a post type.
  1733  * Unregisters a post type.
  1546  *
  1734  *
  1547  * Can not be used to unregister built-in post types.
  1735  * Cannot be used to unregister built-in post types.
  1548  *
  1736  *
  1549  * @since 4.5.0
  1737  * @since 4.5.0
  1550  *
  1738  *
  1551  * @global array $wp_post_types List of post types.
  1739  * @global array $wp_post_types List of post types.
  1552  *
  1740  *
  1784  *
  1972  *
  1785  * @param object|WP_Post_Type $post_type_object Post type object.
  1973  * @param object|WP_Post_Type $post_type_object Post type object.
  1786  * @return object Object with all the labels as member variables.
  1974  * @return object Object with all the labels as member variables.
  1787  */
  1975  */
  1788 function get_post_type_labels( $post_type_object ) {
  1976 function get_post_type_labels( $post_type_object ) {
  1789 	$nohier_vs_hier_defaults = array(
  1977 	$nohier_vs_hier_defaults = WP_Post_Type::get_default_labels();
  1790 		'name'                     => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ),
       
  1791 		'singular_name'            => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ),
       
  1792 		'add_new'                  => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ),
       
  1793 		'add_new_item'             => array( __( 'Add New Post' ), __( 'Add New Page' ) ),
       
  1794 		'edit_item'                => array( __( 'Edit Post' ), __( 'Edit Page' ) ),
       
  1795 		'new_item'                 => array( __( 'New Post' ), __( 'New Page' ) ),
       
  1796 		'view_item'                => array( __( 'View Post' ), __( 'View Page' ) ),
       
  1797 		'view_items'               => array( __( 'View Posts' ), __( 'View Pages' ) ),
       
  1798 		'search_items'             => array( __( 'Search Posts' ), __( 'Search Pages' ) ),
       
  1799 		'not_found'                => array( __( 'No posts found.' ), __( 'No pages found.' ) ),
       
  1800 		'not_found_in_trash'       => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ),
       
  1801 		'parent_item_colon'        => array( null, __( 'Parent Page:' ) ),
       
  1802 		'all_items'                => array( __( 'All Posts' ), __( 'All Pages' ) ),
       
  1803 		'archives'                 => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
       
  1804 		'attributes'               => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
       
  1805 		'insert_into_item'         => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
       
  1806 		'uploaded_to_this_item'    => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
       
  1807 		'featured_image'           => array( _x( 'Featured image', 'post' ), _x( 'Featured image', 'page' ) ),
       
  1808 		'set_featured_image'       => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),
       
  1809 		'remove_featured_image'    => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ),
       
  1810 		'use_featured_image'       => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),
       
  1811 		'filter_items_list'        => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
       
  1812 		'filter_by_date'           => array( __( 'Filter by date' ), __( 'Filter by date' ) ),
       
  1813 		'items_list_navigation'    => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),
       
  1814 		'items_list'               => array( __( 'Posts list' ), __( 'Pages list' ) ),
       
  1815 		'item_published'           => array( __( 'Post published.' ), __( 'Page published.' ) ),
       
  1816 		'item_published_privately' => array( __( 'Post published privately.' ), __( 'Page published privately.' ) ),
       
  1817 		'item_reverted_to_draft'   => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ),
       
  1818 		'item_scheduled'           => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ),
       
  1819 		'item_updated'             => array( __( 'Post updated.' ), __( 'Page updated.' ) ),
       
  1820 		'item_link'                => array(
       
  1821 			_x( 'Post Link', 'navigation link block title' ),
       
  1822 			_x( 'Page Link', 'navigation link block title' ),
       
  1823 		),
       
  1824 		'item_link_description'    => array(
       
  1825 			_x( 'A link to a post.', 'navigation link block description' ),
       
  1826 			_x( 'A link to a page.', 'navigation link block description' ),
       
  1827 		),
       
  1828 	);
       
  1829 
  1978 
  1830 	$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
  1979 	$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
  1831 
  1980 
  1832 	$labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults );
  1981 	$labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults );
  1833 
  1982 
  2082  * For all others, the 'publicly_queryable' value will be used.
  2231  * For all others, the 'publicly_queryable' value will be used.
  2083  *
  2232  *
  2084  * @since 4.4.0
  2233  * @since 4.4.0
  2085  * @since 4.5.0 Added the ability to pass a post type name in addition to object.
  2234  * @since 4.5.0 Added the ability to pass a post type name in addition to object.
  2086  * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
  2235  * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
       
  2236  * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result.
  2087  *
  2237  *
  2088  * @param string|WP_Post_Type $post_type Post type name or object.
  2238  * @param string|WP_Post_Type $post_type Post type name or object.
  2089  * @return bool Whether the post type should be considered viewable.
  2239  * @return bool Whether the post type should be considered viewable.
  2090  */
  2240  */
  2091 function is_post_type_viewable( $post_type ) {
  2241 function is_post_type_viewable( $post_type ) {
  2098 
  2248 
  2099 	if ( ! is_object( $post_type ) ) {
  2249 	if ( ! is_object( $post_type ) ) {
  2100 		return false;
  2250 		return false;
  2101 	}
  2251 	}
  2102 
  2252 
  2103 	return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
  2253 	$is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
       
  2254 
       
  2255 	/**
       
  2256 	 * Filters whether a post type is considered "viewable".
       
  2257 	 *
       
  2258 	 * The returned filtered value must be a boolean type to ensure
       
  2259 	 * `is_post_type_viewable()` only returns a boolean. This strictness
       
  2260 	 * is by design to maintain backwards-compatibility and guard against
       
  2261 	 * potential type errors in PHP 8.1+. Non-boolean values (even falsey
       
  2262 	 * and truthy values) will result in the function returning false.
       
  2263 	 *
       
  2264 	 * @since 5.9.0
       
  2265 	 *
       
  2266 	 * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
       
  2267 	 * @param WP_Post_Type $post_type   Post type object.
       
  2268 	 */
       
  2269 	return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
  2104 }
  2270 }
  2105 
  2271 
  2106 /**
  2272 /**
  2107  * Determine whether a post status is considered "viewable".
  2273  * Determine whether a post status is considered "viewable".
  2108  *
  2274  *
  2109  * For built-in post statuses such as publish and private, the 'public' value will be evaluted.
  2275  * For built-in post statuses such as publish and private, the 'public' value will be evaluated.
  2110  * For all others, the 'publicly_queryable' value will be used.
  2276  * For all others, the 'publicly_queryable' value will be used.
  2111  *
  2277  *
  2112  * @since 5.7.0
  2278  * @since 5.7.0
       
  2279  * @since 5.9.0 Added `is_post_status_viewable` hook to filter the result.
  2113  *
  2280  *
  2114  * @param string|stdClass $post_status Post status name or object.
  2281  * @param string|stdClass $post_status Post status name or object.
  2115  * @return bool Whether the post status should be considered viewable.
  2282  * @return bool Whether the post status should be considered viewable.
  2116  */
  2283  */
  2117 function is_post_status_viewable( $post_status ) {
  2284 function is_post_status_viewable( $post_status ) {
  2128 		$post_status->protected
  2295 		$post_status->protected
  2129 	) {
  2296 	) {
  2130 		return false;
  2297 		return false;
  2131 	}
  2298 	}
  2132 
  2299 
  2133 	return $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
  2300 	$is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public );
       
  2301 
       
  2302 	/**
       
  2303 	 * Filters whether a post status is considered "viewable".
       
  2304 	 *
       
  2305 	 * The returned filtered value must be a boolean type to ensure
       
  2306 	 * `is_post_status_viewable()` only returns a boolean. This strictness
       
  2307 	 * is by design to maintain backwards-compatibility and guard against
       
  2308 	 * potential type errors in PHP 8.1+. Non-boolean values (even falsey
       
  2309 	 * and truthy values) will result in the function returning false.
       
  2310 	 *
       
  2311 	 * @since 5.9.0
       
  2312 	 *
       
  2313 	 * @param bool     $is_viewable Whether the post status is "viewable" (strict type).
       
  2314 	 * @param stdClass $post_status Post status object.
       
  2315 	 */
       
  2316 	return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status );
  2134 }
  2317 }
  2135 
  2318 
  2136 /**
  2319 /**
  2137  * Determine whether a post is publicly viewable.
  2320  * Determine whether a post is publicly viewable.
  2138  *
  2321  *
  2173  *
  2356  *
  2174  * @see WP_Query
  2357  * @see WP_Query
  2175  * @see WP_Query::parse_query()
  2358  * @see WP_Query::parse_query()
  2176  *
  2359  *
  2177  * @param array $args {
  2360  * @param array $args {
  2178  *     Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all
  2361  *     Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments.
  2179  *     available arguments.
       
  2180  *
  2362  *
  2181  *     @type int        $numberposts      Total number of posts to retrieve. Is an alias of `$posts_per_page`
  2363  *     @type int        $numberposts      Total number of posts to retrieve. Is an alias of `$posts_per_page`
  2182  *                                        in WP_Query. Accepts -1 for all. Default 5.
  2364  *                                        in WP_Query. Accepts -1 for all. Default 5.
  2183  *     @type int|string $category         Category ID or comma-separated list of IDs (this or any children).
  2365  *     @type int|string $category         Category ID or comma-separated list of IDs (this or any children).
  2184  *                                        Is an alias of `$cat` in WP_Query. Default 0.
  2366  *                                        Is an alias of `$cat` in WP_Query. Default 0.
  2272  *                           rows will only be removed that match the value.
  2454  *                           rows will only be removed that match the value.
  2273  *                           Must be serializable if non-scalar. Default empty.
  2455  *                           Must be serializable if non-scalar. Default empty.
  2274  * @return bool True on success, false on failure.
  2456  * @return bool True on success, false on failure.
  2275  */
  2457  */
  2276 function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
  2458 function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
  2277 	// Make sure meta is added to the post, not a revision.
  2459 	// Make sure meta is deleted from the post, not from a revision.
  2278 	$the_post = wp_is_post_revision( $post_id );
  2460 	$the_post = wp_is_post_revision( $post_id );
  2279 	if ( $the_post ) {
  2461 	if ( $the_post ) {
  2280 		$post_id = $the_post;
  2462 		$post_id = $the_post;
  2281 	}
  2463 	}
  2282 
  2464 
  2324  * @return int|bool Meta ID if the key didn't exist, true on successful update,
  2506  * @return int|bool Meta ID if the key didn't exist, true on successful update,
  2325  *                  false on failure or if the value passed to the function
  2507  *                  false on failure or if the value passed to the function
  2326  *                  is the same as the one that is already in the database.
  2508  *                  is the same as the one that is already in the database.
  2327  */
  2509  */
  2328 function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
  2510 function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
  2329 	// Make sure meta is added to the post, not a revision.
  2511 	// Make sure meta is updated for the post, not for a revision.
  2330 	$the_post = wp_is_post_revision( $post_id );
  2512 	$the_post = wp_is_post_revision( $post_id );
  2331 	if ( $the_post ) {
  2513 	if ( $the_post ) {
  2332 		$post_id = $the_post;
  2514 		$post_id = $the_post;
  2333 	}
  2515 	}
  2334 
  2516 
  2386  * The post meta fields are retrieved from the cache where possible,
  2568  * The post meta fields are retrieved from the cache where possible,
  2387  * so the function is optimized to be called more than once.
  2569  * so the function is optimized to be called more than once.
  2388  *
  2570  *
  2389  * @since 1.2.0
  2571  * @since 1.2.0
  2390  *
  2572  *
  2391  * @param int $post_id Optional. Post ID. Default is ID of the global $post.
  2573  * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`.
  2392  * @return array Post meta for the given post.
  2574  * @return mixed An array of values.
       
  2575  *               False for an invalid `$post_id` (non-numeric, zero, or negative value).
       
  2576  *               An empty string if a valid but non-existing post ID is passed.
  2393  */
  2577  */
  2394 function get_post_custom( $post_id = 0 ) {
  2578 function get_post_custom( $post_id = 0 ) {
  2395 	$post_id = absint( $post_id );
  2579 	$post_id = absint( $post_id );
  2396 	if ( ! $post_id ) {
  2580 	if ( ! $post_id ) {
  2397 		$post_id = get_the_ID();
  2581 		$post_id = get_the_ID();
  2405  *
  2589  *
  2406  * If there are no meta fields, then nothing (null) will be returned.
  2590  * If there are no meta fields, then nothing (null) will be returned.
  2407  *
  2591  *
  2408  * @since 1.2.0
  2592  * @since 1.2.0
  2409  *
  2593  *
  2410  * @param int $post_id Optional. Post ID. Default is ID of the global $post.
  2594  * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`.
  2411  * @return array|void Array of the keys, if retrieved.
  2595  * @return array|void Array of the keys, if retrieved.
  2412  */
  2596  */
  2413 function get_post_custom_keys( $post_id = 0 ) {
  2597 function get_post_custom_keys( $post_id = 0 ) {
  2414 	$custom = get_post_custom( $post_id );
  2598 	$custom = get_post_custom( $post_id );
  2415 
  2599 
  2430  * will be retrieved and only the meta field key values returned.
  2614  * will be retrieved and only the meta field key values returned.
  2431  *
  2615  *
  2432  * @since 1.2.0
  2616  * @since 1.2.0
  2433  *
  2617  *
  2434  * @param string $key     Optional. Meta field key. Default empty.
  2618  * @param string $key     Optional. Meta field key. Default empty.
  2435  * @param int    $post_id Optional. Post ID. Default is ID of the global $post.
  2619  * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
  2436  * @return array|null Meta field values.
  2620  * @return array|null Meta field values.
  2437  */
  2621  */
  2438 function get_post_custom_values( $key = '', $post_id = 0 ) {
  2622 function get_post_custom_values( $key = '', $post_id = 0 ) {
  2439 	if ( ! $key ) {
  2623 	if ( ! $key ) {
  2440 		return null;
  2624 		return null;
  2455  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  2639  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  2456  * Conditional Tags} article in the Theme Developer Handbook.
  2640  * Conditional Tags} article in the Theme Developer Handbook.
  2457  *
  2641  *
  2458  * @since 2.7.0
  2642  * @since 2.7.0
  2459  *
  2643  *
  2460  * @param int $post_id Optional. Post ID. Default is ID of the global $post.
  2644  * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`.
  2461  * @return bool Whether post is sticky.
  2645  * @return bool Whether post is sticky.
  2462  */
  2646  */
  2463 function is_sticky( $post_id = 0 ) {
  2647 function is_sticky( $post_id = 0 ) {
  2464 	$post_id = absint( $post_id );
  2648 	$post_id = absint( $post_id );
  2465 
  2649 
  2709 	$post_id  = (int) $post_id;
  2893 	$post_id  = (int) $post_id;
  2710 	$stickies = get_option( 'sticky_posts' );
  2894 	$stickies = get_option( 'sticky_posts' );
  2711 	$updated  = false;
  2895 	$updated  = false;
  2712 
  2896 
  2713 	if ( ! is_array( $stickies ) ) {
  2897 	if ( ! is_array( $stickies ) ) {
  2714 		$stickies = array( $post_id );
  2898 		$stickies = array();
  2715 	} else {
  2899 	} else {
  2716 		$stickies = array_unique( array_map( 'intval', $stickies ) );
  2900 		$stickies = array_unique( array_map( 'intval', $stickies ) );
  2717 	}
  2901 	}
  2718 
  2902 
  2719 	if ( ! in_array( $post_id, $stickies, true ) ) {
  2903 	if ( ! in_array( $post_id, $stickies, true ) ) {
  2816  *
  3000  *
  2817  * @global wpdb $wpdb WordPress database abstraction object.
  3001  * @global wpdb $wpdb WordPress database abstraction object.
  2818  *
  3002  *
  2819  * @param string $type Optional. Post type to retrieve count. Default 'post'.
  3003  * @param string $type Optional. Post type to retrieve count. Default 'post'.
  2820  * @param string $perm Optional. 'readable' or empty. Default empty.
  3004  * @param string $perm Optional. 'readable' or empty. Default empty.
  2821  * @return object Number of posts for each status.
  3005  * @return stdClass Number of posts for each status.
  2822  */
  3006  */
  2823 function wp_count_posts( $type = 'post', $perm = '' ) {
  3007 function wp_count_posts( $type = 'post', $perm = '' ) {
  2824 	global $wpdb;
  3008 	global $wpdb;
  2825 
  3009 
  2826 	if ( ! post_type_exists( $type ) ) {
  3010 	if ( ! post_type_exists( $type ) ) {
  2869 	/**
  3053 	/**
  2870 	 * Modify returned post counts by status for the current post type.
  3054 	 * Modify returned post counts by status for the current post type.
  2871 	 *
  3055 	 *
  2872 	 * @since 3.7.0
  3056 	 * @since 3.7.0
  2873 	 *
  3057 	 *
  2874 	 * @param object $counts An object containing the current post_type's post
  3058 	 * @param stdClass $counts An object containing the current post_type's post
  2875 	 *                       counts by status.
  3059 	 *                         counts by status.
  2876 	 * @param string $type   Post type.
  3060 	 * @param string   $type   Post type.
  2877 	 * @param string $perm   The permission to determine if the posts are 'readable'
  3061 	 * @param string   $perm   The permission to determine if the posts are 'readable'
  2878 	 *                       by the current user.
  3062 	 *                         by the current user.
  2879 	 */
  3063 	 */
  2880 	return apply_filters( 'wp_count_posts', $counts, $type, $perm );
  3064 	return apply_filters( 'wp_count_posts', $counts, $type, $perm );
  2881 }
  3065 }
  2882 
  3066 
  2883 /**
  3067 /**
  2892  *
  3076  *
  2893  * @global wpdb $wpdb WordPress database abstraction object.
  3077  * @global wpdb $wpdb WordPress database abstraction object.
  2894  *
  3078  *
  2895  * @param string|string[] $mime_type Optional. Array or comma-separated list of
  3079  * @param string|string[] $mime_type Optional. Array or comma-separated list of
  2896  *                                   MIME patterns. Default empty.
  3080  *                                   MIME patterns. Default empty.
  2897  * @return object An object containing the attachment counts by mime type.
  3081  * @return stdClass An object containing the attachment counts by mime type.
  2898  */
  3082  */
  2899 function wp_count_attachments( $mime_type = '' ) {
  3083 function wp_count_attachments( $mime_type = '' ) {
  2900 	global $wpdb;
  3084 	global $wpdb;
  2901 
  3085 
  2902 	$and   = wp_post_mime_type_where( $mime_type );
  3086 	$and   = wp_post_mime_type_where( $mime_type );
  2911 	/**
  3095 	/**
  2912 	 * Modify returned attachment counts by mime type.
  3096 	 * Modify returned attachment counts by mime type.
  2913 	 *
  3097 	 *
  2914 	 * @since 3.7.0
  3098 	 * @since 3.7.0
  2915 	 *
  3099 	 *
  2916 	 * @param object          $counts    An object containing the attachment counts by
  3100 	 * @param stdClass        $counts    An object containing the attachment counts by
  2917 	 *                                   mime type.
  3101 	 *                                   mime type.
  2918 	 * @param string|string[] $mime_type Array or comma-separated list of MIME patterns.
  3102 	 * @param string|string[] $mime_type Array or comma-separated list of MIME patterns.
  2919 	 */
  3103 	 */
  2920 	return apply_filters( 'wp_count_attachments', (object) $counts, $mime_type );
  3104 	return apply_filters( 'wp_count_attachments', (object) $counts, $mime_type );
  2921 }
  3105 }
  2938 				'Image <span class="count">(%s)</span>',
  3122 				'Image <span class="count">(%s)</span>',
  2939 				'Images <span class="count">(%s)</span>'
  3123 				'Images <span class="count">(%s)</span>'
  2940 			),
  3124 			),
  2941 		),
  3125 		),
  2942 		'audio'       => array(
  3126 		'audio'       => array(
  2943 			__( 'Audio' ),
  3127 			_x( 'Audio', 'file type group' ),
  2944 			__( 'Manage Audio' ),
  3128 			__( 'Manage Audio' ),
  2945 			/* translators: %s: Number of audio files. */
  3129 			/* translators: %s: Number of audio files. */
  2946 			_n_noop(
  3130 			_n_noop(
  2947 				'Audio <span class="count">(%s)</span>',
  3131 				'Audio <span class="count">(%s)</span>',
  2948 				'Audio <span class="count">(%s)</span>'
  3132 				'Audio <span class="count">(%s)</span>'
  2949 			),
  3133 			),
  2950 		),
  3134 		),
  2951 		'video'       => array(
  3135 		'video'       => array(
  2952 			__( 'Video' ),
  3136 			_x( 'Video', 'file type group' ),
  2953 			__( 'Manage Video' ),
  3137 			__( 'Manage Video' ),
  2954 			/* translators: %s: Number of video files. */
  3138 			/* translators: %s: Number of video files. */
  2955 			_n_noop(
  3139 			_n_noop(
  2956 				'Video <span class="count">(%s)</span>',
  3140 				'Video <span class="count">(%s)</span>',
  2957 				'Video <span class="count">(%s)</span>'
  3141 				'Video <span class="count">(%s)</span>'
  3182 	/**
  3366 	/**
  3183 	 * Filters whether a post deletion should take place.
  3367 	 * Filters whether a post deletion should take place.
  3184 	 *
  3368 	 *
  3185 	 * @since 4.4.0
  3369 	 * @since 4.4.0
  3186 	 *
  3370 	 *
  3187 	 * @param bool|null $delete       Whether to go forward with deletion.
  3371 	 * @param WP_Post|false|null $delete       Whether to go forward with deletion. @TODO description
  3188 	 * @param WP_Post   $post         Post object.
  3372 	 * @param WP_Post            $post         Post object.
  3189 	 * @param bool      $force_delete Whether to bypass the Trash.
  3373 	 * @param bool               $force_delete Whether to bypass the Trash.
  3190 	 */
  3374 	 */
  3191 	$check = apply_filters( 'pre_delete_post', null, $post, $force_delete );
  3375 	$check = apply_filters( 'pre_delete_post', null, $post, $force_delete );
  3192 	if ( null !== $check ) {
  3376 	if ( null !== $check ) {
  3193 		return $check;
  3377 		return $check;
  3194 	}
  3378 	}
  3233 	// Point all attachments to this post up one level.
  3417 	// Point all attachments to this post up one level.
  3234 	$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
  3418 	$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
  3235 
  3419 
  3236 	wp_defer_comment_counting( true );
  3420 	wp_defer_comment_counting( true );
  3237 
  3421 
  3238 	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) );
  3422 	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) );
  3239 	foreach ( $comment_ids as $comment_id ) {
  3423 	foreach ( $comment_ids as $comment_id ) {
  3240 		wp_delete_comment( $comment_id, true );
  3424 		wp_delete_comment( $comment_id, true );
  3241 	}
  3425 	}
  3242 
  3426 
  3243 	wp_defer_comment_counting( false );
  3427 	wp_defer_comment_counting( false );
  3338  *
  3522  *
  3339  * @since 2.9.0
  3523  * @since 2.9.0
  3340  *
  3524  *
  3341  * @see wp_delete_post()
  3525  * @see wp_delete_post()
  3342  *
  3526  *
  3343  * @param int $post_id Optional. Post ID. Default is ID of the global $post
  3527  * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`
  3344  *                     if EMPTY_TRASH_DAYS equals true.
  3528  *                     if `EMPTY_TRASH_DAYS` equals true.
  3345  * @return WP_Post|false|null Post data on success, false or null on failure.
  3529  * @return WP_Post|false|null Post data on success, false or null on failure.
  3346  */
  3530  */
  3347 function wp_trash_post( $post_id = 0 ) {
  3531 function wp_trash_post( $post_id = 0 ) {
  3348 	if ( ! EMPTY_TRASH_DAYS ) {
  3532 	if ( ! EMPTY_TRASH_DAYS ) {
  3349 		return wp_delete_post( $post_id, true );
  3533 		return wp_delete_post( $post_id, true );
  3415  *
  3599  *
  3416  * @since 2.9.0
  3600  * @since 2.9.0
  3417  * @since 5.6.0 An untrashed post is now returned to 'draft' status by default, except for
  3601  * @since 5.6.0 An untrashed post is now returned to 'draft' status by default, except for
  3418  *              attachments which are returned to their original 'inherit' status.
  3602  *              attachments which are returned to their original 'inherit' status.
  3419  *
  3603  *
  3420  * @param int $post_id Optional. Post ID. Default is ID of the global `$post`.
  3604  * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`.
  3421  * @return WP_Post|false|null Post data on success, false or null on failure.
  3605  * @return WP_Post|false|null Post data on success, false or null on failure.
  3422  */
  3606  */
  3423 function wp_untrash_post( $post_id = 0 ) {
  3607 function wp_untrash_post( $post_id = 0 ) {
  3424 	$post = get_post( $post_id );
  3608 	$post = get_post( $post_id );
  3425 
  3609 
  3792  *     @type int    $post_author           The ID of the user who added the post. Default is
  3976  *     @type int    $post_author           The ID of the user who added the post. Default is
  3793  *                                         the current user ID.
  3977  *                                         the current user ID.
  3794  *     @type string $post_date             The date of the post. Default is the current time.
  3978  *     @type string $post_date             The date of the post. Default is the current time.
  3795  *     @type string $post_date_gmt         The date of the post in the GMT timezone. Default is
  3979  *     @type string $post_date_gmt         The date of the post in the GMT timezone. Default is
  3796  *                                         the value of `$post_date`.
  3980  *                                         the value of `$post_date`.
  3797  *     @type mixed  $post_content          The post content. Default empty.
  3981  *     @type string $post_content          The post content. Default empty.
  3798  *     @type string $post_content_filtered The filtered post content. Default empty.
  3982  *     @type string $post_content_filtered The filtered post content. Default empty.
  3799  *     @type string $post_title            The post title. Default empty.
  3983  *     @type string $post_title            The post title. Default empty.
  3800  *     @type string $post_excerpt          The post excerpt. Default empty.
  3984  *     @type string $post_excerpt          The post excerpt. Default empty.
  3801  *     @type string $post_status           The post status. Default 'draft'.
  3985  *     @type string $post_status           The post status. Default 'draft'.
  3802  *     @type string $post_type             The post type. Default 'post'.
  3986  *     @type string $post_type             The post type. Default 'post'.
  3822  *     @type int    $import_id             The post ID to be used when inserting a new post.
  4006  *     @type int    $import_id             The post ID to be used when inserting a new post.
  3823  *                                         If specified, must not match any existing post ID. Default 0.
  4007  *                                         If specified, must not match any existing post ID. Default 0.
  3824  *     @type int[]  $post_category         Array of category IDs.
  4008  *     @type int[]  $post_category         Array of category IDs.
  3825  *                                         Defaults to value of the 'default_category' option.
  4009  *                                         Defaults to value of the 'default_category' option.
  3826  *     @type array  $tags_input            Array of tag names, slugs, or IDs. Default empty.
  4010  *     @type array  $tags_input            Array of tag names, slugs, or IDs. Default empty.
  3827  *     @type array  $tax_input             Array of taxonomy terms keyed by their taxonomy name. Default empty.
  4011  *     @type array  $tax_input             An array of taxonomy terms keyed by their taxonomy name.
       
  4012  *                                         If the taxonomy is hierarchical, the term list needs to be
       
  4013  *                                         either an array of term IDs or a comma-separated string of IDs.
       
  4014  *                                         If the taxonomy is non-hierarchical, the term list can be an array
       
  4015  *                                         that contains term names or slugs, or a comma-separated string
       
  4016  *                                         of names or slugs. This is because, in hierarchical taxonomy,
       
  4017  *                                         child terms can have the same names with different parent terms,
       
  4018  *                                         so the only way to connect them is using ID. Default empty.
  3828  *     @type array  $meta_input            Array of post meta values keyed by their post meta key. Default empty.
  4019  *     @type array  $meta_input            Array of post meta values keyed by their post meta key. Default empty.
  3829  * }
  4020  * }
  3830  * @param bool  $wp_error         Optional. Whether to return a WP_Error on failure. Default false.
  4021  * @param bool  $wp_error         Optional. Whether to return a WP_Error on failure. Default false.
  3831  * @param bool  $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
  4022  * @param bool  $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
  3832  * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
  4023  * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
  4154 	if ( 'attachment' === $post_type ) {
  4345 	if ( 'attachment' === $post_type ) {
  4155 		/**
  4346 		/**
  4156 		 * Filters attachment post data before it is updated in or added to the database.
  4347 		 * Filters attachment post data before it is updated in or added to the database.
  4157 		 *
  4348 		 *
  4158 		 * @since 3.9.0
  4349 		 * @since 3.9.0
  4159 		 * @since 5.4.1 `$unsanitized_postarr` argument added.
  4350 		 * @since 5.4.1 The `$unsanitized_postarr` parameter was added.
       
  4351 		 * @since 6.0.0 The `$update` parameter was added.
  4160 		 *
  4352 		 *
  4161 		 * @param array $data                An array of slashed, sanitized, and processed attachment post data.
  4353 		 * @param array $data                An array of slashed, sanitized, and processed attachment post data.
  4162 		 * @param array $postarr             An array of slashed and sanitized attachment post data, but not processed.
  4354 		 * @param array $postarr             An array of slashed and sanitized attachment post data, but not processed.
  4163 		 * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed attachment post data
  4355 		 * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed attachment post data
  4164 		 *                                   as originally passed to wp_insert_post().
  4356 		 *                                   as originally passed to wp_insert_post().
       
  4357 		 * @param bool  $update              Whether this is an existing attachment post being updated.
  4165 		 */
  4358 		 */
  4166 		$data = apply_filters( 'wp_insert_attachment_data', $data, $postarr, $unsanitized_postarr );
  4359 		$data = apply_filters( 'wp_insert_attachment_data', $data, $postarr, $unsanitized_postarr, $update );
  4167 	} else {
  4360 	} else {
  4168 		/**
  4361 		/**
  4169 		 * Filters slashed post data just before it is inserted into the database.
  4362 		 * Filters slashed post data just before it is inserted into the database.
  4170 		 *
  4363 		 *
  4171 		 * @since 2.7.0
  4364 		 * @since 2.7.0
  4172 		 * @since 5.4.1 `$unsanitized_postarr` argument added.
  4365 		 * @since 5.4.1 The `$unsanitized_postarr` parameter was added.
       
  4366 		 * @since 6.0.0 The `$update` parameter was added.
  4173 		 *
  4367 		 *
  4174 		 * @param array $data                An array of slashed, sanitized, and processed post data.
  4368 		 * @param array $data                An array of slashed, sanitized, and processed post data.
  4175 		 * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
  4369 		 * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
  4176 		 * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as
  4370 		 * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as
  4177 		 *                                   originally passed to wp_insert_post().
  4371 		 *                                   originally passed to wp_insert_post().
       
  4372 		 * @param bool  $update              Whether this is an existing post being updated.
  4178 		 */
  4373 		 */
  4179 		$data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr );
  4374 		$data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr, $update );
  4180 	}
  4375 	}
  4181 
  4376 
  4182 	$data  = wp_unslash( $data );
  4377 	$data  = wp_unslash( $data );
  4183 	$where = array( 'ID' => $post_ID );
  4378 	$where = array( 'ID' => $post_ID );
  4184 
  4379 
  4409 		 * Fires once an existing post has been updated.
  4604 		 * Fires once an existing post has been updated.
  4410 		 *
  4605 		 *
  4411 		 * The dynamic portion of the hook name, `$post->post_type`, refers to
  4606 		 * The dynamic portion of the hook name, `$post->post_type`, refers to
  4412 		 * the post type slug.
  4607 		 * the post type slug.
  4413 		 *
  4608 		 *
       
  4609 		 * Possible hook names include:
       
  4610 		 *
       
  4611 		 *  - `edit_post_post`
       
  4612 		 *  - `edit_post_page`
       
  4613 		 *
  4414 		 * @since 5.1.0
  4614 		 * @since 5.1.0
  4415 		 *
  4615 		 *
  4416 		 * @param int     $post_ID Post ID.
  4616 		 * @param int     $post_ID Post ID.
  4417 		 * @param WP_Post $post    Post object.
  4617 		 * @param WP_Post $post    Post object.
  4418 		 */
  4618 		 */
  4445 	/**
  4645 	/**
  4446 	 * Fires once a post has been saved.
  4646 	 * Fires once a post has been saved.
  4447 	 *
  4647 	 *
  4448 	 * The dynamic portion of the hook name, `$post->post_type`, refers to
  4648 	 * The dynamic portion of the hook name, `$post->post_type`, refers to
  4449 	 * the post type slug.
  4649 	 * the post type slug.
       
  4650 	 *
       
  4651 	 * Possible hook names include:
       
  4652 	 *
       
  4653 	 *  - `save_post_post`
       
  4654 	 *  - `save_post_page`
  4450 	 *
  4655 	 *
  4451 	 * @since 3.7.0
  4656 	 * @since 3.7.0
  4452 	 *
  4657 	 *
  4453 	 * @param int     $post_ID Post ID.
  4658 	 * @param int     $post_ID Post ID.
  4454 	 * @param WP_Post $post    Post object.
  4659 	 * @param WP_Post $post    Post object.
  4922 	if ( strlen( $slug ) > $length ) {
  5127 	if ( strlen( $slug ) > $length ) {
  4923 		$decoded_slug = urldecode( $slug );
  5128 		$decoded_slug = urldecode( $slug );
  4924 		if ( $decoded_slug === $slug ) {
  5129 		if ( $decoded_slug === $slug ) {
  4925 			$slug = substr( $slug, 0, $length );
  5130 			$slug = substr( $slug, 0, $length );
  4926 		} else {
  5131 		} else {
  4927 			$slug = utf8_uri_encode( $decoded_slug, $length );
  5132 			$slug = utf8_uri_encode( $decoded_slug, $length, true );
  4928 		}
  5133 		}
  4929 	}
  5134 	}
  4930 
  5135 
  4931 	return rtrim( $slug, '-' );
  5136 	return rtrim( $slug, '-' );
  4932 }
  5137 }
  5100 	/**
  5305 	/**
  5101 	 * Fires when a post is transitioned from one status to another.
  5306 	 * Fires when a post is transitioned from one status to another.
  5102 	 *
  5307 	 *
  5103 	 * The dynamic portions of the hook name, `$new_status` and `$old_status`,
  5308 	 * The dynamic portions of the hook name, `$new_status` and `$old_status`,
  5104 	 * refer to the old and new post statuses, respectively.
  5309 	 * refer to the old and new post statuses, respectively.
       
  5310 	 *
       
  5311 	 * Possible hook names include:
       
  5312 	 *
       
  5313 	 *  - `draft_to_publish`
       
  5314 	 *  - `publish_to_trash`
       
  5315 	 *  - `pending_to_draft`
  5105 	 *
  5316 	 *
  5106 	 * @since 2.3.0
  5317 	 * @since 2.3.0
  5107 	 *
  5318 	 *
  5108 	 * @param WP_Post $post Post object.
  5319 	 * @param WP_Post $post Post object.
  5109 	 */
  5320 	 */
  5139 	 *
  5350 	 *
  5140 	 * Therefore, if you are looking to only fire a callback when a post is first
  5351 	 * Therefore, if you are looking to only fire a callback when a post is first
  5141 	 * transitioned to a status, use the {@see 'transition_post_status'} hook instead.
  5352 	 * transitioned to a status, use the {@see 'transition_post_status'} hook instead.
  5142 	 *
  5353 	 *
  5143 	 * @since 2.3.0
  5354 	 * @since 2.3.0
  5144 	 *
  5355 	 * @since 5.9.0 Added `$old_status` parameter.
  5145 	 * @param int     $post_id Post ID.
  5356 	 *
  5146 	 * @param WP_Post $post    Post object.
  5357 	 * @param int     $post_id    Post ID.
       
  5358 	 * @param WP_Post $post       Post object.
       
  5359 	 * @param string  $old_status Old post status.
  5147 	 */
  5360 	 */
  5148 	do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
  5361 	do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );
  5149 }
  5362 }
  5150 
  5363 
  5151 /**
  5364 /**
  5152  * Fires actions after a post, its terms and meta data has been saved.
  5365  * Fires actions after a post, its terms and meta data has been saved.
  5153  *
  5366  *
  5489 	wp_cache_set( $cache_key, $foundid, 'posts' );
  5702 	wp_cache_set( $cache_key, $foundid, 'posts' );
  5490 
  5703 
  5491 	if ( $foundid ) {
  5704 	if ( $foundid ) {
  5492 		return get_post( $foundid, $output );
  5705 		return get_post( $foundid, $output );
  5493 	}
  5706 	}
       
  5707 
       
  5708 	return null;
  5494 }
  5709 }
  5495 
  5710 
  5496 /**
  5711 /**
  5497  * Retrieve a page given its title.
  5712  * Retrieve a page given its title.
  5498  *
  5713  *
  5546 	$page = $wpdb->get_var( $sql );
  5761 	$page = $wpdb->get_var( $sql );
  5547 
  5762 
  5548 	if ( $page ) {
  5763 	if ( $page ) {
  5549 		return get_post( $page, $output );
  5764 		return get_post( $page, $output );
  5550 	}
  5765 	}
       
  5766 
       
  5767 	return null;
  5551 }
  5768 }
  5552 
  5769 
  5553 /**
  5770 /**
  5554  * Identify descendants of a given page ID in a list of page objects.
  5771  * Identify descendants of a given page ID in a list of page objects.
  5555  *
  5772  *
  6125 	/**
  6342 	/**
  6126 	 * Filters whether an attachment deletion should take place.
  6343 	 * Filters whether an attachment deletion should take place.
  6127 	 *
  6344 	 *
  6128 	 * @since 5.5.0
  6345 	 * @since 5.5.0
  6129 	 *
  6346 	 *
  6130 	 * @param bool|null $delete       Whether to go forward with deletion.
  6347 	 * @param WP_Post|false|null $delete       Whether to go forward with deletion. @TODO description
  6131 	 * @param WP_Post   $post         Post object.
  6348 	 * @param WP_Post            $post         Post object.
  6132 	 * @param bool      $force_delete Whether to bypass the Trash.
  6349 	 * @param bool               $force_delete Whether to bypass the Trash.
  6133 	 */
  6350 	 */
  6134 	$check = apply_filters( 'pre_delete_attachment', null, $post, $force_delete );
  6351 	$check = apply_filters( 'pre_delete_attachment', null, $post, $force_delete );
  6135 	if ( null !== $check ) {
  6352 	if ( null !== $check ) {
  6136 		return $check;
  6353 		return $check;
  6137 	}
  6354 	}
  6141 
  6358 
  6142 	$meta         = wp_get_attachment_metadata( $post_id );
  6359 	$meta         = wp_get_attachment_metadata( $post_id );
  6143 	$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
  6360 	$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
  6144 	$file         = get_attached_file( $post_id );
  6361 	$file         = get_attached_file( $post_id );
  6145 
  6362 
  6146 	if ( is_multisite() ) {
  6363 	if ( is_multisite() && is_string( $file ) && ! empty( $file ) ) {
  6147 		clean_dirsize_cache( $file );
  6364 		clean_dirsize_cache( $file );
  6148 	}
  6365 	}
  6149 
  6366 
  6150 	/**
  6367 	/**
  6151 	 * Fires before an attachment is deleted, at the start of wp_delete_attachment().
  6368 	 * Fires before an attachment is deleted, at the start of wp_delete_attachment().
  6164 	// Delete all for any posts.
  6381 	// Delete all for any posts.
  6165 	delete_metadata( 'post', null, '_thumbnail_id', $post_id, true );
  6382 	delete_metadata( 'post', null, '_thumbnail_id', $post_id, true );
  6166 
  6383 
  6167 	wp_defer_comment_counting( true );
  6384 	wp_defer_comment_counting( true );
  6168 
  6385 
  6169 	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
  6386 	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $post_id ) );
  6170 	foreach ( $comment_ids as $comment_id ) {
  6387 	foreach ( $comment_ids as $comment_id ) {
  6171 		wp_delete_comment( $comment_id, true );
  6388 		wp_delete_comment( $comment_id, true );
  6172 	}
  6389 	}
  6173 
  6390 
  6174 	wp_defer_comment_counting( false );
  6391 	wp_defer_comment_counting( false );
  6299  *     @type int    $height     The height of the attachment.
  6516  *     @type int    $height     The height of the attachment.
  6300  *     @type string $file       The file path relative to `wp-content/uploads`.
  6517  *     @type string $file       The file path relative to `wp-content/uploads`.
  6301  *     @type array  $sizes      Keys are size slugs, each value is an array containing
  6518  *     @type array  $sizes      Keys are size slugs, each value is an array containing
  6302  *                              'file', 'width', 'height', and 'mime-type'.
  6519  *                              'file', 'width', 'height', and 'mime-type'.
  6303  *     @type array  $image_meta Image metadata.
  6520  *     @type array  $image_meta Image metadata.
       
  6521  *     @type int    $filesize   File size of the attachment.
  6304  * }
  6522  * }
  6305  */
  6523  */
  6306 function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
  6524 function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
  6307 	$attachment_id = (int) $attachment_id;
  6525 	$attachment_id = (int) $attachment_id;
  6308 
  6526 
  6374 /**
  6592 /**
  6375  * Retrieve the URL for an attachment.
  6593  * Retrieve the URL for an attachment.
  6376  *
  6594  *
  6377  * @since 2.1.0
  6595  * @since 2.1.0
  6378  *
  6596  *
  6379  * @global string $pagenow
  6597  * @global string $pagenow The filename of the current screen.
  6380  *
  6598  *
  6381  * @param int $attachment_id Optional. Attachment post ID. Defaults to global $post.
  6599  * @param int $attachment_id Optional. Attachment post ID. Defaults to global $post.
  6382  * @return string|false Attachment URL, otherwise false.
  6600  * @return string|false Attachment URL, otherwise false.
  6383  */
  6601  */
  6384 function wp_get_attachment_url( $attachment_id = 0 ) {
  6602 function wp_get_attachment_url( $attachment_id = 0 ) {
  6483 /**
  6701 /**
  6484  * Retrieve thumbnail for an attachment.
  6702  * Retrieve thumbnail for an attachment.
  6485  *
  6703  *
  6486  * @since 2.1.0
  6704  * @since 2.1.0
  6487  *
  6705  *
  6488  * @param int $post_id Optional. Attachment ID. Default 0.
  6706  * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
  6489  * @return string|false Thumbnail file path on success, false on failure.
  6707  * @return string|false Thumbnail file path on success, false on failure.
  6490  */
  6708  */
  6491 function wp_get_attachment_thumb_file( $post_id = 0 ) {
  6709 function wp_get_attachment_thumb_file( $post_id = 0 ) {
  6492 	$post_id = (int) $post_id;
  6710 	$post_id = (int) $post_id;
  6493 	$post    = get_post( $post_id );
  6711 	$post    = get_post( $post_id );
  6523 /**
  6741 /**
  6524  * Retrieve URL for an attachment thumbnail.
  6742  * Retrieve URL for an attachment thumbnail.
  6525  *
  6743  *
  6526  * @since 2.1.0
  6744  * @since 2.1.0
  6527  *
  6745  *
  6528  * @param int $post_id Optional. Attachment ID. Default 0.
  6746  * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
  6529  * @return string|false Thumbnail URL on success, false on failure.
  6747  * @return string|false Thumbnail URL on success, false on failure.
  6530  */
  6748  */
  6531 function wp_get_attachment_thumb_url( $post_id = 0 ) {
  6749 function wp_get_attachment_thumb_url( $post_id = 0 ) {
  6532 	$post_id = (int) $post_id;
  6750 	$post_id = (int) $post_id;
  6533 	$post    = get_post( $post_id );
  6751 	$post    = get_post( $post_id );
  7132 function update_post_cache( &$posts ) {
  7350 function update_post_cache( &$posts ) {
  7133 	if ( ! $posts ) {
  7351 	if ( ! $posts ) {
  7134 		return;
  7352 		return;
  7135 	}
  7353 	}
  7136 
  7354 
       
  7355 	$data = array();
  7137 	foreach ( $posts as $post ) {
  7356 	foreach ( $posts as $post ) {
  7138 		wp_cache_add( $post->ID, $post, 'posts' );
  7357 		if ( empty( $post->filter ) || 'raw' !== $post->filter ) {
  7139 	}
  7358 			$post = sanitize_post( $post, 'raw' );
       
  7359 		}
       
  7360 		$data[ $post->ID ] = $post;
       
  7361 	}
       
  7362 	wp_cache_add_multiple( $data, 'posts' );
  7140 }
  7363 }
  7141 
  7364 
  7142 /**
  7365 /**
  7143  * Will clean the post in the cache.
  7366  * Will clean the post in the cache.
  7144  *
  7367  *
  7387  * Uses XMLRPC_REQUEST and WP_IMPORTING constants.
  7610  * Uses XMLRPC_REQUEST and WP_IMPORTING constants.
  7388  *
  7611  *
  7389  * @since 2.3.0
  7612  * @since 2.3.0
  7390  * @access private
  7613  * @access private
  7391  *
  7614  *
  7392  * @param int $post_id The ID in the database table of the post being published.
  7615  * @param int $post_id The ID of the post being published.
  7393  */
  7616  */
  7394 function _publish_post_hook( $post_id ) {
  7617 function _publish_post_hook( $post_id ) {
  7395 	if ( defined( 'XMLRPC_REQUEST' ) ) {
  7618 	if ( defined( 'XMLRPC_REQUEST' ) ) {
  7396 		/**
  7619 		/**
  7397 		 * Fires when _publish_post_hook() is called during an XML-RPC request.
  7620 		 * Fires when _publish_post_hook() is called during an XML-RPC request.
  7424 
  7647 
  7425 /**
  7648 /**
  7426  * Returns the ID of the post's parent.
  7649  * Returns the ID of the post's parent.
  7427  *
  7650  *
  7428  * @since 3.1.0
  7651  * @since 3.1.0
  7429  *
  7652  * @since 5.9.0 The `$post` parameter was made optional.
  7430  * @param int|WP_Post $post Post ID or post object. Defaults to global $post.
  7653  *
       
  7654  * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
  7431  * @return int|false Post parent ID (which can be 0 if there is no parent),
  7655  * @return int|false Post parent ID (which can be 0 if there is no parent),
  7432  *                   or false if the post does not exist.
  7656  *                   or false if the post does not exist.
  7433  */
  7657  */
  7434 function wp_get_post_parent_id( $post ) {
  7658 function wp_get_post_parent_id( $post = null ) {
  7435 	$post = get_post( $post );
  7659 	$post = get_post( $post );
  7436 	if ( ! $post || is_wp_error( $post ) ) {
  7660 	if ( ! $post || is_wp_error( $post ) ) {
  7437 		return false;
  7661 		return false;
  7438 	}
  7662 	}
  7439 	return (int) $post->post_parent;
  7663 	return (int) $post->post_parent;
  7642  * For internal use.
  7866  * For internal use.
  7643  *
  7867  *
  7644  * @since 4.5.0
  7868  * @since 4.5.0
  7645  * @access private
  7869  * @access private
  7646  *
  7870  *
  7647  * @param string $post_name Slug.
  7871  * @param string $post_name Post slug.
  7648  * @param int    $post_ID   Optional. Post ID that should be ignored. Default 0.
  7872  * @param int    $post_ID   Optional. Post ID that should be ignored. Default 0.
  7649  */
  7873  */
  7650 function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) {
  7874 function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) {
  7651 	$trashed_posts_with_desired_slug = get_posts(
  7875 	$trashed_posts_with_desired_slug = get_posts(
  7652 		array(
  7876 		array(