Changeset 47119 for trunk/src/wp-admin/includes/post.php
- Timestamp:
- 01/29/2020 12:33:45 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/post.php
r46826 r47119 93 93 $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); 94 94 95 // No longer an auto-draft 95 // No longer an auto-draft. 96 96 if ( 'auto-draft' === $post_data['post_status'] ) { 97 97 $post_data['post_status'] = 'draft'; … … 103 103 } 104 104 105 // What to do based on which button they pressed 105 // What to do based on which button they pressed. 106 106 if ( isset( $post_data['saveasdraft'] ) && '' != $post_data['saveasdraft'] ) { 107 107 $post_data['post_status'] = 'draft'; … … 133 133 $published_statuses = array( 'publish', 'future' ); 134 134 135 // Posts 'submitted for approval' presentare submitted to $_POST the same as if they were being published.135 // Posts 'submitted for approval' are submitted to $_POST the same as if they were being published. 136 136 // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. 137 137 if ( isset( $post_data['post_status'] ) && ( in_array( $post_data['post_status'], $published_statuses ) && ! current_user_can( $ptype->cap->publish_posts ) ) ) { … … 209 209 } 210 210 211 // Pass through errors 211 // Pass through errors. 212 212 if ( is_wp_error( $post_data ) ) { 213 213 return $post_data; … … 269 269 $revision = current( $revisions ); 270 270 271 // Check if the revisions have been upgraded 271 // Check if the revisions have been upgraded. 272 272 if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) { 273 273 _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) ); … … 297 297 $translated = _wp_get_allowed_postdata( $post_data ); 298 298 299 // Post Formats299 // Post formats. 300 300 if ( isset( $post_data['post_format'] ) ) { 301 301 set_post_format( $post_ID, $post_data['post_format'] ); … … 337 337 } 338 338 339 // Meta Stuff339 // Meta stuff. 340 340 if ( isset( $post_data['meta'] ) && $post_data['meta'] ) { 341 341 foreach ( $post_data['meta'] as $key => $value ) { … … 373 373 } 374 374 375 // Attachment stuff 375 // Attachment stuff. 376 376 if ( 'attachment' == $post_data['post_type'] ) { 377 377 if ( isset( $post_data['_wp_attachment_image_alt'] ) ) { 378 378 $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] ); 379 379 380 if ( $image_alt != get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) ) { 380 381 $image_alt = wp_strip_all_tags( $image_alt, true ); 381 // update_meta expects slashed. 382 383 // update_post_meta() expects slashed. 382 384 update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); 383 385 } … … 406 408 407 409 $success = wp_update_post( $translated ); 408 // If the save failed, see if we can sanity check the main fields and try again 410 411 // If the save failed, see if we can sanity check the main fields and try again. 409 412 if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { 410 413 $fields = array( 'post_title', 'post_content', 'post_excerpt' ); … … 419 422 } 420 423 421 // Now that we have an ID we can fix any attachment anchor hrefs 424 // Now that we have an ID we can fix any attachment anchor hrefs. 422 425 _fix_attachment_links( $post_ID ); 423 426 … … 677 680 } 678 681 679 // Schedule auto-draft cleanup 682 // Schedule auto-draft cleanup. 680 683 if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) { 681 684 wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' ); … … 817 820 unset( $_POST['filter'] ); 818 821 819 // Edit don't write if we have a post id.822 // Edit, don't write, if we have a post ID. 820 823 if ( isset( $_POST['post_ID'] ) ) { 821 824 return edit_post(); … … 858 861 add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); 859 862 860 // Now that we have an ID we can fix any attachment anchor hrefs 863 // Now that we have an ID we can fix any attachment anchor hrefs. 861 864 _fix_attachment_links( $post_ID ); 862 865 … … 883 886 884 887 // 885 // Post Meta 888 // Post Meta. 886 889 // 887 890 … … 914 917 915 918 if ( $metakeyinput ) { 916 $metakey = $metakeyinput; // default919 $metakey = $metakeyinput; // Default. 917 920 } 918 921 … … 927 930 928 931 return false; 929 } // add_meta932 } 930 933 931 934 /** … … 1018 1021 1019 1022 // 1020 // Private 1023 // Private. 1021 1024 // 1022 1025 … … 1039 1042 } 1040 1043 1041 // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero) 1044 // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero). 1042 1045 if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) { 1043 1046 return; … … 1045 1048 1046 1049 $site_url = get_bloginfo( 'url' ); 1047 $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // remove the http(s)1050 $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s). 1048 1051 $replace = ''; 1049 1052 … … 1055 1058 } 1056 1059 1057 $quote = $url_match[1]; // the quote (single or double)1060 $quote = $url_match[1]; // The quote (single or double). 1058 1061 $url_id = (int) $url_match[2]; 1059 1062 $rel_id = (int) $rel_match[1]; … … 1345 1348 } 1346 1349 1347 // If the user wants to set a new name -- override the current one 1348 // Note: if empty name is supplied -- use the title instead, see #6072 1350 // If the user wants to set a new name -- override the current one. 1351 // Note: if empty name is supplied -- use the title instead, see #6072. 1349 1352 if ( ! is_null( $name ) ) { 1350 1353 $post->post_name = sanitize_title( $name ? $name : $title, $post->ID ); … … 1357 1360 $permalink = get_permalink( $post, true ); 1358 1361 1359 // Replace custom post_type Token with generic pagename token for ease of use.1362 // Replace custom post_type token with generic pagename token for ease of use. 1360 1363 $permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink ); 1361 1364 1362 // Handle page hierarchy 1365 // Handle page hierarchy. 1363 1366 if ( $ptype->hierarchical ) { 1364 1367 $uri = get_page_uri( $post ); … … 1432 1435 $view_link = get_permalink( $post ); 1433 1436 } else { 1434 // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set 1437 // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set. 1435 1438 $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink ); 1436 1439 } … … 1438 1441 } 1439 1442 1440 // Permalinks without a post/page name placeholder don't have anything to edit 1443 // Permalinks without a post/page name placeholder don't have anything to edit. 1441 1444 if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) { 1442 1445 $return = '<strong>' . __( 'Permalink:' ) . "</strong>\n"; … … 1449 1452 } 1450 1453 1451 // Encourage a pretty permalink setting 1454 // Encourage a pretty permalink setting. 1452 1455 if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && ! ( 'page' == get_option( 'show_on_front' ) && $id == get_option( 'page_on_front' ) ) ) { 1453 1456 $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . "</a></span>\n"; … … 1693 1696 if ( get_post_type_object( $post->post_type )->public ) { 1694 1697 if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) { 1695 // Latest content is in autosave 1698 // Latest content is in autosave. 1696 1699 $nonce = wp_create_nonce( 'post_preview_' . $post->ID ); 1697 1700 $query_args['preview_id'] = $post->ID; … … 1748 1751 } 1749 1752 1750 // Allow plugins to prevent some users overriding the post lock 1753 // Allow plugins to prevent some users overriding the post lock. 1751 1754 if ( $override ) { 1752 1755 ?> … … 1820 1823 $new_autosave['post_author'] = $post_author; 1821 1824 1825 $post = get_post( $post_id ); 1826 1822 1827 // If the new autosave has the same content as the post, delete the autosave. 1823 $post = get_post( $post_id );1824 1828 $autosave_is_different = false; 1825 1829 foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) { … … 1850 1854 $post_data = wp_unslash( $post_data ); 1851 1855 1852 // Otherwise create the new autosave as a special post revision 1856 // Otherwise create the new autosave as a special post revision. 1853 1857 return _wp_put_post_revision( $post_data, true ); 1854 1858 } … … 1923 1927 */ 1924 1928 function wp_autosave( $post_data ) { 1925 // Back-compat 1929 // Back-compat. 1926 1930 if ( ! defined( 'DOING_AUTOSAVE' ) ) { 1927 1931 define( 'DOING_AUTOSAVE', true ); … … 1951 1955 1952 1956 if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) { 1953 // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked 1957 // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked. 1954 1958 return edit_post( wp_slash( $post_data ) ); 1955 1959 } else { 1956 // Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user. 1960 // Non-drafts or other users' drafts are not overwritten. 1961 // The autosave is stored in a special post revision for each user. 1957 1962 return wp_create_post_autosave( wp_slash( $post_data ) ); 1958 1963 }
Note: See TracChangeset
for help on using the changeset viewer.