WordPress定时审核插件
这个插件包含以下功能:
-
自动审核一小时前的待审核文章
-
可配置的审核时间间隔(使用WordPress默认的定时选项)
-
后台设置页面
-
安全权限检查
-
自定义时间间隔选项
使用方法:
-
将代码保存为
auto-approve-posts.php
-
上传到
/wp-content/plugins/
目录
-
在WordPress后台激活插件
-
在”设置 → 定时审核设置”中配置审核频率
php插件部分代码:
<?php /* Plugin Name: 智能定时文章审核 Description: 自动审核+数量限制+分类筛选 */ // 初始化插件 register_activation_hook(__FILE__, 'auto_approve_plugin_activation'); register_deactivation_hook(__FILE__, 'auto_approve_plugin_deactivation'); // 插件激活时设置 function auto_approve_plugin_activation() { // 默认设置 add_option('auto_approve_daily_limit', 10); add_option('auto_approve_categories', []); add_option('auto_approve_exclude_cats', []); add_option('auto_approve_interval', 'hourly'); add_option('auto_approve_daily_count', ['date' => '', 'count' => 0]); add_option('auto_approve_last_run', ''); // 设置定时任务 if (!wp_next_scheduled('auto_approve_posts_event')) { wp_schedule_event(time(), get_option('auto_approve_interval', 'hourly'), 'auto_approve_posts_event'); } } // 插件停用时清理 function auto_approve_plugin_deactivation() { wp_clear_scheduled_hook('auto_approve_posts_event'); } // 后台设置菜单 add_action('admin_menu', 'auto_approve_add_admin_menu'); function auto_approve_add_admin_menu() { add_options_page( '智能定时审核设置', '智能定时审核', 'manage_options', 'auto-approve-settings', 'auto_approve_settings_page' ); } // 设置页面 function auto_approve_settings_page() { if (!current_user_can('manage_options')) return; // 保存设置 if (isset($_POST['submit'])) { check_admin_referer('auto_approve_settings'); // 保存基本设置 update_option('auto_approve_daily_limit', absint($_POST['daily_limit'])); update_option('auto_approve_interval', sanitize_text_field($_POST['interval'])); // 保存分类设置 $categories = isset($_POST['categories']) ? array_map('absint', $_POST['categories']) : []; update_option('auto_approve_categories', $categories); // 保存排除分类 $exclude_cats = isset($_POST['exclude_cats']) ? array_map('absint', $_POST['exclude_cats']) : []; update_option('auto_approve_exclude_cats', $exclude_cats); // 更新定时任务 wp_clear_scheduled_hook('auto_approve_posts_event'); wp_schedule_event(time(), get_option('auto_approve_interval'), 'auto_approve_posts_event'); echo '<div class="notice notice-success"><p>设置已保存!</p></div>'; } // 获取当前设置 $current_interval = get_option('auto_approve_interval', 'hourly'); $daily_limit = get_option('auto_approve_daily_limit', 10); $selected_cats = get_option('auto_approve_categories', []); $excluded_cats = get_option('auto_approve_exclude_cats', []); $all_categories = get_terms(['taxonomy' => 'category', 'hide_empty' => false]); ?>