Make WordPress Core

Changeset 34155


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

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

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

See #20662.

Location:
branches/3.9/src
Files:
2 edited

Legend:

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

    r28164 r34155  
    13241324        $data['parent_id'] = $data['post_parent'];
    13251325
    1326     // status
    1327     if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
     1326    // Status.
     1327    if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
     1328        $data['visibility']  = 'private';
    13281329        $data['post_status'] = 'private';
    1329     else
     1330    } else {
    13301331        $data['post_status'] = $data['_status'];
     1332    }
    13311333
    13321334    if ( empty($data['comment_status']) )
  • branches/3.9/src/wp-includes/class-wp-xmlrpc-server.php

    r28083 r34155  
    11091109    }
    11101110
     1111    private function _validate_boolean( $var ) {
     1112        if ( is_bool( $var ) ) {
     1113            return $var;
     1114        }
     1115
     1116        if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
     1117            return false;
     1118        }
     1119
     1120        return (bool) $var;
     1121    }
     1122
     1123    /**
     1124     * Encapsulate the logic for sticking a post
     1125     * and determining if the user has permission to do so
     1126     *
     1127     * @since 4.3.0
     1128     * @access private
     1129     *
     1130     * @param array $post_data
     1131     * @param bool  $update
     1132     * @return void|IXR_Error
     1133     */
     1134    private function _toggle_sticky( $post_data, $update = false ) {
     1135        $post_type = get_post_type_object( $post_data['post_type'] );
     1136
     1137        // Private and password-protected posts cannot be stickied.
     1138        if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
     1139            // Error if the client tried to stick the post, otherwise, silently unstick.
     1140            if ( ! empty( $post_data['sticky'] ) ) {
     1141                return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
     1142            }
     1143
     1144            if ( $update ) {
     1145                unstick_post( $post_data['ID'] );
     1146            }
     1147        } elseif ( isset( $post_data['sticky'] ) )  {
     1148            if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
     1149                return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
     1150            }
     1151
     1152            $sticky = $this->_validate_boolean( $post_data['sticky'] );
     1153            if ( $sticky ) {
     1154                stick_post( $post_data['ID'] );
     1155            } else {
     1156                unstick_post( $post_data['ID'] );
     1157            }
     1158        }
     1159    }
     1160
    11111161    /**
    11121162     * Helper method for wp_newPost and wp_editPost, containing shared logic.
     
    12011251
    12021252        if ( $post_data['post_type'] == 'post' ) {
    1203             // Private and password-protected posts cannot be stickied.
    1204             if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) {
    1205                 // Error if the client tried to stick the post, otherwise, silently unstick.
    1206                 if ( ! empty( $post_data['sticky'] ) )
    1207                     return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
    1208                 if ( $update )
    1209                     unstick_post( $post_ID );
    1210             } elseif ( isset( $post_data['sticky'] ) )  {
    1211                 if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
    1212                     return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
    1213                 if ( $post_data['sticky'] )
    1214                     stick_post( $post_ID );
    1215                 else
    1216                     unstick_post( $post_ID );
     1253            $error = $this->_toggle_sticky( $post_data, $update );
     1254            if ( $error ) {
     1255                return $error;
    12171256            }
    12181257        }
     
    45874626        // Only posts can be sticky
    45884627        if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4589             if ( $content_struct['sticky'] == true )
    4590                 stick_post( $post_ID );
    4591             elseif ( $content_struct['sticky'] == false )
    4592                 unstick_post( $post_ID );
     4628            $data = $postdata;
     4629            $data['sticky'] = $content_struct['sticky'];
     4630            $error = $this->_toggle_sticky( $data );
     4631            if ( $error ) {
     4632                return $error;
     4633            }
    45934634        }
    45944635
     
    48634904        $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
    48644905
    4865         if ( ('publish' == $post_status) ) {
    4866             if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') )
    4867                 return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.'));
    4868             else if ( !current_user_can('publish_posts') )
    4869                 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
     4906        if ( 'publish' == $post_status || 'private' == $post_status ) {
     4907            if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) {
     4908                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this page.' ) );
     4909            } elseif ( ! current_user_can( 'publish_posts' ) ) {
     4910                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this post.' ) );
     4911            }
    48704912        }
    48714913
     
    49074949        // Only posts can be sticky
    49084950        if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4909             if ( $content_struct['sticky'] == true )
    4910                 stick_post( $post_ID );
    4911             elseif ( $content_struct['sticky'] == false )
    4912                 unstick_post( $post_ID );
     4951            $data = $newpost;
     4952            $data['sticky'] = $content_struct['sticky'];
     4953            $data['post_type'] = 'post';
     4954            $error = $this->_toggle_sticky( $data, true );
     4955            if ( $error ) {
     4956                return $error;
     4957            }
    49134958        }
    49144959
Note: See TracChangeset for help on using the changeset viewer.