Changeset 3285203
- Timestamp:
- 04/30/2025 06:48:17 PM (11 months ago)
- Location:
- sapientseo/trunk
- Files:
-
- 1 deleted
- 3 edited
-
inc/api/create-post.php (deleted)
-
inc/api/posts.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
-
sapientseo.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sapientseo/trunk/inc/api/posts.php
r3285196 r3285203 4 4 } 5 5 6 // 🔹 Shared Field Handler (ACF, categories, tags, SEO) 7 function 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 6 51 // 🔹 Register REST API Routes 7 52 add_action('rest_api_init', function () { 8 9 53 register_rest_route('sapientseo/v1', '/create-post', [ 10 54 'methods' => 'POST', … … 109 153 ]); 110 154 } 111 112 // 🔹 Shared Field Handler (ACF, categories, tags, SEO)113 function sapientseo_apply_fields($post_id, $params) {114 // ACF fields115 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 metadata150 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 4 4 Tested up to: 6.8 5 5 Requires PHP: 7.4 6 Stable tag: 1.0. 36 Stable tag: 1.0.4 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
sapientseo/trunk/sapientseo.php
r3285200 r3285203 3 3 * Plugin Name: SapientSEO 4 4 * Description: Connect your WordPress site to SapientSEO using secure custom REST API endpoints. 5 * Version: 1.0. 35 * Version: 1.0.4 6 6 * Author: SapientSEO 7 7 * Plugin URI: https://sapientseo.ai
Note: See TracChangeset
for help on using the changeset viewer.