/** * Plugin Name: WP文章自动刷新插件 * Plugin URI: https://www.imwpweb.com/ * Description: 真正意义上的文章翻新插件,模拟手工重新发布,让老旧文章重新获得搜索引擎青睐,提升网站流量 * Version: 1.0.0 * Author: IMWPWEB * Author URI: https://www.imwpweb.com/ * Text Domain: wp-article-refresh * Domain Path: /languages * License: GPL v2 or later */ if (!defined('ABSPATH')) { exit; } // 插件常量定义 define('WP_ARTICLE_REFRESH_VERSION', '1.0.0'); define('WP_ARTICLE_REFRESH_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('WP_ARTICLE_REFRESH_PLUGIN_URL', plugin_dir_url(__FILE__)); /** * 主插件类 */ class WP_Article_Refresh { /** * 单例实例 */ private static $instance = null; /** * 获取单例实例 */ public static function get_instance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; } /** * 构造函数 */ private function __construct() { // 注册激活/停用钩子 register_activation_hook(__FILE__, array($this, 'activate')); register_deactivation_hook(__FILE__, array($this, 'deactivate')); // 初始化插件 add_action('init', array($this, 'init')); // 添加定时任务钩子 add_action('wp_article_refresh_event', array($this, 'do_refresh')); } /** * 插件激活 */ public function activate() { // 设置默认选项 $default_options = array( 'enabled' => 1, 'refresh_interval' => 60, // 分钟 'days_range' => 365, // 1年内 'daily_limit' => 10, // 每天最多翻新10篇 'time_window_start' => '00:00', 'time_window_end' => '23:59', 'categories' => array(), // 空数组表示所有分类 'exclude_categories' => array(), 'refresh_mode' => 'today', // today:今天, random:随机前几天, gradual:逐渐递增 'refreshed_today' => 0, 'last_refresh_date' => date('Y-m-d'), 'total_refreshed' => 0 ); if (!get_option('wp_article_refresh_options')) { add_option('wp_article_refresh_options', $default_options); } // 设置定时任务 if (!wp_next_scheduled('wp_article_refresh_event')) { wp_schedule_event(time(), 'wp_article_refresh_interval', 'wp_article_refresh_event'); } // 刷新重写规则 flush_rewrite_rules(); } /** * 插件停用 */ public function deactivate() { // 清除定时任务 wp_clear_scheduled_hook('wp_article_refresh_event'); // 刷新重写规则 flush_rewrite_rules(); } /** * 初始化插件 */ public function init() { // 加载文本域 load_plugin_textdomain('wp-article-refresh', false, dirname(plugin_basename(__FILE__)) . '/languages'); // 添加自定义定时间隔 add_filter('cron_schedules', array($this, 'add_cron_interval')); // 添加管理菜单 add_action('admin_menu', array($this, 'add_admin_menu')); // 注册AJAX处理 add_action('wp_ajax_wp_article_refresh', array($this, 'handle_ajax')); // 添加设置链接 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_settings_link')); // 加载前端资源(仅在插件页面加载) add_action('admin_enqueue_scripts', array($this, 'enqueue_assets')); } /** * 添加自定义Cron间隔 */ public function add_cron_interval($schedules) { $options = get_option('wp_article_refresh_options'); $interval = isset($options['refresh_interval']) ? $options['refresh_interval'] : 60; $schedules['wp_article_refresh_interval'] = array( 'interval' => $interval * 60, 'display' => sprintf(__('每 %d 分钟', 'wp-article-refresh'), $interval) ); return $schedules; } /** * 添加管理菜单 */ public function add_admin_menu() { add_menu_page( __('文章自动刷新', 'wp-article-refresh'), __('文章刷新', 'wp-article_refresh'), 'manage_options', 'wp-article-refresh', array($this, 'render_admin_page'), 'dashicons-update', 30 ); } /** * 渲染管理页面 */ public function render_admin_page() { // 处理表单提交 if (isset($_POST['wp_article_refresh_nonce']) && wp_verify_nonce($_POST['wp_article_refresh_nonce'], 'wp_article_refresh_save')) { $this->save_options(); echo '

' . __('设置已保存!', 'wp-article-refresh') . '

'; } // 处理手动刷新 if (isset($_POST['wp_article_refresh_manual']) && wp_verify_nonce($_POST['wp_article_refresh_manual_nonce'], 'wp_article_refresh_manual')) { $result = $this->do_refresh(); if ($result) { echo '

' . sprintf(__('成功刷新了 %d 篇文章!', 'wp-article-refresh'), $result) . '

'; } else { echo '

' . __('没有找到符合条件的文章或已达今日上限!', 'wp-article-refresh') . '

'; } } $options = get_option('wp_article_refresh_options'); $stats = $this->get_statistics(); $categories = get_categories(array('hide_empty' => false)); include WP_ARTICLE_REFRESH_PLUGIN_DIR . 'templates/admin-page.php'; } /** * 保存设置选项 */ private function save_options() { $options = array( 'enabled' => isset($_POST['enabled']) ? 1 : 0, 'refresh_interval' => absint($_POST['refresh_interval']), 'days_range' => absint($_POST['days_range']), 'daily_limit' => absint($_POST['daily_limit']), 'time_window_start' => sanitize_text_field($_POST['time_window_start']), 'time_window_end' => sanitize_text_field($_POST['time_window_end']), 'categories' => isset($_POST['categories']) ? array_map('absint', $_POST['categories']) : array(), 'exclude_categories' => isset($_POST['exclude_categories']) ? array_map('absint', $_POST['exclude_categories']) : array(), 'refresh_mode' => sanitize_text_field($_POST['refresh_mode']), 'refreshed_today' => isset($_POST['reset_count']) ? 0 : get_option('wp_article_refresh_options', array()) ); // 获取之前的设置 $prev_options = get_option('wp_article_refresh_options', array()); $options['refreshed_today'] = isset($prev_options['refreshed_today']) ? $prev_options['refreshed_today'] : 0; $options['last_refresh_date'] = isset($prev_options['last_refresh_date']) ? $prev_options['last_refresh_date'] : date('Y-m-d'); $options['total_refreshed'] = isset($prev_options['total_refreshed']) ? $prev_options['total_refreshed'] : 0; update_option('wp_article_refresh_options', $options); // 重新设置定时任务 wp_clear_scheduled_hook('wp_article_refresh_event'); if ($options['enabled']) { wp_schedule_event(time(), 'wp_article_refresh_interval', 'wp_article_refresh_event'); } } /** * 执行文章刷新 */ public function do_refresh() { $options = get_option('wp_article_refresh_options'); // 检查插件是否启用 if (!$options['enabled']) { return 0; } // 检查时间窗口 $current_time = current_time('H:i'); if ($current_time < $options['time_window_start'] || $current_time > $options['time_window_end']) { return 0; } // 重置每日计数 $today = date('Y-m-d'); if ($options['last_refresh_date'] !== $today) { $options['refreshed_today'] = 0; $options['last_refresh_date'] = $today; } // 检查每日限制 if ($options['refreshed_today'] >= $options['daily_limit']) { return 0; } // 获取符合条件的文章 $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $options['daily_limit'] - $options['refreshed_today'], 'date_query' => array( 'before' => date('Y-m-d H:i:s', strtotime('-1 day')), 'after' => date('Y-m-d H:i:s', strtotime('-' . $options['days_range'] . ' days')) ), 'orderby' => 'rand', 'no_found_rows' => true ); // 分类筛选 if (!empty($options['categories'])) { $args['category__in'] = $options['categories']; } if (!empty($options['exclude_categories'])) { $args['category__not_in'] = $options['exclude_categories']; } $query = new WP_Query($args); $refreshed = 0; if ($query->have_posts()) { foreach ($query->posts as $post) { // 更新文章日期 $new_date = $this->calculate_new_date($post->post_date, $options['refresh_mode']); wp_update_post(array( 'ID' => $post->ID, 'post_date' => $new_date, 'post_date_gmt' => get_gmt_from_date($new_date), 'post_modified' => current_time('mysql'), 'post_modified_gmt' => current_time('mysql', 1) )); // 清理缓存 clean_post_cache($post->ID); $refreshed++; } wp_reset_postdata(); } // 更新统计 $options['refreshed_today'] += $refreshed; $options['total_refreshed'] += $refreshed; update_option('wp_article_refresh_options', $options); return $refreshed; } /** * 计算新日期 */ private function calculate_new_date($original_date, $mode) { $original = strtotime($original_date); $now = time(); switch ($mode) { case 'today': // 设置为今天 return date('Y-m-d H:i:s', time()); case 'random': // 随机1-7天前 $random_days = wp_rand(1, 7); $new_time = strtotime("-{$random_days} days"); return date('Y-m-d H:i:s', $new_time); case 'gradual': // 逐渐递增(基于原日期递减) $days_diff = floor(($now - $original) / 86400); if ($days_diff > 7) { $new_time = strtotime('-7 days'); } else { $new_time = $original + 86400; // 往后推一天 } return date('Y-m-d H:i:s', $new_time); default: return date('Y-m-d H:i:s', time()); } } /** * 获取统计信息 */ public function get_statistics() { $options = get_option('wp_article_refresh_options'); // 统计文章总数 $total_posts = wp_count_posts('post'); // 统计符合条件的文章数量 $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'date_query' => array( 'before' => date('Y-m-d H:i:s', strtotime('-1 day')), 'after' => date('Y-m-d H:i:s', strtotime('-' . $options['days_range'] . ' days')) ), 'no_found_rows' => true ); if (!empty($options['categories'])) { $args['category__in'] = $options['categories']; } if (!empty($options['exclude_categories'])) { $args['category__not_in'] = $options['exclude_categories']; } $query = new WP_Query($args); $eligible_posts = $query->found_posts; return array( 'total_posts' => $total_posts->publish, 'eligible_posts' => $eligible_posts, 'refreshed_today' => $options['refreshed_today'], 'daily_limit' => $options['daily_limit'], 'total_refreshed' => $options['total_refreshed'], 'is_enabled' => $options['enabled'], 'next_refresh' => wp_next_scheduled('wp_article_refresh_event') ? date('Y-m-d H:i:s', wp_next_scheduled('wp_article_refresh_event')) : __('未设置', 'wp-article-refresh') ); } /** * 处理AJAX请求 */ public function handle_ajax() { if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['nonce'], 'wp_article_refresh_ajax')) { wp_die(__('无权限', 'wp-article-refresh')); } $action = sanitize_text_field($_POST['sub_action']); switch ($action) { case 'get_stats': $stats = $this->get_statistics(); wp_send_json_success($stats); break; case 'refresh_now': $result = $this->do_refresh(); wp_send_json_success(array('refreshed' => $result)); break; default: wp_send_json_error(__('未知操作', 'wp-article-refresh')); } } /** * 添加设置链接 */ public function add_settings_link($links) { $settings_link = '' . __('设置', 'wp-article-refresh') . ''; array_unshift($links, $settings_link); return $links; } /** * 加载资源文件 */ public function enqueue_assets($hook) { if ('toplevel_page_wp-article-refresh' !== $hook) { return; } wp_enqueue_style('wp-article-refresh-admin', WP_ARTICLE_REFRESH_PLUGIN_URL . 'assets/css/admin.css', array(), WP_ARTICLE_REFRESH_VERSION); wp_enqueue_script('wp-article-refresh-admin', WP_ARTICLE_REFRESH_PLUGIN_URL . 'assets/js/admin.js', array('jquery'), WP_ARTICLE_REFRESH_VERSION, true); wp_localize_script('wp-article-refresh-admin', 'wpArticleRefresh', array( 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('wp_article_refresh_ajax'), 'strings' => array( 'confirm' => __('确定要手动刷新吗?', 'wp-article-refresh'), 'refreshing' => __('刷新中...', 'wp-article-refresh'), 'success' => __('刷新成功!', 'wp-article-refresh'), 'error' => __('刷新失败!', 'wp-article-refresh') ) )); } } // 初始化插件 WP_Article_Refresh::get_instance(); // 创建模板目录 function wp_article_refresh_create_templates_dir() { $dir = WP_ARTICLE_REFRESH_PLUGIN_DIR . 'templates'; if (!file_exists($dir)) { mkdir($dir, 0755, true); } } add_action('admin_init', 'wp_article_refresh_create_templates_dir'); 兑换码_第26页_创想鸟

兑换码

  • 2025原神7月21日兑换码分享

    2025原神7月21日兑换码分享2025原神7月21日兑换码分享2025原神7月21日兑换码分享2025原神7月21日兑换码分享

    详细答案: 兑换码:6EEDVJ99H5NJ Jenni AI 使用最先进的 AI 写作助手为您的写作增光添彩。 48 查看详情 使用方法:点击游戏界面左上角的派蒙图标,这将带您进入游戏的主菜单栏。在菜单栏中,找到并点击左侧第五个设置齿轮图标,进入设置界面。接着,在设置界面的左侧,选择第七个【账户】…

    2025年11月26日 用户投稿
    100
  • 2025我的世界7月21日最新兑换码

    2025我的世界7月21日最新兑换码2025我的世界7月21日最新兑换码2025我的世界7月21日最新兑换码2025我的世界7月21日最新兑换码

    兑换码: mc8tgd426w 音刻 AI音视频转录和笔记工具 97 查看详情 使用方法:打开《我的世界》游戏,在主界面点击左上角的头像,进入个人中心。在个人中心页面的下方,你会找到一个名为“礼包兑换码”的入口。点击这个入口,输入你的兑换码并提交。系统会自动处理并为你发放相应的奖励。最后,返回主界面…

    2025年11月26日 用户投稿
    200
  • 星之旅人2025最新兑换码分享

    星之旅人2025最新兑换码分享星之旅人2025最新兑换码分享星之旅人2025最新兑换码分享星之旅人2025最新兑换码分享

    星之旅人手游现已正式开启全平台公测,为助力各位玩家的冒险之旅,官方准备了一些礼包%ign%ignore_a_1%re_a_1%,玩家可以使用兑换码在游戏中换取好礼,下面就一起来看看星之旅人2025开服礼包兑换码都有哪些吧! 星之旅人2025最新兑换码 开服兑换码: GameStart VIP666 …

    2025年11月25日 用户投稿
    100
  • 黑子的篮球街头对决2025最新兑换码

    黑子的篮球街头对决2025最新兑换码黑子的篮球街头对决2025最新兑换码黑子的篮球街头对决2025最新兑换码黑子的篮球街头对决2025最新兑换码

    黑子的篮球街头对决现已在全平台开启公测,官方为玩家们准备了%ignore_a_1%礼包,玩家们可以使用礼包兑换码在游戏中换取好礼,下面就为大家带来黑子的篮球街头对决的最新礼包兑换码分享,一起来看看吧! 黑子的篮球街头对决最新兑换码 兑换码:公测开启716 奖励:奇迹夺宝券x1、钻石x100、金币x2…

    2025年11月25日 用户投稿
    000
  • mac怎么在App Store兑换代码_mac应用商店兑换码使用

    mac怎么在App Store兑换代码_mac应用商店兑换码使用mac怎么在App Store兑换代码_mac应用商店兑换码使用mac怎么在App Store兑换代码_mac应用商店兑换码使用mac怎么在App Store兑换代码_mac应用商店兑换码使用

    1、打开Mac上的App Store,点击左下角账户头像,选择“兑换礼品卡或代码”;2、可手动输入兑换码或使用摄像头扫描实体卡;3、按提示完成验证即可将内容添加至账户。 如果您收到了一个Mac应用的兑换码,但不知道如何在App Store中使用,可以直接通过App Store应用内的账户功能进行兑换…

    2025年11月25日 用户投稿
    100
  • 交错战线2025最新兑换码分享

    交错战线2025最新兑换码分享交错战线2025最新兑换码分享交错战线2025最新兑换码分享交错战线2025最新兑换码分享

    交错战线现已迎来全新版本“白垩行旅”,官方推出了一系列新的活动与玩法,以及全新的礼包兑换码,玩家可以在游戏内换取好礼,下面就为大家带来交错战线2025最新兑换码的分享,一起来看看吧! 交错战线2025最新兑换码 兑换码: JCZX41 包含奖励: 100粲晶、200家具币、120燃料 Levity …

    2025年11月25日 用户投稿
    100
  • 《上古卷轴4:湮灭重制版》实体版还需要联网

    《上古卷轴4:湮灭重制版》实体版还需要联网《上古卷轴4:湮灭重制版》实体版还需要联网《上古卷轴4:湮灭重制版》实体版还需要联网《上古卷轴4:湮灭重制版》实体版还需要联网

    据最新消息,《上古卷轴4:湮灭重制版》在Xbox Series X平台的实体豪华版或将采用“盒装代码版”形式发行,包装盒上已明确标注“需下载内容”。这一信息由Wario64在社交平台X上发现并分享。相比之下,PS5版本的实体豪华版则可能附带一张游戏光盘,并包含一个用于兑换豪华版专属数字内容的PSN兑…

    2025年11月25日 用户投稿
    100
  • 桃源深处有人家兑换码通用不过期 兑换码大全及输入位置

    桃源深处有人家兑换码通用不过期 兑换码大全及输入位置桃源深处有人家兑换码通用不过期 兑换码大全及输入位置桃源深处有人家兑换码通用不过期 兑换码大全及输入位置桃源深处有人家兑换码通用不过期 兑换码大全及输入位置

    桃源深处有人家通用%ignore_a_1%包括:方寸之地亦是桃源、人生是桃源、心安处是桃源等,使用后可领取玥琅、铜钱、鱼饵等多种奖励。在游戏内通过设置——政策——兑换码页面输入即可获取对应奖品。 桃源深处有人家兑换码汇总及使用方法 一、有效兑换码列表 1、常用通用码 方寸之地亦是桃源 人生是桃源(含…

    2025年11月25日 用户投稿
    000
  • 深空之眼2025最新兑换码分享

    深空之眼2025最新兑换码分享深空之眼2025最新兑换码分享深空之眼2025最新兑换码分享深空之眼2025最新兑换码分享

    在深空之眼这款游戏中,官方时常会推出各类福利活动并发放礼包兑换码,让玩家能够在游戏中领取丰富奖励。不少玩家朋友对最新可用的兑换码十分关注,下面便为大家整理了2025年最新的深空之眼兑换码信息,有需要的玩家可及时使用。 深空之眼2025最新兑换码分享 Tweeze Tweeze.app是一个AI驱动的…

    2025年11月25日 用户投稿
    000
  • 摇荡的情谊从未停摆:光遇秋千道具永久获取指南

    摇荡的情谊从未停摆:光遇秋千道具永久获取指南摇荡的情谊从未停摆:光遇秋千道具永久获取指南摇荡的情谊从未停摆:光遇秋千道具永久获取指南摇荡的情谊从未停摆:光遇秋千道具永久获取指南

    想象与好友一同坐上看不见尽头的秋千,随风轻轻摇曳,仿佛时间也为之静止——这正是《%igno%ignore_a_1%_a_1%》中秋千道具所承载的独特诗意。它不只是背包中的一件装饰品,更是玩家之间情感联结的温柔见证。一旦入手,永久拥有,无需重复购买,便可无数次邀请伙伴共享这份并肩荡漾的宁静与欢愉。 秘…

    2025年11月25日 用户投稿
    000
关注微信