diff options
Diffstat (limited to 'wp-includes/post.php')
-rw-r--r-- | wp-includes/post.php | 227 |
1 files changed, 148 insertions, 79 deletions
diff --git a/wp-includes/post.php b/wp-includes/post.php index 7645043..993056f 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -328,6 +328,7 @@ function create_initial_post_types() { 'map_meta_cap' => true, 'supports' => array( 'title', + 'excerpt', 'editor', 'revisions', 'custom-fields', @@ -365,6 +366,7 @@ function create_initial_post_types() { 'filter_items_list' => __( 'Filter templates list' ), 'items_list_navigation' => __( 'Templates list navigation' ), 'items_list' => __( 'Templates list' ), + 'item_updated' => __( 'Template updated.' ), ), 'description' => __( 'Templates to include in your theme.' ), 'public' => false, @@ -429,6 +431,7 @@ function create_initial_post_types() { 'filter_items_list' => __( 'Filter template parts list' ), 'items_list_navigation' => __( 'Template parts list navigation' ), 'items_list' => __( 'Template parts list' ), + 'item_updated' => __( 'Template part updated.' ), ), 'description' => __( 'Template parts to include in your templates.' ), 'public' => false, @@ -473,15 +476,19 @@ function create_initial_post_types() { register_post_type( 'wp_global_styles', array( - 'label' => _x( 'Global Styles', 'post type general name' ), - 'description' => __( 'Global styles to include in themes.' ), - 'public' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - '_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */ - 'show_ui' => false, - 'show_in_rest' => false, - 'rewrite' => false, - 'capabilities' => array( + 'label' => _x( 'Global Styles', 'post type general name' ), + 'description' => __( 'Global styles to include in themes.' ), + 'public' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + '_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */ + 'show_ui' => false, + 'show_in_rest' => true, + 'rewrite' => false, + 'rest_base' => 'global-styles', + 'rest_controller_class' => 'WP_REST_Global_Styles_Controller', + 'revisions_rest_controller_class' => 'WP_REST_Global_Styles_Revisions_Controller', + 'late_route_registration' => true, + 'capabilities' => array( 'read' => 'edit_theme_options', 'create_posts' => 'edit_theme_options', 'edit_posts' => 'edit_theme_options', @@ -490,14 +497,16 @@ function create_initial_post_types() { 'edit_others_posts' => 'edit_theme_options', 'delete_others_posts' => 'edit_theme_options', ), - 'map_meta_cap' => true, - 'supports' => array( + 'map_meta_cap' => true, + 'supports' => array( 'title', 'editor', 'revisions', ), ) ); + // Disable autosave endpoints for global styles. + remove_post_type_support( 'wp_global_styles', 'autosave' ); $navigation_post_edit_link = 'site-editor.php?' . build_query( array( @@ -567,14 +576,14 @@ function create_initial_post_types() { register_post_type( 'wp_font_family', array( - 'labels' => array( + 'labels' => array( 'name' => __( 'Font Families' ), 'singular_name' => __( 'Font Family' ), ), - 'public' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - 'hierarchical' => false, - 'capabilities' => array( + 'public' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + 'hierarchical' => false, + 'capabilities' => array( 'read' => 'edit_theme_options', 'read_private_posts' => 'edit_theme_options', 'create_posts' => 'edit_theme_options', @@ -586,28 +595,27 @@ function create_initial_post_types() { 'delete_others_posts' => 'edit_theme_options', 'delete_published_posts' => 'edit_theme_options', ), - 'map_meta_cap' => true, - 'query_var' => false, - 'rewrite' => false, - 'show_in_rest' => true, - 'rest_base' => 'font-families', - 'rest_controller_class' => 'WP_REST_Font_Families_Controller', - // Disable autosave endpoints for font families. - 'autosave_rest_controller_class' => 'stdClass', + 'map_meta_cap' => true, + 'query_var' => false, + 'rewrite' => false, + 'show_in_rest' => true, + 'rest_base' => 'font-families', + 'rest_controller_class' => 'WP_REST_Font_Families_Controller', + 'supports' => array( 'title' ), ) ); register_post_type( 'wp_font_face', array( - 'labels' => array( + 'labels' => array( 'name' => __( 'Font Faces' ), 'singular_name' => __( 'Font Face' ), ), - 'public' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - 'hierarchical' => false, - 'capabilities' => array( + 'public' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + 'hierarchical' => false, + 'capabilities' => array( 'read' => 'edit_theme_options', 'read_private_posts' => 'edit_theme_options', 'create_posts' => 'edit_theme_options', @@ -619,14 +627,13 @@ function create_initial_post_types() { 'delete_others_posts' => 'edit_theme_options', 'delete_published_posts' => 'edit_theme_options', ), - 'map_meta_cap' => true, - 'query_var' => false, - 'rewrite' => false, - 'show_in_rest' => true, - 'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces', - 'rest_controller_class' => 'WP_REST_Font_Faces_Controller', - // Disable autosave endpoints for font faces. - 'autosave_rest_controller_class' => 'stdClass', + 'map_meta_cap' => true, + 'query_var' => false, + 'rewrite' => false, + 'show_in_rest' => true, + 'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces', + 'rest_controller_class' => 'WP_REST_Font_Faces_Controller', + 'supports' => array( 'title' ), ) ); @@ -1217,7 +1224,10 @@ function get_post_mime_type( $post = null ) { * @return string|false Post status on success, false on failure. */ function get_post_status( $post = null ) { - $post = get_post( $post ); + // Normalize the post object if necessary, skip normalization if called from get_sample_permalink(). + if ( ! $post instanceof WP_Post || ! isset( $post->filter ) || 'sample' !== $post->filter ) { + $post = get_post( $post ); + } if ( ! is_object( $post ) ) { return false; @@ -1713,8 +1723,10 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) * 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', * 'page-attributes', 'thumbnail', 'custom-fields', and 'post-formats'. * Additionally, the 'revisions' feature dictates whether the post type - * will store revisions, and the 'comments' feature dictates whether the - * comments count will show on the edit screen. A feature can also be + * will store revisions, the 'autosave' feature dictates whether the post type + * will be autosaved, and the 'comments' feature dictates whether the + * comments count will show on the edit screen. For backward compatibility reasons, + * adding 'editor' support implies 'autosave' support too. A feature can also be * specified as an array of arguments to provide additional information * about supporting that feature. * Example: `array( 'my_feature', array( 'field' => 'value' ) )`. @@ -2071,6 +2083,7 @@ function _post_type_meta_capabilities( $capabilities = null ) { * @since 6.3.0 Added the `item_trashed` label. * @since 6.4.0 Changed default values for the `add_new` label to include the type of content. * This matches `add_new_item` and provides more context for better accessibility. + * @since 6.6.0 Added the `template_name` label. * * @access private * @@ -2084,6 +2097,11 @@ function get_post_type_labels( $post_type_object ) { $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); + if ( ! isset( $post_type_object->labels->template_name ) && isset( $post_type_object->labels->singular_name ) ) { + /* translators: %s: Post type name. */ + $labels->template_name = sprintf( __( 'Single item: %s' ), $post_type_object->labels->singular_name ); + } + $post_type = $post_type_object->name; $default_labels = clone $labels; @@ -2192,7 +2210,8 @@ function _add_post_type_submenus() { * 'thumbnail', 'custom-fields', and 'post-formats'. * * Additionally, the 'revisions' feature dictates whether the post type will - * store revisions, and the 'comments' feature dictates whether the comments + * store revisions, the 'autosave' feature dictates whether the post type + * will be autosaved, and the 'comments' feature dictates whether the comments * count will show on the edit screen. * * A third, optional parameter can also be passed along with a feature to provide @@ -3403,7 +3422,7 @@ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { $post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) ); } - $wheres = array(); + $where_clauses = array(); foreach ( (array) $post_mime_types as $mime_type ) { $mime_type = preg_replace( '/\s/', '', $mime_type ); @@ -3431,14 +3450,14 @@ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { } if ( str_contains( $mime_pattern, '%' ) ) { - $wheres[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; + $where_clauses[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; } else { - $wheres[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; + $where_clauses[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; } } - if ( ! empty( $wheres ) ) { - $where = ' AND (' . implode( ' OR ', $wheres ) . ') '; + if ( ! empty( $where_clauses ) ) { + $where = ' AND (' . implode( ' OR ', $where_clauses ) . ') '; } return $where; @@ -3460,15 +3479,15 @@ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { * @see wp_delete_attachment() * @see wp_trash_post() * - * @param int $postid Optional. Post ID. Default 0. + * @param int $post_id Optional. Post ID. Default 0. * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. * Default false. * @return WP_Post|false|null Post data on success, false or null on failure. */ -function wp_delete_post( $postid = 0, $force_delete = false ) { +function wp_delete_post( $post_id = 0, $force_delete = false ) { global $wpdb; - $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $postid ) ); + $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); if ( ! $post ) { return $post; @@ -3476,12 +3495,15 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { $post = get_post( $post ); - if ( ! $force_delete && ( 'post' === $post->post_type || 'page' === $post->post_type ) && 'trash' !== get_post_status( $postid ) && EMPTY_TRASH_DAYS ) { - return wp_trash_post( $postid ); + if ( ! $force_delete + && ( 'post' === $post->post_type || 'page' === $post->post_type ) + && 'trash' !== get_post_status( $post_id ) && EMPTY_TRASH_DAYS + ) { + return wp_trash_post( $post_id ); } if ( 'attachment' === $post->post_type ) { - return wp_delete_attachment( $postid, $force_delete ); + return wp_delete_attachment( $post_id, $force_delete ); } /** @@ -3506,30 +3528,39 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { * * @see wp_delete_post() * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'before_delete_post', $postid, $post ); + do_action( 'before_delete_post', $post_id, $post ); - delete_post_meta( $postid, '_wp_trash_meta_status' ); - delete_post_meta( $postid, '_wp_trash_meta_time' ); + delete_post_meta( $post_id, '_wp_trash_meta_status' ); + delete_post_meta( $post_id, '_wp_trash_meta_time' ); - wp_delete_object_term_relationships( $postid, get_object_taxonomies( $post->post_type ) ); + wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) ); $parent_data = array( 'post_parent' => $post->post_parent ); - $parent_where = array( 'post_parent' => $postid ); + $parent_where = array( 'post_parent' => $post_id ); if ( is_post_type_hierarchical( $post->post_type ) ) { // Point children of this page to its parent, also clean the cache of affected children. - $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type ); - $children = $wpdb->get_results( $children_query ); + $children_query = $wpdb->prepare( + "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", + $post_id, + $post->post_type + ); + + $children = $wpdb->get_results( $children_query ); + if ( $children ) { $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); } } // Do raw query. wp_get_post_revisions() is filtered. - $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); + $revision_ids = $wpdb->get_col( + $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $post_id ) + ); + // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. foreach ( $revision_ids as $revision_id ) { wp_delete_post_revision( $revision_id ); @@ -3540,14 +3571,20 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { wp_defer_comment_counting( true ); - $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) ); + $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 ) + ); + foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); } wp_defer_comment_counting( false ); - $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) ); + $post_meta_ids = $wpdb->get_col( + $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) + ); + foreach ( $post_meta_ids as $mid ) { delete_metadata_by_mid( 'post', $mid ); } @@ -3555,15 +3592,28 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { /** * Fires immediately before a post is deleted from the database. * + * The dynamic portion of the hook name, `$post->post_type`, refers to + * the post type slug. + * + * @since 6.6.0 + * + * @param int $post_id Post ID. + * @param WP_Post $post Post object. + */ + do_action( "delete_post_{$post->post_type}", $post_id, $post ); + + /** + * Fires immediately before a post is deleted from the database. + * * @since 1.2.0 * @since 5.5.0 Added the `$post` parameter. * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'delete_post', $postid, $post ); + do_action( 'delete_post', $post_id, $post ); - $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) ); + $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); if ( ! $result ) { return false; } @@ -3571,13 +3621,26 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { /** * Fires immediately after a post is deleted from the database. * + * The dynamic portion of the hook name, `$post->post_type`, refers to + * the post type slug. + * + * @since 6.6.0 + * + * @param int $post_id Post ID. + * @param WP_Post $post Post object. + */ + do_action( "deleted_post_{$post->post_type}", $post_id, $post ); + + /** + * Fires immediately after a post is deleted from the database. + * * @since 2.2.0 * @since 5.5.0 Added the `$post` parameter. * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'deleted_post', $postid, $post ); + do_action( 'deleted_post', $post_id, $post ); clean_post_cache( $post ); @@ -3587,7 +3650,7 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { } } - wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) ); + wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); /** * Fires after a post is deleted, at the conclusion of wp_delete_post(). @@ -3597,10 +3660,10 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { * * @see wp_delete_post() * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'after_delete_post', $postid, $post ); + do_action( 'after_delete_post', $post_id, $post ); return $post; } @@ -6813,6 +6876,11 @@ function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) { $icon = wp_cache_get( "mime_type_icon_$mime" ); } + // Check if preferred file format variable is present and is a validly formatted file extension. + if ( ! empty( $preferred_ext ) && is_string( $preferred_ext ) && ! str_starts_with( $preferred_ext, '.' ) ) { + $preferred_ext = '.' . strtolower( $preferred_ext ); + } + $post_id = 0; if ( empty( $icon ) ) { $post_mimes = array(); @@ -7886,10 +7954,10 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache /** * Prime the cache containing the parent ID of various post objects. * - * @global wpdb $wpdb WordPress database abstraction object. - * * @since 6.4.0 * + * @global wpdb $wpdb WordPress database abstraction object. + * * @param int[] $ids ID list. */ function _prime_post_parent_id_caches( array $ids ) { @@ -8026,10 +8094,11 @@ function get_available_post_mime_types( $type = 'attachment' ) { $mime_types = apply_filters( 'pre_get_available_post_mime_types', null, $type ); if ( ! is_array( $mime_types ) ) { - $mime_types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type ) ); + $mime_types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s AND post_mime_type != ''", $type ) ); } - return $mime_types; + // Remove nulls from returned $mime_types. + return array_values( array_filter( $mime_types ) ); } /** |