Make WordPress Core

Changeset 34152


Ignore:
Timestamp:
09/14/2015 10:50:03 PM (11 years ago)
Author:
ocean90
Message:

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

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

See #20662.

Location:
branches/4.2/src
Files:
2 edited

Legend:

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

    r33302 r34152  
    15411541
    15421542        // Status.
    1543         if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
     1543        if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
     1544                $data['visibility']  = 'private';
    15441545                $data['post_status'] = 'private';
    1545         else
     1546        } else {
    15461547                $data['post_status'] = $data['_status'];
     1548        }
    15471549
    15481550        if ( empty($data['comment_status']) )
  • branches/4.2/src/wp-includes/class-wp-xmlrpc-server.php

    r32209 r34152  
    11511151        }
    11521152
     1153        private function _validate_boolean( $var ) {
     1154                if ( is_bool( $var ) ) {
     1155                        return $var;
     1156                }
     1157
     1158                if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
     1159                        return false;
     1160                }
     1161
     1162                return (bool) $var;
     1163        }
     1164
     1165        /**
     1166         * Encapsulate the logic for sticking a post
     1167         * and determining if the user has permission to do so
     1168         *
     1169         * @since 4.3.0
     1170         * @access private
     1171         *
     1172         * @param array $post_data
     1173         * @param bool  $update
     1174         * @return void|IXR_Error
     1175         */
     1176        private function _toggle_sticky( $post_data, $update = false ) {
     1177                $post_type = get_post_type_object( $post_data['post_type'] );
     1178
     1179                // Private and password-protected posts cannot be stickied.
     1180                if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
     1181                        // Error if the client tried to stick the post, otherwise, silently unstick.
     1182                        if ( ! empty( $post_data['sticky'] ) ) {
     1183                                return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
     1184                        }
     1185
     1186                        if ( $update ) {
     1187                                unstick_post( $post_data['ID'] );
     1188                        }
     1189                } elseif ( isset( $post_data['sticky'] ) )  {
     1190                        if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
     1191                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
     1192                        }
     1193
     1194                        $sticky = $this->_validate_boolean( $post_data['sticky'] );
     1195                        if ( $sticky ) {
     1196                                stick_post( $post_data['ID'] );
     1197                        } else {
     1198                                unstick_post( $post_data['ID'] );
     1199                        }
     1200                }
     1201        }
     1202
    11531203        /**
    11541204         * Helper method for wp_newPost and wp_editPost, containing shared logic.
    … …  
    12431293
    12441294                if ( $post_data['post_type'] == 'post' ) {
    1245                         // Private and password-protected posts cannot be stickied.
    1246                         if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) {
    1247                                 // Error if the client tried to stick the post, otherwise, silently unstick.
    1248                                 if ( ! empty( $post_data['sticky'] ) )
    1249                                         return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
    1250                                 if ( $update )
    1251                                         unstick_post( $post_ID );
    1252                         } elseif ( isset( $post_data['sticky'] ) )  {
    1253                                 if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
    1254                                         return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
    1255                                 if ( $post_data['sticky'] )
    1256                                         stick_post( $post_ID );
    1257                                 else
    1258                                         unstick_post( $post_ID );
     1295                        $error = $this->_toggle_sticky( $post_data, $update );
     1296                        if ( $error ) {
     1297                                return $error;
    12591298                        }
    12601299                }
    … …  
    45814620                // Only posts can be sticky
    45824621                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4583                         if ( $content_struct['sticky'] == true )
    4584                                 stick_post( $post_ID );
    4585                         elseif ( $content_struct['sticky'] == false )
    4586                                 unstick_post( $post_ID );
     4622                        $data = $postdata;
     4623                        $data['sticky'] = $content_struct['sticky'];
     4624                        $error = $this->_toggle_sticky( $data );
     4625                        if ( $error ) {
     4626                                return $error;
     4627                        }
    45874628                }
    45884629
    … …  
    48744915                $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
    48754916
    4876                 if ( ('publish' == $post_status) ) {
    4877                         if ( ( 'page' == $post_type ) && ! current_user_can( 'publish_pages' ) ) {
     4917                if ( 'publish' == $post_status || 'private' == $post_status ) {
     4918                        if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) {
    48784919                                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this page.' ) );
    48794920                        } elseif ( ! current_user_can( 'publish_posts' ) ) {
    … …  
    49194960                // Only posts can be sticky
    49204961                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    4921                         if ( $content_struct['sticky'] == true )
    4922                                 stick_post( $post_ID );
    4923                         elseif ( $content_struct['sticky'] == false )
    4924                                 unstick_post( $post_ID );
     4962                        $data = $newpost;
     4963                        $data['sticky'] = $content_struct['sticky'];
     4964                        $data['post_type'] = 'post';
     4965                        $error = $this->_toggle_sticky( $data, true );
     4966                        if ( $error ) {
     4967                                return $error;
     4968                        }
    49254969                }
    49264970
Note: See TracChangeset for help on using the changeset viewer.