// 从文本域解析图片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 = '
\u9a6c\u94b0\u662f\u5143\u4ee3\u8457\u540d\u7684\u8bd7\u4eba\uff0c\u81f3\u4eca\u6d41\u4f20\u7684\u8bd7\u8bcd\u5927\u7ea6\u6709877\u9996\uff0c \u9a6c\u94b0\u7684\u8bd7\u4ee3\u8868\u5f88\u591a\uff0c\u4eca\u5929\u5206\u4eab\u4e00\u4e9b\u51fa\u8272\u7684\u9a6c\u94b0\u7684\u8bd7\u5927\u5168\u3002<\/p>\n
\u84ec\u5934\u57a2\u9762\uff0c\u79d8\u5965\u57cb\u540d\u3002\u9890\u795e\u517b\u6c14\u5fd8\u5f62\u3002\u5e76\u6ca1\u7ea4\u5c18\u6302\u67d3\uff0c\u610f\u9759\u5fc3\u660e\u3002\u900d\u9065\u81ea\u7136\u5feb\u4e50\uff0c\u63e1\u7384\u673a\u3001\u4fee\u8fdb\u957f\u751f\u3002\u6e05\u95f2\u5904\uff0c\u7ba1\u80dc\u5982\u706b\u9662\uff0c\u82e6\u6d77\u51a4\u5751\u3002\u5367\u6708\u7720\u4e91\u5f04\u6597\uff0c\u8c03\u9f99\u864e\uff0c\u5a74\u5a07\u5973\u59f9\u582a\u51ed\u3002\u65a1\u8fd0\u98de\u91d1\u8d70\u7389\uff0c\u6773\u6773\u51a5\u51a5\u3002\u7075\u5149\u4e00\u70b9\u6765\u5f80\uff0c\u73b0\u5143\u521d\u3001\u5999\u76f8\u8eab\u8f7b\u3002\u4e58\u9e3e\u51e4\uff0c\u6307\u84ec\u701b\u8def\u4e0a\u524d\u884c\u3002<\/p>\n
\u597d\u723d\u5229\uff0c\u597d\u8c41\u7545\u3002\u5750\u5367\u4f4f\u884c\uff0c\u900d\u9065\u5766\u8361\u3002\u7ec6\u5bfb\u601d\u3001\u540d\u5229\u4e4b\u4eba\uff0c\u600e\u77e5\u6b64\u5473\u51b5\u3002\u5411\u95f2\u4e2d\uff0c\u641c\u4fee\u517b\u3002\u953b\u70bc\u4e00\u9897\uff0c\u795e\u73e0\u6643\u6717\u3002\u7b97\u4e09\u6b21\u3001\u6d77\u53d8\u6851\u7530\uff0c\u662f\u4ed9<\/p>\n
\u4e5e\u89c5\u6b8b\u9980\u771f\u6d3b\u8ba1\uff0c\u65e0\u7f9e\u65e0\u803b\u65e0\u8363\u3002\u820d\u8eab\u5c82\u662f\u5582\u9965\u9e70\u3002\u4ea6\u975e\u4e3a\u864e\u98df\uff0c\u4e0d\u8457\u5047\u8eab\u5f62\u3002\u4e07\u79cd\u5c18\u52b3\u9f50\u653e\u4e0b\uff0c\u81ea\u7136\u795e\u6c14\u7075\u7075\u3002\u5fc3\u733f\u610f\u9a6c\u4e24\u505c\u505c\u3002\u65e0\u7f18\u6c89\u82e6\u6d77\uff0c\u6709\u5206\u770b\u84ec\u701b\u3002<\/p>\n
\u4f0a\u4e88\u540c\u91cc\u3002\u81ea\u6765\u4ea4\u5951\u3002\u5404\u8d2a\u6d6e\u540d\u6d6e\u5229\u3002\u603b\u609f\u65e0\u5e38\uff0c\u7269\u7269\u822c\u822c\u6350\u5f03\u3002\u4e88\u5148\u522b\u79bb\u5b81\u6d77\uff0c\u53c8\u7ee7\u800c\u3001\u8d24\u6765\u5173\u91cc\u3002\u613f\u540c\u5fd7\uff0c\u66f4\u540c\u5fc3\u540c\u5fb7\uff0c\u540c\u641c\u7384\u7406\u3002\u614e\u52ff\u6500\u63f4\u7231\u5ff5\uff0c\u4fbf\u5b81\u5fc3\u5b81\u610f\uff0c\u5168\u795e\u517b\u6c14\u3002\u5c18\u4e16\u4e4b\u4e2d\uff0c\u4e0d\u67d3\u4e0d\u8457\u4e3a\u6700\u3002\u6bb7\u52e4\u5b8c\u5168\u529f\u884c\uff0c\u5e38\u6e05\u9759\u3001\u6709\u4e9b\u6d88\u606f\u3002\u795e\u5149\u707f\uff0c\u6cfc\u7130\u7130\u7130\u5730\uff0c\u662f\u4f60\u771f\u5e95\u3002<\/p>\n
\u5fc3\u72c2\u610f\u4e71\u6b4c\u8ff7\u9152\u60d1\u3002\u635f\u4f24\u4e09\u9b42\u4e03\u9b44\u3002\u4e0d\u987e\u5371\u4ea1\uff0c\u4e00\u5411\u8d2a\u604b\u8d22\u8272\u3002\u8ffd\u966a\u82b1\u670b\u9152\u53cb\uff0c\u4fbf\u8054\u9573\u3001\u5938\uff0a\u7389\u52d2\u3002\u5bb4\u8d4f\u5904\uff0c\u5411\u7b19\u6b4c\u4e1b\u91cc\uff0c\u5356\u5f04\u4fca\u683c\u3002\u7eb5\u6709\u77f3\u5d07\u5bcc\u8d35\uff0c\u8fd9\u6731\u989c\u7eff\u9b13\uff0c\u600e\u751f\u7559\u5f97\u3002\u6b62\u662f\u884c\u5c38\u8d70\u9aa8\uff0c\u5446\u8001\u4e5d\u4f2f\u3002\u65f6\u95f4\u8363\u534e\u867d\u597d\uff0c\u5948\u65e0\u5e38\u4e4b\u4e8b\u600e\u6d4b\u3002\u5982\u7701\u89c9\uff0c\u505a\u4fee\u6301\uff0c\u975e\u51e1\u5bbe\u5ba2\u3002<\/p>\n
\u5bb6\u7f18\u731b\u5f03\uff0c\u66f4\u4e0d\u7591\u60d1\u3002\u8fa8\u8ba4\u9634\u9b42\u9633\u9b44\u3002\u5484\u51fa\u5c38\u866b\uff0c\u5c4f\u5c3d\u6c14\u8d22\u9152\u8272\u3002\u597d\u4e8b\u5148\u4eba\u540e\u5df1\uff0c\u505a\u61a8\u61a8\u3001\u6709\u4f3c\u5f25\u52d2\u3002\u4fee\u5927\u9053\uff0c\u5904\u65e0\u4e3a\u65e0\u4f5c\uff0c\u6e10\u901a\u5999\u683c\u3002\u7269\u5916\u900d\u9065\u81ea\u5728\uff0c\u771f\u6b22\u4e50\uff0c\u6e05\u4e2d\u9759\u4e2d\u62db\u5f97\u3002\u529f\u7d2f\u4e09\u5343\uff0c\u66f4\u8981\u884c\u6ee1\u516b\u767e\u3002\u65f6\u65f6\u8fd0\u884c\u65e5\u6708\uff0c\u8fd9\u4e9b\u513f\u3001\u4ed6\u4eba\u96be\u6d4b\u3002\u771f\u4e86\u4e86\uff0c\u4fbf\u5f97\u4e3a\u84ec\u83b1\u4ed9\u5ba2\u3002<\/p>\n
\u822c\u822c\u8bc6\u7834\uff0c\u7269\u7269\u96be\u60d1\u3002\u81ea\u7136\u5b89\u9b42\u5b9a\u9b44\u3002\u89c6\u542c\u5982\u804b\u5982\u77bd\uff0c\u7edd\u5c3d\u58f0\u8272\u3002\u8eab\u5fc3\u900d\u9065\u81ea\u5728\uff0c\u6ca1\u5bb6\u7f18\u3001\u6069\u7231\u7cfb\u52d2\u3002\u65e0\u4e3a\u4f5c\uff0c\u4e5e\u6b8b\u9980\u5ea6\u65e5\uff0c\u65e0\u803b\u65e0\u683c\u3002\u6e38\u5386\u6063\u60c5\u5766\u8361\uff0c\u4f3c\u5b64\u4e91\u91ce\u9e64\uff0c\u6709\u8c01\u7ba1\u5f97\u3002\u4e0d\u7fa1\u8363\u534e\u5bcc\u8d35\uff0c\u9769\u8f66\u4e09\u767e\u3002\u7ec8\u65e5\u6f84\u5fc3\u9063\u6b32\uff0c\u89c9\u7384\u673a\u3001\u5bc6\u5999\u6613\u6d4b\u3002\u529f\u884c\u6ee1\uff0c\u505a\u5341\u6d32\u4e09\u5c9b\u771f\u5ba2\u3002<\/p>\n
\u89c1\u4eba\u9519\u5931\uff0c\u52a8\u6211\u5fc3\u80a0\u3002\u4ea4\u4e88\u600e\u4e0d\u60b2\u4f24\u3002\u601d\u60f3\u70ef\u6307\u7136\u81c2\uff0c\u9876\u4e0a\u7136\u9999\u3002\u5047\u9976\u6295\u5d16\u5582\u864e\uff0c\u5c3d\u820d\u8eab\u3001\u5f03\u547d\u975e\u5e38\u3002\u4e89\u77e5\u5f97\uff0c\u6709\u4e9b\u513f\u5999\u7406\uff0c\u522b\u662f\u5609\u7965\u3002\u6e05\u9759\u65e0\u4e3a\u9f0e\u5185\uff0c\u89c9\u5fc3\u4e2d\u771f\u706b\uff0c\u4e0b\u964d\u80be\u5802\u3002\u80be\u6c34\u5316\u4e3a\u771f\u6c14\uff0c\u6c14\u7ed3\u7ea2\u971c\u3002\u5e38\u5e38\u718f\u84b8\u56db\u5927\uff0c\u4fbf\u73b2\u73d1\u3001\u54cd\uff0a\u53ee\u94db\u3002\u795e\u5149\u707f\uff0c\u5f97\u643a\u4e91\uff0c\u5f52\u53bb\u84ec\u5e84\u3002<\/p>\n
\u6614\u5e74\u540d\u5229\uff0c\u5f79\u788e\u987d\u5fc3\u3002\u6c14\u8d22\u9152\u8272\u6df1\u6c88\u3002\u65b9\u5bf8\u4e4b\u95f4\uff0c\u8346\u68d8\u4eff\u4f5b\u6210\u6797\u3002\u56e0\u9047\u98ce\u4ed9\u7701\u609f\uff0c\u89c9\u4ece\u524d\u3001\u7f6a\u4e1a\u5f25\u6df1\u3002\u4fbf\u6539\u6b63\uff0c\u4fbf\u6539\u6b63\u6539\u6b63\u3002\u6539\u6b63\u6539\u6b63\u3002\u6e38\u5386\u5929\u5fc3\u5730\u80ba\uff0c\u7ed3\u4e91\u670b\u971e\u53cb\uff0c\u6708\u4f34\u98ce\u90bb\u3002\u81ea\u5728\u900d\u9065\u5feb\u4e50\uff0c\u7edd\u5c3d\u641c\u5bfb\u3002\u5047\u4f7f\u8d2b\u4eba\u9000\u9053\uff0c\u5f97\u8363\u534e\u3001\u5bcc\u8d35\u4eba\u94a6\u3002\u6211\u4e0d\u80af\uff0c\u6211\u4e0d\u80af\u4e0d\u80af\uff0c\u4e0d\u80af\u4e0d\u80af\u3002<\/p>\n
\u5c71\u4f97\u6614\u65e5\uff0c\u706b\u9662\u4e2d\u95f4\uff0c\u5343\u65a4\u91cd\u62c5\u5e38\u803d\u3002\u9547\u65e5\u4e89\u540d\u7ade\u5229\uff0c\u5ac9\u5992\u60ad\u8d2a\u3002\u4e07\u822c\u5fe7\u6101\u601d\u8651\uff0c\u53c8\u4f55\u66fe\u3001\u65f6\u6682\u5fc3\u95f2\u3002\u56e0\u4e2a\u751a\uff0c\u517b\u6028\u4eb2\u4eba\u53e3\uff0c\u4e8c\u5341\u6709\u4e09\u3002\u6b63\u5728\u8ff7\u6d25\u53d7\u82e6\uff0c\u98ce\u4ed9\u81f3\uff0c\u4e13\u4e13\u6551\u5ea6\u611a\u987d\u3002\u4e8c\u8f7d\u624d\u65b9\u7701\u609f\uff0c\u8df3\u51fa\u4e61\u5173\u3002\u5982\u4eca\u900d\u9065\u5766\u8361\uff0c\u70bc\u8eab\u4e2d\u3001\u4e03\u5b9d\u8fd8\u4e39\u3002\u529f\u884c\u6ee1\uff0c\u8bbf\u84ec\u701b\uff0c\u518d\u89c1\u5e08\u989c\u3002<\/p>\n