文章目录[隐藏]
网络传媒柔性内容供应链的WordPress实现教程
概述:什么是柔性内容供应链?
在当今快速变化的网络传媒环境中,内容供应链的"柔性"已成为核心竞争力。柔性内容供应链指的是能够快速响应市场变化、多渠道分发、易于扩展和调整的内容生产与管理系统。传统的内容管理方式往往僵化、单一,而柔性供应链则强调模块化、自动化和智能化。
WordPress作为全球最流行的内容管理系统,凭借其强大的插件生态和灵活的架构,成为实现柔性内容供应链的理想平台。本教程将指导您如何利用WordPress构建一个高效、灵活的传媒内容供应链系统。
系统架构设计
核心组件规划
一个完整的柔性内容供应链系统应包含以下核心模块:
- 内容创作与编辑模块 - 支持多格式内容创作
- 工作流管理模块 - 实现内容生产流程自动化
- 多渠道发布模块 - 一键发布到多个平台
- 数据分析与优化模块 - 基于数据的内容策略调整
- 资源管理模块 - 统一管理多媒体资源
技术栈选择
- WordPress 6.0+ 作为基础平台
- 自定义插件开发(核心功能)
- REST API 用于系统集成
- MySQL 数据库优化
- 缓存机制提升性能
核心功能实现
1. 自定义内容类型与字段
<?php
/**
* 注册自定义内容类型:新闻稿件
*/
function register_news_article_post_type() {
$labels = array(
'name' => '新闻稿件',
'singular_name' => '新闻稿件',
'menu_name' => '新闻稿件管理',
'add_new' => '添加新稿件',
'add_new_item' => '添加新新闻稿件',
'edit_item' => '编辑新闻稿件',
'new_item' => '新新闻稿件',
'view_item' => '查看新闻稿件',
'search_items' => '搜索新闻稿件',
'not_found' => '未找到新闻稿件',
'not_found_in_trash' => '回收站中无新闻稿件'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'news-article'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'),
'show_in_rest' => true, // 启用Gutenberg编辑器支持
);
register_post_type('news_article', $args);
}
add_action('init', 'register_news_article_post_type');
/**
* 为新闻稿件添加自定义字段
*/
function add_news_article_meta_fields() {
// 使用WordPress原生函数注册元字段
register_post_meta('news_article', 'news_source', array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'label' => '新闻来源',
'description' => '新闻的原始来源机构'
));
register_post_meta('news_article', 'priority_level', array(
'show_in_rest' => true,
'single' => true,
'type' => 'integer',
'label' => '优先级',
'description' => '内容发布优先级(1-5,5为最高)'
));
register_post_meta('news_article', 'target_platforms', array(
'show_in_rest' => true,
'single' => false,
'type' => 'array',
'label' => '目标发布平台',
'description' => '选择要发布到的平台'
));
}
add_action('init', 'add_news_article_meta_fields');
?>
2. 工作流管理系统
<?php
/**
* 内容工作流状态管理
*/
class ContentWorkflow {
private $statuses = array();
public function __construct() {
$this->statuses = array(
'draft' => '草稿',
'editing' => '编辑中',
'reviewing' => '审核中',
'approved' => '已审核',
'scheduled' => '已排期',
'published' => '已发布',
'archived' => '已归档'
);
$this->init_hooks();
}
private function init_hooks() {
add_action('init', array($this, 'register_workflow_statuses'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_workflow_scripts'));
add_action('wp_ajax_update_content_status', array($this, 'ajax_update_status'));
}
/**
* 注册自定义工作流状态
*/
public function register_workflow_statuses() {
foreach ($this->statuses as $status => $label) {
register_post_status($status, array(
'label' => $label,
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop("{$label} <span class='count'>(%s)</span>", "{$label} <span class='count'>(%s)</span>"),
));
}
}
/**
* 更新内容状态的AJAX处理
*/
public function ajax_update_status() {
// 安全检查
if (!check_ajax_referer('workflow_nonce', 'nonce', false)) {
wp_die('安全验证失败');
}
$post_id = intval($_POST['post_id']);
$new_status = sanitize_text_field($_POST['new_status']);
$user_id = get_current_user_id();
// 验证用户权限
if (!current_user_can('edit_post', $post_id)) {
wp_send_json_error('权限不足');
}
// 更新文章状态
$result = wp_update_post(array(
'ID' => $post_id,
'post_status' => $new_status
));
if ($result) {
// 记录状态变更日志
$this->log_status_change($post_id, $user_id, $new_status);
// 如果是审核通过状态,触发后续操作
if ($new_status === 'approved') {
$this->trigger_post_approval_actions($post_id);
}
wp_send_json_success(array(
'message' => '状态更新成功',
'new_status' => $new_status,
'status_label' => $this->statuses[$new_status]
));
} else {
wp_send_json_error('状态更新失败');
}
}
/**
* 记录状态变更日志
*/
private function log_status_change($post_id, $user_id, $new_status) {
$log_entry = array(
'post_id' => $post_id,
'user_id' => $user_id,
'old_status' => get_post_status($post_id),
'new_status' => $new_status,
'timestamp' => current_time('mysql'),
'user_ip' => $_SERVER['REMOTE_ADDR']
);
// 获取现有日志
$logs = get_post_meta($post_id, '_workflow_logs', true);
if (!is_array($logs)) {
$logs = array();
}
// 添加新日志(限制最多保存50条)
array_unshift($logs, $log_entry);
$logs = array_slice($logs, 0, 50);
update_post_meta($post_id, '_workflow_logs', $logs);
}
/**
* 触发审核通过后的操作
*/
private function trigger_post_approval_actions($post_id) {
// 获取目标发布平台
$target_platforms = get_post_meta($post_id, 'target_platforms', true);
if (!empty($target_platforms) && is_array($target_platforms)) {
// 这里可以添加自动发布到其他平台的逻辑
foreach ($target_platforms as $platform) {
// 调用各平台的发布API
$this->publish_to_platform($post_id, $platform);
}
}
// 发送通知邮件
$this->send_approval_notification($post_id);
}
/**
* 发布到指定平台
*/
private function publish_to_platform($post_id, $platform) {
// 根据平台类型调用不同的API
// 这里是一个示例框架,实际需要根据具体平台API实现
$post_data = $this->prepare_post_data_for_platform($post_id, $platform);
// 实际API调用代码将在这里实现
// 例如:wp_remote_post($platform_api_url, $post_data);
// 记录发布日志
$this->log_platform_publish($post_id, $platform);
}
}
// 初始化工作流系统
new ContentWorkflow();
?>
3. 多渠道发布模块
/**
* 前端多渠道发布界面组件
*/
class MultiPlatformPublisher {
constructor() {
this.platforms = [
{ id: 'wechat', name: '微信公众号', icon: 'wechat-icon' },
{ id: 'weibo', name: '微博', icon: 'weibo-icon' },
{ id: 'toutiao', name: '今日头条', icon: 'toutiao-icon' },
{ id: 'zhihu', name: '知乎', icon: 'zhihu-icon' },
{ id: 'site', name: '自有网站', icon: 'website-icon' }
];
this.init();
}
init() {
this.renderPlatformSelector();
this.bindEvents();
}
/**
* 渲染平台选择器
*/
renderPlatformSelector() {
const container = document.getElementById('platform-selector');
if (!container) return;
let html = '<div class="platform-selector">';
html += '<h3>选择发布平台</h3>';
html += '<div class="platform-grid">';
this.platforms.forEach(platform => {
const isChecked = this.getSavedPlatforms().includes(platform.id);
html += `
<div class="platform-item">
<input type="checkbox"
id="platform-${platform.id}"
value="${platform.id}"
${isChecked ? 'checked' : ''}>
<label for="platform-${platform.id}">
<span class="platform-icon ${platform.icon}"></span>
<span class="platform-name">${platform.name}</span>
</label>
</div>
`;
});
html += '</div>';
html += '<button id="publish-to-selected" class="button button-primary">发布到选中平台</button>';
html += '</div>';
container.innerHTML = html;
}
/**
* 绑定事件
*/
bindEvents() {
document.getElementById('publish-to-selected')?.addEventListener('click', () => {
this.publishToSelectedPlatforms();
});
// 平台选择变化时保存状态
document.querySelectorAll('.platform-item input').forEach(input => {
input.addEventListener('change', () => {
this.saveSelectedPlatforms();
});
});
}
/**
* 发布到选中的平台
*/
async publishToSelectedPlatforms() {
const selectedPlatforms = this.getSelectedPlatforms();
const postId = this.getCurrentPostId();
if (selectedPlatforms.length === 0) {
alert('请至少选择一个发布平台');
return;
}
// 显示发布进度
this.showPublishingProgress(selectedPlatforms);
// 逐个平台发布
for (const platformId of selectedPlatforms) {
try {
await this.publishToPlatform(postId, platformId);
this.updateProgress(platformId, 'success');
} catch (error) {
console.error(`发布到${platformId}失败:`, error);
this.updateProgress(platformId, 'failed', error.message);
}
}
// 发布完成
this.showPublishComplete();
}
/**
* 发布到单个平台
*/
async publishToPlatform(postId, platformId) {
const response = await fetch('/wp-json/content-supply/v1/publish', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': wpApiSettings.nonce
},
body: JSON.stringify({
post_id: postId,
platform: platformId,
action: 'publish'
})
});
if (!response.ok) {
throw new Error(`HTTP错误: ${response.status}`);
}
const data = await response.json();
if (!data.success) {
throw new Error(data.message || '发布失败');
}
return data;
}
/**
* 显示发布进度
*/
showPublishingProgress(platforms) {
// 实现进度显示逻辑
}
/**
* 获取当前文章ID
*/
getCurrentPostId() {
return parseInt(document.getElementById('post_ID')?.value) || 0;
}
/**
* 获取选中的平台
*/
getSelectedPlatforms() {
const selected = [];
document.querySelectorAll('.platform-item input:checked').forEach(input => {
selected.push(input.value);
});
return selected;
}
/**
* 保存选中的平台
*/
saveSelectedPlatforms() {
const selected = this.getSelectedPlatforms();
const postId = this.getCurrentPostId();
// 保存到文章元数据
fetch('/wp-json/content-supply/v1/update-platforms', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': wpApiSettings.nonce
},
body: JSON.stringify({
post_id: postId,
platforms: selected
})
});
}
/**
* 获取已保存的平台
*/
getSavedPlatforms() {
// 从页面数据中获取已保存的平台
const savedData = document.getElementById('saved-platforms')?.dataset.platforms;
return savedData ? JSON.parse(savedData) : [];
}
}
// 初始化发布器
document.addEventListener('DOMContentLoaded', () => {
new MultiPlatformPublisher();
});
系统优化与扩展
性能优化策略
- 数据库优化:为自定义字段添加索引,定期清理日志数据
- 缓存机制:使用Redis或Memcached缓存频繁查询的数据
- 图片优化:自动压缩和转换图片格式,使用CDN加速
- 懒加载:对长列表和图片实现懒加载
扩展功能建议
- AI内容辅助:集成AI写作助手和内容优化建议
- 智能推荐系统:基于用户行为的内容推荐算法
- 跨平台同步:与更多社交媒体平台深度集成
- 数据分析面板:实时监控内容表现和用户互动
部署与维护
环境要求
- PHP 7.4+
- MySQL 5.7+ 或 MariaDB 10.3+
- WordPress 6.0+
- HTTPS支持(必需)
安全建议
- 定期更新WordPress核心、主题和插件
- 使用强密码和双因素认证
- 限制登录尝试次数
- 定期备份数据库和文件
- 使用安全插件进行漏洞扫描
总结
通过WordPress构建柔性内容供应链系统,传媒机构可以实现内容生产、管理和分发的全流程数字化、自动化。本文提供的实现方案涵盖了核心功能模块,包括自定义内容类型、工作流管理、多渠道发布等关键组件。
实际部署时,建议根据具体业务需求进行定制开发,并充分考虑系统的扩展性和维护性。随着业务发展,可以逐步引入AI辅助、大数据分析等先进技术,进一步提升内容供应链的智能化水平。
柔性内容供应链的建设是一个持续优化的过程,需要不断根据市场反馈和技术发展进行调整。WordPress的灵活性和丰富的生态系统为此提供了坚实的基础,使传媒机构能够以较低的成本构建高效、灵活的内容管理系统。
网络传媒柔性内容供应链的WordPress实现教程(续)
智能内容分发与自动化模块
4. 基于规则的内容自动分发系统
<?php
/**
* 智能内容分发引擎
*/
class IntelligentContentDistributor {
private $distribution_rules = array();
public function __construct() {
$this->load_distribution_rules();
$this->init_hooks();
}
private function init_hooks() {
// 文章状态变更时触发分发检查
add_action('transition_post_status', array($this, 'check_distribution_on_status_change'), 10, 3);
// 定时任务检查待分发内容
add_action('content_distribution_cron', array($this, 'process_pending_distribution'));
// 注册REST API端点
add_action('rest_api_init', array($this, 'register_rest_endpoints'));
}
/**
* 加载分发规则
*/
private function load_distribution_rules() {
// 从数据库或配置文件中加载规则
$this->distribution_rules = get_option('content_distribution_rules', array(
'rules' => array(
array(
'id' => 'rule_high_priority',
'name' => '高优先级内容即时发布',
'conditions' => array(
array('field' => 'priority_level', 'operator' => '>=', 'value' => 4),
array('field' => 'content_type', 'operator' => '=', 'value' => 'breaking_news')
),
'actions' => array(
array('type' => 'publish_immediately', 'platforms' => array('wechat', 'weibo', 'site')),
array('type' => 'send_notification', 'channels' => array('email', 'slack'))
),
'enabled' => true
),
array(
'id' => 'rule_scheduled_morning',
'name' => '早间新闻定时发布',
'conditions' => array(
array('field' => 'category', 'operator' => 'IN', 'value' => array('morning_news', 'daily_brief')),
array('field' => 'publish_time', 'operator' => 'BETWEEN', 'value' => array('06:00', '09:00'))
),
'actions' => array(
array('type' => 'schedule_publish', 'time' => '07:00', 'platforms' => array('wechat', 'toutiao'))
),
'enabled' => true
)
)
));
}
/**
* 文章状态变更时的分发检查
*/
public function check_distribution_on_status_change($new_status, $old_status, $post) {
// 仅处理特定文章类型
if (!in_array($post->post_type, array('news_article', 'post'))) {
return;
}
// 当文章从草稿变为发布时触发分发
if ($old_status === 'draft' && $new_status === 'publish') {
$this->evaluate_distribution_rules($post->ID);
}
// 当文章被批准时触发分发
if ($new_status === 'approved') {
$this->process_approved_content($post->ID);
}
}
/**
* 评估分发规则
*/
private function evaluate_distribution_rules($post_id) {
$post = get_post($post_id);
$post_meta = get_post_meta($post_id);
foreach ($this->distribution_rules['rules'] as $rule) {
if (!$rule['enabled']) {
continue;
}
if ($this->check_rule_conditions($rule['conditions'], $post, $post_meta)) {
$this->execute_rule_actions($rule['actions'], $post_id);
// 记录规则触发日志
$this->log_rule_execution($post_id, $rule['id']);
}
}
}
/**
* 检查规则条件
*/
private function check_rule_conditions($conditions, $post, $post_meta) {
foreach ($conditions as $condition) {
$field = $condition['field'];
$operator = $condition['operator'];
$value = $condition['value'];
$field_value = $this->get_field_value($field, $post, $post_meta);
if (!$this->compare_values($field_value, $operator, $value)) {
return false;
}
}
return true;
}
/**
* 获取字段值
*/
private function get_field_value($field, $post, $post_meta) {
switch ($field) {
case 'priority_level':
return isset($post_meta['priority_level'][0]) ? intval($post_meta['priority_level'][0]) : 1;
case 'content_type':
return $post->post_type;
case 'category':
$categories = wp_get_post_categories($post->ID, array('fields' => 'slugs'));
return $categories;
case 'publish_time':
return get_the_time('H:i', $post->ID);
case 'word_count':
return str_word_count(strip_tags($post->post_content));
default:
// 尝试从自定义字段获取
return isset($post_meta[$field][0]) ? $post_meta[$field][0] : null;
}
}
/**
* 比较值
*/
private function compare_values($field_value, $operator, $rule_value) {
switch ($operator) {
case '=':
return $field_value == $rule_value;
case '!=':
return $field_value != $rule_value;
case '>':
return $field_value > $rule_value;
case '>=':
return $field_value >= $rule_value;
case '<':
return $field_value < $rule_value;
case '<=':
return $field_value <= $rule_value;
case 'IN':
if (!is_array($field_value)) {
$field_value = array($field_value);
}
return count(array_intersect($field_value, (array)$rule_value)) > 0;
case 'NOT_IN':
if (!is_array($field_value)) {
$field_value = array($field_value);
}
return count(array_intersect($field_value, (array)$rule_value)) === 0;
case 'BETWEEN':
if (!is_array($rule_value) || count($rule_value) !== 2) {
return false;
}
return $field_value >= $rule_value[0] && $field_value <= $rule_value[1];
case 'CONTAINS':
return stripos($field_value, $rule_value) !== false;
default:
return false;
}
}
/**
* 执行规则动作
*/
private function execute_rule_actions($actions, $post_id) {
foreach ($actions as $action) {
switch ($action['type']) {
case 'publish_immediately':
$this->publish_to_platforms($post_id, $action['platforms']);
break;
case 'schedule_publish':
$this->schedule_content_publish($post_id, $action['time'], $action['platforms']);
break;
case 'send_notification':
$this->send_distribution_notification($post_id, $action['channels']);
break;
case 'add_to_collection':
$this->add_to_content_collection($post_id, $action['collection_id']);
break;
case 'apply_template':
$this->apply_content_template($post_id, $action['template_id']);
break;
}
}
}
/**
* 发布到多个平台
*/
private function publish_to_platforms($post_id, $platforms) {
foreach ($platforms as $platform) {
$this->publish_to_single_platform($post_id, $platform);
}
}
/**
* 发布到单个平台
*/
private function publish_to_single_platform($post_id, $platform) {
// 获取平台配置
$platform_config = $this->get_platform_config($platform);
if (!$platform_config || !$platform_config['enabled']) {
return;
}
// 准备发布数据
$post_data = $this->prepare_platform_content($post_id, $platform);
// 调用平台API
$result = $this->call_platform_api($platform, 'publish', $post_data);
// 记录发布结果
$this->log_platform_publish_result($post_id, $platform, $result);
return $result;
}
/**
* 准备平台内容
*/
private function prepare_platform_content($post_id, $platform) {
$post = get_post($post_id);
$post_meta = get_post_meta($post_id);
$base_data = array(
'title' => $post->post_title,
'content' => $post->post_content,
'excerpt' => $post->post_excerpt,
'author' => get_the_author_meta('display_name', $post->post_author),
'publish_time' => $post->post_date,
'categories' => wp_get_post_categories($post_id, array('fields' => 'names')),
'tags' => wp_get_post_tags($post_id, array('fields' => 'names'))
);
// 平台特定的内容处理
switch ($platform) {
case 'wechat':
// 微信公众号有字数限制和格式要求
$content = strip_tags($post->post_content);
if (mb_strlen($content) > 2000) {
$content = mb_substr($content, 0, 1997) . '...';
}
$base_data['content'] = $content;
$base_data['cover_image'] = get_the_post_thumbnail_url($post_id, 'full');
break;
case 'weibo':
// 微博有140字限制
$content = strip_tags($post->post_excerpt ?: $post->post_content);
if (mb_strlen($content) > 140) {
$content = mb_substr($content, 0, 137) . '...';
}
$base_data['content'] = $content;
$base_data['images'] = $this->get_post_images($post_id, 9); // 微博最多9图
break;
case 'toutiao':
// 今日头条需要摘要和封面图
$base_data['abstract'] = $post->post_excerpt ?: wp_trim_words(strip_tags($post->post_content), 100);
$base_data['cover_images'] = array(
get_the_post_thumbnail_url($post_id, 'large')
);
break;
}
return $base_data;
}
/**
* 获取文章图片
*/
private function get_post_images($post_id, $limit = 5) {
$images = array();
// 获取特色图片
$thumbnail_id = get_post_thumbnail_id($post_id);
if ($thumbnail_id) {
$images[] = wp_get_attachment_url($thumbnail_id);
}
// 从内容中提取图片
$post = get_post($post_id);
preg_match_all('/<img[^>]+src=["']([^"']+)["'][^>]*>/i', $post->post_content, $matches);
if (!empty($matches[1])) {
$images = array_merge($images, $matches[1]);
}
// 限制数量并去重
$images = array_slice(array_unique($images), 0, $limit);
return $images;
}
/**
* 注册REST API端点
*/
public function register_rest_endpoints() {
register_rest_route('content-supply/v1', '/distribution/rules', array(
array(
'methods' => 'GET',
'callback' => array($this, 'get_distribution_rules'),
'permission_callback' => array($this, 'check_admin_permission')
),
array(
'methods' => 'POST',
'callback' => array($this, 'update_distribution_rules'),
'permission_callback' => array($this, 'check_admin_permission')
)
));
register_rest_route('content-supply/v1', '/distribution/test-rule', array(
'methods' => 'POST',
'callback' => array($this, 'test_distribution_rule'),
'permission_callback' => array($this, 'check_admin_permission')
));
register_rest_route('content-supply/v1', '/distribution/logs/(?P<post_id>d+)', array(
'methods' => 'GET',
'callback' => array($this, 'get_distribution_logs'),
'permission_callback' => array($this, 'check_edit_permission')
));
}
/**
* 获取分发规则
*/
public function get_distribution_rules($request) {
return rest_ensure_response($this->distribution_rules);
}
/**
* 更新分发规则
*/
public function update_distribution_rules($request) {
$new_rules = $request->get_json_params();
if (!isset($new_rules['rules'])) {
return new WP_Error('invalid_data', '无效的规则数据', array('status' => 400));
}
// 验证规则结构
foreach ($new_rules['rules'] as $rule) {
if (!$this->validate_rule_structure($rule)) {
return new WP_Error('invalid_rule', '规则结构无效', array('status' => 400));
}
}
update_option('content_distribution_rules', $new_rules);
$this->distribution_rules = $new_rules;
return rest_ensure_response(array(
'success' => true,
'message' => '规则更新成功'
));
}
/**
* 验证规则结构
*/
private function validate_rule_structure($rule) {
$required_fields = array('id', 'name', 'conditions', 'actions', 'enabled');
foreach ($required_fields as $field) {
if (!isset($rule[$field])) {
return false;
}
}
return true;
}
/**
* 权限检查
*/
public function check_admin_permission() {
return current_user_can('manage_options');
}
public function check_edit_permission($request) {
$post_id = $request->get_param('post_id');
return current_user_can('edit_post', $post_id);
}
}
// 初始化分发器
new IntelligentContentDistributor();
?>
5. 内容性能分析与优化建议系统
<?php
/**
* 内容性能分析系统
*/
class ContentPerformanceAnalyzer {
private $metrics = array();
public function __construct() {
$this->init_metrics();
$this->init_hooks();
$this->schedule_analysis_tasks();
}
private function init_metrics() {
$this->metrics = array(
'engagement' => array(
'name' => '用户参与度',
'weight' => 0.3,
'factors' => array(
'time_on_page' => 0.4,
'scroll_depth' => 0.3,
'interaction_rate' => 0.3
)
),
'conversion' => array(
'name' => '转化率',
'weight' => 0.25,
'factors' => array(
'ctr' => 0.4,
'share_rate' => 0.3,
'comment_rate' => 0.3
)
),
'seo' => array(
'name' => 'SEO表现',
'weight' => 0.2,
'factors' => array(
'organic_traffic' => 0.5,
'keyword_ranking' => 0.3,
'backlinks' => 0.2
)
),
'social' => array(
'name' => '社交媒体表现',
'weight' => 0.15,
'factors' => array(
'social_shares' => 0.4,
'social_reach' => 0.4,
'social_engagement' => 0.2
)
),
'monetization' => array(
'name' => '变现能力',
'weight' => 0.1,
'factors' => array(
'ad_revenue' => 0.6,
'affiliate_income' => 0.4
)
)
);
}
private function init_hooks() {
// 文章保存时记录基准数据
add_action('save_post', array($this, 'record_content_baseline'), 10, 3);
// 每日分析任务
add_action('daily_content_analysis', array($this, 'run_daily_analysis'));
// REST API
add_action('rest_api_init', array($this, 'register_performance_endpoints'));
// 管理界面
add_action('admin_menu', array($this, 'add_admin_menu'));
}
private function schedule_analysis_tasks() {
if (!wp_next_scheduled('daily_content_analysis')) {
wp_schedule_event(time(), 'daily', 'daily_content_analysis');
}
}
/**
* 记录内容基准数据
*/
public function record_content_baseline($post_id, $post, $update) {
if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
return;
}
$baseline_data = array(
'word_count' => str_word_count(strip_tags($post->post_content)),
