Make WordPress Core

Changeset 34153


Ignore:
Timestamp:
09/14/2015 11:00:40 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.1 branch.

See #20662.

Location:
branches/4.1/src
Files:
2 edited

Legend:

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

    r31430 r34153  
    15391539
    15401540    // Status.
    1541     if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
     1541    if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
     1542        $data['visibility']  = 'private';
    15421543        $data['post_status'] = 'private';
    1543     else
     1544    } else {
    15441545        $data['post_status'] = $data['_status'];
     1546    }
    15451547
    15461548    if ( empty($data['comment_status']) )
  • branches/4.1/src/wp-includes/class-wp-xmlrpc-server.php

    r30681 r34153  
    11501150    }
    11511151
     1152    private function _validate_boolean( $var ) {
     1153        if ( is_bool( $var ) ) {
     1154            return $var;
     1155        }
     1156
     1157        if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
     1158            return false;
     1159        }
     1160
     1161        return (bool) $var;
     1162    }
     1163
     1164    /**
     1165     * Encapsulate the logic for sticking a post
     1166     * and determining if the user has permission to do so
     1167     *
     1168     * @since 4.3.0
     1169     * @access private
     1170     *
     1171     * @param array $post_data
     1172     * @param bool  $update
     1173     * @return void|IXR_Error
     1174     */
     1175    private function _toggle_sticky( $post_data, $update = false ) {
     1176        $post_type = get_post_type_object( $post_data['post_type'] );
     1177
     1178        // Private and password-protected posts cannot be stickied.
     1179        if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
     1180            // Error if the client tried to stick the post, otherwise, silently unstick.
     1181            if ( ! empty( $post_data['sticky'] ) ) {
     1182                return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
     1183            }
     1184
     1185            if ( $update ) {
     1186                unstick_post( $post_data['ID'] );
     1187            }
     1188        } elseif ( isset( $post_data['sticky'] ) )  {
     1189            if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
     1190                return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
     1191            }
     1192
     1193            $sticky = $this->_validate_boolean( $post_data['sticky'] );
     1194            if ( $sticky ) {
     1195                stick_post( $post_data['ID'] );
     1196            } else {
     1197                unstick_post( $post_data['ID'] );
     1198            }
     1199        }
     1200    }
     1201
    11521202    /**
    11531203     * Helper method for wp_newPost and wp_editPost, containing shared logic.
     
    12421292
    12431293        if ( $post_data['post_type'] == 'post' ) {
    1244             // Private and password-protected posts cannot be stickied.
    1245             if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) {
    1246                 // Error if the client tried to stick the post, otherwise, silently unstick.
    1247                 if ( ! empty( $post_data['sticky'] ) )
    1248                     return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
    1249                 if ( $update )
    1250                     unstick_post( $post_ID );
    1251             } elseif ( isset( $post_data['sticky'] ) )  {
    1252                 if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
    1253                     return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
    1254                 if ( $post_data['sticky'] )
    1255                     stick_post( $post_ID );
    1256                 else
    1257                     unstick_post( $post_ID );
     1294            $error = $this->_toggle_sticky( $post_data, $update );
     1295            if ( $error ) {
     1296                return $error;
    12581297            }
    12591298        }
     
    45844623        // Only posts can be sticky
    45854624        if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4586             if ( $content_struct['sticky'] == true )
    4587                 stick_post( $post_ID );
    4588             elseif ( $content_struct['sticky'] == false )
    4589                 unstick_post( $post_ID );
     4625            $data = $postdata;
     4626            $data['sticky'] = $content_struct['sticky'];
     4627            $error = $this->_toggle_sticky( $data );
     4628            if ( $error ) {
     4629                return $error;
     4630            }
    45904631        }
    45914632
     
    48734914        $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
    48744915
    4875         if ( ('publish' == $post_status) ) {
    4876             if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') )
    4877                 return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.'));
    4878             else if ( !current_user_can('publish_posts') )
    4879                 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
     4916        if ( 'publish' == $post_status || 'private' == $post_status ) {
     4917            if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) {
     4918                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this page.' ) );
     4919            } elseif ( ! current_user_can( 'publish_posts' ) ) {
     4920                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this post.' ) );
     4921            }
    48804922        }
    48814923
     
    49174959        // Only posts can be sticky
    49184960        if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4919             if ( $content_struct['sticky'] == true )
    4920                 stick_post( $post_ID );
    4921             elseif ( $content_struct['sticky'] == false )
    4922                 unstick_post( $post_ID );
     4961            $data = $newpost;
     4962            $data['sticky'] = $content_struct['sticky'];
     4963            $data['post_type'] = 'post';
     4964            $error = $this->_toggle_sticky( $data, true );
     4965            if ( $error ) {
     4966                return $error;
     4967            }
    49234968        }
    49244969
Note: See TracChangeset for help on using the changeset viewer.