WordPress.org

Make WordPress Core

Changeset 47922


Ignore:
Timestamp:
06/07/2020 09:22:07 AM (4 months ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Display a more specific error message when an attachment could not be inserted into the database.

Props shital-patel, Presskopp, ocean90.
Fixes #50325.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/bookmark.php

    r47851 r47922  
    206206        if ( false === $wpdb->update( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ), compact( 'link_id' ) ) ) {
    207207            if ( $wp_error ) {
    208                 return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
     208                return new WP_Error( 'db_update_error', __( 'Could not update link in the database.' ), $wpdb->last_error );
    209209            } else {
    210210                return 0;
     
    214214        if ( false === $wpdb->insert( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ) ) ) {
    215215            if ( $wp_error ) {
    216                 return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
     216                return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database.' ), $wpdb->last_error );
    217217            } else {
    218218                return 0;
  • trunk/src/wp-includes/comment.php

    r47887 r47922  
    23062306    if ( ! $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $comment_old->comment_ID ) ) ) {
    23072307        if ( $wp_error ) {
    2308             return new WP_Error( 'db_update_error', __( 'Could not update comment status' ), $wpdb->last_error );
     2308            return new WP_Error( 'db_update_error', __( 'Could not update comment status.' ), $wpdb->last_error );
    23092309        } else {
    23102310            return false;
  • trunk/src/wp-includes/post.php

    r47892 r47922  
    36443644        $post_ID     = $postarr['ID'];
    36453645        $post_before = get_post( $post_ID );
     3646
    36463647        if ( is_null( $post_before ) ) {
    36473648            if ( $wp_error ) {
     
    36623663    $post_content = $postarr['post_content'];
    36633664    $post_excerpt = $postarr['post_excerpt'];
     3665
    36643666    if ( isset( $postarr['post_name'] ) ) {
    36653667        $post_name = $postarr['post_name'];
     
    37003702
    37013703    $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
     3704
    37023705    if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash', 'auto-draft' ), true ) ) {
    37033706        $post_status = 'inherit';
     
    37453748        // On updates, we need to check to see if it's using the old, fixed sanitization context.
    37463749        $check_name = sanitize_title( $post_name, '', 'old-save' );
     3750
    37473751        if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_ID ) == $check_name ) {
    37483752            $post_name = $check_name;
     
    38763880    if ( 'trash' === $previous_status && 'trash' !== $post_status ) {
    38773881        $desired_post_slug = get_post_meta( $post_ID, '_wp_desired_post_slug', true );
     3882
    38783883        if ( $desired_post_slug ) {
    38793884            delete_post_meta( $post_ID, '_wp_desired_post_slug' );
     
    39183923        if ( isset( $data[ $emoji_field ] ) ) {
    39193924            $charset = $wpdb->get_col_charset( $wpdb->posts, $emoji_field );
     3925
    39203926            if ( 'utf8' === $charset ) {
    39213927                $data[ $emoji_field ] = wp_encode_emoji( $data[ $emoji_field ] );
     
    39513957        $data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr );
    39523958    }
     3959
    39533960    $data  = wp_unslash( $data );
    39543961    $where = array( 'ID' => $post_ID );
     
    39643971         */
    39653972        do_action( 'pre_post_update', $post_ID, $data );
     3973
    39663974        if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
    39673975            if ( $wp_error ) {
    3968                 return new WP_Error( 'db_update_error', __( 'Could not update post in the database' ), $wpdb->last_error );
     3976                if ( 'attachment' === $post_type ) {
     3977                    $message = __( 'Could not update attachment in the database.' );
     3978                } else {
     3979                    $message = __( 'Could not update post in the database.' );
     3980                }
     3981
     3982                return new WP_Error( 'db_update_error', $message, $wpdb->last_error );
    39693983            } else {
    39703984                return 0;
     
    39753989        if ( ! empty( $import_id ) ) {
    39763990            $import_id = (int) $import_id;
     3991
    39773992            if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) {
    39783993                $data['ID'] = $import_id;
    39793994            }
    39803995        }
     3996
    39813997        if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
    39823998            if ( $wp_error ) {
    3983                 return new WP_Error( 'db_insert_error', __( 'Could not insert post into the database' ), $wpdb->last_error );
     3999                if ( 'attachment' === $post_type ) {
     4000                    $message = __( 'Could not insert attachment into the database.' );
     4001                } else {
     4002                    $message = __( 'Could not insert post into the database.' );
     4003                }
     4004
     4005                return new WP_Error( 'db_insert_error', $message, $wpdb->last_error );
    39844006            } else {
    39854007                return 0;
    39864008            }
    39874009        }
     4010
    39884011        $post_ID = (int) $wpdb->insert_id;
    39894012
     
    39944017    if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) ) {
    39954018        $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post_ID ), $post_ID, $data['post_status'], $post_type, $post_parent );
     4019
    39964020        $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
    39974021        clean_post_cache( $post_ID );
     
    40104034        foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
    40114035            $taxonomy_obj = get_taxonomy( $taxonomy );
     4036
    40124037            if ( ! $taxonomy_obj ) {
    40134038                /* translators: %s: Taxonomy name. */
     
    40204045                $tags = array_filter( $tags );
    40214046            }
     4047
    40224048            if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
    40234049                wp_set_post_terms( $post_ID, $tags, $taxonomy );
     
    40524078    if ( isset( $postarr['_thumbnail_id'] ) ) {
    40534079        $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;
     4080
    40544081        if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) {
    40554082            if ( wp_attachment_is( 'audio', $post_ID ) ) {
     
    40774104        $post->page_template = $postarr['page_template'];
    40784105        $page_templates      = wp_get_theme()->get_page_templates( $post );
     4106
    40794107        if ( 'default' !== $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
    40804108            if ( $wp_error ) {
    40814109                return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) );
    40824110            }
     4111
    40834112            update_post_meta( $post_ID, '_wp_page_template', 'default' );
    40844113        } else {
     
    40994128             */
    41004129            do_action( 'edit_attachment', $post_ID );
     4130
    41014131            $post_after = get_post( $post_ID );
    41024132
Note: See TracChangeset for help on using the changeset viewer.