WordPress.org

Make WordPress Core

Ticket #17115: 17115.7.diff

File 17115.7.diff, 4.5 KB (added by adamsilverstein, 3 years ago)
  • src/wp-admin/edit-form-advanced.php

    diff --git src/wp-admin/edit-form-advanced.php src/wp-admin/edit-form-advanced.php
    index 852b88c..a877c30 100644
    $messages['post'] = array( 
    145145         8 => __( 'Post submitted.' ) . $preview_post_link_html,
    146146         9 => sprintf( __( 'Post scheduled for: %s.' ), '<strong>' . $scheduled_date . '</strong>' ) . $scheduled_post_link_html,
    147147        10 => __( 'Post draft updated.' ) . $preview_post_link_html,
     148        11 => __( 'You attempted to publish an empty post. Provide some content before saving.' ),
    148149);
    149150$messages['page'] = array(
    150151         0 => '', // Unused. Messages start at index 1.
    $messages['page'] = array( 
    159160         8 => __( 'Page submitted.' ) . $preview_page_link_html,
    160161         9 => sprintf( __( 'Page scheduled for: %s.' ), '<strong>' . $scheduled_date . '</strong>' ) . $scheduled_page_link_html,
    161162        10 => __( 'Page draft updated.' ) . $preview_page_link_html,
     163        11 => __( 'You attempted to publish an empty page. Provide some content before saving.' ),
    162164);
    163165$messages['attachment'] = array_fill( 1, 10, __( 'Media file updated.' ) ); // Hack, for now.
    164166
    if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create 
    489491<div id="notice" class="notice notice-warning"><p id="has-newer-autosave"><?php echo $notice ?></p></div>
    490492<?php endif; ?>
    491493<?php if ( $message ) : ?>
    492 <div id="message" class="updated notice notice-success is-dismissible"><p><?php echo $message; ?></p></div>
     494<div id="message" class="notice <?php echo ( isset( $_GET['error'] ) && '1' === $_GET['error'] ) ? 'notice-error' : 'updated notice-success'; ?> is-dismissible"><p><?php echo $message; ?></p></div>
    493495<?php endif; ?>
    494496<div id="lost-connection-notice" class="error hidden">
    495497        <p><span class="spinner"></span> <?php _e( '<strong>Connection lost.</strong> Saving has been disabled until you&#8217;re reconnected.' ); ?>
  • src/wp-admin/includes/post.php

    diff --git src/wp-admin/includes/post.php src/wp-admin/includes/post.php
    index 1054f2b..87c612c 100644
    function wp_autosave( $post_data ) { 
    18151815function redirect_post($post_id = '') {
    18161816        if ( isset($_POST['save']) || isset($_POST['publish']) ) {
    18171817                $status = get_post_status( $post_id );
    1818 
     1818                $error = false;
    18191819                if ( isset( $_POST['publish'] ) ) {
    18201820                        switch ( $status ) {
    18211821                                case 'pending':
    function redirect_post($post_id = '') { 
    18241824                                case 'future':
    18251825                                        $message = 9;
    18261826                                        break;
     1827                                case 'auto-draft':
     1828                                case 'draft':
     1829                                        $message = 11;
     1830                                        $error   = true;
     1831                                        break;
    18271832                                default:
    18281833                                        $message = 6;
    18291834                        }
    function redirect_post($post_id = '') { 
    18311836                        $message = 'draft' == $status ? 10 : 1;
    18321837                }
    18331838
    1834                 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
     1839                $location = add_query_arg( array( 'error' => $error, 'message' => $message ), get_edit_post_link( $post_id, 'url' ) );
    18351840        } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
    18361841                $location = add_query_arg( 'message', 2, wp_get_referer() );
    18371842                $location = explode('#', $location);
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index d879491..4bc06c1 100644
    function wp_insert_post( $postarr, $wp_error = false ) { 
    30323032                $post_name = $post_before->post_name;
    30333033        }
    30343034
     3035        $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
     3036        if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash', 'auto-draft' ), true ) ) {
     3037                $post_status = 'inherit';
     3038        }
     3039
    30353040        $maybe_empty = 'attachment' !== $post_type
    30363041                && ! $post_content && ! $post_title && ! $post_excerpt
    30373042                && post_type_supports( $post_type, 'editor' )
    30383043                && post_type_supports( $post_type, 'title' )
    3039                 && post_type_supports( $post_type, 'excerpt' );
     3044                && post_type_supports( $post_type, 'excerpt' )
     3045                && ( 'draft' !== $post_status && isset( $_POST['publish'] ) );
    30403046
    30413047        /**
    30423048         * Filters whether the post should be considered "empty".
    function wp_insert_post( $postarr, $wp_error = false ) { 
    30623068                }
    30633069        }
    30643070
    3065         $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
    3066         if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash', 'auto-draft' ), true ) ) {
    3067                 $post_status = 'inherit';
    3068         }
    3069 
    30703071        if ( ! empty( $postarr['post_category'] ) ) {
    30713072                // Filter out empty terms.
    30723073                $post_category = array_filter( $postarr['post_category'] );