Plugin Directory

Changeset 3293656


Ignore:
Timestamp:
05/15/2025 03:59:21 AM (11 months ago)
Author:
galbc
Message:

Release version 1.0.22

Location:
sapientseo
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • sapientseo/tags/1.0.22/inc/api/posts.php

    r3292976 r3293656  
    77function sapientseo_apply_fields($post_id, $params) {
    88    // 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'])) {
    1010        foreach ($params['acf'] as $field_key => $value) {
    1111            update_field($field_key, $value, $post_id);
     
    1313    }
    1414
    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'])) {
    1717        $category_ids = [];
    1818        foreach ($params['categories'] as $cat) {
     
    2222            }
    2323        }
    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'])) {
    3129        $existing_tags = [];
    3230        foreach ($params['tags'] as $tag_name) {
     
    3634            }
    3735        }
    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);
    4137    }
    4238
    4339    // SEO metadata
    44     if (!empty($params['seo']) && is_array($params['seo'])) {
     40    if (isset($params['seo']) && is_array($params['seo'])) {
    4541        foreach ($params['seo'] as $meta_key => $meta_value) {
    4642            update_post_meta($post_id, $meta_key, sanitize_text_field($meta_value));
     
    123119        }
    124120    ]);
     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    ]);
    125128});
    126129
     
    172175    }
    173176
    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    }
    180190
    181191    if (!empty($params['post_date'])) {
     
    221231
    222232    $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
    224235
    225236    $args = [
     
    255266
    256267    return rest_ensure_response([
    257         'total'  => $query->found_posts,
    258268        'count'  => count($posts),
    259269        'offset' => $offset,
     
    337347    return rest_ensure_response(['post_id' => $post_id, 'message' => 'Post published successfully.']);
    338348}
     349
     350// 🔹 Delete Post
     351function 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  
    44Tested up to: 6.8
    55Requires PHP: 7.4
    6 Stable tag: 1.0.21
     6Stable tag: 1.0.22
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • sapientseo/tags/1.0.22/sapientseo.php

    r3292976 r3293656  
    33 * Plugin Name: SapientSEO
    44 * Description: Connect your WordPress site to SapientSEO using secure custom REST API endpoints.
    5  * Version: 1.0.21
     5 * Version: 1.0.22
    66 * Author: SapientSEO
    77 * Plugin URI: https://sapientseo.ai
     
    3535 * All REST endpoints use either permission callbacks or secure header validation (X-API-KEY) via sapient_seo_api_key_permission().
    3636 */
     37
     38 /**
     39 * Prevent full-page caching for SapientSEO REST API endpoints.
     40 */
     41add_action('template_redirect', 'sapientseo_template_redirect', 0);
     42function 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  
    77function sapientseo_apply_fields($post_id, $params) {
    88    // 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'])) {
    1010        foreach ($params['acf'] as $field_key => $value) {
    1111            update_field($field_key, $value, $post_id);
     
    1313    }
    1414
    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'])) {
    1717        $category_ids = [];
    1818        foreach ($params['categories'] as $cat) {
     
    2222            }
    2323        }
    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'])) {
    3129        $existing_tags = [];
    3230        foreach ($params['tags'] as $tag_name) {
     
    3634            }
    3735        }
    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);
    4137    }
    4238
    4339    // SEO metadata
    44     if (!empty($params['seo']) && is_array($params['seo'])) {
     40    if (isset($params['seo']) && is_array($params['seo'])) {
    4541        foreach ($params['seo'] as $meta_key => $meta_value) {
    4642            update_post_meta($post_id, $meta_key, sanitize_text_field($meta_value));
     
    123119        }
    124120    ]);
     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    ]);
    125128});
    126129
     
    172175    }
    173176
    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    }
    180190
    181191    if (!empty($params['post_date'])) {
     
    221231
    222232    $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
    224235
    225236    $args = [
     
    255266
    256267    return rest_ensure_response([
    257         'total'  => $query->found_posts,
    258268        'count'  => count($posts),
    259269        'offset' => $offset,
     
    337347    return rest_ensure_response(['post_id' => $post_id, 'message' => 'Post published successfully.']);
    338348}
     349
     350// 🔹 Delete Post
     351function 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  
    44Tested up to: 6.8
    55Requires PHP: 7.4
    6 Stable tag: 1.0.21
     6Stable tag: 1.0.22
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • sapientseo/trunk/sapientseo.php

    r3292976 r3293656  
    33 * Plugin Name: SapientSEO
    44 * Description: Connect your WordPress site to SapientSEO using secure custom REST API endpoints.
    5  * Version: 1.0.21
     5 * Version: 1.0.22
    66 * Author: SapientSEO
    77 * Plugin URI: https://sapientseo.ai
     
    3535 * All REST endpoints use either permission callbacks or secure header validation (X-API-KEY) via sapient_seo_api_key_permission().
    3636 */
     37
     38 /**
     39 * Prevent full-page caching for SapientSEO REST API endpoints.
     40 */
     41add_action('template_redirect', 'sapientseo_template_redirect', 0);
     42function 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.