Make WordPress Core

Changeset 34154


Ignore:
Timestamp:
09/14/2015 11:00:53 PM (9 years ago)
Author:
ocean90
Message:

XMLRPC: Don't allow private posts to be sticky.

Merge of [33325], [33612], and [34135] to the 4.0 branch.

See #20662.

Location:
branches/4.0/src
Files:
2 edited

Legend:

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

    r29681 r34154  
    15301530
    15311531    // Status.
    1532     if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
     1532    if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
     1533        $data['visibility']  = 'private';
    15331534        $data['post_status'] = 'private';
    1534     else
     1535    } else {
    15351536        $data['post_status'] = $data['_status'];
     1537    }
    15361538
    15371539    if ( empty($data['comment_status']) )
  • branches/4.0/src/wp-includes/class-wp-xmlrpc-server.php

    r29464 r34154  
    11391139    }
    11401140
     1141    private function _validate_boolean( $var ) {
     1142        if ( is_bool( $var ) ) {
     1143            return $var;
     1144        }
     1145
     1146        if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
     1147            return false;
     1148        }
     1149
     1150        return (bool) $var;
     1151    }
     1152
     1153    /**
     1154     * Encapsulate the logic for sticking a post
     1155     * and determining if the user has permission to do so
     1156     *
     1157     * @since 4.3.0
     1158     * @access private
     1159     *
     1160     * @param array $post_data
     1161     * @param bool  $update
     1162     * @return void|IXR_Error
     1163     */
     1164    private function _toggle_sticky( $post_data, $update = false ) {
     1165        $post_type = get_post_type_object( $post_data['post_type'] );
     1166
     1167        // Private and password-protected posts cannot be stickied.
     1168        if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
     1169            // Error if the client tried to stick the post, otherwise, silently unstick.
     1170            if ( ! empty( $post_data['sticky'] ) ) {
     1171                return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
     1172            }
     1173
     1174            if ( $update ) {
     1175                unstick_post( $post_data['ID'] );
     1176            }
     1177        } elseif ( isset( $post_data['sticky'] ) )  {
     1178            if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
     1179                return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
     1180            }
     1181
     1182            $sticky = $this->_validate_boolean( $post_data['sticky'] );
     1183            if ( $sticky ) {
     1184                stick_post( $post_data['ID'] );
     1185            } else {
     1186                unstick_post( $post_data['ID'] );
     1187            }
     1188        }
     1189    }
     1190
    11411191    /**
    11421192     * Helper method for wp_newPost and wp_editPost, containing shared logic.
     
    12311281
    12321282        if ( $post_data['post_type'] == 'post' ) {
    1233             // Private and password-protected posts cannot be stickied.
    1234             if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) {
    1235                 // Error if the client tried to stick the post, otherwise, silently unstick.
    1236                 if ( ! empty( $post_data['sticky'] ) )
    1237                     return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
    1238                 if ( $update )
    1239                     unstick_post( $post_ID );
    1240             } elseif ( isset( $post_data['sticky'] ) )  {
    1241                 if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
    1242                     return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
    1243                 if ( $post_data['sticky'] )
    1244                     stick_post( $post_ID );
    1245                 else
    1246                     unstick_post( $post_ID );
     1283            $error = $this->_toggle_sticky( $post_data, $update );
     1284            if ( $error ) {
     1285                return $error;
    12471286            }
    12481287        }
     
    46184657        // Only posts can be sticky
    46194658        if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4620             if ( $content_struct['sticky'] == true )
    4621                 stick_post( $post_ID );
    4622             elseif ( $content_struct['sticky'] == false )
    4623                 unstick_post( $post_ID );
     4659            $data = $postdata;
     4660            $data['sticky'] = $content_struct['sticky'];
     4661            $error = $this->_toggle_sticky( $data );
     4662            if ( $error ) {
     4663                return $error;
     4664            }
    46244665        }
    46254666
     
    49034944        $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
    49044945
    4905         if ( ('publish' == $post_status) ) {
    4906             if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') )
    4907                 return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.'));
    4908             else if ( !current_user_can('publish_posts') )
    4909                 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
     4946        if ( 'publish' == $post_status || 'private' == $post_status ) {
     4947            if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) {
     4948                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this page.' ) );
     4949            } elseif ( ! current_user_can( 'publish_posts' ) ) {
     4950                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this post.' ) );
     4951            }
    49104952        }
    49114953
     
    49474989        // Only posts can be sticky
    49484990        if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4949             if ( $content_struct['sticky'] == true )
    4950                 stick_post( $post_ID );
    4951             elseif ( $content_struct['sticky'] == false )
    4952                 unstick_post( $post_ID );
     4991            $data = $newpost;
     4992            $data['sticky'] = $content_struct['sticky'];
     4993            $data['post_type'] = 'post';
     4994            $error = $this->_toggle_sticky( $data, true );
     4995            if ( $error ) {
     4996                return $error;
     4997            }
    49534998        }
    49544999
Note: See TracChangeset for help on using the changeset viewer.