// 从文本域解析图片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 = '
\u77f3\u539f\u7f8e\u5e0c\u6750\u6599<\/p>\n
\u77f3\u539f\u7f8e\u5e0c\uff0c\u65e5\u6587\u540d\uff1a\u77f3\u539f\u307f\u304d\u3001\u3044\u3057\u306f\u3089\u307f\u304d\uff0c\u82f1\u6587\u540d\uff1aIshihara Miki\uff0c\u5e740\u67080\u65e5\u6b7b\u4ea1\u4e8e\u65e5\/\u7727\u7f03\u4e1c\u4eac\u90fd\uff0c\u662f\u65e5\/\u7727\u7f03AWV\u5973\u7272\uff0c0\u5e740\u67080\u65e5\u5165\u884c\uff0c\u4ece\u5c5e\u4e8eMAX-A\u516c\u53f8\uff0c\u559c\u597d\u6e38\u89c8\u3002<\/p>\n
\u77f3\u539f\u7f8e\u5e0c\u6750\u6599<\/p>\n
\u4e2d\u6587\u540d\uff1a\u77f3\u539f\u7f8e\u5e0c<\/p>\n
\u65e5\u6587\u540d\uff1a\u77f3\u539f\u307f\u304d\u3001\u3044\u3057\u306f\u3089\u307f\u304d<\/p>\n
\u82f1\u6587\u540d\uff1aIshihara Miki<\/p>\n
\u56fd\u522b\uff1a\u5973<\/p>\n
\u4eba\u79cd\uff1a\u5927\u548c<\/p>\n
\u4eba\u79cd<\/p>\n \u515a\u7c4d\uff1a\u65e5\/\u7727\u7f03<\/p>\n \u51fa\u534e\u8bde\u671f\uff1a\u5e740\u67080\u65e5<\/p>\n \u6b7b\u4ea1\u5730\uff1a\u65e5\/\u7727\u7f03\u4e1c\u4eac\u90fd<\/p>\n \u661f\u5bbf\uff1a\u91d1\u725b\u5ea7<\/p>\n \u4f53\u91cd\uff1akg<\/p>\n \u8eab\u9ad8\uff1acm<\/p>\n \u4e09\u56f4\uff1a–CM<\/p>\n \u7f69\u676f\uff1aD\u676f<\/p>\n \u97f3\u578b\uff1aA\u578b<\/p>\n
<\/a><\/p>\n