wp/wp-admin/includes/post.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   491  *
   491  *
   492  * @global wpdb $wpdb WordPress database abstraction object.
   492  * @global wpdb $wpdb WordPress database abstraction object.
   493  *
   493  *
   494  * @param array|null $post_data Optional. The array of post data to process.
   494  * @param array|null $post_data Optional. The array of post data to process.
   495  *                              Defaults to the `$_POST` superglobal.
   495  *                              Defaults to the `$_POST` superglobal.
   496  * @return array
   496  * @return array {
       
   497  *     An array of updated, skipped, and locked post IDs.
       
   498  *
       
   499  *     @type int[] $updated An array of updated post IDs.
       
   500  *     @type int[] $skipped An array of skipped post IDs.
       
   501  *     @type int[] $locked  An array of locked post IDs.
       
   502  * }
   497  */
   503  */
   498 function bulk_edit_posts( $post_data = null ) {
   504 function bulk_edit_posts( $post_data = null ) {
   499 	global $wpdb;
   505 	global $wpdb;
   500 
   506 
   501 	if ( empty( $post_data ) ) {
   507 	if ( empty( $post_data ) ) {
  1169 
  1175 
  1170 		$quote  = $url_match[1]; // The quote (single or double).
  1176 		$quote  = $url_match[1]; // The quote (single or double).
  1171 		$url_id = (int) $url_match[2];
  1177 		$url_id = (int) $url_match[2];
  1172 		$rel_id = (int) $rel_match[1];
  1178 		$rel_id = (int) $rel_match[1];
  1173 
  1179 
  1174 		if ( ! $url_id || ! $rel_id || $url_id != $rel_id || ! str_contains( $url_match[0], $site_url ) ) {
  1180 		if ( ! $url_id || ! $rel_id || $url_id !== $rel_id || ! str_contains( $url_match[0], $site_url ) ) {
  1175 			continue;
  1181 			continue;
  1176 		}
  1182 		}
  1177 
  1183 
  1178 		$link    = $link_matches[0][ $key ];
  1184 		$link    = $link_matches[0][ $key ];
  1179 		$replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link );
  1185 		$replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link );
  1209  *
  1215  *
  1210  * @since 2.5.0
  1216  * @since 2.5.0
  1211  *
  1217  *
  1212  * @param array|false $q Optional. Array of query variables to use to build the query.
  1218  * @param array|false $q Optional. Array of query variables to use to build the query.
  1213  *                       Defaults to the `$_GET` superglobal.
  1219  *                       Defaults to the `$_GET` superglobal.
  1214  * @return array
  1220  * @return string[] An array of all the statuses for the queried post type.
  1215  */
  1221  */
  1216 function wp_edit_posts_query( $q = false ) {
  1222 function wp_edit_posts_query( $q = false ) {
  1217 	if ( false === $q ) {
  1223 	if ( false === $q ) {
  1218 		$q = $_GET;
  1224 		$q = $_GET;
  1219 	}
  1225 	}
  1381  *
  1387  *
  1382  * @since 2.5.0
  1388  * @since 2.5.0
  1383  *
  1389  *
  1384  * @param array|false $q Optional. Array of query variables to use to build the query.
  1390  * @param array|false $q Optional. Array of query variables to use to build the query.
  1385  *                       Defaults to the `$_GET` superglobal.
  1391  *                       Defaults to the `$_GET` superglobal.
  1386  * @return array
  1392  * @return array {
       
  1393  *     Array containing the post mime types and available post mime types.
       
  1394  *
       
  1395  *     @type array[]  $post_mime_types       Post mime types.
       
  1396  *     @type string[] $avail_post_mime_types Available post mime types.
       
  1397  * }
  1387  */
  1398  */
  1388 function wp_edit_attachments_query( $q = false ) {
  1399 function wp_edit_attachments_query( $q = false ) {
  1389 	wp( wp_edit_attachments_query_vars( $q ) );
  1400 	wp( wp_edit_attachments_query_vars( $q ) );
  1390 
  1401 
  1391 	$post_mime_types       = get_post_mime_types();
  1402 	$post_mime_types       = get_post_mime_types();
  1802 		$locked = true;
  1813 		$locked = true;
  1803 	} else {
  1814 	} else {
  1804 		$locked = false;
  1815 		$locked = false;
  1805 	}
  1816 	}
  1806 
  1817 
  1807 	$sendback = wp_get_referer();
  1818 	$sendback      = wp_get_referer();
  1808 	if ( $locked && $sendback && ! str_contains( $sendback, 'post.php' ) && ! str_contains( $sendback, 'post-new.php' ) ) {
  1819 	$sendback_text = __( 'Go back' );
  1809 
  1820 
  1810 		$sendback_text = __( 'Go back' );
  1821 	if ( ! $locked || ! $sendback || str_contains( $sendback, 'post.php' ) || str_contains( $sendback, 'post-new.php' ) ) {
  1811 	} else {
       
  1812 		$sendback = admin_url( 'edit.php' );
  1822 		$sendback = admin_url( 'edit.php' );
  1813 
  1823 
  1814 		if ( 'post' !== $post->post_type ) {
  1824 		if ( 'post' !== $post->post_type ) {
  1815 			$sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
  1825 			$sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
  1816 		}
  1826 		}
  1817 
  1827 
  1818 		$sendback_text = get_post_type_object( $post->post_type )->labels->all_items;
  1828 		$post_type_object = get_post_type_object( $post->post_type );
       
  1829 
       
  1830 		if ( $post_type_object ) {
       
  1831 			$sendback_text = $post_type_object->labels->all_items;
       
  1832 		}
  1819 	}
  1833 	}
  1820 
  1834 
  1821 	$hidden = $locked ? '' : ' hidden';
  1835 	$hidden = $locked ? '' : ' hidden';
  1822 
  1836 
  1823 	?>
  1837 	?>
  2003 
  2017 
  2004 	return $revision;
  2018 	return $revision;
  2005 }
  2019 }
  2006 
  2020 
  2007 /**
  2021 /**
  2008  * Autosave the revisioned meta fields.
  2022  * Autosaves the revisioned meta fields.
  2009  *
  2023  *
  2010  * Iterates through the revisioned meta fields and checks each to see if they are set,
  2024  * Iterates through the revisioned meta fields and checks each to see if they are set,
  2011  * and have a changed value. If so, the meta value is saved and attached to the autosave.
  2025  * and have a changed value. If so, the meta value is saved and attached to the autosave.
  2012  *
  2026  *
  2013  * @since 6.4.0
  2027  * @since 6.4.0
  2025 	$posted_data = isset( $_POST['data']['wp_autosave'] ) ? $_POST['data']['wp_autosave'] : $_POST;
  2039 	$posted_data = isset( $_POST['data']['wp_autosave'] ) ? $_POST['data']['wp_autosave'] : $_POST;
  2026 
  2040 
  2027 	$post_type = get_post_type( $new_autosave['post_parent'] );
  2041 	$post_type = get_post_type( $new_autosave['post_parent'] );
  2028 
  2042 
  2029 	/*
  2043 	/*
  2030 	 * Go thru the revisioned meta keys and save them as part of the autosave, if
  2044 	 * Go through the revisioned meta keys and save them as part of the autosave,
  2031 	 * the meta key is part of the posted data, the meta value is not blank and
  2045 	 * if the meta key is part of the posted data, the meta value is not blank,
  2032 	 * the the meta value has changes from the last autosaved value.
  2046 	 * and the meta value has changes from the last autosaved value.
  2033 	 */
  2047 	 */
  2034 	foreach ( wp_post_revision_meta_keys( $post_type ) as $meta_key ) {
  2048 	foreach ( wp_post_revision_meta_keys( $post_type ) as $meta_key ) {
  2035 
  2049 
  2036 		if (
  2050 		if ( isset( $posted_data[ $meta_key ] )
  2037 		isset( $posted_data[ $meta_key ] ) &&
  2051 			&& get_post_meta( $new_autosave['ID'], $meta_key, true ) !== wp_unslash( $posted_data[ $meta_key ] )
  2038 		get_post_meta( $new_autosave['ID'], $meta_key, true ) !== wp_unslash( $posted_data[ $meta_key ] )
       
  2039 		) {
  2052 		) {
  2040 			/*
  2053 			/*
  2041 			 * Use the underlying delete_metadata() and add_metadata() functions
  2054 			 * Use the underlying delete_metadata() and add_metadata() functions
  2042 			 * vs delete_post_meta() and add_post_meta() to make sure we're working
  2055 			 * vs delete_post_meta() and add_post_meta() to make sure we're working
  2043 			 * with the actual revision meta.
  2056 			 * with the actual revision meta.
  2044 			 */
  2057 			 */
  2045 			delete_metadata( 'post', $new_autosave['ID'], $meta_key );
  2058 			delete_metadata( 'post', $new_autosave['ID'], $meta_key );
  2046 
  2059 
  2047 			/*
  2060 			// One last check to ensure meta value is not empty.
  2048 			 * One last check to ensure meta value not empty().
       
  2049 			 */
       
  2050 			if ( ! empty( $posted_data[ $meta_key ] ) ) {
  2061 			if ( ! empty( $posted_data[ $meta_key ] ) ) {
  2051 				/*
  2062 				// Add the revisions meta data to the autosave.
  2052 				 * Add the revisions meta data to the autosave.
       
  2053 				 */
       
  2054 				add_metadata( 'post', $new_autosave['ID'], $meta_key, $posted_data[ $meta_key ] );
  2063 				add_metadata( 'post', $new_autosave['ID'], $meta_key, $posted_data[ $meta_key ] );
  2055 			}
  2064 			}
  2056 		}
  2065 		}
  2057 	}
  2066 	}
  2058 }
  2067 }