Changeset 3293656
- Timestamp:
- 05/15/2025 03:59:21 AM (11 months ago)
- Location:
- sapientseo
- Files:
-
- 6 edited
- 1 copied
-
tags/1.0.22 (copied) (copied from sapientseo/trunk)
-
tags/1.0.22/inc/api/posts.php (modified) (9 diffs)
-
tags/1.0.22/readme.txt (modified) (1 diff)
-
tags/1.0.22/sapientseo.php (modified) (2 diffs)
-
trunk/inc/api/posts.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/sapientseo.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sapientseo/tags/1.0.22/inc/api/posts.php
r3292976 r3293656 7 7 function sapientseo_apply_fields($post_id, $params) { 8 8 // ACF fields 9 if (function_exists('update_field') && !empty($params['acf']) && is_array($params['acf'])) {9 if (function_exists('update_field') && isset($params['acf']) && is_array($params['acf'])) { 10 10 foreach ($params['acf'] as $field_key => $value) { 11 11 update_field($field_key, $value, $post_id); … … 13 13 } 14 14 15 // Categories (only if they exist)16 if ( !empty($params['categories']) && is_array($params['categories'])) {15 // Categories 16 if (isset($params['categories']) && is_array($params['categories'])) { 17 17 $category_ids = []; 18 18 foreach ($params['categories'] as $cat) { … … 22 22 } 23 23 } 24 if (!empty($category_ids)) { 25 wp_set_post_categories($post_id, $category_ids, false); 26 } 27 } 28 29 // Tags (only if they exist) 30 if (!empty($params['tags']) && is_array($params['tags'])) { 24 wp_set_post_categories($post_id, $category_ids, false); 25 } 26 27 // Tags 28 if (isset($params['tags']) && is_array($params['tags'])) { 31 29 $existing_tags = []; 32 30 foreach ($params['tags'] as $tag_name) { … … 36 34 } 37 35 } 38 if (!empty($existing_tags)) { 39 wp_set_post_terms($post_id, $existing_tags, 'post_tag', false); 40 } 36 wp_set_post_terms($post_id, $existing_tags, 'post_tag', false); 41 37 } 42 38 43 39 // SEO metadata 44 if ( !empty($params['seo']) && is_array($params['seo'])) {40 if (isset($params['seo']) && is_array($params['seo'])) { 45 41 foreach ($params['seo'] as $meta_key => $meta_value) { 46 42 update_post_meta($post_id, $meta_key, sanitize_text_field($meta_value)); … … 123 119 } 124 120 ]); 121 register_rest_route('sapientseo/v1', '/delete-post', [ 122 'methods' => 'POST', 123 'callback' => 'sapient_seo_delete_post', 124 'permission_callback' => function ($request) { 125 return sapient_seo_api_key_permission($request); 126 } 127 ]); 125 128 }); 126 129 … … 172 175 } 173 176 174 $post_data = [ 175 'ID' => $post_id, 176 'post_title' => sanitize_text_field($params['title'] ?? ''), 177 'post_content' => wp_kses_post($params['content'] ?? ''), 178 'post_excerpt' => sanitize_text_field($params['excerpt'] ?? ''), 179 ]; 177 $post_data = ['ID' => $post_id]; 178 179 if (array_key_exists('title', $params)) { 180 $post_data['post_title'] = sanitize_text_field($params['title']); 181 } 182 183 if (array_key_exists('content', $params)) { 184 $post_data['post_content'] = wp_kses_post($params['content']); 185 } 186 187 if (array_key_exists('excerpt', $params)) { 188 $post_data['post_excerpt'] = sanitize_text_field($params['excerpt']); 189 } 180 190 181 191 if (!empty($params['post_date'])) { … … 221 231 222 232 $offset = intval($request->get_param('offset') ?? 0); 223 $per_page = intval($request->get_param('per_page') ?? 10); 233 $per_page = $request->get_param('per_page'); 234 $per_page = is_numeric($per_page) && intval($per_page) > 0 ? intval($per_page) : -1; // -1 means all 224 235 225 236 $args = [ … … 255 266 256 267 return rest_ensure_response([ 257 'total' => $query->found_posts,258 268 'count' => count($posts), 259 269 'offset' => $offset, … … 337 347 return rest_ensure_response(['post_id' => $post_id, 'message' => 'Post published successfully.']); 338 348 } 349 350 // 🔹 Delete Post 351 function sapient_seo_delete_post(WP_REST_Request $request) { 352 $post_id = intval($request->get_param('post_id')); 353 354 if (!$post_id || get_post_status($post_id) === false) { 355 return new WP_Error('invalid_post', 'Post not found.', ['status' => 404]); 356 } 357 358 $result = wp_delete_post($post_id, true); // `true` = force delete 359 360 if (!$result) { 361 return rest_ensure_response([ 362 'error' => 'delete_failed', 363 'message' => 'Could not delete post.', 364 'status' => 500 365 ]); 366 } 367 368 return rest_ensure_response(['post_id' => $post_id, 'message' => 'Post deleted successfully.']); 369 } -
sapientseo/tags/1.0.22/readme.txt
r3292976 r3293656 4 4 Tested up to: 6.8 5 5 Requires PHP: 7.4 6 Stable tag: 1.0.2 16 Stable tag: 1.0.22 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
sapientseo/tags/1.0.22/sapientseo.php
r3292976 r3293656 3 3 * Plugin Name: SapientSEO 4 4 * Description: Connect your WordPress site to SapientSEO using secure custom REST API endpoints. 5 * Version: 1.0.2 15 * Version: 1.0.22 6 6 * Author: SapientSEO 7 7 * Plugin URI: https://sapientseo.ai … … 35 35 * All REST endpoints use either permission callbacks or secure header validation (X-API-KEY) via sapient_seo_api_key_permission(). 36 36 */ 37 38 /** 39 * Prevent full-page caching for SapientSEO REST API endpoints. 40 */ 41 add_action('template_redirect', 'sapientseo_template_redirect', 0); 42 function sapientseo_template_redirect() { 43 if (strpos($_SERVER['REQUEST_URI'], '/wp-json/sapientseo/v1/') !== false) { 44 header('Cache-Control: no-cache, must-revalidate, max-age=0'); 45 header('Pragma: no-cache'); 46 header('Expires: 0'); 47 } 48 } -
sapientseo/trunk/inc/api/posts.php
r3292976 r3293656 7 7 function sapientseo_apply_fields($post_id, $params) { 8 8 // ACF fields 9 if (function_exists('update_field') && !empty($params['acf']) && is_array($params['acf'])) {9 if (function_exists('update_field') && isset($params['acf']) && is_array($params['acf'])) { 10 10 foreach ($params['acf'] as $field_key => $value) { 11 11 update_field($field_key, $value, $post_id); … … 13 13 } 14 14 15 // Categories (only if they exist)16 if ( !empty($params['categories']) && is_array($params['categories'])) {15 // Categories 16 if (isset($params['categories']) && is_array($params['categories'])) { 17 17 $category_ids = []; 18 18 foreach ($params['categories'] as $cat) { … … 22 22 } 23 23 } 24 if (!empty($category_ids)) { 25 wp_set_post_categories($post_id, $category_ids, false); 26 } 27 } 28 29 // Tags (only if they exist) 30 if (!empty($params['tags']) && is_array($params['tags'])) { 24 wp_set_post_categories($post_id, $category_ids, false); 25 } 26 27 // Tags 28 if (isset($params['tags']) && is_array($params['tags'])) { 31 29 $existing_tags = []; 32 30 foreach ($params['tags'] as $tag_name) { … … 36 34 } 37 35 } 38 if (!empty($existing_tags)) { 39 wp_set_post_terms($post_id, $existing_tags, 'post_tag', false); 40 } 36 wp_set_post_terms($post_id, $existing_tags, 'post_tag', false); 41 37 } 42 38 43 39 // SEO metadata 44 if ( !empty($params['seo']) && is_array($params['seo'])) {40 if (isset($params['seo']) && is_array($params['seo'])) { 45 41 foreach ($params['seo'] as $meta_key => $meta_value) { 46 42 update_post_meta($post_id, $meta_key, sanitize_text_field($meta_value)); … … 123 119 } 124 120 ]); 121 register_rest_route('sapientseo/v1', '/delete-post', [ 122 'methods' => 'POST', 123 'callback' => 'sapient_seo_delete_post', 124 'permission_callback' => function ($request) { 125 return sapient_seo_api_key_permission($request); 126 } 127 ]); 125 128 }); 126 129 … … 172 175 } 173 176 174 $post_data = [ 175 'ID' => $post_id, 176 'post_title' => sanitize_text_field($params['title'] ?? ''), 177 'post_content' => wp_kses_post($params['content'] ?? ''), 178 'post_excerpt' => sanitize_text_field($params['excerpt'] ?? ''), 179 ]; 177 $post_data = ['ID' => $post_id]; 178 179 if (array_key_exists('title', $params)) { 180 $post_data['post_title'] = sanitize_text_field($params['title']); 181 } 182 183 if (array_key_exists('content', $params)) { 184 $post_data['post_content'] = wp_kses_post($params['content']); 185 } 186 187 if (array_key_exists('excerpt', $params)) { 188 $post_data['post_excerpt'] = sanitize_text_field($params['excerpt']); 189 } 180 190 181 191 if (!empty($params['post_date'])) { … … 221 231 222 232 $offset = intval($request->get_param('offset') ?? 0); 223 $per_page = intval($request->get_param('per_page') ?? 10); 233 $per_page = $request->get_param('per_page'); 234 $per_page = is_numeric($per_page) && intval($per_page) > 0 ? intval($per_page) : -1; // -1 means all 224 235 225 236 $args = [ … … 255 266 256 267 return rest_ensure_response([ 257 'total' => $query->found_posts,258 268 'count' => count($posts), 259 269 'offset' => $offset, … … 337 347 return rest_ensure_response(['post_id' => $post_id, 'message' => 'Post published successfully.']); 338 348 } 349 350 // 🔹 Delete Post 351 function sapient_seo_delete_post(WP_REST_Request $request) { 352 $post_id = intval($request->get_param('post_id')); 353 354 if (!$post_id || get_post_status($post_id) === false) { 355 return new WP_Error('invalid_post', 'Post not found.', ['status' => 404]); 356 } 357 358 $result = wp_delete_post($post_id, true); // `true` = force delete 359 360 if (!$result) { 361 return rest_ensure_response([ 362 'error' => 'delete_failed', 363 'message' => 'Could not delete post.', 364 'status' => 500 365 ]); 366 } 367 368 return rest_ensure_response(['post_id' => $post_id, 'message' => 'Post deleted successfully.']); 369 } -
sapientseo/trunk/readme.txt
r3292976 r3293656 4 4 Tested up to: 6.8 5 5 Requires PHP: 7.4 6 Stable tag: 1.0.2 16 Stable tag: 1.0.22 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
sapientseo/trunk/sapientseo.php
r3292976 r3293656 3 3 * Plugin Name: SapientSEO 4 4 * Description: Connect your WordPress site to SapientSEO using secure custom REST API endpoints. 5 * Version: 1.0.2 15 * Version: 1.0.22 6 6 * Author: SapientSEO 7 7 * Plugin URI: https://sapientseo.ai … … 35 35 * All REST endpoints use either permission callbacks or secure header validation (X-API-KEY) via sapient_seo_api_key_permission(). 36 36 */ 37 38 /** 39 * Prevent full-page caching for SapientSEO REST API endpoints. 40 */ 41 add_action('template_redirect', 'sapientseo_template_redirect', 0); 42 function sapientseo_template_redirect() { 43 if (strpos($_SERVER['REQUEST_URI'], '/wp-json/sapientseo/v1/') !== false) { 44 header('Cache-Control: no-cache, must-revalidate, max-age=0'); 45 header('Pragma: no-cache'); 46 header('Expires: 0'); 47 } 48 }
Note: See TracChangeset
for help on using the changeset viewer.