Changeset 3473199
- Timestamp:
- 03/03/2026 02:26:18 AM (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
organicstack-publisher/trunk/organicstack-publisher.php
r3450007 r3473199 60 60 if (!headers_sent()) { 61 61 header('Access-Control-Allow-Origin: *'); 62 header('Access-Control-Allow-Methods: GET, POST, OPTIONS');62 header('Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS'); 63 63 header('Access-Control-Allow-Headers: Content-Type, X-API-Key'); 64 64 } … … 151 151 'permission_callback' => [$this, 'check_api_key_permission'], 152 152 ]); 153 154 // Delete/trash post 155 register_rest_route('organicstack-publisher/v1', '/posts/(?P<id>\d+)', [ 156 'methods' => 'DELETE', 157 'callback' => [$this, 'delete_post'], 158 'permission_callback' => [$this, 'check_api_key_permission'], 159 'args' => ['id' => ['required' => true, 'type' => 'integer']], 160 ]); 153 161 154 162 // Create author … … 259 267 260 268 // Create post 269 $status = sanitize_text_field($params['status'] ?? 'draft'); 261 270 $post_data = [ 262 271 'post_title' => sanitize_text_field($params['title']), 263 272 'post_content' => wp_kses_post($params['content']), 264 273 'post_excerpt' => sanitize_textarea_field($params['excerpt'] ?? ''), 265 'post_status' => sanitize_text_field($params['status'] ?? 'draft'),274 'post_status' => $status, 266 275 'post_author' => intval($params['author_id'] ?? get_option('organicstack_publisher_default_author', 1)), 267 276 'post_type' => 'post', 268 277 ]; 278 279 // For scheduled (future) posts, set post_date and post_date_gmt 280 if ($status === 'future' && !empty($params['post_date']) && !empty($params['post_date_gmt'])) { 281 $post_data['post_date'] = sanitize_text_field($params['post_date']); 282 $post_data['post_date_gmt'] = sanitize_text_field($params['post_date_gmt']); 283 } 269 284 270 285 $post_id = wp_insert_post($post_data); … … 613 628 ] 614 629 ], 200); 630 } 631 632 /** 633 * Delete (trash) a post 634 */ 635 public function delete_post($request) { 636 $post_id = intval($request['id']); 637 if ($post_id <= 0) { 638 return new WP_Error('invalid_id', 'Invalid post ID', ['status' => 400]); 639 } 640 $post = get_post($post_id); 641 if (!$post || $post->post_type !== 'post') { 642 return new WP_Error('post_not_found', 'Post not found', ['status' => 404]); 643 } 644 $result = wp_trash_post($post_id); 645 if (!$result) { 646 return new WP_Error('delete_failed', 'Failed to trash post', ['status' => 500]); 647 } 648 return new WP_REST_Response(['success' => true, 'message' => 'Post trashed successfully'], 200); 615 649 } 616 650
Note: See TracChangeset
for help on using the changeset viewer.