文章目录[隐藏]
一步步实现:为WordPress打造智能化的内容过期检测与更新提醒工具
引言:为什么WordPress需要内容过期检测功能
在当今信息爆炸的时代,网站内容的时效性变得尤为重要。无论是新闻资讯、产品评测、技术教程还是行业分析,过时的内容不仅会降低用户体验,还可能影响网站的权威性和搜索引擎排名。对于拥有大量内容的WordPress网站来说,手动跟踪每篇文章的时效性几乎是不可能的任务。
据统计,超过60%的企业网站存在大量过时内容,这些内容可能导致用户流失率增加40%以上。同时,搜索引擎越来越重视内容的时效性,新鲜度已成为排名算法的重要因素之一。
本文将通过WordPress代码二次开发,打造一个智能化的内容过期检测与更新提醒工具,帮助网站管理员自动识别需要更新的内容,确保网站始终保持活力与相关性。
第一部分:需求分析与功能规划
1.1 核心需求分析
在开始开发之前,我们需要明确工具的核心需求:
- 自动检测内容时效性:根据预设规则判断内容是否过期
- 智能提醒机制:通过多种渠道通知相关人员
- 优先级分类系统:区分内容的紧急更新程度
- 数据统计与分析:提供内容时效性的整体报告
- 灵活的配置选项:允许不同网站根据需求调整参数
1.2 功能模块设计
基于以上需求,我们将工具分为以下几个模块:
- 过期检测引擎:核心检测逻辑
- 提醒通知系统:邮件、站内信、Slack等通知方式
- 管理界面:后台配置和内容管理
- 数据统计面板:可视化报告和数据分析
- API接口:与其他系统集成的可能性
第二部分:开发环境准备与基础架构
2.1 开发环境配置
首先,我们需要准备一个安全的开发环境:
// 创建插件基础结构
/*
Plugin Name: 智能内容过期检测工具
Description: 自动检测WordPress内容时效性并发送更新提醒
Version: 1.0.0
Author: Your Name
*/
// 防止直接访问
if (!defined('ABSPATH')) {
exit;
}
2.2 数据库表设计
为了存储检测结果和配置信息,我们需要创建必要的数据库表:
class ContentExpiry_Setup {
public static function activate() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'content_expiry_logs';
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id bigint(20) NOT NULL AUTO_INCREMENT,
post_id bigint(20) NOT NULL,
post_type varchar(50) NOT NULL,
expiry_status varchar(50) NOT NULL,
expiry_date datetime DEFAULT NULL,
last_checked datetime DEFAULT CURRENT_TIMESTAMP,
notified tinyint(1) DEFAULT 0,
notification_sent_date datetime DEFAULT NULL,
priority_level int(11) DEFAULT 1,
custom_notes text,
PRIMARY KEY (id),
KEY post_id (post_id),
KEY expiry_status (expiry_status),
KEY priority_level (priority_level)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
// 创建配置表
$config_table = $wpdb->prefix . 'content_expiry_config';
$sql_config = "CREATE TABLE IF NOT EXISTS $config_table (
config_id bigint(20) NOT NULL AUTO_INCREMENT,
config_key varchar(100) NOT NULL,
config_value text,
config_group varchar(50) DEFAULT 'general',
PRIMARY KEY (config_id),
UNIQUE KEY config_key (config_key)
) $charset_collate;";
dbDelta($sql_config);
}
}
第三部分:核心检测引擎的实现
3.1 过期检测算法设计
内容过期检测需要考虑多个因素:
class ContentExpiry_Detector {
private $detection_rules = array();
public function __construct() {
$this->load_detection_rules();
}
private function load_detection_rules() {
// 默认检测规则
$this->detection_rules = array(
'time_based' => array(
'enabled' => true,
'max_age_days' => 365, // 默认365天为过期
'warning_before_days' => 30 // 提前30天警告
),
'reference_based' => array(
'enabled' => true,
'check_external_links' => true,
'broken_link_threshold' => 3
),
'engagement_based' => array(
'enabled' => true,
'comment_threshold' => 50,
'view_threshold' => 1000
),
'seasonal_content' => array(
'enabled' => true,
'seasonal_months' => array(12, 1, 2) // 季节性内容检测
)
);
}
public function check_post_expiry($post_id) {
$post = get_post($post_id);
if (!$post) {
return false;
}
$expiry_data = array(
'post_id' => $post_id,
'post_type' => $post->post_type,
'checks' => array(),
'score' => 0,
'status' => 'fresh'
);
// 执行各项检测
$expiry_data['checks']['time_check'] = $this->check_by_time($post);
$expiry_data['checks']['reference_check'] = $this->check_references($post);
$expiry_data['checks']['engagement_check'] = $this->check_engagement($post);
$expiry_data['checks']['seasonal_check'] = $this->check_seasonal($post);
// 计算综合分数
$expiry_data['score'] = $this->calculate_expiry_score($expiry_data['checks']);
$expiry_data['status'] = $this->determine_status($expiry_data['score']);
return $expiry_data;
}
private function check_by_time($post) {
$post_date = strtotime($post->post_date);
$current_time = current_time('timestamp');
$days_old = floor(($current_time - $post_date) / (60 * 60 * 24));
$max_age = $this->detection_rules['time_based']['max_age_days'];
$warning_days = $this->detection_rules['time_based']['warning_before_days'];
$result = array(
'days_old' => $days_old,
'max_allowed' => $max_age,
'status' => 'fresh'
);
if ($days_old > $max_age) {
$result['status'] = 'expired';
} elseif ($days_old > ($max_age - $warning_days)) {
$result['status'] = 'warning';
}
return $result;
}
private function check_references($post) {
// 检查外部链接是否有效
$content = $post->post_content;
$broken_links = 0;
$total_links = 0;
// 使用正则表达式提取链接
preg_match_all('/href=["'](https?://[^"']+)["']/i', $content, $matches);
if (!empty($matches[1])) {
$total_links = count($matches[1]);
// 抽样检查部分链接
$sample_links = array_slice($matches[1], 0, min(5, $total_links));
foreach ($sample_links as $link) {
if (!$this->check_link_status($link)) {
$broken_links++;
}
}
}
return array(
'total_links' => $total_links,
'broken_links' => $broken_links,
'status' => ($broken_links > 2) ? 'warning' : 'fresh'
);
}
private function check_link_status($url) {
// 简化的链接检查
$headers = @get_headers($url);
if (!$headers) {
return false;
}
$status_code = substr($headers[0], 9, 3);
return ($status_code == '200' || $status_code == '301' || $status_code == '302');
}
}
3.2 智能检测算法优化
为了提高检测的准确性,我们可以引入机器学习概念:
class ContentExpiry_AI_Detector extends ContentExpiry_Detector {
private $learning_data = array();
public function __construct() {
parent::__construct();
$this->load_learning_data();
}
private function load_learning_data() {
// 从数据库加载历史学习数据
global $wpdb;
$table_name = $wpdb->prefix . 'content_expiry_learning';
$results = $wpdb->get_results("SELECT * FROM $table_name LIMIT 1000");
foreach ($results as $row) {
$this->learning_data[] = array(
'features' => unserialize($row->feature_vector),
'label' => $row->expiry_label
);
}
}
public function enhanced_check($post_id) {
$basic_result = parent::check_post_expiry($post_id);
// 添加AI增强检测
$ai_features = $this->extract_ai_features($post_id);
$ai_prediction = $this->predict_expiry($ai_features);
// 结合传统检测和AI预测
$final_score = ($basic_result['score'] * 0.7) + ($ai_prediction * 0.3);
$basic_result['ai_prediction'] = $ai_prediction;
$basic_result['enhanced_score'] = $final_score;
$basic_result['status'] = $this->determine_status($final_score);
return $basic_result;
}
private function extract_ai_features($post_id) {
$features = array();
// 提取多种特征
$post = get_post($post_id);
// 1. 内容特征
$content = strip_tags($post->post_content);
$features['content_length'] = strlen($content);
$features['word_count'] = str_word_count($content);
// 2. 互动特征
$features['comment_count'] = get_comments_number($post_id);
$features['view_count'] = $this->get_post_views($post_id);
// 3. SEO特征
$features['seo_score'] = $this->calculate_seo_score($content);
// 4. 更新历史
$features['update_frequency'] = $this->get_update_frequency($post_id);
return $features;
}
private function predict_expiry($features) {
// 简化的预测算法
$score = 0;
// 基于规则的基础预测
if ($features['content_length'] < 500) {
$score += 20; // 短内容更容易过期
}
if ($features['comment_count'] > 50) {
$score -= 15; // 高互动内容更持久
}
if ($features['update_frequency'] < 0.5) {
$score += 25; // 很少更新的内容
}
return min(max($score, 0), 100);
}
}
第四部分:通知提醒系统的构建
4.1 多渠道通知系统
class ContentExpiry_Notifier {
private $notification_methods = array();
public function __construct() {
$this->init_notification_methods();
}
private function init_notification_methods() {
$this->notification_methods = array(
'email' => array(
'enabled' => true,
'priority' => 1,
'handler' => 'send_email_notification'
),
'slack' => array(
'enabled' => false,
'priority' => 2,
'handler' => 'send_slack_notification'
),
'webhook' => array(
'enabled' => false,
'priority' => 3,
'handler' => 'send_webhook_notification'
),
'dashboard' => array(
'enabled' => true,
'priority' => 0,
'handler' => 'add_dashboard_notice'
)
);
}
public function send_expiry_notification($post_id, $expiry_data) {
$notifications_sent = array();
// 按优先级排序
uasort($this->notification_methods, function($a, $b) {
return $a['priority'] <=> $b['priority'];
});
foreach ($this->notification_methods as $method => $config) {
if ($config['enabled']) {
$handler = $config['handler'];
if (method_exists($this, $handler)) {
$result = $this->$handler($post_id, $expiry_data);
if ($result) {
$notifications_sent[] = $method;
}
}
}
}
return $notifications_sent;
}
private function send_email_notification($post_id, $expiry_data) {
$post = get_post($post_id);
$admin_email = get_option('admin_email');
$subject = sprintf('[内容过期提醒] %s 需要更新', $post->post_title);
$message = $this->build_email_template($post, $expiry_data);
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: WordPress内容管理系统 <noreply@' . $_SERVER['HTTP_HOST'] . '>'
);
return wp_mail($admin_email, $subject, $message, $headers);
}
private function build_email_template($post, $expiry_data) {
$template = '
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #f8f9fa; padding: 20px; border-radius: 5px; }
.content { padding: 20px 0; }
.status-badge {
display: inline-block;
padding: 5px 10px;
border-radius: 3px;
color: white;
font-weight: bold;
}
.status-expired { background: #dc3545; }
.status-warning { background: #ffc107; color: #000; }
.status-fresh { background: #28a745; }
.button {
display: inline-block;
padding: 10px 20px;
background: #0073aa;
color: white;
text-decoration: none;
border-radius: 3px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>内容过期检测提醒</h2>
</div>
<div class="content">
<h3>' . esc_html($post->post_title) . '</h3>
<p><strong>状态:</strong>
<span class="status-badge status-' . $expiry_data['status'] . '">
' . $this->get_status_text($expiry_data['status']) . '
</span>
</p>
<p><strong>过期评分:</strong> ' . $expiry_data['score'] . '/100</p>
<h4>检测详情:</h4>
<ul>';
foreach ($expiry_data['checks'] as $check_name => $check_result) {
$template .= '<li>' . $this->format_check_result($check_name, $check_result) . '</li>';
}
$template .= '
</ul>
<p>建议您在方便的时候更新此内容,以保持网站的新鲜度和权威性。</p>
<a href="' . get_edit_post_link($post->ID) . '" class="button">
立即编辑内容
</a>
<p style="margin-top: 30px; color: #666; font-size: 12px;">
此邮件由智能内容过期检测系统自动发送。<br>
如需调整通知设置,请访问插件设置页面。
</p>
</div>
</div>
</body>
</html>';
return $template;
}
private function send_slack_notification($post_id, $expiry_data) {
$slack_webhook = get_option('content_expiry_slack_webhook');
if (!$slack_webhook) {
return false;
}
$post = get_post($post_id);
$message = array(
'text' => sprintf('*内容过期提醒*: %s', $post->post_title),
'attachments' => array(
array(
'color' => $this->get_slack_color($expiry_data['status']),
'fields' => array(
array(
'title' => '状态',
'value' => $this->get_status_text($expiry_data['status']),
'short' => true
),
array(
'title' => '评分',
'value' => $expiry_data['score'] . '/100',
'short' => true
),
array(
'title' => '操作',
'value' => '<' . get_edit_post_link($post_id) . '|编辑内容>',
'short' => false
)
)
)
)
);
$args = array(
'body' => json_encode($message),
'headers' => array(
第四部分:通知提醒系统的构建(续)
4.2 智能通知调度与频率控制
class ContentExpiry_Notification_Scheduler {
private $notification_log = array();
public function __construct() {
add_action('content_expiry_daily_check', array($this, 'daily_notification_batch'));
}
public function schedule_notification($post_id, $expiry_data) {
$notification_needed = $this->should_notify($post_id, $expiry_data);
if (!$notification_needed) {
return false;
}
// 根据紧急程度安排通知时间
$schedule_time = $this->calculate_schedule_time($expiry_data['status']);
// 将通知加入队列
$this->add_to_notification_queue($post_id, $expiry_data, $schedule_time);
return true;
}
private function should_notify($post_id, $expiry_data) {
// 检查是否已发送过通知
$last_notification = $this->get_last_notification_time($post_id);
if ($last_notification) {
$days_since_last = (time() - $last_notification) / (60 * 60 * 24);
// 根据状态确定通知频率
$min_interval_days = $this->get_notification_interval($expiry_data['status']);
if ($days_since_last < $min_interval_days) {
return false;
}
}
// 检查是否达到通知阈值
return $expiry_data['score'] >= $this->get_notification_threshold($expiry_data['status']);
}
private function get_notification_interval($status) {
$intervals = array(
'expired' => 7, // 过期内容每周提醒一次
'warning' => 14, // 警告内容每两周提醒一次
'fresh' => 30 // 新鲜内容每月提醒一次
);
return isset($intervals[$status]) ? $intervals[$status] : 30;
}
public function daily_notification_batch() {
global $wpdb;
$table_name = $wpdb->prefix . 'content_expiry_logs';
// 获取需要今天发送通知的内容
$today = current_time('mysql');
$query = $wpdb->prepare(
"SELECT * FROM $table_name
WHERE expiry_status IN ('expired', 'warning')
AND notified = 0
AND DATE(expiry_date) <= DATE(%s)
ORDER BY priority_level DESC",
$today
);
$expired_items = $wpdb->get_results($query);
if (empty($expired_items)) {
return;
}
// 分组处理,避免一次性发送太多通知
$batches = array_chunk($expired_items, 10); // 每批10个
foreach ($batches as $batch) {
$this->process_notification_batch($batch);
}
}
private function process_notification_batch($items) {
$notifier = new ContentExpiry_Notifier();
foreach ($items as $item) {
$expiry_data = array(
'status' => $item->expiry_status,
'score' => $item->priority_level * 10,
'checks' => unserialize($item->custom_notes)
);
$notifier->send_expiry_notification($item->post_id, $expiry_data);
// 标记为已通知
$this->mark_as_notified($item->id);
}
}
private function mark_as_notified($log_id) {
global $wpdb;
$table_name = $wpdb->prefix . 'content_expiry_logs';
$wpdb->update(
$table_name,
array(
'notified' => 1,
'notification_sent_date' => current_time('mysql')
),
array('id' => $log_id)
);
}
}
4.3 邮件模板优化与个性化
class ContentExpiry_Email_Templates {
private $templates = array();
public function __construct() {
$this->load_templates();
}
private function load_templates() {
$this->templates = array(
'expired' => array(
'subject' => '紧急:内容已过期 - {post_title}',
'priority' => 'high',
'template' => 'expired-template.php'
),
'warning' => array(
'subject' => '提醒:内容即将过期 - {post_title}',
'priority' => 'normal',
'template' => 'warning-template.php'
),
'weekly_summary' => array(
'subject' => '内容过期情况周报 - {site_name}',
'priority' => 'low',
'template' => 'weekly-summary.php'
)
);
}
public function get_template($type, $data = array()) {
if (!isset($this->templates[$type])) {
$type = 'warning';
}
$template_config = $this->templates[$type];
// 加载模板文件
$template_path = plugin_dir_path(__FILE__) . 'templates/email/' . $template_config['template'];
if (file_exists($template_path)) {
ob_start();
extract($data);
include($template_path);
return ob_get_clean();
}
// 如果模板文件不存在,返回默认模板
return $this->get_default_template($type, $data);
}
private function get_default_template($type, $data) {
$default_templates = array(
'expired' => '
<h2>紧急内容更新通知</h2>
<p>您的内容 <strong>{post_title}</strong> 已被标记为过期。</p>
<p>过期时间:{expiry_date}</p>
<p>过期评分:{expiry_score}/100</p>
<p>请尽快更新此内容以保持网站质量。</p>
<a href="{edit_link}" style="background: #dc3545; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;">
立即更新
</a>
',
'weekly_summary' => '
<h2>内容过期情况周报</h2>
<p>本周内容过期统计:</p>
<ul>
<li>过期内容:{expired_count} 篇</li>
<li>即将过期:{warning_count} 篇</li>
<li>需要关注:{attention_count} 篇</li>
</ul>
<p>详细报告请登录后台查看。</p>
'
);
$template = isset($default_templates[$type]) ? $default_templates[$type] : $default_templates['expired'];
// 替换变量
foreach ($data as $key => $value) {
$template = str_replace('{' . $key . '}', $value, $template);
}
return $template;
}
public function send_weekly_summary() {
$stats = $this->get_weekly_stats();
$data = array(
'site_name' => get_bloginfo('name'),
'expired_count' => $stats['expired'],
'warning_count' => $stats['warning'],
'attention_count' => $stats['attention'],
'report_date' => date('Y年m月d日'),
'admin_url' => admin_url('admin.php?page=content-expiry-reports')
);
$subject = $this->templates['weekly_summary']['subject'];
$subject = str_replace('{site_name}', $data['site_name'], $subject);
$message = $this->get_template('weekly_summary', $data);
// 获取所有管理员邮箱
$admin_emails = $this->get_admin_emails();
foreach ($admin_emails as $email) {
wp_mail($email, $subject, $message, array('Content-Type: text/html; charset=UTF-8'));
}
}
private function get_weekly_stats() {
global $wpdb;
$table_name = $wpdb->prefix . 'content_expiry_logs';
$week_ago = date('Y-m-d', strtotime('-7 days'));
$stats = $wpdb->get_row("
SELECT
SUM(CASE WHEN expiry_status = 'expired' THEN 1 ELSE 0 END) as expired,
SUM(CASE WHEN expiry_status = 'warning' THEN 1 ELSE 0 END) as warning,
SUM(CASE WHEN expiry_status = 'attention' THEN 1 ELSE 0 END) as attention
FROM $table_name
WHERE last_checked >= '$week_ago'
", ARRAY_A);
return $stats ?: array('expired' => 0, 'warning' => 0, 'attention' => 0);
}
}
第五部分:管理界面与用户交互
5.1 后台管理页面开发
class ContentExpiry_Admin_Interface {
public function __construct() {
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
add_action('wp_ajax_content_expiry_actions', array($this, 'handle_ajax_requests'));
}
public function add_admin_menu() {
// 主菜单
add_menu_page(
'内容过期检测',
'内容过期',
'manage_options',
'content-expiry',
array($this, 'render_main_page'),
'dashicons-calendar-alt',
30
);
// 子菜单
add_submenu_page(
'content-expiry',
'过期内容列表',
'过期内容',
'manage_options',
'content-expiry-list',
array($this, 'render_expired_list')
);
add_submenu_page(
'content-expiry',
'检测设置',
'设置',
'manage_options',
'content-expiry-settings',
array($this, 'render_settings_page')
);
add_submenu_page(
'content-expiry',
'统计报告',
'报告',
'manage_options',
'content-expiry-reports',
array($this, 'render_reports_page')
);
}
public function render_main_page() {
?>
<div class="wrap content-expiry-dashboard">
<h1 class="wp-heading-inline">内容过期检测仪表板</h1>
<div class="dashboard-widgets">
<div class="widget-card">
<h3>内容健康度概览</h3>
<div class="health-score">
<?php $this->render_health_score(); ?>
</div>
</div>
<div class="widget-card">
<h3>紧急任务</h3>
<div class="urgent-tasks">
<?php $this->render_urgent_tasks(); ?>
</div>
</div>
<div class="widget-card full-width">
<h3>最近检测结果</h3>
<div class="recent-checks">
<?php $this->render_recent_checks(); ?>
</div>
</div>
</div>
<div class="quick-actions">
<button class="button button-primary" onclick="runQuickScan()">
<span class="dashicons dashicons-update"></span>
快速扫描
</button>
<button class="button button-secondary" onclick="viewFullReport()">
<span class="dashicons dashicons-chart-bar"></span>
查看完整报告
</button>
<button class="button" onclick="manageNotifications()">
<span class="dashicons dashicons-email"></span>
通知设置
</button>
</div>
</div>
<script>
function runQuickScan() {
jQuery.post(ajaxurl, {
action: 'content_expiry_actions',
task: 'quick_scan'
}, function(response) {
alert('扫描完成:' + response.message);
location.reload();
});
}
</script>
<style>
.content-expiry-dashboard {
padding: 20px;
}
.dashboard-widgets {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin: 20px 0;
}
.widget-card {
background: white;
border: 1px solid #ccd0d4;
border-radius: 4px;
padding: 20px;
box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.widget-card.full-width {
grid-column: 1 / -1;
}
.quick-actions {
margin-top: 30px;
display: flex;
gap: 10px;
}
</style>
<?php
}
private function render_health_score() {
global $wpdb;
$table_name = $wpdb->prefix . 'content_expiry_logs';
$stats = $wpdb->get_row("
SELECT
COUNT(*) as total,
AVG(priority_level) as avg_score,
SUM(CASE WHEN expiry_status = 'expired' THEN 1 ELSE 0 END) as expired_count
FROM $table_name
");
if ($stats) {
$health_score = 100 - ($stats->expired_count / max(1, $stats->total) * 100);
?>
<div class="score-circle" style="
width: 120px;
height: 120px;
border-radius: 50%;
background: conic-gradient(
#4CAF50 <?php echo $health_score * 3.6; ?>deg,
#f0f0f0 0deg
);
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
">
<div style="
background: white;
width: 80px;
height: 80px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
font-weight: bold;
">
<?php echo round($health_score); ?>%
</div>
</div>
<p>已检测内容:<?php echo $stats->total; ?> 篇</p>
<p>过期内容:<?php echo $stats->expired_count; ?> 篇</p>
<?php
}
}
public function render_expired_list() {
?>
<div class="wrap">
<h1 class="wp-heading-inline">过期内容管理</h1>
<div class="tablenav top">
<div class="alignleft actions">
<select name="filter_status">
<option value="">所有状态</option>
<option value="expired">已过期</option>
<option value="warning">即将过期</option>
<option value="fresh">正常</option>
</select>
<select name="filter_post_type">
<option value="">所有类型</option>
<?php
$post_types = get_post_types(array('public' => true), 'objects');
foreach ($post_types as $post_type) {
echo '<option value="' . $post_type->name . '">' . $post_type->label . '</option>';
}
?>
</select>
<button class="button" onclick="filterContent()">筛选</button>
</div>
<div class="alignright">
<button class="button button-primary" onclick="exportToCSV()">
<span class="dashicons dashicons-download"></span>
导出CSV
</button>
</div>
</div>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th width="50">ID</th>
<th>标题</th>
<th width="100">类型</th>
<th width="100">状态</th>
<th width="120">过期时间</th>
<th width="100">优先级</th>
<th width="150">操作</th>
</tr>
</thead>
<tbody id="expired-content-list">
<?php $this->render_expired_content_rows(); ?>
</tbody>
</table>
<div class="tablenav bottom">
<div class="tablenav-pages">
<?php $this->render_pagination(); ?>
</div>
</div>
</div>
<script>
function filterContent() {
var status = jQuery('select[name="filter_status"]').val();
var postType = jQuery('select[name="filter_post_type"]').val();
jQuery.post(ajaxurl, {
action: 'content_expiry_actions',
task: 'filter_content',
status: status,
post_type: postType
}, function(response) {
jQuery('#expired-content-list').html(response.data);
});
}
function exportToCSV() {
window.location.href = ajaxurl + '?action=content_expiry_export&type=csv';
}
</script>
<?php
}
private function render_expired_content_rows() {
global $wpdb;
$table_name = $wpdb->prefix . 'content_expiry_logs';
$page = isset($_GET['paged']) ? max(1, intval($_GET['paged'])) : 1;
$per_page = 20;
$offset = ($page - 1) * $per_page;
$items = $wpdb->get_results("
SELECT l.*, p.post_title, p.post_type
FROM $table_name l
