/**
* 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');
xrp_第29页_创想鸟
创想鸟 首页xrp 第29页
xrp
xrp领涨,比特币盘整:近期加密货币反弹背后的原因及对投资者的意义 加密市场最近热闹非凡。虽然比特币表现相对平稳,但XRP却成为了焦点。随着潜在的ETF获批和监管前景逐渐明朗,市场正在升温。让我们深入了解这波反弹背后的推动力。 XRP的意外飙升 当比特币和以太坊还在阻力位下方震荡时,XRP已成为最活…
比特币狂潮、xrp人工智能预测与katie stockton在加密动荡中的技术视角 比特币、XRP与Katie Stockton:穿越加密风暴 加密市场风起云涌!比特币价格屡破纪录,XRP借力AI预测波动剧烈,而分析师Katie Stockton持续带来专业解读。我们来逐一剖析这些热点。 比特币强势…
探索瑞波币(ripple)的xrp账本如何在迪拜革新房地产代币化,提升数字资产领域的安全性与可及性。 迪拜正在区块链领域掀起波澜!瑞波(Ripple)正与Ctrl Alt合作,利用XRP账本对房产所有权进行代币化处理。这一举措使得房地产投资更加普及,并正在重塑数字资产生态。 XRP账本保障迪拜房地产…
xrp价格波动分析、监管政策预期与市场情绪下的价格发现路径 XRP的价格发现:是否正在开启新一轮上涨周期? XRP近期再度引发关注!在监管利好预期增强及技术面看涨信号的双重推动下,XRP能否延续当前的上升趋势?本文将解析影响XRP价格的关键因素,并探讨其未来走势的可能性。 重拾上升动能的XRP 最新…
xrp释放积极信号,经典杯柄形态浮现,这是否是通往财富自由的关键一步? 受杯柄形态支撑,XRP正朝着5.2美元的潜在目标迈进。这是迈向财务自由的机会吗?我们一起来分析! XRP构建看涨杯柄模式 从周线图观察,XRP正在形成一个经典的杯柄形态(cup and handle),这是一种广受认可的上升趋势…
比特币创纪录飙升,xrp 和以太坊迎来新一轮热潮?在监管变化与市场动能的推动下,它们是否有望重返历史高点? 比特币屡创新高:XRP 与以太坊能否紧随其后? 比特币近期不断刷新价格纪录,在加密市场引发高度关注。眼下投资者关心的问题是:XRP 和以太坊是否能够跟上节奏,冲击自己的历史峰值? 比特币势不可…
随着比特币的迅猛发展,xrp 和 sol 等替代币(altcoins)也逐渐升温。本文将深入探讨 blockdag、xrp 和 sol 的动态表现,分析它们在当前加密货币市场中的潜力。 BlockDAG、XRP、SOL:在比特币创历史新高时代把握加密浪潮 比特币价格屡创新高,点燃了整个加密市场,也让…
以太坊与xrp强势崛起:趋势解析与投资机会 以太坊与XRP:牛市动能持续增强 以太坊(Ethereum)和瑞波币(XRP)正在展现出强劲的上涨动力。ETH价格已站上3,000美元心理关口,而XRP正向3美元目标发起冲击。本文将分析推动本轮行情的关键因素,并探讨其对投资者的意义。 以太坊突破关键阻力位…
xrp显现出看涨信号,预示可能创下价格新高。本文将探讨xrp的价格走势,并进一步审视整个山寨币市场的动向。 XRP走势预示潜在历史新高:深入剖析山寨币市场 XRP正展现出积极的市场信号,有分析人士预测其价格或将大幅上涨至前所未有的水平。我们将深入探讨支撑这种乐观预期的成因,并分析其对山寨币市场的影响…
一位分析师指出xrp展现出看涨信号,有望冲击历史高点。背后原因包括ripple积极申请银行牌照以及稳定币监管政策的推进。 各位加密货币爱好者,关于XRP的热议再度升温,有传言称其价格可能再次刷新纪录。有位分析师对XRP的未来走势非常乐观。接下来的内容不容错过。 XRP技术图表释放积极信号:能否突破前…