X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/41578db67d72562346e4dbb2a14889b23d522813..88550bc3400cc7c035ff590ecb007c7938041ded:/wp-admin/includes/post.php diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 64b63d64..49060309 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -177,6 +177,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { * @return int Post ID. */ function edit_post( $post_data = null ) { + global $wpdb; if ( empty($post_data) ) $post_data = &$_POST; @@ -302,7 +303,7 @@ function edit_post( $post_data = null ) { $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] ); if ( $image_alt != get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) ) { $image_alt = wp_strip_all_tags( $image_alt, true ); - // update_meta expects slashed + // update_meta expects slashed. update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); } } @@ -317,7 +318,19 @@ function edit_post( $post_data = null ) { update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); - wp_update_post( $post_data ); + $success = wp_update_post( $post_data ); + // If the save failed, see if we can sanity check the main fields and try again + if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { + $fields = array( 'post_title', 'post_content', 'post_excerpt' ); + + foreach( $fields as $field ) { + if ( isset( $post_data[ $field ] ) ) { + $post_data[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $post_data[ $field ] ); + } + } + + wp_update_post( $post_data ); + } // Now that we have an ID we can fix any attachment anchor hrefs _fix_attachment_links( $post_ID ); @@ -518,8 +531,6 @@ function bulk_edit_posts( $post_data = null ) { * @return WP_Post Post object containing all the default post data as attributes */ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) { - global $wpdb; - $post_title = ''; if ( !empty( $_REQUEST['post_title'] ) ) $post_title = esc_html( wp_unslash( $_REQUEST['post_title'] )); @@ -544,6 +555,7 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) $post->post_date = ''; $post->post_date_gmt = ''; $post->post_password = ''; + $post->post_name = ''; $post->post_type = $post_type; $post->post_status = 'draft'; $post->to_ping = ''; @@ -587,7 +599,6 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) * @param WP_Post $post Post object. */ $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post ); - $post->post_name = ''; return $post; } @@ -638,7 +649,7 @@ function post_exists($title, $content = '', $date = '') { * * @since 2.1.0 * - * @return unknown + * @return int|WP_Error */ function wp_write_post() { if ( isset($_POST['post_type']) ) @@ -706,11 +717,8 @@ function wp_write_post() { * Calls wp_write_post() and handles the errors. * * @since 2.0.0 - - * @uses wp_write_post() - * @uses is_wp_error() - * @uses wp_die() - * @return unknown + * + * @return int|null */ function write_post() { $result = wp_write_post(); @@ -729,11 +737,10 @@ function write_post() { * * @since 1.2.0 * - * @param unknown_type $post_ID - * @return unknown + * @param int $post_ID + * @return int|bool */ function add_meta( $post_ID ) { - global $wpdb; $post_ID = (int) $post_ID; $metakeyselect = isset($_POST['metakeyselect']) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : ''; @@ -743,9 +750,10 @@ function add_meta( $post_ID ) { $metavalue = trim( $metavalue ); if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ( ( ( '#NONE#' != $metakeyselect ) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput ) ) ) { - // We have a key/value pair. If both the select and the - // input for the key have data, the input takes precedence: - + /* + * We have a key/value pair. If both the select and the input + * for the key have data, the input takes precedence. + */ if ( '#NONE#' != $metakeyselect ) $metakey = $metakeyselect; @@ -768,8 +776,8 @@ function add_meta( $post_ID ) { * * @since 1.2.0 * - * @param unknown_type $mid - * @return unknown + * @param int $mid + * @return bool */ function delete_meta( $mid ) { return delete_metadata_by_mid( 'post' , $mid ); @@ -780,7 +788,7 @@ function delete_meta( $mid ) { * * @since 1.2.0 * - * @return unknown + * @return mixed */ function get_meta_keys() { global $wpdb; @@ -799,8 +807,8 @@ function get_meta_keys() { * * @since 2.1.0 * - * @param unknown_type $mid - * @return unknown + * @param int $mid + * @return object|bool */ function get_post_meta_by_id( $mid ) { return get_metadata_by_mid( 'post', $mid ); @@ -813,8 +821,8 @@ function get_post_meta_by_id( $mid ) { * * @since 1.2.0 * - * @param unknown_type $postid - * @return unknown + * @param int $postid + * @return mixed */ function has_meta( $postid ) { global $wpdb; @@ -829,10 +837,10 @@ function has_meta( $postid ) { * * @since 1.2.0 * - * @param unknown_type $meta_id - * @param unknown_type $meta_key Expect Slashed - * @param unknown_type $meta_value Expect Slashed - * @return unknown + * @param int $meta_id + * @param string $meta_key Expect Slashed + * @param string $meta_value Expect Slashed + * @return bool */ function update_meta( $meta_id, $meta_key, $meta_value ) { $meta_key = wp_unslash( $meta_key ); @@ -949,7 +957,7 @@ function wp_edit_posts_query( $q = false ) { elseif ( isset($q['post_status']) && 'pending' == $q['post_status'] ) $order = 'ASC'; - $per_page = 'edit_' . $post_type . '_per_page'; + $per_page = "edit_{$post_type}_per_page"; $posts_per_page = (int) get_user_option( $per_page ); if ( empty( $posts_per_page ) || $posts_per_page < 1 ) $posts_per_page = 20; @@ -957,26 +965,25 @@ function wp_edit_posts_query( $q = false ) { /** * Filter the number of items per page to show for a specific 'per_page' type. * - * The dynamic hook name, $per_page, refers to a hook name comprised of the post type, - * preceded by 'edit_', and succeeded by '_per_page', e.g. 'edit_$post_type_per_page'. + * The dynamic portion of the hook name, `$post_type`, refers to the post type. * * Some examples of filter hooks generated here include: 'edit_attachment_per_page', * 'edit_post_per_page', 'edit_page_per_page', etc. * * @since 3.0.0 * - * @param int $posts_per_page Number of posts to display per page for the given 'per_page' + * @param int $posts_per_page Number of posts to display per page for the given post * type. Default 20. */ - $posts_per_page = apply_filters( $per_page, $posts_per_page ); + $posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page ); /** * Filter the number of posts displayed per page when specifically listing "posts". * * @since 2.8.0 * - * @param int $per_page Number of posts to be displayed. Default 20. - * @param string $post_type The post type. + * @param int $posts_per_page Number of posts to be displayed. Default 20. + * @param string $post_type The post type. */ $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type ); @@ -1003,8 +1010,8 @@ function wp_edit_posts_query( $q = false ) { * * @since 2.5.0 * - * @param unknown_type $type - * @return unknown + * @param string $type + * @return mixed */ function get_available_post_mime_types($type = 'attachment') { global $wpdb; @@ -1035,6 +1042,8 @@ function wp_edit_attachments_query( $q = false ) { $states .= ',private'; $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states; + $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' == $q['attachment-filter'] ? 'trash' : $states; + $media_per_page = (int) get_user_option( 'upload_per_page' ); if ( empty( $media_per_page ) || $media_per_page < 1 ) $media_per_page = 20; @@ -1054,8 +1063,16 @@ function wp_edit_attachments_query( $q = false ) { if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) ) unset($q['post_mime_type']); - if ( isset($q['detached']) ) + foreach( array_keys( $post_mime_types ) as $type ) { + if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" == $q['attachment-filter'] ) { + $q['post_mime_type'] = $type; + break; + } + } + + if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' == $q['attachment-filter'] ) ) { $q['post_parent'] = 0; + } wp( $q ); @@ -1065,12 +1082,11 @@ function wp_edit_attachments_query( $q = false ) { /** * Returns the list of classes to be used by a metabox * - * @uses get_user_option() * @since 2.5.0 * - * @param unknown_type $id - * @param unknown_type $page - * @return unknown + * @param string $id + * @param string $page + * @return string */ function postbox_classes( $id, $page ) { if ( isset( $_GET['edit'] ) && $_GET['edit'] == $id ) { @@ -1088,8 +1104,8 @@ function postbox_classes( $id, $page ) { /** * Filter the postbox classes for a specific screen and screen ID combo. * - * The dynamic portions of the hook name, $page, and $id, refer to - * the screen, and screen ID, respectively. + * The dynamic portions of the hook name, `$page` and `$id`, refer to + * the screen and screen ID, respectively. * * @since 3.2.0 * @@ -1100,14 +1116,14 @@ function postbox_classes( $id, $page ) { } /** - * {@internal Missing Short Description}} + * Get a sample permalink based off of the post name. * * @since 2.5.0 * - * @param int|object $id Post ID or post object. - * @param string $title (optional) Title - * @param string $name (optional) Name - * @return array With two entries of type string + * @param int $id Post ID or post object. + * @param string $title Optional. Title. Default null. + * @param string $name Optional. Name. Default null. + * @return array Array with two entries of type string. */ function get_sample_permalink($id, $title = null, $name = null) { $post = get_post( $id ); @@ -1169,9 +1185,9 @@ function get_sample_permalink($id, $title = null, $name = null) { * * @since 2.5.0 * - * @param int|object $id Post ID or post object. - * @param string $new_title Optional. New title. - * @param string $new_slug Optional. New slug. + * @param int $id Post ID or post object. + * @param string $new_title Optional. New title. Default null. + * @param string $new_slug Optional. New slug. Default null. * @return string The HTML of the sample permalink slug editor. */ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { @@ -1192,56 +1208,57 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $title = __('Temporary permalink. Click to edit this part.'); } - if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { + if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) { $return = '' . __('Permalink:') . "\n" . '' . $permalink . "\n"; - if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) + if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) { $return .= '' . __('Change Permalinks') . "\n"; - if ( isset( $view_post ) ) - $return .= "$view_post\n"; - - /** - * Filter the sample permalink HTML markup. - * - * @since 2.9.0 - * - * @param string $return Sample permalink HTML markup. - * @param int|WP_Post $id Post object or ID. - * @param string $new_title New sample permalink title. - * @param string $new_slug New sample permalink slug. - */ - $return = apply_filters( 'get_sample_permalink_html', $return, $id, $new_title, $new_slug ); - - return $return; - } - - if ( function_exists('mb_strlen') ) { - if ( mb_strlen($post_name) > 30 ) { - $post_name_abridged = mb_substr($post_name, 0, 14). '…' . mb_substr($post_name, -14); - } else { - $post_name_abridged = $post_name; } } else { - if ( strlen($post_name) > 30 ) { - $post_name_abridged = substr($post_name, 0, 14). '…' . substr($post_name, -14); + if ( function_exists( 'mb_strlen' ) ) { + if ( mb_strlen( $post_name ) > 30 ) { + $post_name_abridged = mb_substr( $post_name, 0, 14 ) . '…' . mb_substr( $post_name, -14 ); + } else { + $post_name_abridged = $post_name; + } } else { - $post_name_abridged = $post_name; + if ( strlen( $post_name ) > 30 ) { + $post_name_abridged = substr( $post_name, 0, 14 ) . '…' . substr( $post_name, -14 ); + } else { + $post_name_abridged = $post_name; + } } - } - $post_name_html = '' . $post_name_abridged . ''; - $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink); - $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink); - $return = '' . __('Permalink:') . "\n"; - $return .= '' . $display_link . "\n"; - $return .= '‎'; // Fix bi-directional text display defect in RTL languages. - $return .= '' . __('Edit') . "\n"; - $return .= '' . $post_name . "\n"; + $post_name_html = '' . $post_name_abridged . ''; + $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, urldecode( $permalink ) ); + + $return = '' . __( 'Permalink:' ) . "\n"; + $return .= '' . $display_link . "\n"; + $return .= '‎'; // Fix bi-directional text display defect in RTL languages. + $return .= '' . __( 'Edit' ) . "\n"; + $return .= '' . $post_name . "\n"; + } if ( isset( $view_post ) ) { - $return .= "$view_post\n"; + if( 'draft' == $post->post_status ) { + $preview_link = set_url_scheme( get_permalink( $post->ID ) ); + /** This filter is documented in wp-admin/includes/meta-boxes.php */ + $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post ); + $return .= "$view_post\n"; + } else { + $return .= "$view_post\n"; + } } - /** This filter is documented in wp-admin/includes/post.php */ + /** + * Filter the sample permalink HTML markup. + * + * @since 2.9.0 + * + * @param string $return Sample permalink HTML markup. + * @param int|WP_Post $id Post object or ID. + * @param string $new_title New sample permalink title. + * @param string $new_slug New sample permalink slug. + */ $return = apply_filters( 'get_sample_permalink_html', $return, $id, $new_title, $new_slug ); return $return; @@ -1297,7 +1314,7 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { * @since 2.5.0 * * @param int $post_id ID of the post to check for editing - * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock. + * @return integer False: not locked or locked by current user. Int: user ID of user with lock. */ function wp_check_post_lock( $post_id ) { if ( !$post = get_post( $post_id ) ) @@ -1409,7 +1426,7 @@ function _admin_notice_post_locked() { } /** This filter is documented in wp-admin/includes/meta-boxes.php */ - $preview_link = apply_filters( 'preview_post_link', $preview_link ); + $preview_link = apply_filters( 'preview_post_link', $preview_link, $post ); /** * Filter whether to allow the post lock to be overridden. @@ -1469,7 +1486,7 @@ function _admin_notice_post_locked() {

-
+

@@ -1501,9 +1518,6 @@ function _admin_notice_post_locked() { * @subpackage Post_Revisions * @since 2.6.0 * - * @uses _wp_translate_postdata() - * @uses _wp_post_revision_fields() - * * @param mixed $post_data Associative array containing the post data or int post ID. * @return mixed The autosave revision ID. WP_Error or 0 on error. */ @@ -1542,6 +1556,15 @@ function wp_create_post_autosave( $post_data ) { return 0; } + /** + * Fires before an autosave is stored. + * + * @since 4.1.0 + * + * @param array $new_autosave Post array - the autosave that is about to be saved. + */ + do_action( 'wp_creating_autosave', $new_autosave ); + return wp_update_post( $new_autosave ); } @@ -1558,15 +1581,6 @@ function wp_create_post_autosave( $post_data ) { * @package WordPress * @since 2.7.0 * - * @uses get_post_status() - * @uses edit_post() - * @uses get_post() - * @uses current_user_can() - * @uses wp_die() - * @uses wp_create_post_autosave() - * @uses add_query_arg() - * @uses wp_create_nonce() - * * @return str URL to redirect to show the preview */ function post_preview() { @@ -1611,7 +1625,7 @@ function post_preview() { $url = add_query_arg( $query_args, get_permalink( $post->ID ) ); /** This filter is documented in wp-admin/includes/meta-boxes.php */ - return apply_filters( 'preview_post_link', $url ); + return apply_filters( 'preview_post_link', $url, $post ); } /** @@ -1619,9 +1633,9 @@ function post_preview() { * * Intended for use with heartbeat and autosave.js * - * @since 3.9 + * @since 3.9.0 * - * @param $post_data Associative array of the submitted post data. + * @param array $post_data Associative array of the submitted post data. * @return mixed The value 0 or WP_Error on failure. The saved post ID on success. * Te ID can be the draft post_id or the autosave revision post_id. */