Plugin Directory

Changeset 3478683


Ignore:
Timestamp:
03/10/2026 02:23:17 AM (3 weeks ago)
Author:
infility
Message:

v2.14.59 (20260310) Ben: 导入SEO添加导入图片title、alt和descrtion功能。

Location:
infility-global/trunk
Files:
2 edited

Legend:

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

    r3476026 r3478683  
    44Plugin URI: https://www.infility.cn/
    55Description: Infility公共插件
    6 Version: 2.14.57
     6Version: 2.14.59
    77Author: Infility
    88Author URI: https://www.infility.cn/
     
    143143v2.14.54 (20260224) Ben: 新增获取cf7表单数据接口,废弃infility_get_data接口。
    144144v2.14.58 (20260306) Ben: 优化批量导入产品功能。
     145v2.14.59 (20260310) Ben: 导入SEO添加导入图片title、alt和descrtion功能。
    145146*/
    146147
     
    148149    function __construct()
    149150    {
    150         define( 'INFILITY_GLOBAL_VERSION', '2.14.57' );
     151        define( 'INFILITY_GLOBAL_VERSION', '2.14.59' );
    151152        define( 'INFILITY_GLOBAL_PATH', plugin_dir_path( __FILE__ ) ); // fullpath/wp-content/plugins/infility-global/ // 有斜杠
    152153        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

    r3398661 r3478683  
    419419        }
    420420
     421        /** 检查 URL 是否是图片 */
     422        public static function is_image_url($url) {
     423            $path = parse_url($url, PHP_URL_PATH);
     424            if (!$path) return false;
     425            return (bool)preg_match('/\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i', $path);
     426        }
     427
     428        /** 更新图片(附件)的 Title, Alt, Description */
     429        public static function update_image_meta($post_id, $title, $description) {
     430            $updated_keys = [];
     431            $post_data = ['ID' => $post_id];
     432            $should_update_post = false;
     433
     434            if ($title !== '') {
     435                $post_data['post_title'] = $title;
     436                $should_update_post = true;
     437                $updated_keys[] = 'post_title';
     438
     439                // 图片的Alt也用title
     440                update_post_meta($post_id, '_wp_attachment_image_alt', $title);
     441                $updated_keys[] = '_wp_attachment_image_alt';
     442            }
     443
     444            if ($description !== '') {
     445                $post_data['post_content'] = $description;
     446                $should_update_post = true;
     447                $updated_keys[] = 'post_content';
     448            }
     449
     450            if ($should_update_post) {
     451                wp_update_post($post_data);
     452            }
     453
     454            // 清理缓存
     455            if (function_exists('clean_post_cache')) {
     456                clean_post_cache((int)$post_id);
     457            }
     458
     459            return $updated_keys;
     460        }
     461
    421462        /** 主执行:读取XLSX并导入SEO元数据 */
    422463        public static function run($filePath) {
     
    483524                        $summary['skipped_blank']++;
    484525                        continue;
     526                    }
     527
     528                    // 0) 优先判断是否为图片
     529                    if (self::is_image_url($address)) {
     530                        $attachment_id = attachment_url_to_postid($address);
     531                        if ($attachment_id) {
     532                            $updated_keys = self::update_image_meta($attachment_id, $title, $desc);
     533                            if (!empty($updated_keys)) {
     534                                $summary['updated']++;
     535                                $updated_posts++;
     536                                $summary['samples'][] = [
     537                                    'type' => 'image',
     538                                    'post_id' => $attachment_id,
     539                                    'address' => $address,
     540                                    'title' => $title,
     541                                    'description' => $desc,
     542                                    'keys' => $updated_keys,
     543                                ];
     544                            } else {
     545                                $summary['skipped_blank']++;
     546                            }
     547                            continue;
     548                        }
    485549                    }
    486550
Note: See TracChangeset for help on using the changeset viewer.