]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/post.php
WordPress 4.0
[autoinstalls/wordpress.git] / wp-admin / includes / post.php
index 64b63d649614a9340365bb22ad75b8273bcbdf69..d230667c6835556e23d558b9da00273f4e8b1245 100644 (file)
@@ -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 = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\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 .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
-               if ( isset( $view_post ) )
-                       $return .= "<span id='view-post-btn'><a href='$permalink' class='button button-small'>$view_post</a></span>\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). '&hellip;' . 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). '&hellip;' . substr($post_name, -14);
+               if ( function_exists( 'mb_strlen' ) && mb_strlen( $post_name ) > 30 ) {
+                       $post_name_abridged = mb_substr( $post_name, 0, 14 ) . '&hellip;' . mb_substr( $post_name, -14 );
+               } elseif ( strlen( $post_name ) > 30 ) {
+                       $post_name_abridged = substr( $post_name, 0, 14 ) . '&hellip;' . substr( $post_name, -14 );
                } else {
                        $post_name_abridged = $post_name;
                }
-       }
 
-       $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
-       $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
-       $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
-       $return =  '<strong>' . __('Permalink:') . "</strong>\n";
-       $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
-       $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
-       $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
-       $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
+               $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
+               $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, $permalink );
+
+               $return =  '<strong>' . __( 'Permalink:' ) . "</strong>\n";
+               $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
+               $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
+               $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __( 'Edit' ) . "</a></span>\n";
+               $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
+       }
 
        if ( isset( $view_post ) ) {
-               $return .= "<span id='view-post-btn'><a href='" . get_permalink( $post ) . "' class='button button-small'>$view_post</a></span>\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 .= "<span id='view-post-btn'><a href='" . esc_url( $preview_link ) . "' class='button button-small' target='wp-preview-{$post->ID}'>$view_post</a></span>\n";
+               } else {
+                       $return .= "<span id='view-post-btn'><a href='" . get_permalink( $post ) . "' class='button button-small'>$view_post</a></span>\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() {
                <div class="post-taken-over">
                        <div class="post-locked-avatar"></div>
                        <p class="wp-tab-first" tabindex="0">
-                       <span class="currently-editing"></span><br>
+                       <span class="currently-editing"></span><br />
                        <span class="locked-saving hidden"><img src="images/wpspin_light-2x.gif" width="16" height="16" /> <?php _e('Saving revision...'); ?></span>
                        <span class="locked-saved hidden"><?php _e('Your latest changes were saved as a revision.'); ?></span>
                        </p>
@@ -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.