文章目录[隐藏]
WordPress文创插件实现柔性版权管理的详细教程
引言:文创产业的版权管理挑战
在数字文创产业蓬勃发展的今天,内容创作者面临着版权保护与内容传播之间的平衡难题。传统的"全有或全无"版权模式已无法满足文创作品的多样化需求。柔性版权管理应运而生,它允许创作者根据作品特性和商业策略,灵活设置不同的使用权限。本文将详细介绍如何在WordPress中通过自定义插件实现柔性版权管理系统。
柔性版权管理的基本概念
柔性版权管理是一种介于传统版权和开放许可之间的版权管理模式。它允许创作者保留部分权利,同时授权他人在特定条件下使用作品。常见的柔性版权选项包括:
- 署名要求:使用者必须注明原作者
- 非商业性使用:禁止商业用途
- 禁止演绎:不允许修改原作品
- 相同方式共享:衍生作品必须采用相同许可
插件开发环境准备
在开始开发前,请确保您的开发环境满足以下要求:
<?php
/**
* WordPress文创插件 - 柔性版权管理
* 插件主文件:wp-cultural-license.php
*
* 开发环境要求:
* 1. WordPress 5.0+
* 2. PHP 7.2+
* 3. MySQL 5.6+
*/
/*
* 插件基本信息
*/
/*
Plugin Name: WordPress文创柔性版权管理器
Plugin URI: https://example.com/wp-cultural-license
Description: 为WordPress文创内容提供灵活的版权管理解决方案
Version: 1.0.0
Author: 文创开发者
Author URI: https://example.com
License: GPL v2 or later
Text Domain: wp-cultural-license
Domain Path: /languages
*/
// 防止直接访问
if (!defined('ABSPATH')) {
exit;
}
// 定义插件常量
define('WCL_VERSION', '1.0.0');
define('WCL_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('WCL_PLUGIN_URL', plugin_dir_url(__FILE__));
?>
数据库表结构设计
柔性版权管理需要存储版权配置信息,我们需要创建自定义数据库表:
<?php
/**
* 创建版权管理数据库表
*/
function wcl_create_database_tables() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'cultural_licenses';
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
post_id bigint(20) NOT NULL,
license_type varchar(50) NOT NULL,
require_attribution tinyint(1) DEFAULT 1,
allow_commercial tinyint(1) DEFAULT 0,
allow_modifications varchar(20) DEFAULT 'no',
share_alike tinyint(1) DEFAULT 0,
custom_terms text,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY post_id (post_id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
// 添加示例数据(仅用于演示)
wcl_insert_sample_licenses();
}
/**
* 插入示例版权配置
*/
function wcl_insert_sample_licenses() {
global $wpdb;
$table_name = $wpdb->prefix . 'cultural_licenses';
$sample_licenses = array(
array(
'license_type' => 'flexible',
'require_attribution' => 1,
'allow_commercial' => 0,
'allow_modifications' => 'yes_with_notice',
'share_alike' => 1
),
array(
'license_type' => 'strict',
'require_attribution' => 1,
'allow_commercial' => 0,
'allow_modifications' => 'no',
'share_alike' => 0
)
);
foreach ($sample_licenses as $license) {
$wpdb->insert($table_name, $license);
}
}
// 注册激活钩子
register_activation_hook(__FILE__, 'wcl_create_database_tables');
?>
版权管理元框实现
在文章编辑页面添加版权管理元框:
<?php
/**
* 添加版权管理元框
*/
function wcl_add_license_meta_box() {
$post_types = array('post', 'page'); // 可以扩展到自定义文章类型
foreach ($post_types as $post_type) {
add_meta_box(
'wcl_license_meta_box',
__('文创作品版权设置', 'wp-cultural-license'),
'wcl_render_license_meta_box',
$post_type,
'side',
'high'
);
}
}
add_action('add_meta_boxes', 'wcl_add_license_meta_box');
/**
* 渲染版权管理元框内容
*/
function wcl_render_license_meta_box($post) {
// 添加安全验证
wp_nonce_field('wcl_save_license_data', 'wcl_license_nonce');
// 获取现有版权设置
$license_data = wcl_get_license_data($post->ID);
?>
<div class="wcl-license-settings">
<p>
<label for="wcl_license_type">
<strong><?php _e('版权类型:', 'wp-cultural-license'); ?></strong>
</label>
<select name="wcl_license_type" id="wcl_license_type" class="widefat">
<option value="standard" <?php selected($license_data['license_type'], 'standard'); ?>>
<?php _e('标准版权', 'wp-cultural-license'); ?>
</option>
<option value="flexible" <?php selected($license_data['license_type'], 'flexible'); ?>>
<?php _e('柔性版权', 'wp-cultural-license'); ?>
</option>
<option value="custom" <?php selected($license_data['license_type'], 'custom'); ?>>
<?php _e('自定义', 'wp-cultural-license'); ?>
</option>
</select>
</p>
<div id="wcl_flexible_options" style="display: <?php echo $license_data['license_type'] === 'flexible' ? 'block' : 'none'; ?>;">
<p>
<input type="checkbox" name="wcl_require_attribution" id="wcl_require_attribution"
value="1" <?php checked($license_data['require_attribution'], 1); ?>>
<label for="wcl_require_attribution">
<?php _e('要求署名', 'wp-cultural-license'); ?>
</label>
</p>
<p>
<input type="checkbox" name="wcl_allow_commercial" id="wcl_allow_commercial"
value="1" <?php checked($license_data['allow_commercial'], 1); ?>>
<label for="wcl_allow_commercial">
<?php _e('允许商业使用', 'wp-cultural-license'); ?>
</label>
</p>
<p>
<label for="wcl_allow_modifications">
<?php _e('允许修改:', 'wp-cultural-license'); ?>
</label>
<select name="wcl_allow_modifications" id="wcl_allow_modifications" class="widefat">
<option value="no" <?php selected($license_data['allow_modifications'], 'no'); ?>>
<?php _e('不允许', 'wp-cultural-license'); ?>
</option>
<option value="yes" <?php selected($license_data['allow_modifications'], 'yes'); ?>>
<?php _e('允许', 'wp-cultural-license'); ?>
</option>
<option value="yes_with_notice" <?php selected($license_data['allow_modifications'], 'yes_with_notice'); ?>>
<?php _e('允许但需通知', 'wp-cultural-license'); ?>
</option>
</select>
</p>
<p>
<input type="checkbox" name="wcl_share_alike" id="wcl_share_alike"
value="1" <?php checked($license_data['share_alike'], 1); ?>>
<label for="wcl_share_alike">
<?php _e('相同方式共享', 'wp-cultural-license'); ?>
</label>
</p>
</div>
<div id="wcl_custom_terms" style="display: <?php echo $license_data['license_type'] === 'custom' ? 'block' : 'none'; ?>;">
<p>
<label for="wcl_custom_terms_text">
<strong><?php _e('自定义条款:', 'wp-cultural-license'); ?></strong>
</label>
<textarea name="wcl_custom_terms" id="wcl_custom_terms_text"
class="widefat" rows="4"><?php echo esc_textarea($license_data['custom_terms']); ?></textarea>
</p>
</div>
</div>
<script>
jQuery(document).ready(function($) {
$('#wcl_license_type').change(function() {
var selected = $(this).val();
$('#wcl_flexible_options, #wcl_custom_terms').hide();
if (selected === 'flexible') {
$('#wcl_flexible_options').show();
} else if (selected === 'custom') {
$('#wcl_custom_terms').show();
}
});
});
</script>
<?php
}
/**
* 获取版权数据
*/
function wcl_get_license_data($post_id) {
global $wpdb;
$table_name = $wpdb->prefix . 'cultural_licenses';
$license = $wpdb->get_row($wpdb->prepare(
"SELECT * FROM $table_name WHERE post_id = %d",
$post_id
));
if ($license) {
return array(
'license_type' => $license->license_type,
'require_attribution' => $license->require_attribution,
'allow_commercial' => $license->allow_commercial,
'allow_modifications' => $license->allow_modifications,
'share_alike' => $license->share_alike,
'custom_terms' => $license->custom_terms
);
}
// 返回默认值
return array(
'license_type' => 'standard',
'require_attribution' => 1,
'allow_commercial' => 0,
'allow_modifications' => 'no',
'share_alike' => 0,
'custom_terms' => ''
);
}
?>
保存版权设置数据
<?php
/**
* 保存版权设置
*/
function wcl_save_license_data($post_id) {
// 检查自动保存
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// 验证nonce
if (!isset($_POST['wcl_license_nonce']) ||
!wp_verify_nonce($_POST['wcl_license_nonce'], 'wcl_save_license_data')) {
return;
}
// 检查用户权限
if (!current_user_can('edit_post', $post_id)) {
return;
}
// 准备数据
$license_data = array(
'post_id' => $post_id,
'license_type' => sanitize_text_field($_POST['wcl_license_type']),
'require_attribution' => isset($_POST['wcl_require_attribution']) ? 1 : 0,
'allow_commercial' => isset($_POST['wcl_allow_commercial']) ? 1 : 0,
'allow_modifications' => sanitize_text_field($_POST['wcl_allow_modifications']),
'share_alike' => isset($_POST['wcl_share_alike']) ? 1 : 0,
'custom_terms' => isset($_POST['wcl_custom_terms']) ?
sanitize_textarea_field($_POST['wcl_custom_terms']) : ''
);
// 保存到数据库
global $wpdb;
$table_name = $wpdb->prefix . 'cultural_licenses';
$existing = $wpdb->get_var($wpdb->prepare(
"SELECT id FROM $table_name WHERE post_id = %d",
$post_id
));
if ($existing) {
$wpdb->update($table_name, $license_data, array('post_id' => $post_id));
} else {
$wpdb->insert($table_name, $license_data);
}
}
add_action('save_post', 'wcl_save_license_data');
?>
前端版权信息显示
<?php
/**
* 在文章内容后显示版权信息
*/
function wcl_display_license_info($content) {
if (!is_single() && !is_page()) {
return $content;
}
global $post;
$license_data = wcl_get_license_data($post->ID);
if ($license_data['license_type'] === 'standard') {
return $content;
}
$license_html = '<div class="wcl-license-display" style="margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px;">';
$license_html .= '<h4>' . __('版权信息', 'wp-cultural-license') . '</h4>';
if ($license_data['license_type'] === 'flexible') {
$license_html .= '<p>' . __('本作品采用柔性版权许可', 'wp-cultural-license') . '</p>';
$license_html .= '<ul>';
if ($license_data['require_attribution']) {
$license_html .= '<li>' . __('✓ 必须署名原作者', 'wp-cultural-license') . '</li>';
}
if ($license_data['allow_commercial']) {
$license_html .= '<li>' . __('✓ 允许商业使用', 'wp-cultural-license') . '</li>';
} else {
$license_html .= '<li>' . __('✗ 禁止商业使用', 'wp-cultural-license') . '</li>';
}
$modification_text = array(
'no' => __('✗ 不允许修改', 'wp-cultural-license'),
'yes' => __('✓ 允许修改', 'wp-cultural-license'),
'yes_with_notice' => __('✓ 允许修改但需通知作者', 'wp-cultural-license')
);
$license_html .= '<li>' . $modification_text[$license_data['allow_modifications']] . '</li>';
if ($license_data['share_alike']) {
$license_html .= '<li>' . __('✓ 衍生作品必须采用相同许可', 'wp-cultural-license') . '</li>';
}
$license_html .= '</ul>';
} elseif ($license_data['license_type'] === 'custom' && !empty($license_data['custom_terms'])) {
$license_html .= '<p>' . esc_html($license_data['custom_terms']) . '</p>';
}
$license_html .= '</div>';
return $content . $license_html;
}
add_filter('the_content', 'wcl_display_license_info');
?>
版权验证API接口
<?php
/**
* 创建REST API端点用于版权验证
*/
function wcl_register_rest_routes() {
register_rest_route('wcl/v1', '/verify-license/(?P<id>d+)', array(
'methods' => 'GET',
'callback' => 'wcl_verify_license_api',
'permission_callback' => '__return_true',
'args' => array(
'id' => array(
'validate_callback' => function($param) {
return is_numeric($param);
}
)
)
));
register_rest_route('wcl/v1', '/check-usage', array(
'methods' => 'POST',
'callback' => 'wcl_check_usage_permission',
'permission_callback' => '__return_true'
));
}
add_action('rest_api_init', 'wcl_register_rest_routes');
/**
* 验证特定文章的版权信息
*/
function wcl_verify_license_api($request) {
$post_id = $request['id'];
$post = get_post($post_id);
if (!$post) {
return new WP_Error('not_found', '文章不存在', array('status' => 404));
}
$license_data = wcl_get_license_data($post_id);
$response = array(
'post_id' => $post_id,
'post_title' => $post->post_title,
'license_info' => $license_data,
'verification_date' => current_time('mysql')
);
return rest_ensure_response($response);
}
/**
* 检查使用权限
*/
function wcl_check_usage_permission($request) {
$parameters = $request->get_json_params();
$post_id = isset($parameters['post_id']) ? intval($parameters['post_id']) : 0;
$usage_type = isset($parameters['usage_type']) ? sanitize_text_field($parameters['usage_type']) : '';
$intended_modification = isset($parameters['modification']) ? boolval($parameters['modification']) : false;
$license_data = wcl_get_license_data($post_id);
$result = array(
'allowed' => true,
'conditions' => array()
);
// 检查商业使用
if ($usage_type === 'commercial' && !$license_data['allow_commercial']) {
$result['allowed'] = false;
$result['conditions'][] = '商业使用不被允许';
}
// 检查修改权限
if ($intended_modification && $license_data['allow_modifications'] === 'no') {
$result['conditions'][] = '修改作品不被允许';
}
// 检查署名要求
if ($license_data['require_attribution']) {
$result['conditions'][] = '必须署名原作者';
}
// 检查相同方式共享
if ($license_data['share_alike']) {
$result['conditions'][] = '衍生作品必须采用相同许可';
}
return rest_ensure_response($result);
}
?>
## 版权水印和元数据管理
<?php
/**
- 为图片添加版权水印(仅适用于柔性版权作品)
*/
function wcl_add_watermark_to_images($html, $post_id) {
// 检查是否为柔性版权
$license_data = wcl_get_license_data($post_id);
if ($license_data['license_type'] !== 'flexible' ||
!$license_data['require_attribution']) {
return $html;
}
// 使用DOMDocument处理图片
if (class_exists('DOMDocument')) {
$dom = new DOMDocument();
@$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
// 添加data-license属性
$image->setAttribute('data-license', 'flexible');
// 添加alt属性中的版权信息
$current_alt = $image->getAttribute('alt');
$post_title = get_the_title($post_id);
$new_alt = $current_alt . ' | ' . sprintf(__('版权归属: %s', 'wp-cultural-license'), $post_title);
$image->setAttribute('alt', $new_alt);
// 添加title属性
$image->setAttribute('title', sprintf(__('本图片采用柔性版权许可 - %s', 'wp-cultural-license'), get_bloginfo('name')));
}
// 保存修改后的HTML
$html = $dom->saveHTML();
}
return $html;
}
add_filter('the_content', 'wcl_add_watermark_to_images', 20, 2);
/**
- 在图片附件页面添加版权信息
*/
function wcl_add_attachment_license_info($content) {
if (!is_attachment()) {
return $content;
}
$attachment_id = get_the_ID();
$parent_post_id = wp_get_post_parent_id($attachment_id);
if ($parent_post_id) {
$license_data = wcl_get_license_data($parent_post_id);
if ($license_data['license_type'] !== 'standard') {
$license_info = '<div class="attachment-license-info">';
$license_info .= '<h3>' . __('版权许可信息', 'wp-cultural-license') . '</h3>';
$license_info .= '<p>' . __('本附件所属文章采用特殊版权许可:', 'wp-cultural-license') . '</p>';
if ($license_data['license_type'] === 'flexible') {
$conditions = array();
if ($license_data['require_attribution']) {
$conditions[] = __('必须署名', 'wp-cultural-license');
}
if (!$license_data['allow_commercial']) {
$conditions[] = __('非商业使用', 'wp-cultural-license');
}
if ($license_data['allow_modifications'] !== 'yes') {
$conditions[] = __('限制修改', 'wp-cultural-license');
}
$license_info .= '<p>' . implode(' | ', $conditions) . '</p>';
}
$license_info .= '</div>';
$content .= $license_info;
}
}
return $content;
}
add_filter('the_content', 'wcl_add_attachment_license_info');
?>
## 版权使用统计和报告
<?php
<?php
/**
- 记录版权使用情况
*/
function wcl_log_license_usage() {
if (!is_single() && !is_page()) {
return;
}
global $post;
$license_data = wcl_get_license_data($post->ID);
if ($license_data['license_type'] === 'standard') {
return;
}
$usage_data = array(
'post_id' => $post->ID,
'user_ip' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
'access_time' => current_time('mysql'),
'license_type' => $license_data['license_type']
);
// 存储使用记录(简化版,实际应用中可能需要更复杂的存储)
$usage_log = get_option('wcl_usage_log', array());
$usage_log[] = $usage_data;
// 只保留最近1000条记录
if (count($usage_log) > 1000) {
$usage_log = array_slice($usage_log, -1000);
}
update_option('wcl_usage_log', $usage_log);
}
add_action('wp', 'wcl_log_license_usage');
/**
- 生成版权使用报告
*/
function wcl_generate_license_report() {
$usage_log = get_option('wcl_usage_log', array());
if (empty($usage_log)) {
return __('暂无使用数据', 'wp-cultural-license');
}
$report = array();
// 按文章ID统计
foreach ($usage_log as $log) {
$post_id = $log['post_id'];
if (!isset($report[$post_id])) {
$report[$post_id] = array(
'title' => get_the_title($post_id),
'count' => 0,
'license_type' => $log['license_type']
);
}
$report[$post_id]['count']++;
}
// 生成HTML报告
$html = '<div class="wcl-license-report">';
$html .= '<h3>' . __('柔性版权使用统计', 'wp-cultural-license') . '</h3>';
$html .= '<table class="wp-list-table widefat fixed striped">';
$html .= '<thead><tr>';
$html .= '<th>' . __('文章标题', 'wp-cultural-license') . '</th>';
$html .= '<th>' . __('版权类型', 'wp-cultural-license') . '</th>';
$html .= '<th>' . __('访问次数', 'wp-cultural-license') . '</th>';
$html .= '</tr></thead><tbody>';
foreach ($report as $post_id => $data) {
$html .= '<tr>';
$html .= '<td>' . esc_html($data['title']) . '</td>';
$html .= '<td>' . esc_html($data['license_type']) . '</td>';
$html .= '<td>' . $data['count'] . '</td>';
$html .= '</tr>';
}
$html .= '</tbody></table>';
$html .= '</div>';
return $html;
}
/**
- 添加管理页面
*/
function wcl_add_admin_page() {
add_menu_page(
__('文创版权管理', 'wp-cultural-license'),
__('版权管理', 'wp-cultural-license'),
'manage_options',
'wcl-license-manager',
'wcl_render_admin_page',
'dashicons-media-text',
30
);
}
add_action('admin_menu', 'wcl_add_admin_page');
/**
- 渲染管理页面
*/
function wcl_render_admin_page() {
?>
<div class="wrap">
<h1><?php _e('文创柔性版权管理系统', 'wp-cultural-license'); ?></h1>
<div class="wcl-admin-container">
<div class="wcl-admin-section">
<h2><?php _e('使用统计', 'wp-cultural-license'); ?></h2>
<?php echo wcl_generate_license_report(); ?>
</div>
<div class="wcl-admin-section">
<h2><?php _e('批量设置', 'wp-cultural-license'); ?></h2>
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
<input type="hidden" name="action" value="wcl_batch_update">
<?php wp_nonce_field('wcl_batch_update_action', 'wcl_batch_nonce'); ?>
<p>
<label for="batch_license_type">
<?php _e('批量设置版权类型:', 'wp-cultural-license'); ?>
</label>
<select name="batch_license_type" id="batch_license_type">
<option value="standard"><?php _e('标准版权', 'wp-cultural-license'); ?></option>
<option value="flexible"><?php _e('柔性版权', 'wp-cultural-license'); ?></option>
</select>
</p>
<p>
<label for="post_types">
<?php _e('应用于文章类型:', 'wp-cultural-license'); ?>
</label><br>
<input type="checkbox" name="post_types[]" value="post" checked> <?php _e('文章', 'wp-cultural-license'); ?><br>
<input type="checkbox" name="post_types[]" value="page"> <?php _e('页面', 'wp-cultural-license'); ?>
</p>
<p>
<input type="submit" class="button button-primary" value="<?php _e('批量更新', 'wp-cultural-license'); ?>">
</p>
</form>
</div>
</div>
</div>
<style>
.wcl-admin-container {
display: grid;
grid-template-columns: 2fr 1fr;
gap: 20px;
margin-top: 20px;
}
.wcl-admin-section {
background: #fff;
padding: 20px;
border: 1px solid #ccd0d4;
border-radius: 4px;
}
</style>
<?php
}
/**
- 处理批量更新
*/
function wcl_handle_batch_update() {
// 验证nonce和权限
if (!isset($_POST['wcl_batch_nonce']) ||
!wp_verify_nonce($_POST['wcl_batch_nonce'], 'wcl_batch_update_action') ||
!current_user_can('manage_options')) {
wp_die(__('权限不足', 'wp-cultural-license'));
}
$license_type = sanitize_text_field($_POST['batch_license_type']);
$post_types = isset($_POST['post_types']) ? array_map('sanitize_text_field', $_POST['post_types']) : array('post');
// 批量更新文章
$args = array(
'post_type' => $post_types,
'posts_per_page' => -1,
'post_status' => 'publish'
);
$query = new WP_Query($args);
$updated_count = 0;
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
// 更新版权设置
global $wpdb;
$table_name = $wpdb->prefix . 'cultural_licenses';
$existing = $wpdb->get_var($wpdb->prepare(
"SELECT id FROM $table_name WHERE post_id = %d",
$post_id
));
$license_data = array(
'post_id' => $post_id,
'license_type' => $license_type,
'require_attribution' => 1,
'allow_commercial' => 0,
'allow_modifications' => 'no',
'share_alike' => 0
);
if ($existing) {
$wpdb->update($table_name, $license_data, array('post_id' => $post_id));
} else {
$wpdb->insert($table_name, $license_data);
}
$updated_count++;
}
wp_reset_postdata();
}
// 重定向回管理页面
wp_redirect(add_query_arg(
array(
'page' => 'wcl-license-manager',
'updated' => $updated_count
),
admin_url('admin.php')
));
exit;
}
add_action('admin_post_wcl_batch_update', 'wcl_handle_batch_update');
?>
## 插件优化和国际化
<?php
/**
- 加载文本域
*/
function wcl_load_textdomain() {
load_plugin_textdomain(
'wp-cultural-license',
false,
dirname(plugin_basename(__FILE__)) . '/languages'
);
}
add_action('plugins_loaded', 'wcl_load_textdomain');
/**
- 添加设置链接
*/
function wcl_add_settings_link($links) {
$settings_link = '<a href="admin.php?page=wcl-license-manager">' .
__('设置', 'wp-cultural-license') . '</a>';
array_unshift($links, $settings_link);
return $links;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wcl_add_settings_link');
/**
- 清理数据
*/
function wcl_cleanup_data() {
global $wpdb;
$table_name = $wpdb->prefix . 'cultural_licenses';
// 删除不存在的文章对应的版权记录
$wpdb->query("DELETE FROM $table_name WHERE post_id NOT IN (SELECT ID FROM {$wpdb->posts})");
}
add_action('wcl_daily_cleanup', 'wcl_cleanup_data');
/**
- 安排定时任务
*/
function wcl_schedule_cleanup() {
if (!wp_next_scheduled('wcl_daily_cleanup')) {
wp_schedule_event(time(), 'daily', 'wcl_daily_cleanup');
}
}
register_activation_hook(__FILE__, 'wcl_schedule_cleanup');
/**
- 清除定时任务
*/
function wcl_unschedule_cleanup() {
$timestamp = wp_next_scheduled('wcl_daily_cleanup');
if ($timestamp) {
wp_unschedule_event($timestamp, 'wcl_daily_cleanup');
}
}
register_deactivation_hook(__FILE__, 'wcl_unschedule_cleanup');
?>
## 总结与扩展建议
通过本教程,我们成功构建了一个完整的WordPress文创柔性版权管理插件。该插件实现了:
1. **灵活的版权设置**:支持标准版权、柔性版权和自定义版权
2. **完整的元数据管理**:在数据库和文章编辑界面中管理版权信息
3. **前端展示**:自动在文章末尾显示版权信息
4. **API接口**:提供版权验证和使用权限检查
5. **使用统计**:记录和报告版权使用情况
6. **管理界面**:提供批量操作和统计查看功能
### 扩展建议:
1. **与水印插件集成**:为图片添加可见的版权水印
2. **数字签名**:为作品添加区块链数字签名
3. **授权管理**:创建授权证书生成和验证系统
4. **支付集成**:支持付费获取更宽松的版权许可
5. **社交分享集成**:在分享时自动包含版权信息
6. **多语言支持**:完善国际化,支持更多语言
### 性能优化建议:
1. 添加缓存机制,减少数据库查询
2. 使用索引优化数据库表
3. 实现懒加载版权信息
4. 添加CDN支持
