Plugin Directory

Changeset 3398651


Ignore:
Timestamp:
11/19/2025 08:38:40 AM (4 months ago)
Author:
infility
Message:

v2.14.32 (20251119) Ben: 修改导入term的seo标题和描述

Location:
infility-global/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • infility-global/trunk/infility_global.php

    r3398580 r3398651  
    44Plugin URI: https://www.infility.cn/
    55Description: Infility公共插件
    6 Version: 2.14.31
     6Version: 2.14.32
    77Author: Infility
    88Author URI: https://www.infility.cn/
     
    138138    function __construct()
    139139    {
    140         define( 'INFILITY_GLOBAL_VERSION', '2.14.31' );
     140        define( 'INFILITY_GLOBAL_VERSION', '2.14.32' );
    141141        define( 'INFILITY_GLOBAL_PATH', plugin_dir_path( __FILE__ ) ); // fullpath/wp-content/plugins/infility-global/ // 有斜杠
    142142        define( 'INFILITY_GLOBAL_URL', plugins_url( '/', __FILE__ ) ); // https://the_domain/wp-content/plugins/infility-global/ // 斜杠是自己加的
  • infility-global/trunk/widgets/infility-import-data/include/infility-import-seo.php

    r3398580 r3398651  
    244244                $updated_keys[] = '_aioseop_description';
    245245                $updated_keys[] = '_aioseo_description';
     246            }
     247
     248            // 标记为过期并清理缓存,确保前端/管理端读取到最新数据
     249            if (function_exists('YoastSEO')) {
     250                self::mark_yoast_indexable_stale((int)$post_id, 'post');
     251            }
     252            if (function_exists('clean_post_cache')) {
     253                clean_post_cache((int)$post_id);
    246254            }
    247255
     
    367375            }
    368376
     377            // 标记为过期并清理缓存,确保前端/管理端读取到最新数据
     378            if (function_exists('YoastSEO')) {
     379                self::mark_yoast_indexable_stale((int)$term_id, 'term');
     380            }
     381            if (function_exists('clean_term_cache')) {
     382                clean_term_cache([(int)$term_id], (string)$taxonomy);
     383            }
     384
    369385            return $updated_keys;
     386        }
     387
     388        /**
     389         * 标记 Yoast Indexable 为过期(version=0),以便后续重建索引。
     390         * @param int $object_id 文章ID或分类ID
     391         * @param string $object_type 'post' 或 'term'
     392         * @return bool 是否标记成功
     393         */
     394        public static function mark_yoast_indexable_stale($object_id, $object_type = 'post') {
     395            $object_id = (int) $object_id;
     396            $object_type = ($object_type === 'term') ? 'term' : 'post';
     397
     398            try {
     399                if (!function_exists('YoastSEO')) {
     400                    return false;
     401                }
     402
     403                $repo = \YoastSEO()->classes->get(\Yoast\WP\SEO\Repositories\Indexable_Repository::class);
     404                if (!$repo) {
     405                    return false;
     406                }
     407
     408                $indexable = $repo->find_by_id_and_type($object_id, $object_type);
     409                if ($indexable instanceof \Yoast\WP\SEO\Models\Indexable) {
     410                    $indexable->version = 0;
     411                    $indexable->save();
     412                    return true;
     413                }
     414            } catch (\Throwable $e) {
     415                // 忽略异常,返回失败以避免中断导入流程
     416            }
     417
     418            return false;
    370419        }
    371420
     
    384433                'errors' => [],
    385434                'samples' => [],
     435                'not_found_arr' => [],
    386436            ];
    387437
     
    427477                    if ($address === '') {
    428478                        $summary['not_found']++;
     479                        $summary['not_found_arr'][] = $address;
    429480                        continue;
    430481                    }
     
    480531
    481532                    $summary['not_found']++;
     533                    $summary['not_found_arr'][] = $address;
    482534                }
    483535            } catch (Throwable $e) {
     
    505557            }
    506558
     559            if(!empty($summary['not_found_arr'])){
     560                $message[] = '<p>没匹配到的链接:</p>';
     561                foreach ($summary['not_found_arr'] as $s) {
     562                    $message[] = '<p>- ' . esc_html($s) . '</p>';
     563                }
     564            }
     565
    507566            return $message;
    508567            // error_log('[Infility SEO Import] ' . implode(' | ', $message));
Note: See TracChangeset for help on using the changeset viewer.