X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0461a5f2e55c8d5f1fde96ca2e83117152573c7d..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-admin/includes/post.php diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 64b63d64..d230667c 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -302,7 +302,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 ) ); } } @@ -518,8 +518,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'] )); @@ -733,7 +731,6 @@ function write_post() { * @return unknown */ function add_meta( $post_ID ) { - global $wpdb; $post_ID = (int) $post_ID; $metakeyselect = isset($_POST['metakeyselect']) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : ''; @@ -743,9 +740,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; @@ -949,7 +947,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 +955,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 ); @@ -1035,6 +1032,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 +1053,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 ); @@ -1192,56 +1199,51 @@ 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' ) && mb_strlen( $post_name ) > 30 ) { + $post_name_abridged = mb_substr( $post_name, 0, 14 ) . '…' . mb_substr( $post_name, -14 ); + } elseif ( 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, $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; @@ -1409,7 +1411,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 +1471,7 @@ function _admin_notice_post_locked() {

-
+

@@ -1611,7 +1613,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,7 +1621,7 @@ 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. * @return mixed The value 0 or WP_Error on failure. The saved post ID on success.