Changeset 3403932
- Timestamp:
- 11/27/2025 09:55:43 AM (3 months ago)
- Location:
- repostra/trunk
- Files:
-
- 2 edited
-
README.md (modified) (2 diffs)
-
repostra.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
repostra/trunk/README.md
r3403928 r3403932 4 4 Requires at least: 6.0 5 5 Tested up to: 6.8 6 Stable tag: 1.0. 56 Stable tag: 1.0.6 7 7 Requires PHP: 8.0 8 8 License: GPLv2 or later … … 37 37 == Changelog == 38 38 39 = 1.0. 5=39 = 1.0.6 = 40 40 * Initial release 41 41 * Webhook integration for blog posts -
repostra/trunk/repostra.php
r3403928 r3403932 4 4 * Plugin URI: https://repostra.app 5 5 * Description: Integrate Repostra content creation platform with your WordPress site. Automatically receive and publish blog posts from Repostra. 6 * Version: 1.0. 56 * Version: 1.0.6 7 7 * Author: AWcode Co Ltd 8 8 * License: GPL v2 or later … … 17 17 18 18 // Define plugin constants 19 define('REPOSTRA_PLUGIN_VERSION', '1.0. 0');19 define('REPOSTRA_PLUGIN_VERSION', '1.0.6'); 20 20 define('REPOSTRA_PLUGIN_DIR', plugin_dir_path(__FILE__)); 21 21 define('REPOSTRA_PLUGIN_URL', plugin_dir_url(__FILE__)); … … 156 156 $excerpt = isset($data['excerpt']) ? sanitize_textarea_field($data['excerpt']) : ''; 157 157 158 // Determine category to use 159 $category_id = null; 160 161 // First, check if a category is provided in the payload 162 if (isset($data['category']) && !empty($data['category'])) { 163 // Try to find category by slug (sanitize first) 164 $category_slug = sanitize_title($data['category']); 165 $category = get_category_by_slug($category_slug); 166 if ($category) { 167 $category_id = absint($category->term_id); 168 } 169 } 170 171 // If no category from payload, use default category if set 172 if (!$category_id) { 173 $default_category_id = get_option('repostra_default_category'); 174 // Convert to integer and check if it's a valid category 175 $default_category_id = absint($default_category_id); 176 if ($default_category_id > 0) { 177 // Verify the category exists 178 $term = get_term($default_category_id, 'category'); 179 if ($term && !is_wp_error($term)) { 180 $category_id = $default_category_id; 181 } 182 } 183 } 184 158 185 $post_data = array( 159 186 'post_title' => $title, … … 168 195 } 169 196 197 // Set category during post creation if we have one 198 if ($category_id) { 199 $post_data['post_category'] = array($category_id); 200 } 201 170 202 $post_id = wp_insert_post($post_data); 171 203 … … 174 206 } 175 207 176 // Set category 177 $category_id = null; 178 179 // First, check if a category is provided in the payload 180 if (isset($data['category']) && !empty($data['category'])) { 181 // Try to find category by slug (sanitize first) 182 $category_slug = sanitize_title($data['category']); 183 $category = get_category_by_slug($category_slug); 184 if ($category) { 185 $category_id = $category->term_id; 208 // Also set category after creation as a fallback (in case post_category didn't work) 209 if ($category_id) { 210 $result = wp_set_post_categories($post_id, array($category_id), false); 211 if (is_wp_error($result)) { 212 error_log('Repostra: Failed to set category: ' . $result->get_error_message()); 186 213 } 187 }188 189 // If no category from payload, use default category if set190 if (!$category_id) {191 $default_category_id = get_option('repostra_default_category');192 if ($default_category_id && term_exists($default_category_id, 'category')) {193 $category_id = $default_category_id;194 }195 }196 197 // Apply category if we have one198 if ($category_id) {199 wp_set_post_categories($post_id, array($category_id));200 214 } 201 215
Note: See TracChangeset
for help on using the changeset viewer.