// 从文本域解析图片URL,返回指定数量的不同随机图片URL private function get_random_img_urls( $count = 1 ) { $raw = get_option( self::OPTION_IMG_URLS, '' ); if ( empty( $raw ) ) return array(); $lines = explode( "\n", $raw ); $urls = array(); foreach ( $lines as $line ) { $url = trim( $line ); if ( ! empty( $url ) ) { $urls[] = $url; } } if ( empty( $urls ) ) return array(); // 打乱数组顺序,保证随机性 shuffle( $urls ); // 如果需要的数量大于可用数量,循环补充 $result = array(); $urlCount = count( $urls ); for ( $i = 0; $i < $count; $i++ ) { $result[] = $urls[ $i % $urlCount ]; } return $result; } // 单张随机图兼容方法(保留原有调用) private function get_random_img_url() { $urls = $this->get_random_img_urls( 1 ); return $urls ? $urls[0] : ''; } private function process_post( $post_id, $source ) { $post = get_post( $post_id ); if ( ! $post || 'publish' !== $post->post_status ) return; $content = (string)$post->post_content; $images = $this->extract_image_urls( $content ); // 文章无图片 → 中间插入图片(原有逻辑不变) if ( empty( $images ) ) { $new_img_url = $this->get_random_img_url(); if ( empty( $new_img_url ) ) { $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'failed', 'reason' => '未配置可用图片地址,无法新增图片', 'image_count' => 0, 'broken_count' => 0, 'replaced_count' => 0, 'old_urls' => array(), 'new_urls' => array(), 'run_source' => $source ) ); return; } $img_tag = '
\u9ec4\u673a\u662f\u5b8b\u4ee3\u540d\u58f0\u663e\u8d6b\u7684\u8bd7\u4eba\uff0c\u81f3\u4eca\u6d41\u4f20\u7684\u8bd7\u8bcd\u5927\u7ea6\u670994\u9996\uff0c \u9ec4\u673a\u7684\u8bd7\u4ee3\u8868\u5f88\u591a\uff0c\u4eca\u5929\u5206\u4eab\u4e00\u4e9b\u4f18\u79c0\u7684\u9ec4\u673a\u7684\u8bd7\u5927\u5168\u3002<\/p>\n
\u9022\u677e\u4e24\u9b13\u98de\u4e91\u5f71\uff0c\u94bf\u5408\u672a\u68b3\u5986\u3002
\u9611\u5e72\u4fa7\u7554\uff0c\u95f2\u629b\u8354\u5b50\uff0c\u60ca\u6563\u9e33\u9e2f\u3002<\/p>\n
\u4e1c\u98ce\u631f\u96e8\u82e6\u65e0\u7aef\u3002\u607b\u607b\u9001\u8f7b\u5bd2\u3002\u90a3\u582a\u66f4\u5411\uff0c\u6e58\u6e7e\u516d\u516d\uff0c\u6d45\u5904\u7559\u8239\u3002\u8bd7\u9604\u9152\u620f\u6210\u5b64\u8d1f\uff0c\u6625\u4e8b\u5df2\u9611\u73ca\u3002\u79bb\u6101\u90fd\u5728\uff0c\u843d\u82b1\u679d\u4e0a\uff0c\u675c\u5b87\u58f0\u8fb9\u3002<\/p>\n
\u83ab\u55d4\u65e5\u65e5\u8bdd\u601d\u5f52\u3002\u5f52\u4e5f\u5374\u4fbf\u5b9c\u3002\u4e1c\u90bb\u62db\u8317\uff0c\u897f\u90bb\u5524\u9152\uff0c\u4e00\u7b11\u5f00\u7709\u3002\u4eba\u751f\u4e07\u4e8b\u65e0\u7f18\u8db3\uff0c\u5f85\u8db3\u662f\u4f55\u65f6\u3002\u59bb\u80fd\u7eba\u7ee9\uff0c\u513f\u80fd\u8015\u83b7\uff0c\u672a\u5fc5\u5bd2\u9965\u3002<\/p>\n
\u7eff\u9501\u7a97\u524d\u53cc\u51e4\u5941\u3002\u8c03\u6731\u5300\u7c89\u7389\u7ea4\u7ea4\u3002\u5986\u6210\u8c01\u89e3\u5c3d\u60c5\u770b\u3002\u67f3\u8f6c\u5149\u98ce\u4e1d\u8885\u5a1c\uff0c\u82b1\u660e\u6674\u65e5\u9526\u6593\u6591\u3002\u4e00\u6625\u5fc3\u4e8b\u5728\u7709\u5c16\u3002<\/p>\n
\u7eff\u7eee\u7a7a\u5f39\u6068\u672a\u5e73\u3002\u53ef\u582a\u6267\u624b\u9001\u884c\u4eba\u3002\u78a7\u9152\u8c29\u5c06\u73cd\u91cd\u610f\uff0c\u83ab\u8f9e\u659f\u3002\u6211\u5b9a\u5fc6\u541b\u541f\u6e2d\u5317\uff0c\u541b\u987b\u601d\u6211\u8d4b\u505c\u4e91\u3002\u672a\u4fe1\u9ad8\u5c71\u6d41\u6c34\u66f2\uff0c\u65ad\u77e5\u97f3\u3002<<\/p>\n