Plugin Directory

Changeset 3743334


Ignore:
Timestamp:
10/13/2026 09:00:03 AM (5 weeks ago)
Author:
autoseoai
Message:

Tag version 1.3.116. Restore WordPress post tags after an image save, and restore them on the next sync when the article body did not change.

Location:
getautoseo-ai-content-publisher
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • getautoseo-ai-content-publisher/tags/1.3.116/autoseo.php

    r3734214 r3743334  
    44 * Plugin URI: https://getautoseo.com
    55 * Description: Automate your SEO content creation and publishing with AI-powered tools. Generate high-quality articles, optimize for search engines, and publish directly to your WordPress site.
    6  * Version: 1.3.115
     6 * Version: 1.3.116
    77 * Author: GetAutoSEO Team
    88 * License: GPL v2 or later
    … …  
    2121
    2222// Define plugin constants
    23 define('AUTOSEO_VERSION', '1.3.115');
     23define('AUTOSEO_VERSION', '1.3.116');
    2424define('AUTOSEO_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2525define('AUTOSEO_PLUGIN_URL', plugin_dir_url(__FILE__));
    … …  
    37093709        }
    37103710
     3711        // The hero path does not bake content, but attachment hooks can still
     3712        // change tags. Restore the AutoSEO list after either image type.
     3713        AutoSEO_Publisher::reapply_stored_tags($post_id);
     3714
    37113715        return rest_ensure_response(array(
    37123716            'success' => true,
  • getautoseo-ai-content-publisher/tags/1.3.116/includes/class-autoseo-api.php

    r3734214 r3743334  
    866866                            && !$force_content_update
    867867                        ) {
     868                            // Content is unchanged, but a later image save can replace
     869                            // tags. Apply the AutoSEO tag list without rewriting the post.
     870                            if (!empty($article['wordpress_tags'])) {
     871                                AutoSEO_Publisher::sync_tags_if_different($wp_post->ID, $article['wordpress_tags']);
     872                            }
     873
    868874                            if ($needs_url_confirmation) {
    869875                                $publisher = new AutoSEO_Publisher();
  • getautoseo-ai-content-publisher/tags/1.3.116/includes/class-autoseo-publisher.php

    r3734214 r3743334  
    1515    private static $batch_mode = false;
    1616    private static $batched_webhooks = array();
     17    private static $pending_tag_sync = array();
     18    private static $tag_shutdown_registered = false;
    1719
    1820    private $seo_owned_titles = array();
    … …  
    728730            AutoSEO_Plugin::disallow_content_updates();
    729731        }
     732
     733        // wp_update_post runs save_post. Another plugin can replace tags there.
     734        self::reapply_stored_tags($post_id);
    730735
    731736        $this->log_debug(sprintf('Baked infographic into post_content for post %d', $post_id));
    … …  
    20692074     */
    20702075    private function set_wordpress_tags($post_id, $article) {
    2071         // Skip if no tags available
    20722076        if (empty($article->wordpress_tags)) {
    20732077            return;
    20742078        }
    20752079
    2076         // Parse comma-separated tags
    2077         $tags_array = array_map('trim', explode(',', $article->wordpress_tags));
    2078         $tags_array = array_filter($tags_array); // Remove empty values
    2079 
    2080         if (empty($tags_array)) {
    2081             return;
    2082         }
    2083 
    2084         // Set the tags on the post (wp_set_post_tags will create tags if they don't exist)
    2085         $result = wp_set_post_tags($post_id, $tags_array, false); // false = replace existing tags
     2080        self::sync_tags_if_different($post_id, $article->wordpress_tags);
     2081    }
     2082
     2083    /**
     2084     * Replace the post's tags when they are not the AutoSEO list.
     2085     *
     2086     * A later save in the same request (infographic bake, another plugin's
     2087     * save_post or shutdown hook) can replace these tags. The list is applied
     2088     * again at the end of the request.
     2089     *
     2090     * @param int $post_id WordPress post ID
     2091     * @param string $tag_string Comma-separated AutoSEO tags
     2092     */
     2093    public static function sync_tags_if_different($post_id, $tag_string) {
     2094        $post_id = (int) $post_id;
     2095        $desired = self::parse_tag_list($tag_string);
     2096        if ($post_id <= 0 || empty($desired)) {
     2097            return;
     2098        }
     2099
     2100        $current = wp_get_post_tags($post_id, array('fields' => 'names'));
     2101        if (!is_array($current)) {
     2102            $current = array();
     2103        }
     2104
     2105        if (self::tag_lists_match($current, $desired)) {
     2106            update_post_meta($post_id, '_autoseo_wordpress_tags', $tag_string);
     2107            return;
     2108        }
     2109
     2110        $result = wp_set_post_tags($post_id, $desired, false);
    20862111
    20872112        if (is_wp_error($result)) {
    2088             $this->log_debug(sprintf(
    2089                 'Failed to set tags for post %d: %s',
     2113            error_log(sprintf(
     2114                '[AutoSEO Publisher] Failed to set tags for post %d: %s',
    20902115                $post_id,
    20912116                $result->get_error_message()
    20922117            ));
    2093         } else {
    2094             $this->log_debug(sprintf(
    2095                 'Set %d tags for post %d: %s',
    2096                 count($tags_array),
    2097                 $post_id,
    2098                 implode(', ', $tags_array)
    2099             ));
    2100         }
    2101 
    2102         // Store the original tags in post meta for reference
    2103         update_post_meta($post_id, '_autoseo_wordpress_tags', $article->wordpress_tags);
     2118            return;
     2119        }
     2120
     2121        update_post_meta($post_id, '_autoseo_wordpress_tags', $tag_string);
     2122        self::$pending_tag_sync[$post_id] = $tag_string;
     2123
     2124        if (!self::$tag_shutdown_registered) {
     2125            self::$tag_shutdown_registered = true;
     2126            add_action('shutdown', array(__CLASS__, 'reapply_pending_tags'), PHP_INT_MAX);
     2127        }
     2128    }
     2129
     2130    /**
     2131     * Put AutoSEO tags back after other plugins run on shutdown.
     2132     */
     2133    public static function reapply_pending_tags() {
     2134        $pending = self::$pending_tag_sync;
     2135        self::$pending_tag_sync = array();
     2136
     2137        foreach ($pending as $post_id => $tag_string) {
     2138            $desired = self::parse_tag_list($tag_string);
     2139            if (empty($desired)) {
     2140                continue;
     2141            }
     2142            $current = wp_get_post_tags((int) $post_id, array('fields' => 'names'));
     2143            if (!is_array($current) || self::tag_lists_match($current, $desired)) {
     2144                continue;
     2145            }
     2146            wp_set_post_tags((int) $post_id, $desired, false);
     2147            update_post_meta((int) $post_id, '_autoseo_wordpress_tags', $tag_string);
     2148        }
     2149    }
     2150
     2151    /**
     2152     * Restore tags stored on the post after a later content save.
     2153     *
     2154     * @param int $post_id WordPress post ID
     2155     */
     2156    public static function reapply_stored_tags($post_id) {
     2157        $tag_string = get_post_meta((int) $post_id, '_autoseo_wordpress_tags', true);
     2158        if (!is_string($tag_string) || trim($tag_string) === '') {
     2159            return;
     2160        }
     2161        self::sync_tags_if_different((int) $post_id, $tag_string);
     2162    }
     2163
     2164    /**
     2165     * @param string $tag_string Comma-separated tags
     2166     * @return array
     2167     */
     2168    private static function parse_tag_list($tag_string) {
     2169        $tags = array_map('trim', explode(',', (string) $tag_string));
     2170        $tags = array_filter($tags, function ($tag) {
     2171            return $tag !== '';
     2172        });
     2173        return array_values($tags);
     2174    }
     2175
     2176    /**
     2177     * @param array $left Tag names
     2178     * @param array $right Tag names
     2179     * @return bool
     2180     */
     2181    private static function tag_lists_match($left, $right) {
     2182        $normalize = function ($tags) {
     2183            $tags = array_map(function ($tag) {
     2184                return strtolower(trim((string) $tag));
     2185            }, $tags);
     2186            $tags = array_values(array_filter($tags, function ($tag) {
     2187                return $tag !== '';
     2188            }));
     2189            sort($tags);
     2190            return $tags;
     2191        };
     2192
     2193        return $normalize($left) === $normalize($right);
    21042194    }
    21052195
  • getautoseo-ai-content-publisher/tags/1.3.116/readme.txt

    r3734214 r3743334  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.3.115
     7Stable tag: 1.3.116
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    112112
    113113== Changelog ==
     114
     115= 1.3.116 =
     116* FIXED: WordPress post tags from AutoSEO are applied again when a later image save replaces them. The next sync also restores tags on posts that already lost them, without rewriting the article.
    114117
    115118= 1.3.115 =
  • getautoseo-ai-content-publisher/trunk/autoseo.php

    r3734214 r3743334  
    44 * Plugin URI: https://getautoseo.com
    55 * Description: Automate your SEO content creation and publishing with AI-powered tools. Generate high-quality articles, optimize for search engines, and publish directly to your WordPress site.
    6  * Version: 1.3.115
     6 * Version: 1.3.116
    77 * Author: GetAutoSEO Team
    88 * License: GPL v2 or later
    … …  
    2121
    2222// Define plugin constants
    23 define('AUTOSEO_VERSION', '1.3.115');
     23define('AUTOSEO_VERSION', '1.3.116');
    2424define('AUTOSEO_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2525define('AUTOSEO_PLUGIN_URL', plugin_dir_url(__FILE__));
    … …  
    37093709        }
    37103710
     3711        // The hero path does not bake content, but attachment hooks can still
     3712        // change tags. Restore the AutoSEO list after either image type.
     3713        AutoSEO_Publisher::reapply_stored_tags($post_id);
     3714
    37113715        return rest_ensure_response(array(
    37123716            'success' => true,
  • getautoseo-ai-content-publisher/trunk/includes/class-autoseo-api.php

    r3734214 r3743334  
    866866                            && !$force_content_update
    867867                        ) {
     868                            // Content is unchanged, but a later image save can replace
     869                            // tags. Apply the AutoSEO tag list without rewriting the post.
     870                            if (!empty($article['wordpress_tags'])) {
     871                                AutoSEO_Publisher::sync_tags_if_different($wp_post->ID, $article['wordpress_tags']);
     872                            }
     873
    868874                            if ($needs_url_confirmation) {
    869875                                $publisher = new AutoSEO_Publisher();
  • getautoseo-ai-content-publisher/trunk/includes/class-autoseo-publisher.php

    r3734214 r3743334  
    1515    private static $batch_mode = false;
    1616    private static $batched_webhooks = array();
     17    private static $pending_tag_sync = array();
     18    private static $tag_shutdown_registered = false;
    1719
    1820    private $seo_owned_titles = array();
    … …  
    728730            AutoSEO_Plugin::disallow_content_updates();
    729731        }
     732
     733        // wp_update_post runs save_post. Another plugin can replace tags there.
     734        self::reapply_stored_tags($post_id);
    730735
    731736        $this->log_debug(sprintf('Baked infographic into post_content for post %d', $post_id));
    … …  
    20692074     */
    20702075    private function set_wordpress_tags($post_id, $article) {
    2071         // Skip if no tags available
    20722076        if (empty($article->wordpress_tags)) {
    20732077            return;
    20742078        }
    20752079
    2076         // Parse comma-separated tags
    2077         $tags_array = array_map('trim', explode(',', $article->wordpress_tags));
    2078         $tags_array = array_filter($tags_array); // Remove empty values
    2079 
    2080         if (empty($tags_array)) {
    2081             return;
    2082         }
    2083 
    2084         // Set the tags on the post (wp_set_post_tags will create tags if they don't exist)
    2085         $result = wp_set_post_tags($post_id, $tags_array, false); // false = replace existing tags
     2080        self::sync_tags_if_different($post_id, $article->wordpress_tags);
     2081    }
     2082
     2083    /**
     2084     * Replace the post's tags when they are not the AutoSEO list.
     2085     *
     2086     * A later save in the same request (infographic bake, another plugin's
     2087     * save_post or shutdown hook) can replace these tags. The list is applied
     2088     * again at the end of the request.
     2089     *
     2090     * @param int $post_id WordPress post ID
     2091     * @param string $tag_string Comma-separated AutoSEO tags
     2092     */
     2093    public static function sync_tags_if_different($post_id, $tag_string) {
     2094        $post_id = (int) $post_id;
     2095        $desired = self::parse_tag_list($tag_string);
     2096        if ($post_id <= 0 || empty($desired)) {
     2097            return;
     2098        }
     2099
     2100        $current = wp_get_post_tags($post_id, array('fields' => 'names'));
     2101        if (!is_array($current)) {
     2102            $current = array();
     2103        }
     2104
     2105        if (self::tag_lists_match($current, $desired)) {
     2106            update_post_meta($post_id, '_autoseo_wordpress_tags', $tag_string);
     2107            return;
     2108        }
     2109
     2110        $result = wp_set_post_tags($post_id, $desired, false);
    20862111
    20872112        if (is_wp_error($result)) {
    2088             $this->log_debug(sprintf(
    2089                 'Failed to set tags for post %d: %s',
     2113            error_log(sprintf(
     2114                '[AutoSEO Publisher] Failed to set tags for post %d: %s',
    20902115                $post_id,
    20912116                $result->get_error_message()
    20922117            ));
    2093         } else {
    2094             $this->log_debug(sprintf(
    2095                 'Set %d tags for post %d: %s',
    2096                 count($tags_array),
    2097                 $post_id,
    2098                 implode(', ', $tags_array)
    2099             ));
    2100         }
    2101 
    2102         // Store the original tags in post meta for reference
    2103         update_post_meta($post_id, '_autoseo_wordpress_tags', $article->wordpress_tags);
     2118            return;
     2119        }
     2120
     2121        update_post_meta($post_id, '_autoseo_wordpress_tags', $tag_string);
     2122        self::$pending_tag_sync[$post_id] = $tag_string;
     2123
     2124        if (!self::$tag_shutdown_registered) {
     2125            self::$tag_shutdown_registered = true;
     2126            add_action('shutdown', array(__CLASS__, 'reapply_pending_tags'), PHP_INT_MAX);
     2127        }
     2128    }
     2129
     2130    /**
     2131     * Put AutoSEO tags back after other plugins run on shutdown.
     2132     */
     2133    public static function reapply_pending_tags() {
     2134        $pending = self::$pending_tag_sync;
     2135        self::$pending_tag_sync = array();
     2136
     2137        foreach ($pending as $post_id => $tag_string) {
     2138            $desired = self::parse_tag_list($tag_string);
     2139            if (empty($desired)) {
     2140                continue;
     2141            }
     2142            $current = wp_get_post_tags((int) $post_id, array('fields' => 'names'));
     2143            if (!is_array($current) || self::tag_lists_match($current, $desired)) {
     2144                continue;
     2145            }
     2146            wp_set_post_tags((int) $post_id, $desired, false);
     2147            update_post_meta((int) $post_id, '_autoseo_wordpress_tags', $tag_string);
     2148        }
     2149    }
     2150
     2151    /**
     2152     * Restore tags stored on the post after a later content save.
     2153     *
     2154     * @param int $post_id WordPress post ID
     2155     */
     2156    public static function reapply_stored_tags($post_id) {
     2157        $tag_string = get_post_meta((int) $post_id, '_autoseo_wordpress_tags', true);
     2158        if (!is_string($tag_string) || trim($tag_string) === '') {
     2159            return;
     2160        }
     2161        self::sync_tags_if_different((int) $post_id, $tag_string);
     2162    }
     2163
     2164    /**
     2165     * @param string $tag_string Comma-separated tags
     2166     * @return array
     2167     */
     2168    private static function parse_tag_list($tag_string) {
     2169        $tags = array_map('trim', explode(',', (string) $tag_string));
     2170        $tags = array_filter($tags, function ($tag) {
     2171            return $tag !== '';
     2172        });
     2173        return array_values($tags);
     2174    }
     2175
     2176    /**
     2177     * @param array $left Tag names
     2178     * @param array $right Tag names
     2179     * @return bool
     2180     */
     2181    private static function tag_lists_match($left, $right) {
     2182        $normalize = function ($tags) {
     2183            $tags = array_map(function ($tag) {
     2184                return strtolower(trim((string) $tag));
     2185            }, $tags);
     2186            $tags = array_values(array_filter($tags, function ($tag) {
     2187                return $tag !== '';
     2188            }));
     2189            sort($tags);
     2190            return $tags;
     2191        };
     2192
     2193        return $normalize($left) === $normalize($right);
    21042194    }
    21052195
  • getautoseo-ai-content-publisher/trunk/readme.txt

    r3734214 r3743334  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.3.115
     7Stable tag: 1.3.116
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    112112
    113113== Changelog ==
     114
     115= 1.3.116 =
     116* FIXED: WordPress post tags from AutoSEO are applied again when a later image save replaces them. The next sync also restores tags on posts that already lost them, without rewriting the article.
    114117
    115118= 1.3.115 =
Note: See TracChangeset for help on using the changeset viewer.