$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'] );
}
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'] );
$q['post_parent'] = 0;
}
+ // Filter query clauses to include filenames.
+ if ( isset( $q['s'] ) ) {
+ add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+ }
+
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.
* @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 );
*
* @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).
$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 {
- // 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 );
}
}
*
* @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 ) {
- 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 );