Make WordPress Core

Ticket #20662: 20662.2.diff

File 20662.2.diff, 3.4 KB (added by wonderboymusic, 10 years ago)
  • src/wp-includes/class-wp-xmlrpc-server.php

     
    11931193        }
    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         *
    11981232         * @since 3.4.0
     
    12871321                $post_ID = $post_data['ID'];
    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                }
    13061329
     
    49024925
    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
    49114936                if ( isset($content_struct['custom_fields']) )
     
    52505275
    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
    52595286                if ( isset($content_struct['custom_fields']) )