Plugin Directory

Changeset 3285203


Ignore:
Timestamp:
04/30/2025 06:48:17 PM (11 months ago)
Author:
galbc
Message:

Update trunk to version 1.0.4

Location:
sapientseo/trunk
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • sapientseo/trunk/inc/api/posts.php

    r3285196 r3285203  
    44}
    55
     6// 🔹 Shared Field Handler (ACF, categories, tags, SEO)
     7function sapientseo_apply_fields($post_id, $params) {
     8    // ACF fields
     9    if (function_exists('update_field') && !empty($params['acf']) && is_array($params['acf'])) {
     10        foreach ($params['acf'] as $field_key => $value) {
     11            update_field($field_key, $value, $post_id);
     12        }
     13    }
     14
     15    // Categories (only if they exist)
     16    if (!empty($params['categories']) && is_array($params['categories'])) {
     17        $category_ids = [];
     18        foreach ($params['categories'] as $cat) {
     19            $term = get_term_by('name', sanitize_text_field($cat), 'category');
     20            if ($term && !is_wp_error($term)) {
     21                $category_ids[] = $term->term_id;
     22            }
     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'])) {
     31        $existing_tags = [];
     32        foreach ($params['tags'] as $tag_name) {
     33            $term = get_term_by('name', sanitize_text_field($tag_name), 'post_tag');
     34            if ($term && !is_wp_error($term)) {
     35                $existing_tags[] = $term->name;
     36            }
     37        }
     38        if (!empty($existing_tags)) {
     39            wp_set_post_terms($post_id, $existing_tags, 'post_tag', false);
     40        }
     41    }
     42
     43    // SEO metadata
     44    if (!empty($params['seo']) && is_array($params['seo'])) {
     45        foreach ($params['seo'] as $meta_key => $meta_value) {
     46            update_post_meta($post_id, $meta_key, sanitize_text_field($meta_value));
     47        }
     48    }
     49}
     50
    651// 🔹 Register REST API Routes
    752add_action('rest_api_init', function () {
    8 
    953    register_rest_route('sapientseo/v1', '/create-post', [
    1054        'methods'  => 'POST',
     
    109153    ]);
    110154}
    111 
    112 // 🔹 Shared Field Handler (ACF, categories, tags, SEO)
    113 function sapientseo_apply_fields($post_id, $params) {
    114     // ACF fields
    115     if (function_exists('update_field') && !empty($params['acf']) && is_array($params['acf'])) {
    116         foreach ($params['acf'] as $field_key => $value) {
    117             update_field($field_key, $value, $post_id);
    118         }
    119     }
    120 
    121     // Categories (only if they exist)
    122     if (!empty($params['categories']) && is_array($params['categories'])) {
    123         $category_ids = [];
    124         foreach ($params['categories'] as $cat) {
    125             $term = get_term_by('name', sanitize_text_field($cat), 'category');
    126             if ($term && !is_wp_error($term)) {
    127                 $category_ids[] = $term->term_id;
    128             }
    129         }
    130         if (!empty($category_ids)) {
    131             wp_set_post_categories($post_id, $category_ids, false);
    132         }
    133     }
    134 
    135     // Tags (only if they exist)
    136     if (!empty($params['tags']) && is_array($params['tags'])) {
    137         $existing_tags = [];
    138         foreach ($params['tags'] as $tag_name) {
    139             $term = get_term_by('name', sanitize_text_field($tag_name), 'post_tag');
    140             if ($term && !is_wp_error($term)) {
    141                 $existing_tags[] = $term->name;
    142             }
    143         }
    144         if (!empty($existing_tags)) {
    145             wp_set_post_terms($post_id, $existing_tags, 'post_tag', false);
    146         }
    147     }
    148 
    149     // SEO metadata
    150     if (!empty($params['seo']) && is_array($params['seo'])) {
    151         foreach ($params['seo'] as $meta_key => $meta_value) {
    152             update_post_meta($post_id, $meta_key, sanitize_text_field($meta_value));
    153         }
    154     }
    155 }
  • sapientseo/trunk/readme.txt

    r3285200 r3285203  
    44Tested up to: 6.8
    55Requires PHP: 7.4
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • sapientseo/trunk/sapientseo.php

    r3285200 r3285203  
    33 * Plugin Name: SapientSEO
    44 * Description: Connect your WordPress site to SapientSEO using secure custom REST API endpoints.
    5  * Version: 1.0.3
     5 * Version: 1.0.4
    66 * Author: SapientSEO
    77 * Plugin URI: https://sapientseo.ai
Note: See TracChangeset for help on using the changeset viewer.