Plugin Directory

Changeset 3403932


Ignore:
Timestamp:
11/27/2025 09:55:43 AM (3 months ago)
Author:
awcode
Message:

fix category

Location:
repostra/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • repostra/trunk/README.md

    r3403928 r3403932  
    44Requires at least: 6.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.5
     6Stable tag: 1.0.6
    77Requires PHP: 8.0
    88License: GPLv2 or later
     
    3737== Changelog ==
    3838
    39 = 1.0.5 =
     39= 1.0.6 =
    4040* Initial release
    4141* Webhook integration for blog posts
  • repostra/trunk/repostra.php

    r3403928 r3403932  
    44 * Plugin URI: https://repostra.app
    55 * Description: Integrate Repostra content creation platform with your WordPress site. Automatically receive and publish blog posts from Repostra.
    6  * Version: 1.0.5
     6 * Version: 1.0.6
    77 * Author: AWcode Co Ltd
    88 * License: GPL v2 or later
     
    1717
    1818// Define plugin constants
    19 define('REPOSTRA_PLUGIN_VERSION', '1.0.0');
     19define('REPOSTRA_PLUGIN_VERSION', '1.0.6');
    2020define('REPOSTRA_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2121define('REPOSTRA_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    156156        $excerpt = isset($data['excerpt']) ? sanitize_textarea_field($data['excerpt']) : '';
    157157       
     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       
    158185        $post_data = array(
    159186            'post_title' => $title,
     
    168195        }
    169196       
     197        // Set category during post creation if we have one
     198        if ($category_id) {
     199            $post_data['post_category'] = array($category_id);
     200        }
     201       
    170202        $post_id = wp_insert_post($post_data);
    171203       
     
    174206        }
    175207       
    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());
    186213            }
    187         }
    188        
    189         // If no category from payload, use default category if set
    190         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 one
    198         if ($category_id) {
    199             wp_set_post_categories($post_id, array($category_id));
    200214        }
    201215       
Note: See TracChangeset for help on using the changeset viewer.