| | 1196 | * @since 4.3.0 |
| | 1197 | * |
| | 1198 | * @param array $post_data |
| | 1199 | * @param bool $update |
| | 1200 | * @return void|IXR_Error |
| | 1201 | */ |
| | 1202 | private function _toggle_sticky( $post_data, $update = false ) { |
| | 1203 | $post_type = get_post_type_object( $post_data['post_type'] ); |
| | 1204 | |
| | 1205 | // Private and password-protected posts cannot be stickied. |
| | 1206 | if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) { |
| | 1207 | // Error if the client tried to stick the post, otherwise, silently unstick. |
| | 1208 | if ( ! empty( $post_data['sticky'] ) ) { |
| | 1209 | return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) ); |
| | 1210 | } |
| | 1211 | |
| | 1212 | if ( $update ) { |
| | 1213 | unstick_post( $post_data['ID'] ); |
| | 1214 | } |
| | 1215 | } elseif ( isset( $post_data['sticky'] ) ) { |
| | 1216 | if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
| | 1217 | return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) ); |
| | 1218 | } |
| | 1219 | |
| | 1220 | $sticky = wp_validate_boolean( $post_data['sticky'] ); |
| | 1221 | if ( $sticky ) { |
| | 1222 | stick_post( $post_data['ID'] ); |
| | 1223 | } else { |
| | 1224 | unstick_post( $post_data['ID'] ); |
| | 1225 | } |
| | 1226 | } |
| | 1227 | } |
| | 1228 | |
| | 1229 | /** |
| 1290 | | // Private and password-protected posts cannot be stickied. |
| 1291 | | if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) { |
| 1292 | | // Error if the client tried to stick the post, otherwise, silently unstick. |
| 1293 | | if ( ! empty( $post_data['sticky'] ) ) |
| 1294 | | return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) ); |
| 1295 | | if ( $update ) |
| 1296 | | unstick_post( $post_ID ); |
| 1297 | | } elseif ( isset( $post_data['sticky'] ) ) { |
| 1298 | | if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) |
| 1299 | | return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) ); |
| 1300 | | if ( $post_data['sticky'] ) |
| 1301 | | stick_post( $post_ID ); |
| 1302 | | else |
| 1303 | | unstick_post( $post_ID ); |
| | 1324 | $error = $this->_toggle_sticky( $post_data, $update ); |
| | 1325 | if ( $error ) { |
| | 1326 | return $error; |