XMLRPC: Don't allow private posts to be sticky.
Merge of [33325], [33612], and [34135] to the 3.7 branch. See #20662. Built from https://develop.svn.wordpress.org/branches/3.7@34157 git-svn-id: http://core.svn.wordpress.org/branches/3.7@34125 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
82dac61d61
commit
79809190ac
|
@ -1377,11 +1377,13 @@ function wp_ajax_inline_save() {
|
||||||
if ( isset($data['post_parent']) )
|
if ( isset($data['post_parent']) )
|
||||||
$data['parent_id'] = $data['post_parent'];
|
$data['parent_id'] = $data['post_parent'];
|
||||||
|
|
||||||
// status
|
// Status.
|
||||||
if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
|
if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
|
||||||
|
$data['visibility'] = 'private';
|
||||||
$data['post_status'] = 'private';
|
$data['post_status'] = 'private';
|
||||||
else
|
} else {
|
||||||
$data['post_status'] = $data['_status'];
|
$data['post_status'] = $data['_status'];
|
||||||
|
}
|
||||||
|
|
||||||
if ( empty($data['comment_status']) )
|
if ( empty($data['comment_status']) )
|
||||||
$data['comment_status'] = 'closed';
|
$data['comment_status'] = 'closed';
|
||||||
|
|
|
@ -990,6 +990,56 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
return $count > 1;
|
return $count > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function _validate_boolean( $var ) {
|
||||||
|
if ( is_bool( $var ) ) {
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bool) $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulate the logic for sticking a post
|
||||||
|
* and determining if the user has permission to do so
|
||||||
|
*
|
||||||
|
* @since 4.3.0
|
||||||
|
* @access private
|
||||||
|
*
|
||||||
|
* @param array $post_data
|
||||||
|
* @param bool $update
|
||||||
|
* @return void|IXR_Error
|
||||||
|
*/
|
||||||
|
private function _toggle_sticky( $post_data, $update = false ) {
|
||||||
|
$post_type = get_post_type_object( $post_data['post_type'] );
|
||||||
|
|
||||||
|
// Private and password-protected posts cannot be stickied.
|
||||||
|
if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
|
||||||
|
// Error if the client tried to stick the post, otherwise, silently unstick.
|
||||||
|
if ( ! empty( $post_data['sticky'] ) ) {
|
||||||
|
return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $update ) {
|
||||||
|
unstick_post( $post_data['ID'] );
|
||||||
|
}
|
||||||
|
} elseif ( isset( $post_data['sticky'] ) ) {
|
||||||
|
if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
|
||||||
|
return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$sticky = $this->_validate_boolean( $post_data['sticky'] );
|
||||||
|
if ( $sticky ) {
|
||||||
|
stick_post( $post_data['ID'] );
|
||||||
|
} else {
|
||||||
|
unstick_post( $post_data['ID'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method for wp_newPost and wp_editPost, containing shared logic.
|
* Helper method for wp_newPost and wp_editPost, containing shared logic.
|
||||||
*
|
*
|
||||||
|
@ -1082,20 +1132,9 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$post_ID = $post_data['ID'];
|
$post_ID = $post_data['ID'];
|
||||||
|
|
||||||
if ( $post_data['post_type'] == 'post' ) {
|
if ( $post_data['post_type'] == 'post' ) {
|
||||||
// Private and password-protected posts cannot be stickied.
|
$error = $this->_toggle_sticky( $post_data, $update );
|
||||||
if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) {
|
if ( $error ) {
|
||||||
// Error if the client tried to stick the post, otherwise, silently unstick.
|
return $error;
|
||||||
if ( ! empty( $post_data['sticky'] ) )
|
|
||||||
return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
|
|
||||||
if ( $update )
|
|
||||||
unstick_post( $post_ID );
|
|
||||||
} elseif ( isset( $post_data['sticky'] ) ) {
|
|
||||||
if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
|
|
||||||
return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
|
|
||||||
if ( $post_data['sticky'] )
|
|
||||||
stick_post( $post_ID );
|
|
||||||
else
|
|
||||||
unstick_post( $post_ID );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4272,10 +4311,12 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
|
|
||||||
// Only posts can be sticky
|
// Only posts can be sticky
|
||||||
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
|
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
|
||||||
if ( $content_struct['sticky'] == true )
|
$data = $postdata;
|
||||||
stick_post( $post_ID );
|
$data['sticky'] = $content_struct['sticky'];
|
||||||
elseif ( $content_struct['sticky'] == false )
|
$error = $this->_toggle_sticky( $data );
|
||||||
unstick_post( $post_ID );
|
if ( $error ) {
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset($content_struct['custom_fields']) )
|
if ( isset($content_struct['custom_fields']) )
|
||||||
|
@ -4539,11 +4580,12 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
|
|
||||||
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
|
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
|
||||||
|
|
||||||
if ( ('publish' == $post_status) ) {
|
if ( 'publish' == $post_status || 'private' == $post_status ) {
|
||||||
if ( ( 'page' == $post_type ) && !current_user_can('publish_pages') )
|
if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) {
|
||||||
return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.'));
|
return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this page.' ) );
|
||||||
else if ( !current_user_can('publish_posts') )
|
} elseif ( ! current_user_can( 'publish_posts' ) ) {
|
||||||
return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
|
return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this post.' ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $post_more )
|
if ( $post_more )
|
||||||
|
@ -4583,10 +4625,13 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
|
|
||||||
// Only posts can be sticky
|
// Only posts can be sticky
|
||||||
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
|
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
|
||||||
if ( $content_struct['sticky'] == true )
|
$data = $newpost;
|
||||||
stick_post( $post_ID );
|
$data['sticky'] = $content_struct['sticky'];
|
||||||
elseif ( $content_struct['sticky'] == false )
|
$data['post_type'] = 'post';
|
||||||
unstick_post( $post_ID );
|
$error = $this->_toggle_sticky( $data, true );
|
||||||
|
if ( $error ) {
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset($content_struct['custom_fields']) )
|
if ( isset($content_struct['custom_fields']) )
|
||||||
|
|
Loading…
Reference in New Issue