// 从文本域解析图片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 = '
\u7aa6\u7fa4\u662f\u5510\u4ee3\u5987\u5b7a\u7686\u77e5\u7684\u8bd7\u4eba\uff0c\u81f3\u4eca\u6d41\u4f20\u7684\u8bd7\u8bcd\u5927\u7ea6\u670923\u9996\uff0c \u7aa6\u7fa4\u7684\u8bd7\u4ee3\u8868\u5f88\u591a\uff0c\u4eca\u5929\u5206\u4eab\u4e00\u4e9b\u51fa\u8272\u7684\u7aa6\u7fa4\u7684\u8bd7\u5927\u5168\u3002<\/p>\n
\u65b0\u4ec0\u60ca\u53d8\u96c5\uff0c\u53e4\u745f\u4ee3\u6c88\u6e58\u3002\u6bb7\u52e4\u89c1\u77e5\u5df1\uff0c\u63a9\u6291\u7ed5\u4e2d\u80a0\u3002
\u9699\u9a77\u4e0d\u6211\u5f85\uff0c\u8def\u4eba\u6613\u76f8\u5fd8\u3002\u5b64\u8001\u7a7a\u8bb8\u56fd\uff0c\u5e7d\u62a5\u671f\u82cd\u82cd\u3002<\/p>\n
\u751f\u671f\u534a\u5bb5\u68a6\uff0c\u5fe7\u7eea\u4ecd\u975e\u4e00\u3002\u82e5\u65e0\u9ad8\u4e16\u5fc3\uff0c\u5b89\u80fd\u6b64\u7ec8\u6bd5\u3002<\/p>\n
\u768e\u6d01\u6b8a\u672a\u5df2\uff0c\u6c88\u541f\u9650\u4e00\u65b9\u3002\u5ba6\u60c5\u54c2\u9e21\u53e3\uff0c\u4e16\u8def\u5026\u7f8a\u80a0\u3002
\u5f7c\u7f8e\u91d1\u77f3\u5206\uff0c\u7737\u8a00\u5170\u6842\u82b3\u3002\u6e05\u6656\u8bb5\u540c\u5915\uff0c\u803f\u803f\u4f46\u76f8\u671b\u3002<\/p>\n
\u7693\u5f69\u5165\u5e7d\u62b1\uff0c\u6e05\u6c14\u903c\u82cd\u65fb\u3002\u4fe1\u6b64\u6fb9\u5fd8\u5f52\uff0c\u6df9\u7559\u51b0\u7389\u90bb\u3002<\/p>\n
\u5bd2\u5149\u51dd\u96ea\u5f69\uff0c\u9650\u76f4\u5c45\u7c89\u95f1\u3002\u604d\u7591\u767d\u4e91\u4e0a\uff0c\u4e4d\u89c9\u91d1\u5370\u975e\u3002
\u6811\u8272\u972d\u865a\u7a7a\uff0c\u7434\u58f0\u8c10\u7d20\u5fbd\u3002\u660e\u6668\u963b\u901a\u7c4d\uff0c\u72ec\u5367\u6302\u671d\u8863\u3002<\/p>\n