/**
* 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');
App开发方式是什么呢?_创想鸟
创想鸟 首页用户投稿
App开发方式是什么呢?
程序猿
•
2025年11月26日 15:31:11
•
用户投稿 •
阅读 1
你是否曾好奇,那些每天为我们带来便利的app,究竟是如何从一个简单的创意变成现实的呢?今天,我们将揭开app开发的神秘面纱,带你了解我们是如何将创意转化为触手可及的应用程序的。
一切都源于一个想法,一个旨在解决问题、提升体验或创造价值的想法。这个想法可能来自我们团队的头脑风暴,也可能源自用户的反馈和建议。一旦确定了目标,我们就会进入需求分析阶段,深入挖掘用户的痛点和需求,明确App的功能和定位,勾勒出产品的初步框架。
随后,我们进入设计阶段。我们的设计师会将抽象的想法转化为具体的界面和交互流程,致力于打造美观易用、符合用户习惯的产品界面。在设计过程中,我们会进行多次用户测试,根据用户的反馈不断优化设计方案,确保最终呈现的界面能够真正满足用户的需求。
设计稿确定后,我们进入开发阶段。我们的开发团队会根据设计稿和功能需求,选择合适的编程语言和开发工具 ,将设计稿转化为可运行的应用程序。这是一个需要高度技术和团队协作的过程,开发者们需要编写大量的代码,并进行反复的测试和调试,确保App的稳定性和性能。
开发完成后,我们会进行严格的测试,模拟各种用户场景和使用环境,以确保App的质量和稳定性。除了功能测试,我们还会进行安全测试、性能测试等,力求将风险降到最低,为用户提供安全可靠的产品。
PHP开发实用指南 2.0
对于一个刚进入PHP 开发大门的程序员,最需要的就是一本实用的开发参考书,而不仅仅是各种快速入门的only hello wold。在开发的时候,也要注意到许多技巧和一些“潜规则”。PHP是一门很简单的脚本语言,但是用好它,也要下功夫的。同时,由于PHP 的特性,我一再强调,最NB 的PHP 程序员都不是搞PHP 的。为什么呢?因为PHP 作为一种胶水语言,用于粘合后端 数据库和前端 页面,更多需
387 查看详情
最后,经过层层考验的App就可以正式上线了!我们会选择合适的应用商店进行发布,并将App的信息推送给目标用户。上线后,我们还会持续关注用户反馈,不断优化产品功能,提升用户体验。
当然,App开发并不是一劳永逸的过程,它需要不断的迭代和优化。我们会根据市场变化和用户需求,不断推出新功能、修复bug,以保持产品的竞争力和用户粘性。
总之,App开发是一个系统而复杂的工程,需要多个团队的紧密配合和高效协作。我们致力于用专业的技术和严谨的态度,将每一个想法都打磨成优秀的产品,为用户创造价值。
以上就是App开发方式是什么呢?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/794708.html
赞 (0)
打赏
微信扫一扫
支付宝扫一扫
大数组怎么定义java
上一篇
2025年11月26日 15:31:10
电脑蓝牙怎么打开 蓝牙功能开启步骤说明
下一篇
2025年11月26日 15:31:11
相关推荐
前端固定定位为什么会出现移动现象? 在进行前端开发时,我们经常会使用CSS中的position属性来控制元素的定位。其中,固定定位(position: fixed)是一种常用的定位方式,它可以让元素相对于浏览器窗口进行定位,保持在页面的固定位置不动。 然而,有时候我们会遇到一个问题:在使用固定定位时…
CSS是网站设计中重要的一部分,它控制着网站的外观和布局。前端开发人员为了让页面更加美观和易于使用,通常使用CSS框架。这篇文章将带领您了解这五种前端CSS框架,从入门到精通。 Bootstrap Bootstrap是最受欢迎的CSS框架之一。它由Twitter公司开发,具有可定制的响应式网格系统、…
选择恐惧症?这五个前端CSS框架能帮你解决问题 近年来,前端开发者已经进入了一个黄金时代。随着互联网的快速发展,人们对于网页设计和用户体验的要求也越来越高。然而,要想快速高效地构建出漂亮的网页并不容易,特别是对于那些可能对CSS编码感到畏惧的人来说。所幸的是,前端开发者们早已为我们准备好了一些CSS…
is与where选择器:提升前端编程效率的秘密武器 在前端开发中,选择器是一种非常重要的工具。它们用于选择文档中的元素,从而对其进行操作和样式设置。随着前端技术的不断发展,选择器也在不断演化。而其中,is与where选择器成为了提升前端编程效率的秘密武器。 is选择器是CSS Selectors L…
前端技巧分享:使用CSS3 fit-content让元素水平居中 在前端开发中,我们常常会遇到需要将某个元素水平居中的情况。使用CSS3的fit-content属性可以很方便地实现这个效果。本文将介绍fit-content属性的使用方法,并提供代码示例。 fit-content属性是一个相对于元素父…
前端技术分享:利用fit-content实现页面元素的水平对齐效果 在前端开发中,实现页面元素的水平对齐是一个常见的需求。尤其在响应式布局中,我们经常需要让元素根据设备的屏幕大小自动调整位置,使页面更加美观和易读。在本文中,我将分享一种利用CSS属性fit-content来实现页面元素的水平对齐效果…
本篇文章整理分享13 个前端可能用得上的 css技巧,包括修改输入占位符样式、多行文本溢出、隐藏滚动条、修改光标颜色等,希望对大家有所帮助! 修改输入占位符样式、多行文本溢出、隐藏滚动条、修改光标颜色、水平和垂直居中。多么熟悉的场景!前端开发者几乎每天都会和它们打交道,本文收集 13 个CSS技巧,…
今天在网上看到一个炫酷的登录按钮效果;初看时感觉好牛掰;但是一点一点的抛开以后发现,并没有那么难;我会将全部代码贴出来;如果有不对的地方,大家指点一哈。 分析 我们抛开before不谈的话;其实原理和就是通过背景大小以及配合位置达到颜色渐变的效果。 text-transform: uppercase…