]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/post.php
WordPress 4.7
[autoinstalls/wordpress.git] / wp-admin / includes / post.php
index 790b736cdf2c0c09b5021c24410c827c354e88f8..ab50c27d941a269f49bf7c4e817497292609ca50 100644 (file)
@@ -160,7 +160,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
                $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
                $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
                if ( !$valid_date ) {
                $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
                $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
                if ( !$valid_date ) {
-                       return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );
+                       return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
                }
                $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
        }
                }
                $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
        }
@@ -288,6 +288,8 @@ function edit_post( $post_data = null ) {
                                continue;
                        if ( $meta->post_id != $post_ID )
                                continue;
                                continue;
                        if ( $meta->post_id != $post_ID )
                                continue;
+                       if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $meta->meta_key ) )
+                               continue;
                        if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) )
                                continue;
                        update_meta( $key, $value['key'], $value['value'] );
                        if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) )
                                continue;
                        update_meta( $key, $value['key'], $value['value'] );
@@ -1144,9 +1146,43 @@ function wp_edit_attachments_query_vars( $q = false ) {
                $q['post_parent'] = 0;
        }
 
                $q['post_parent'] = 0;
        }
 
+       // Filter query clauses to include filenames.
+       if ( isset( $q['s'] ) ) {
+               add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+       }
+
        return $q;
 }
 
        return $q;
 }
 
+/**
+ * Filter the SQL clauses of an attachment query to include filenames.
+ *
+ * @since 4.7.0
+ * @access private
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
+ *                       DISTINCT, fields (SELECT), and LIMITS clauses.
+ * @return array The modified clauses.
+ */
+function _filter_query_attachment_filenames( $clauses ) {
+       global $wpdb;
+       remove_filter( 'posts_clauses', __FUNCTION__ );
+
+       // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
+       $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
+
+       $clauses['groupby'] = "{$wpdb->posts}.ID";
+
+       $clauses['where'] = preg_replace(
+               "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
+               "$0 OR ( sq1.meta_value $1 $2 )",
+               $clauses['where'] );
+
+       return $clauses;
+}
+
 /**
  * Executes a query for attachments. An array of WP_Query arguments
  * can be passed in, which will override the arguments set by this function.
 /**
  * Executes a query for attachments. An array of WP_Query arguments
  * can be passed in, which will override the arguments set by this function.
@@ -1207,9 +1243,9 @@ function postbox_classes( $id, $page ) {
  * @since 2.5.0
  *
  * @param int    $id    Post ID or post object.
  * @since 2.5.0
  *
  * @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.
+ * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
+ * @param string $name  Optional. Name to override the post name. Default null.
+ * @return array Array containing the sample permalink with placeholder for the post name, and the post name.
  */
 function get_sample_permalink($id, $title = null, $name = null) {
        $post = get_post( $id );
  */
 function get_sample_permalink($id, $title = null, $name = null) {
        $post = get_post( $id );
@@ -1270,7 +1306,7 @@ function get_sample_permalink($id, $title = null, $name = null) {
         *
         * @since 4.4.0
         *
         *
         * @since 4.4.0
         *
-        * @param string  $permalink Sample permalink.
+        * @param array   $permalink Array containing the sample permalink with placeholder for the post name, and the post name.
         * @param int     $post_id   Post ID.
         * @param string  $title     Post title.
         * @param string  $name      Post name (slug).
         * @param int     $post_id   Post ID.
         * @param string  $title     Post title.
         * @param string  $name      Post name (slug).
@@ -1300,14 +1336,14 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
        $preview_target = '';
 
        if ( current_user_can( 'read_post', $post->ID ) ) {
        $preview_target = '';
 
        if ( current_user_can( 'read_post', $post->ID ) ) {
-               if ( 'draft' === $post->post_status ) {
+               if ( 'draft' === $post->post_status || empty( $post->post_name ) ) {
                        $view_link = get_preview_post_link( $post );
                        $preview_target = " target='wp-preview-{$post->ID}'";
                } else {
                        if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
                                $view_link = get_permalink( $post );
                        } else {
                        $view_link = get_preview_post_link( $post );
                        $preview_target = " target='wp-preview-{$post->ID}'";
                } else {
                        if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
                                $view_link = get_permalink( $post );
                        } else {
-                               // Allow non-published (private, future) to be viewed at a pretty permalink.
+                               // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set
                                $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
                        }
                }
                                $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
                        }
                }
@@ -1367,14 +1403,12 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
  *
  * @since 2.9.0
  *
  *
  * @since 2.9.0
  *
- * @global array $_wp_additional_image_sizes
- *
  * @param int $thumbnail_id ID of the attachment used for thumbnail
  * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post.
  * @return string html
  */
 function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
  * @param int $thumbnail_id ID of the attachment used for thumbnail
  * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post.
  * @return string html
  */
 function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
-       global $_wp_additional_image_sizes;
+       $_wp_additional_image_sizes = wp_get_additional_image_sizes();
 
        $post               = get_post( $post );
        $post_type_object   = get_post_type_object( $post->post_type );
 
        $post               = get_post( $post );
        $post_type_object   = get_post_type_object( $post->post_type );