// 从文本域解析图片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 = '
\u30102016\u5e74\u3011\u9ad8\u5343\u7a57\u94c3\uff08\u9ad8\u5343\u7a42\u3059\u305a\uff09\u4e2a\u4eba\u4f5c\u54c1\u6587\u7ae0\u56fe\u7247\u5c01\u9762\u4ee5\u53ca\u756a\u53f7 \u5ef6\u7eed\u66f4\u65b0
\n\u30102016\u5e74\u3011\u9ad8\u5343\u7a57\u94c3\uff08\u9ad8\u5343\u7a42\u3059\u305a\uff09\u4e2a\u4eba\u4f5c\u54c1\u6587\u7ae0\u56fe\u7247\u5c01\u9762\u4ee5\u53ca\u756a\u53f7 \u5ef6\u7eed\u66f4\u65b0
\n\u65e5\/\u7727\u7f03AWV\u5973\u7272\u7167\u7247\u5199\u5b9e\u65f6\u9ae6\u56fe\u7247\u5c01\u9762\uff0c\u6700\u65b0\u4f5c\u54c1\u6587\u7ae0\u756a\u53f7\u5927\u5168\u9700\u8981\u65e5\/\u7727\u7f03\u5973\u4eba\u756a\u53f7\u9009\u96c6\u5927\u5168<\/p>\n