Changeset 34152 for branches/4.2/src/wp-includes/class-wp-xmlrpc-server.php
- Timestamp:
- 09/14/2015 10:50:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.2/src/wp-includes/class-wp-xmlrpc-server.php
r32209 r34152 1151 1151 } 1152 1152 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 1153 1203 /** 1154 1204 * Helper method for wp_newPost and wp_editPost, containing shared logic. … … 1243 1293 1244 1294 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; 1259 1298 } 1260 1299 } … … 4581 4620 // Only posts can be sticky 4582 4621 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 } 4587 4628 } 4588 4629 … … 4874 4915 $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; 4875 4916 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' ) ) { 4878 4919 return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this page.' ) ); 4879 4920 } elseif ( ! current_user_can( 'publish_posts' ) ) { … … 4919 4960 // Only posts can be sticky 4920 4961 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 } 4925 4969 } 4926 4970
Note: See TracChangeset
for help on using the changeset viewer.