Make WordPress Core

Changeset 33325


Ignore:
Timestamp:
07/19/2015 06:08:55 PM (11 years ago)
Author:
wonderboymusic
Message:

Ensure that private posts cannot be made sticky via Quick Edit.
DRY the logic for stickies in wp_xmlrpc_server by introducing ->_toggle_sticky().

Props wonderboymusic, obenland, chriscct7.
Fixes #20662.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r33280 r33325  
    15681568
    15691569        // Status.
    1570         if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
     1570        if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
     1571                $data['visibility']  = 'private';
    15711572                $data['post_status'] = 'private';
    1572         else
     1573        } else {
    15731574                $data['post_status'] = $data['_status'];
     1575        }
    15741576
    15751577        if ( empty($data['comment_status']) )
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r33054 r33325  
    11941194
    11951195        /**
     1196         * @since 4.3.0
     1197         *
     1198         * @param array $post_data
     1199         * @param bool  $update
     1200         * @return void|IXR_Error
     1201         */
     1202        private function _toggle_sticky( $post_data, $update = false ) {
     1203                $post_type = get_post_type_object( $post_data['post_type'] );
     1204
     1205                // Private and password-protected posts cannot be stickied.
     1206                if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
     1207                        // Error if the client tried to stick the post, otherwise, silently unstick.
     1208                        if ( ! empty( $post_data['sticky'] ) ) {
     1209                                return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
     1210                        }
     1211
     1212                        if ( $update ) {
     1213                                unstick_post( $post_data['ID'] );
     1214                        }
     1215                } elseif ( isset( $post_data['sticky'] ) )  {
     1216                        if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
     1217                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
     1218                        }
     1219
     1220                        $sticky = wp_validate_boolean( $post_data['sticky'] );
     1221                        if ( $sticky ) {
     1222                                stick_post( $post_data['ID'] );
     1223                        } else {
     1224                                unstick_post( $post_data['ID'] );
     1225                        }
     1226                }
     1227        }
     1228
     1229        /**
    11961230         * Helper method for wp_newPost() and wp_editPost(), containing shared logic.
    11971231         *
    … …  
    12881322
    12891323                if ( $post_data['post_type'] == 'post' ) {
    1290                         // Private and password-protected posts cannot be stickied.
    1291                         if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) {
    1292                                 // Error if the client tried to stick the post, otherwise, silently unstick.
    1293                                 if ( ! empty( $post_data['sticky'] ) )
    1294                                         return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
    1295                                 if ( $update )
    1296                                         unstick_post( $post_ID );
    1297                         } elseif ( isset( $post_data['sticky'] ) )  {
    1298                                 if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
    1299                                         return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
    1300                                 if ( $post_data['sticky'] )
    1301                                         stick_post( $post_ID );
    1302                                 else
    1303                                         unstick_post( $post_ID );
     1324                        $error = $this->_toggle_sticky( $post_data, $update );
     1325                        if ( $error ) {
     1326                                return $error;
    13041327                        }
    13051328                }
    … …  
    49034926                // Only posts can be sticky
    49044927                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4905                         if ( $content_struct['sticky'] == true )
    4906                                 stick_post( $post_ID );
    4907                         elseif ( $content_struct['sticky'] == false )
    4908                                 unstick_post( $post_ID );
     4928                        $data = $postdata;
     4929                        $data['sticky'] = $content_struct['sticky'];
     4930                        $error = $this->_toggle_sticky( $data );
     4931                        if ( $error ) {
     4932                                return $error;
     4933                        }
    49094934                }
    49104935
    … …  
    52515276                // Only posts can be sticky
    52525277                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    5253                         if ( $content_struct['sticky'] == true )
    5254                                 stick_post( $post_ID );
    5255                         elseif ( $content_struct['sticky'] == false )
    5256                                 unstick_post( $post_ID );
     5278                        $data = $newpost;
     5279                        $data['sticky'] = $content_struct['sticky'];
     5280                        $error = $this->_toggle_sticky( $data, true );
     5281                        if ( $error ) {
     5282                                return $error;
     5283                        }
    52575284                }
    52585285
Note: See TracChangeset for help on using the changeset viewer.