mirror of
https://github.com/WenPai-org/wpavatar.git
synced 2025-08-08 02:39:12 +08:00
v1.9.2 稳定版发布
This commit is contained in:
parent
88d798a5a5
commit
dc54b02c54
7 changed files with 1090 additions and 165 deletions
|
@ -20,6 +20,7 @@ jQuery(document).ready(function($) {
|
|||
$('.wpavatar-section').hide();
|
||||
$('#wpavatar-section-' + tab).show();
|
||||
|
||||
// 当切换到缓存标签页时自动检查缓存状态
|
||||
if (tab === 'cache' && $('#cache-stats').is(':empty')) {
|
||||
setTimeout(function() {
|
||||
if (wpavatar.is_network_admin === '1') {
|
||||
|
@ -30,6 +31,11 @@ jQuery(document).ready(function($) {
|
|||
}, 300);
|
||||
}
|
||||
|
||||
// 当切换到营销组件标签页时的特殊处理
|
||||
if (tab === 'marketing') {
|
||||
// 可以在这里添加特殊初始化代码,如果需要的话
|
||||
}
|
||||
|
||||
if (window.history && window.history.pushState) {
|
||||
var url = new URL(window.location.href);
|
||||
url.searchParams.set('tab', tab);
|
||||
|
@ -323,6 +329,47 @@ jQuery(document).ready(function($) {
|
|||
return true;
|
||||
});
|
||||
|
||||
// 添加营销组件表单的验证
|
||||
$('#wpavatar-marketing-form').on('submit', function(e) {
|
||||
var isValid = true;
|
||||
var $status = $('#wpavatar-status');
|
||||
|
||||
// 验证最近评论者设置
|
||||
var commentersCount = parseInt($('input[name="wpavatar_commenters_count"]').val());
|
||||
var commentersSize = parseInt($('input[name="wpavatar_commenters_size"]').val());
|
||||
|
||||
if (isNaN(commentersCount) || commentersCount < 1 || commentersCount > 50) {
|
||||
$status.removeClass('notice-success').addClass('notice-error').text('请设置有效的评论者显示数量(1-50)').show();
|
||||
$('input[name="wpavatar_commenters_count"]').focus();
|
||||
isValid = false;
|
||||
} else if (isNaN(commentersSize) || commentersSize < 20 || commentersSize > 150) {
|
||||
$status.removeClass('notice-success').addClass('notice-error').text('请设置有效的评论者头像大小(20-150像素)').show();
|
||||
$('input[name="wpavatar_commenters_size"]').focus();
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// 验证用户设置
|
||||
var usersCount = parseInt($('input[name="wpavatar_users_count"]').val());
|
||||
var usersSize = parseInt($('input[name="wpavatar_users_size"]').val());
|
||||
|
||||
if (isNaN(usersCount) || usersCount < 1 || usersCount > 50) {
|
||||
$status.removeClass('notice-success').addClass('notice-error').text('请设置有效的用户显示数量(1-50)').show();
|
||||
$('input[name="wpavatar_users_count"]').focus();
|
||||
isValid = false;
|
||||
} else if (isNaN(usersSize) || usersSize < 20 || usersSize > 150) {
|
||||
$status.removeClass('notice-success').addClass('notice-error').text('请设置有效的用户头像大小(20-150像素)').show();
|
||||
$('input[name="wpavatar_users_size"]').focus();
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// For network import and bulk operations
|
||||
if ($('#import-site-settings').length) {
|
||||
$('#import-site-settings').on('click', function(e) {
|
||||
|
@ -369,8 +416,8 @@ jQuery(document).ready(function($) {
|
|||
// Applied to all sites notification
|
||||
if (window.location.search.indexOf('applied=true') > -1) {
|
||||
$('#wpavatar-status')
|
||||
.removeClass('notice-error')
|
||||
.addClass('notice-success')
|
||||
.removeClass('notice-success')
|
||||
.addClass('notice-error')
|
||||
.text('网络设置已成功应用到所有站点。')
|
||||
.show()
|
||||
.delay(3000)
|
||||
|
|
|
@ -43,6 +43,12 @@ class Settings {
|
|||
register_setting('wpavatar_shortcodes', 'wpavatar_shortcode_size', ['type' => 'integer']);
|
||||
register_setting('wpavatar_shortcodes', 'wpavatar_shortcode_class', ['type' => 'string']);
|
||||
register_setting('wpavatar_shortcodes', 'wpavatar_shortcode_shape', ['type' => 'string']);
|
||||
|
||||
// 注册营销组件设置
|
||||
register_setting('wpavatar_marketing', 'wpavatar_commenters_count', ['type' => 'integer']);
|
||||
register_setting('wpavatar_marketing', 'wpavatar_commenters_size', ['type' => 'integer']);
|
||||
register_setting('wpavatar_marketing', 'wpavatar_users_count', ['type' => 'integer']);
|
||||
register_setting('wpavatar_marketing', 'wpavatar_users_size', ['type' => 'integer']);
|
||||
}
|
||||
|
||||
public static function sanitize_cache_path($value) {
|
||||
|
@ -164,10 +170,11 @@ class Settings {
|
|||
settings_errors('wpavatar_cache');
|
||||
settings_errors('wpavatar_advanced');
|
||||
settings_errors('wpavatar_shortcodes');
|
||||
settings_errors('wpavatar_marketing');
|
||||
}
|
||||
|
||||
public static function render_settings_page() {
|
||||
// Check for network control in multisite
|
||||
// 检查多站点网络控制
|
||||
if (is_multisite()) {
|
||||
$network_enabled = get_site_option('wpavatar_network_enabled', 1);
|
||||
$network_enforce = get_site_option('wpavatar_network_enforce', 0);
|
||||
|
@ -182,9 +189,9 @@ class Settings {
|
|||
?>
|
||||
<div class="wrap wpavatar-settings">
|
||||
<h1><?php esc_html_e('文派头像设置', 'wpavatar'); ?>
|
||||
<span style="font-size: 13px; padding-left: 10px;"><?php printf(esc_html__('Version: %s', 'wpavatar'), esc_html(WPAVATAR_VERSION)); ?></span>
|
||||
<a href="https://wpavatar.com/document/" target="_blank" class="button button-secondary" style="margin-left: 10px;"><?php esc_html_e('Document', 'wpavatar'); ?></a>
|
||||
<a href="https://sharecms.com/forums/" target="_blank" class="button button-secondary"><?php esc_html_e('Support', 'wpavatar'); ?></a>
|
||||
<span style="font-size: 13px; padding-left: 10px;"><?php printf(esc_html__('版本: %s', 'wpavatar'), esc_html(WPAVATAR_VERSION)); ?></span>
|
||||
<a href="https://wpavatar.com/document/" target="_blank" class="button button-secondary" style="margin-left: 10px;"><?php esc_html_e('文档', 'wpavatar'); ?></a>
|
||||
<a href="https://cravatar.com/forums/" target="_blank" class="button button-secondary"><?php esc_html_e('支持', 'wpavatar'); ?></a>
|
||||
</h1>
|
||||
|
||||
<div id="wpavatar-status" class="notice" style="display:none; margin-top: 10px;"></div>
|
||||
|
@ -203,6 +210,9 @@ class Settings {
|
|||
<button type="button" class="wpavatar-tab <?php echo $active_tab === 'shortcodes' ? 'active' : ''; ?>" data-tab="shortcodes">
|
||||
<?php _e('头像简码', 'wpavatar'); ?>
|
||||
</button>
|
||||
<button type="button" class="wpavatar-tab <?php echo $active_tab === 'marketing' ? 'active' : ''; ?>" data-tab="marketing">
|
||||
<?php _e('营销组件', 'wpavatar'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -338,7 +348,7 @@ class Settings {
|
|||
<span class="wpavatar-radio-label"><?php _e('SHA256 (Gravatar默认)', 'wpavatar'); ?></span>
|
||||
</label>
|
||||
<p class="description"><?php _e('选择头像邮箱的哈希方法,Cravatar目前使用MD5,一般Gravatar镜像均为SHA256', 'wpavatar'); ?></p>
|
||||
<p class="description hash-method-notice" style="color: #d63638; <?php echo $cdn_type !== 'cravatar_route' ? 'display:none;' : ''; ?>"><?php _e('注意:使用Cravatar服务时,哈希方法将仅使用MD5。', 'wpavatar'); ?> <a href="https://cravatar.com/docs" target="_blank" rel="noopener noreferrer"><?php _e('进一步了解↗', 'wpavatar'); ?></a></p>
|
||||
<p class="description hash-method-notice" style="color: #d63638; <?php echo $cdn_type !== 'cravatar_route' ? 'display:none;' : ''; ?>"><?php _e('注意:使用Cravatar服务时,哈希方法将仅使用MD5。', 'wpavatar'); ?> <a href="https://cravatar.com/document/?p=46" target="_blank" rel="noopener noreferrer"><?php _e('进一步了解↗', 'wpavatar'); ?></a></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -694,6 +704,37 @@ class Settings {
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 营销组件标签页 -->
|
||||
<div class="wpavatar-section" id="wpavatar-section-marketing" style="<?php echo $active_tab !== 'marketing' ? 'display: none;' : ''; ?>">
|
||||
<h2><?php _e('营销组件设置', 'wpavatar'); ?></h2>
|
||||
<p class="wpavatar-section-desc"><?php _e('配置营销组件简码和显示效果。', 'wpavatar'); ?></p>
|
||||
|
||||
<?php if (is_multisite() && $network_enabled): ?>
|
||||
<div class="wpavatar-network-notice">
|
||||
<p>
|
||||
<?php if (in_array('wpavatar_commenters_count', $network_controlled_options)): ?>
|
||||
<span class="dashicons dashicons-lock"></span> <?php _e('评论者数量', 'wpavatar'); ?><br>
|
||||
<?php endif; ?>
|
||||
<?php if (in_array('wpavatar_commenters_size', $network_controlled_options)): ?>
|
||||
<span class="dashicons dashicons-lock"></span> <?php _e('评论者头像大小', 'wpavatar'); ?><br>
|
||||
<?php endif; ?>
|
||||
<?php if (in_array('wpavatar_users_count', $network_controlled_options)): ?>
|
||||
<span class="dashicons dashicons-lock"></span> <?php _e('用户数量', 'wpavatar'); ?><br>
|
||||
<?php endif; ?>
|
||||
<?php if (in_array('wpavatar_users_size', $network_controlled_options)): ?>
|
||||
<span class="dashicons dashicons-lock"></span> <?php _e('用户头像大小', 'wpavatar'); ?><br>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (array_intersect(['wpavatar_commenters_count', 'wpavatar_commenters_size', 'wpavatar_users_count', 'wpavatar_users_size'], $network_controlled_options)): ?>
|
||||
<em><?php _e('以上选项由网络管理员控制,您的更改将不会生效。', 'wpavatar'); ?></em>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php \WPAvatar\Marketing::render_admin_page(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
|
@ -780,5 +821,5 @@ class Settings {
|
|||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -957,8 +957,12 @@ class Cache {
|
|||
$user = wp_get_current_user();
|
||||
}
|
||||
|
||||
$username = $user && $user->display_name ? $user->display_name : __('匿名用户', 'wpavatar');
|
||||
return $atts['before'] . $username . $atts['after'];
|
||||
// 检查用户是否已登录且有显示名称,如果没有则返回空字符串
|
||||
if (!$user || !$user->ID || empty($user->display_name)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $atts['before'] . $user->display_name . $atts['after'];
|
||||
}
|
||||
|
||||
public static function menu_item_replace($item_output, $item, $depth, $args) {
|
||||
|
|
573
includes/marketing.php
Normal file
573
includes/marketing.php
Normal file
|
@ -0,0 +1,573 @@
|
|||
<?php
|
||||
namespace WPAvatar;
|
||||
|
||||
/**
|
||||
* Marketing Class
|
||||
*
|
||||
* 处理营销组件相关的功能和管理界面
|
||||
*/
|
||||
class Marketing {
|
||||
/**
|
||||
* 初始化营销组件功能
|
||||
*/
|
||||
public static function init() {
|
||||
// 注册短代码
|
||||
add_shortcode('wpavatar_latest_commenters', [__CLASS__, 'render_latest_commenters']);
|
||||
add_shortcode('wpavatar_latest_users', [__CLASS__, 'render_latest_users']);
|
||||
add_shortcode('wpavatar_random_users', [__CLASS__, 'render_random_users']);
|
||||
add_shortcode('wpavatar_author', [__CLASS__, 'render_author_avatar']);
|
||||
|
||||
// 添加头像样式
|
||||
add_action('wp_head', [__CLASS__, 'add_frontend_styles']);
|
||||
|
||||
// 如果是管理员界面,添加管理界面功能
|
||||
if (is_admin()) {
|
||||
add_action('admin_init', [__CLASS__, 'register_settings']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册设置字段
|
||||
*/
|
||||
public static function register_settings() {
|
||||
register_setting('wpavatar_marketing', 'wpavatar_commenters_count', ['type' => 'integer', 'default' => 15]);
|
||||
register_setting('wpavatar_marketing', 'wpavatar_commenters_size', ['type' => 'integer', 'default' => 45]);
|
||||
register_setting('wpavatar_marketing', 'wpavatar_users_count', ['type' => 'integer', 'default' => 15]);
|
||||
register_setting('wpavatar_marketing', 'wpavatar_users_size', ['type' => 'integer', 'default' => 40]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前端样式
|
||||
*/
|
||||
public static function add_frontend_styles() {
|
||||
echo '
|
||||
<style>
|
||||
/* 最近评论者头像样式 */
|
||||
.wpavatar-latest-commenters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.wpavatar-latest-commenters .comment-avatar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
.wpavatar-latest-commenters .comment-avatar a {
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
margin-left: -15px;
|
||||
}
|
||||
.wpavatar-latest-commenters .comment-avatar:first-child a {
|
||||
margin-left: 0;
|
||||
}
|
||||
.wpavatar-latest-commenters .comment-avatar img {
|
||||
border-radius: 50%;
|
||||
width: auto;
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 1px 0 1px rgba(0, 0, 0, .1);
|
||||
border: 3px solid #FFF;
|
||||
position: relative;
|
||||
}
|
||||
.wpavatar-latest-commenters .comment-avatar img:hover {
|
||||
border: 3px solid #000;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
/* 用户头像列表样式 */
|
||||
.wpavatar-latest-users,
|
||||
.wpavatar-random-users {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 15px;
|
||||
justify-content: center;
|
||||
}
|
||||
.wpavatar-latest-user,
|
||||
.wpavatar-random-user {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
width: 80px;
|
||||
}
|
||||
.wpavatar-latest-user img,
|
||||
.wpavatar-random-user img {
|
||||
border-radius: 50%;
|
||||
margin-bottom: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.wpavatar-latest-user-name,
|
||||
.wpavatar-random-user-name {
|
||||
font-size: 12px;
|
||||
line-height: 1.3;
|
||||
margin-top: 5px;
|
||||
word-break: break-word;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
';
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染最近评论者头像
|
||||
*/
|
||||
public static function render_latest_commenters($atts) {
|
||||
$default_count = wpavatar_get_option('wpavatar_commenters_count', 15);
|
||||
$default_size = wpavatar_get_option('wpavatar_commenters_size', 45);
|
||||
|
||||
$atts = shortcode_atts([
|
||||
'size' => $default_size,
|
||||
'number' => $default_count,
|
||||
], $atts, 'wpavatar_latest_commenters');
|
||||
|
||||
// 获取全部文章的最新评论,限制为指定的评论者数量
|
||||
$comments = get_comments(array(
|
||||
'number' => $atts['number'] * 3, // 获取更多评论以确保有足够不重复的评论者
|
||||
'status' => 'approve',
|
||||
));
|
||||
|
||||
if (empty($comments)) {
|
||||
return '<div class="wpavatar-latest-commenters">暂无评论用户头像</div>';
|
||||
}
|
||||
|
||||
// 初始化一个数组用于存储已显示的评论者
|
||||
$seen_emails = array();
|
||||
$output = '<div class="wpavatar-latest-commenters">';
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
// 检查评论者的电子邮件地址
|
||||
$comment_email = $comment->comment_author_email;
|
||||
|
||||
// 如果该评论者已经显示过,则跳过
|
||||
if (in_array($comment_email, $seen_emails) || empty($comment_email)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取评论的链接
|
||||
$comment_link = get_comment_link($comment);
|
||||
|
||||
// 创建带链接的头像
|
||||
$avatar_with_link = '<a href="' . esc_url($comment_link) . '" title="' . esc_attr($comment->comment_author) . '">';
|
||||
$avatar_with_link .= get_avatar($comment, $atts['size'], '', $comment->comment_author);
|
||||
$avatar_with_link .= '</a>';
|
||||
|
||||
// 添加头像到输出
|
||||
$output .= '<div class="comment-avatar">' . $avatar_with_link . '</div>';
|
||||
|
||||
// 记录该评论者,防止重复显示
|
||||
$seen_emails[] = $comment_email;
|
||||
|
||||
// 如果已经达到了显示数量限制,跳出循环
|
||||
if (count($seen_emails) >= $atts['number']) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染最新用户头像
|
||||
*/
|
||||
public static function render_latest_users($atts) {
|
||||
$default_count = wpavatar_get_option('wpavatar_users_count', 15);
|
||||
$default_size = wpavatar_get_option('wpavatar_users_size', 40);
|
||||
|
||||
$atts = shortcode_atts([
|
||||
'number' => $default_count,
|
||||
'size' => $default_size
|
||||
], $atts);
|
||||
|
||||
$users = get_users([
|
||||
'orderby' => 'registered',
|
||||
'order' => 'DESC',
|
||||
'number' => $atts['number']
|
||||
]);
|
||||
|
||||
if (empty($users)) {
|
||||
return '<div class="wpavatar-latest-users">暂无用户</div>';
|
||||
}
|
||||
|
||||
$output = '<div class="wpavatar-latest-users">';
|
||||
foreach ($users as $user) {
|
||||
$output .= '<div class="wpavatar-latest-user">';
|
||||
$output .= get_avatar($user->ID, $atts['size'], '', $user->display_name);
|
||||
$output .= '<div class="wpavatar-latest-user-name">' . esc_html($user->display_name) . '</div>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染随机用户头像
|
||||
*/
|
||||
public static function render_random_users($atts) {
|
||||
$default_count = wpavatar_get_option('wpavatar_users_count', 15);
|
||||
$default_size = wpavatar_get_option('wpavatar_users_size', 40);
|
||||
|
||||
$atts = shortcode_atts([
|
||||
'number' => $default_count,
|
||||
'size' => $default_size
|
||||
], $atts);
|
||||
|
||||
$args = [
|
||||
'orderby' => 'registered',
|
||||
'order' => 'DESC',
|
||||
'number' => intval($atts['number']) * 2 // 获取更多用户以便随机选择
|
||||
];
|
||||
$users = get_users($args);
|
||||
|
||||
if (empty($users)) {
|
||||
return '<div class="wpavatar-random-users">暂无用户</div>';
|
||||
}
|
||||
|
||||
// 打乱用户数组以随机化顺序
|
||||
shuffle($users);
|
||||
|
||||
// 限制显示的用户数量
|
||||
$users = array_slice($users, 0, intval($atts['number']));
|
||||
|
||||
$output = '<div class="wpavatar-random-users">';
|
||||
foreach ($users as $user) {
|
||||
$output .= '<div class="wpavatar-random-user">';
|
||||
$output .= get_avatar($user->ID, $atts['size'], '', $user->display_name);
|
||||
$output .= '<div class="wpavatar-random-user-name">' . esc_html($user->display_name) . '</div>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染文章作者头像
|
||||
*/
|
||||
public static function render_author_avatar($atts) {
|
||||
$atts = shortcode_atts([
|
||||
'size' => '96',
|
||||
], $atts);
|
||||
|
||||
$post_id = get_the_ID();
|
||||
if (!$post_id) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$author_id = get_post_field('post_author', $post_id);
|
||||
if (!$author_id) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$avatar = get_avatar($author_id, $atts['size']);
|
||||
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成预览头像
|
||||
*/
|
||||
public static function generate_preview($shape = 'square', $size = 96, $count = 6) {
|
||||
global $wpdb;
|
||||
|
||||
// 获取最近的评论者
|
||||
$sql = "SELECT DISTINCT comment_author_email, comment_author
|
||||
FROM {$wpdb->comments}
|
||||
WHERE comment_approved = '1'
|
||||
AND comment_author_email != ''
|
||||
ORDER BY comment_date DESC
|
||||
LIMIT %d";
|
||||
|
||||
$commenters = $wpdb->get_results($wpdb->prepare($sql, $count));
|
||||
|
||||
$output = '<div class="wpavatar-preview-grid">';
|
||||
|
||||
if (!empty($commenters)) {
|
||||
$output .= '<div class="preview-section">';
|
||||
$output .= '<h4>最近评论者预览</h4>';
|
||||
$output .= '<div class="wpavatar-preview-commenters">';
|
||||
|
||||
foreach ($commenters as $commenter) {
|
||||
if (empty($commenter->comment_author_email)) continue;
|
||||
|
||||
$output .= '<div class="preview-item">';
|
||||
$avatar_args = [
|
||||
'class' => 'preview-avatar',
|
||||
'size' => $size
|
||||
];
|
||||
|
||||
if ($shape === 'circle') {
|
||||
$avatar_args['extra_attr'] = 'style="border-radius: 50%; overflow: hidden;"';
|
||||
} elseif ($shape === 'rounded') {
|
||||
$avatar_args['extra_attr'] = 'style="border-radius: 8px; overflow: hidden;"';
|
||||
}
|
||||
|
||||
$output .= get_avatar($commenter->comment_author_email, $size, '', $commenter->comment_author, $avatar_args);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
// 获取最新用户
|
||||
$recent_users = get_users([
|
||||
'orderby' => 'registered',
|
||||
'order' => 'DESC',
|
||||
'number' => $count
|
||||
]);
|
||||
|
||||
if (!empty($recent_users)) {
|
||||
$output .= '<div class="preview-section">';
|
||||
$output .= '<h4>最新用户预览</h4>';
|
||||
$output .= '<div class="wpavatar-preview-users">';
|
||||
|
||||
foreach ($recent_users as $user) {
|
||||
$output .= '<div class="preview-item">';
|
||||
$avatar_args = [
|
||||
'class' => 'preview-avatar',
|
||||
'size' => $size
|
||||
];
|
||||
|
||||
if ($shape === 'circle') {
|
||||
$avatar_args['extra_attr'] = 'style="border-radius: 50%; overflow: hidden;"';
|
||||
} elseif ($shape === 'rounded') {
|
||||
$avatar_args['extra_attr'] = 'style="border-radius: 8px; overflow: hidden;"';
|
||||
}
|
||||
|
||||
$output .= get_avatar($user->ID, $size, '', $user->display_name, $avatar_args);
|
||||
$output .= '<span class="preview-name">' . esc_html($user->display_name) . '</span>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染管理界面
|
||||
*/
|
||||
public static function render_admin_page() {
|
||||
// 使用wpavatar_get_option而不是get_option获取设置
|
||||
$commenters_count = wpavatar_get_option('wpavatar_commenters_count', 15);
|
||||
$commenters_size = wpavatar_get_option('wpavatar_commenters_size', 45);
|
||||
$users_count = wpavatar_get_option('wpavatar_users_count', 15);
|
||||
$users_size = wpavatar_get_option('wpavatar_users_size', 40);
|
||||
|
||||
// 检查多站点网络控制
|
||||
$is_option_disabled = false;
|
||||
if (is_multisite() && get_site_option('wpavatar_network_enabled', 1)) {
|
||||
$network_controlled_options = get_site_option('wpavatar_network_controlled_options', array());
|
||||
if (!is_array($network_controlled_options)) {
|
||||
$network_controlled_options = explode(',', $network_controlled_options);
|
||||
}
|
||||
|
||||
// 检查营销组件选项是否由网络控制
|
||||
$is_commenters_count_disabled = in_array('wpavatar_commenters_count', $network_controlled_options) ? 'disabled' : '';
|
||||
$is_commenters_size_disabled = in_array('wpavatar_commenters_size', $network_controlled_options) ? 'disabled' : '';
|
||||
$is_users_count_disabled = in_array('wpavatar_users_count', $network_controlled_options) ? 'disabled' : '';
|
||||
$is_users_size_disabled = in_array('wpavatar_users_size', $network_controlled_options) ? 'disabled' : '';
|
||||
|
||||
// 检查是否强制使用网络设置
|
||||
if (get_site_option('wpavatar_network_enforce', 0)) {
|
||||
$is_commenters_count_disabled = 'disabled';
|
||||
$is_commenters_size_disabled = 'disabled';
|
||||
$is_users_count_disabled = 'disabled';
|
||||
$is_users_size_disabled = 'disabled';
|
||||
}
|
||||
} else {
|
||||
$is_commenters_count_disabled = '';
|
||||
$is_commenters_size_disabled = '';
|
||||
$is_users_count_disabled = '';
|
||||
$is_users_size_disabled = '';
|
||||
}
|
||||
|
||||
?>
|
||||
<form method="post" action="options.php" id="wpavatar-marketing-form">
|
||||
<?php settings_fields('wpavatar_marketing'); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th colspan="2"><h3><?php _e('最近评论者设置', 'wpavatar'); ?></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('显示数量', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_commenters_count" value="<?php echo esc_attr($commenters_count); ?>" min="1" max="50" class="small-text wpavatar-input" <?php echo $is_commenters_count_disabled; ?>>
|
||||
<p class="description"><?php _e('显示的最近评论者数量', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('头像大小', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_commenters_size" value="<?php echo esc_attr($commenters_size); ?>" min="20" max="150" class="small-text wpavatar-input" <?php echo $is_commenters_size_disabled; ?>>
|
||||
<p class="description"><?php _e('评论者头像大小(像素)', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th colspan="2"><h3><?php _e('用户头像设置', 'wpavatar'); ?></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('显示数量', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_users_count" value="<?php echo esc_attr($users_count); ?>" min="1" max="50" class="small-text wpavatar-input" <?php echo $is_users_count_disabled; ?>>
|
||||
<p class="description"><?php _e('显示的用户数量', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('头像大小', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_users_size" value="<?php echo esc_attr($users_size); ?>" min="20" max="150" class="small-text wpavatar-input" <?php echo $is_users_size_disabled; ?>>
|
||||
<p class="description"><?php _e('用户头像大小(像素)', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="wpavatar-preview-container">
|
||||
<h3><?php _e('预览效果', 'wpavatar'); ?></h3>
|
||||
<?php echo self::generate_preview('circle', 45, 5); ?>
|
||||
<p class="description"><?php _e('预览显示使用圆形头像样式', 'wpavatar'); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="wpavatar-submit-wrapper">
|
||||
<button type="submit" class="button button-primary"><?php _e('保存设置', 'wpavatar'); ?></button>
|
||||
</div>
|
||||
|
||||
<div class="wpavatar-card shortcode-docs">
|
||||
<h3><?php _e('可用简码', 'wpavatar'); ?></h3>
|
||||
<div class="wpavatar-table-wrapper">
|
||||
<table class="widefat wpavatar-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e('简码', 'wpavatar'); ?></th>
|
||||
<th><?php _e('描述', 'wpavatar'); ?></th>
|
||||
<th><?php _e('参数', 'wpavatar'); ?></th>
|
||||
<th><?php _e('示例', 'wpavatar'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>[wpavatar_latest_commenters]</code></td>
|
||||
<td><?php _e('显示最近评论者头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>number</code> - <?php _e('显示的评论者数量', 'wpavatar'); ?></li>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_latest_commenters number="10" size="50"]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>[wpavatar_latest_users]</code></td>
|
||||
<td><?php _e('显示最新注册的用户头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>number</code> - <?php _e('显示的用户数量', 'wpavatar'); ?></li>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_latest_users number="12" size="40"]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>[wpavatar_random_users]</code></td>
|
||||
<td><?php _e('显示随机用户头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>number</code> - <?php _e('显示的用户数量', 'wpavatar'); ?></li>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_random_users number="12" size="40"]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>[wpavatar_author]</code></td>
|
||||
<td><?php _e('显示当前文章作者头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_author size="96"]</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h4><?php _e('使用场景', 'wpavatar'); ?></h4>
|
||||
<p><?php _e('这些简码非常适合用于:', 'wpavatar'); ?></p>
|
||||
<ul style="list-style-type: disc; margin-left: 20px;">
|
||||
<li><?php _e('侧边栏挂件:展示活跃评论者和用户', 'wpavatar'); ?></li>
|
||||
<li><?php _e('文章底部:增强社区感并鼓励互动', 'wpavatar'); ?></li>
|
||||
<li><?php _e('关于页面:展示您的社区成员', 'wpavatar'); ?></li>
|
||||
<li><?php _e('会员页面:显示最新加入的会员', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
<p><strong><?php _e('提示:', 'wpavatar'); ?></strong> <?php _e('您可以将这些简码与其他WordPress挂件组合使用,创建更丰富的社区展示。', 'wpavatar'); ?></p>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.wpavatar-preview-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
.preview-section {
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
padding: 15px;
|
||||
}
|
||||
.preview-section h4 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 15px;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.wpavatar-preview-commenters {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0;
|
||||
}
|
||||
.wpavatar-preview-commenters .preview-item {
|
||||
margin-right: -15px;
|
||||
}
|
||||
.wpavatar-preview-users {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 15px;
|
||||
}
|
||||
.wpavatar-preview-users .preview-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
.preview-avatar {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.preview-name {
|
||||
font-size: 12px;
|
||||
margin-top: 5px;
|
||||
max-width: 80px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
}
|
|
@ -87,7 +87,12 @@ class Network {
|
|||
'wpavatar_fallback_avatar',
|
||||
'wpavatar_shortcode_size',
|
||||
'wpavatar_shortcode_class',
|
||||
'wpavatar_shortcode_shape'
|
||||
'wpavatar_shortcode_shape',
|
||||
// 添加营销组件选项
|
||||
'wpavatar_commenters_count',
|
||||
'wpavatar_commenters_size',
|
||||
'wpavatar_users_count',
|
||||
'wpavatar_users_size'
|
||||
];
|
||||
|
||||
foreach ($options_to_copy as $option) {
|
||||
|
@ -234,10 +239,10 @@ class Network {
|
|||
|
||||
?>
|
||||
<div class="wrap wpavatar-settings">
|
||||
<h1><?php esc_html_e('WPAvatar网络设置', 'wpavatar'); ?>
|
||||
<span style="font-size: 13px; padding-left: 10px;"><?php printf(esc_html__('Version: %s', 'wpavatar'), esc_html(WPAVATAR_VERSION)); ?></span>
|
||||
<h1><?php esc_html_e('文派头像设置', 'wpavatar'); ?>
|
||||
<span style="font-size: 13px; padding-left: 10px;"><?php printf(esc_html__('版本: %s', 'wpavatar'), esc_html(WPAVATAR_VERSION)); ?></span>
|
||||
<a href="https://wpavatar.com/document/" target="_blank" class="button button-secondary" style="margin-left: 10px;"><?php esc_html_e('文档', 'wpavatar'); ?></a>
|
||||
<a href="https://sharecms.com/forums/" target="_blank" class="button button-secondary"><?php esc_html_e('支持', 'wpavatar'); ?></a>
|
||||
<a href="https://cravatar.com/forums/" target="_blank" class="button button-secondary"><?php esc_html_e('支持', 'wpavatar'); ?></a>
|
||||
</h1>
|
||||
|
||||
<div id="wpavatar-status" class="notice" style="display:none; margin-top: 10px; padding: 8px 12px;"></div>
|
||||
|
@ -261,8 +266,11 @@ class Network {
|
|||
<button type="button" class="wpavatar-tab <?php echo $active_tab === 'shortcodes' ? 'active' : ''; ?>" data-tab="shortcodes">
|
||||
<?php _e('头像简码', 'wpavatar'); ?>
|
||||
</button>
|
||||
<button type="button" class="wpavatar-tab <?php echo $active_tab === 'marketing' ? 'active' : ''; ?>" data-tab="marketing">
|
||||
<?php _e('营销组件', 'wpavatar'); ?>
|
||||
</button>
|
||||
<button type="button" class="wpavatar-tab <?php echo $active_tab === 'tools' ? 'active' : ''; ?>" data-tab="tools">
|
||||
<?php _e('工具', 'wpavatar'); ?>
|
||||
<?php _e('实用工具', 'wpavatar'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -327,6 +335,10 @@ class Network {
|
|||
'wpavatar_shortcode_size' => __('默认头像大小', 'wpavatar'),
|
||||
'wpavatar_shortcode_class' => __('默认CSS类名', 'wpavatar'),
|
||||
'wpavatar_shortcode_shape' => __('默认头像形状', 'wpavatar'),
|
||||
'wpavatar_commenters_count' => __('评论者数量', 'wpavatar'),
|
||||
'wpavatar_commenters_size' => __('评论者头像大小', 'wpavatar'),
|
||||
'wpavatar_users_count' => __('用户数量', 'wpavatar'),
|
||||
'wpavatar_users_size' => __('用户头像大小', 'wpavatar'),
|
||||
];
|
||||
|
||||
// Group options by category
|
||||
|
@ -366,6 +378,15 @@ class Network {
|
|||
'wpavatar_shortcode_class',
|
||||
'wpavatar_shortcode_shape'
|
||||
]
|
||||
],
|
||||
'marketing' => [
|
||||
'title' => __('营销组件', 'wpavatar'),
|
||||
'options' => [
|
||||
'wpavatar_commenters_count',
|
||||
'wpavatar_commenters_size',
|
||||
'wpavatar_users_count',
|
||||
'wpavatar_users_size'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
|
@ -398,7 +419,7 @@ class Network {
|
|||
</table>
|
||||
|
||||
<div class="wpavatar-submit-wrapper">
|
||||
<button type="submit" class="button button-primary"><?php _e('保存网络管理设置', 'wpavatar'); ?></button>
|
||||
<button type="submit" class="button button-primary"><?php _e('保存设置', 'wpavatar'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -500,7 +521,7 @@ class Network {
|
|||
</table>
|
||||
|
||||
<div class="wpavatar-submit-wrapper">
|
||||
<button type="submit" class="button button-primary"><?php _e('保存基础设置', 'wpavatar'); ?></button>
|
||||
<button type="submit" class="button button-primary"><?php _e('保存设置', 'wpavatar'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -553,7 +574,7 @@ class Network {
|
|||
</table>
|
||||
|
||||
<div class="wpavatar-submit-wrapper">
|
||||
<button type="submit" class="button button-primary"><?php _e('保存缓存设置', 'wpavatar'); ?></button>
|
||||
<button type="submit" class="button button-primary"><?php _e('保存设置', 'wpavatar'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -609,7 +630,7 @@ class Network {
|
|||
</table>
|
||||
|
||||
<div class="wpavatar-submit-wrapper">
|
||||
<button type="submit" class="button button-primary"><?php _e('保存高级设置', 'wpavatar'); ?></button>
|
||||
<button type="submit" class="button button-primary"><?php _e('保存设置', 'wpavatar'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -671,7 +692,121 @@ class Network {
|
|||
</table>
|
||||
|
||||
<div class="wpavatar-submit-wrapper">
|
||||
<button type="submit" class="button button-primary"><?php _e('保存简码设置', 'wpavatar'); ?></button>
|
||||
<button type="submit" class="button button-primary"><?php _e('保存设置', 'wpavatar'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Marketing Settings Section -->
|
||||
<div class="wpavatar-section" id="wpavatar-section-marketing" style="<?php echo $active_tab !== 'marketing' ? 'display: none;' : ''; ?>">
|
||||
<h2><?php _e('营销组件设置', 'wpavatar'); ?></h2>
|
||||
<p class="wpavatar-section-desc"><?php _e('配置营销组件简码和显示效果,应用于所有网络站点。', 'wpavatar'); ?></p>
|
||||
|
||||
<form method="post" action="edit.php?action=wpavatar_network_settings" id="wpavatar-marketing-form">
|
||||
<?php wp_nonce_field('wpavatar_network_settings'); ?>
|
||||
<input type="hidden" name="tab" value="marketing">
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th colspan="2"><h3><?php _e('最近评论者设置', 'wpavatar'); ?></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('显示数量', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_commenters_count" value="<?php echo esc_attr(get_site_option('wpavatar_commenters_count', 15)); ?>" min="1" max="50" class="small-text wpavatar-input">
|
||||
<p class="description"><?php _e('显示的最近评论者数量', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('头像大小', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_commenters_size" value="<?php echo esc_attr(get_site_option('wpavatar_commenters_size', 45)); ?>" min="20" max="150" class="small-text wpavatar-input">
|
||||
<p class="description"><?php _e('评论者头像大小(像素)', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th colspan="2"><h3><?php _e('用户头像设置', 'wpavatar'); ?></h3></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('显示数量', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_users_count" value="<?php echo esc_attr(get_site_option('wpavatar_users_count', 15)); ?>" min="1" max="50" class="small-text wpavatar-input">
|
||||
<p class="description"><?php _e('显示的用户数量', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php _e('头像大小', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<input type="number" name="wpavatar_users_size" value="<?php echo esc_attr(get_site_option('wpavatar_users_size', 40)); ?>" min="20" max="150" class="small-text wpavatar-input">
|
||||
<p class="description"><?php _e('用户头像大小(像素)', 'wpavatar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="wpavatar-submit-wrapper">
|
||||
<button type="submit" class="button button-primary"><?php _e('保存设置', 'wpavatar'); ?></button>
|
||||
</div>
|
||||
|
||||
<div class="wpavatar-card shortcode-docs">
|
||||
<h3><?php _e('可用简码', 'wpavatar'); ?></h3>
|
||||
<div class="wpavatar-table-wrapper">
|
||||
<table class="widefat wpavatar-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e('简码', 'wpavatar'); ?></th>
|
||||
<th><?php _e('描述', 'wpavatar'); ?></th>
|
||||
<th><?php _e('参数', 'wpavatar'); ?></th>
|
||||
<th><?php _e('示例', 'wpavatar'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>[wpavatar_latest_commenters]</code></td>
|
||||
<td><?php _e('显示最近评论者头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>number</code> - <?php _e('显示的评论者数量', 'wpavatar'); ?></li>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_latest_commenters number="10" size="50"]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>[wpavatar_latest_users]</code></td>
|
||||
<td><?php _e('显示最新注册的用户头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>number</code> - <?php _e('显示的用户数量', 'wpavatar'); ?></li>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_latest_users number="12" size="40"]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>[wpavatar_random_users]</code></td>
|
||||
<td><?php _e('显示随机用户头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>number</code> - <?php _e('显示的用户数量', 'wpavatar'); ?></li>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_random_users number="12" size="40"]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>[wpavatar_author]</code></td>
|
||||
<td><?php _e('显示当前文章作者头像', 'wpavatar'); ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><code>size</code> - <?php _e('头像大小(像素)', 'wpavatar'); ?></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td><code>[wpavatar_author size="96"]</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -994,6 +1129,14 @@ class Network {
|
|||
update_site_option('wpavatar_shortcode_shape', sanitize_text_field($_POST['wpavatar_shortcode_shape'] ?? 'square'));
|
||||
}
|
||||
|
||||
// Process marketing settings
|
||||
if ($current_tab === 'marketing') {
|
||||
update_site_option('wpavatar_commenters_count', intval($_POST['wpavatar_commenters_count'] ?? 15));
|
||||
update_site_option('wpavatar_commenters_size', intval($_POST['wpavatar_commenters_size'] ?? 45));
|
||||
update_site_option('wpavatar_users_count', intval($_POST['wpavatar_users_count'] ?? 15));
|
||||
update_site_option('wpavatar_users_size', intval($_POST['wpavatar_users_size'] ?? 40));
|
||||
}
|
||||
|
||||
// Redirect back to the appropriate page with update message
|
||||
$redirect_url = add_query_arg([
|
||||
'page' => 'wpavatar-network',
|
||||
|
@ -1046,7 +1189,12 @@ class Network {
|
|||
'wpavatar_fallback_avatar',
|
||||
'wpavatar_shortcode_size',
|
||||
'wpavatar_shortcode_class',
|
||||
'wpavatar_shortcode_shape'
|
||||
'wpavatar_shortcode_shape',
|
||||
// 添加营销组件选项
|
||||
'wpavatar_commenters_count',
|
||||
'wpavatar_commenters_size',
|
||||
'wpavatar_users_count',
|
||||
'wpavatar_users_size'
|
||||
];
|
||||
|
||||
// Copy options from site to network
|
||||
|
@ -1101,6 +1249,23 @@ class Network {
|
|||
}
|
||||
}
|
||||
|
||||
// 确保也应用营销组件设置
|
||||
$marketing_options = [
|
||||
'wpavatar_commenters_count',
|
||||
'wpavatar_commenters_size',
|
||||
'wpavatar_users_count',
|
||||
'wpavatar_users_size'
|
||||
];
|
||||
|
||||
foreach ($marketing_options as $option) {
|
||||
if (in_array($option, $controlled_options)) {
|
||||
$network_value = get_site_option($option);
|
||||
if ($network_value !== false) {
|
||||
update_option($option, $network_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure site cache directory exists
|
||||
$cache_base = get_site_option('wpavatar_cache_path', WPAVATAR_CACHE_DIR);
|
||||
$site_cache_dir = trailingslashit($cache_base) . 'site-' . $site->blog_id;
|
||||
|
|
131
includes/wpcy-compatibility.php
Normal file
131
includes/wpcy-compatibility.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/**
|
||||
* WPAvatar 兼容性修复
|
||||
*
|
||||
* 用于处理与其他插件的兼容性问题
|
||||
*/
|
||||
|
||||
namespace WPAvatar;
|
||||
|
||||
class Compatibility {
|
||||
/**
|
||||
* 初始化兼容性修复
|
||||
*/
|
||||
public static function init() {
|
||||
// 在所有插件加载后、主题初始化前运行
|
||||
add_action('after_setup_theme', [__CLASS__, 'handle_wp_china_yes_compatibility'], 5);
|
||||
|
||||
// 处理与 Marketing 和 Shortcode 类之间的兼容性
|
||||
add_action('init', [__CLASS__, 'handle_shortcode_compatibility'], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理与 WP-China-Yes 插件的兼容性
|
||||
*/
|
||||
public static function handle_wp_china_yes_compatibility() {
|
||||
// 检查 WP-China-Yes 插件是否激活
|
||||
if (self::is_wp_china_yes_active()) {
|
||||
// 移除 WP-China-Yes 的头像替换过滤器
|
||||
self::remove_wp_china_yes_filters();
|
||||
|
||||
// 重新初始化 WPAvatar 的 Cravatar 功能,使用更高的优先级
|
||||
self::reinitialize_wpavatar_filters();
|
||||
|
||||
// 可选:添加管理界面通知
|
||||
if (is_admin()) {
|
||||
add_action('admin_notices', [__CLASS__, 'admin_compatibility_notice']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 Marketing 和 Shortcode 类之间的简码兼容性
|
||||
*/
|
||||
public static function handle_shortcode_compatibility() {
|
||||
// 确保只处理一次
|
||||
static $done = false;
|
||||
if ($done) {
|
||||
return;
|
||||
}
|
||||
$done = true;
|
||||
|
||||
// 移除 Marketing 类中可能与 Shortcode 类冲突的简码定义
|
||||
remove_shortcode('wpavatar');
|
||||
remove_shortcode('wpavatar_username');
|
||||
remove_filter('walker_nav_menu_start_el', array('\WPAvatar\Marketing', 'menu_item_replace'), 10);
|
||||
|
||||
// 重新添加 Shortcode 类的简码
|
||||
add_shortcode('wpavatar', ['\WPAvatar\Shortcode', 'render_avatar']);
|
||||
add_shortcode('wpavatar_username', ['\WPAvatar\Shortcode', 'render_username']);
|
||||
add_filter('walker_nav_menu_start_el', ['\WPAvatar\Shortcode', 'menu_item_replace'], 10, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 WP-China-Yes 插件是否激活
|
||||
*/
|
||||
private static function is_wp_china_yes_active() {
|
||||
return class_exists('WenPai\\ChinaYes\\Service\\Super') ||
|
||||
defined('CHINA_YES_VERSION') ||
|
||||
function_exists('WenPai\\ChinaYes\\get_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除 WP-China-Yes 的头像替换过滤器
|
||||
*/
|
||||
private static function remove_wp_china_yes_filters() {
|
||||
// 找到可能的 Super 类实例
|
||||
global $wp_filter;
|
||||
|
||||
$filters_to_check = [
|
||||
'get_avatar_url',
|
||||
'um_user_avatar_url_filter',
|
||||
'bp_gravatar_url',
|
||||
'user_profile_picture_description',
|
||||
'avatar_defaults'
|
||||
];
|
||||
|
||||
foreach ($filters_to_check as $filter_name) {
|
||||
if (isset($wp_filter[$filter_name])) {
|
||||
foreach ($wp_filter[$filter_name]->callbacks as $priority => $callbacks) {
|
||||
foreach ($callbacks as $callback_key => $callback_data) {
|
||||
if (is_array($callback_data['function']) &&
|
||||
is_object($callback_data['function'][0]) &&
|
||||
get_class($callback_data['function'][0]) === 'WenPai\\ChinaYes\\Service\\Super') {
|
||||
|
||||
$method_name = $callback_data['function'][1];
|
||||
remove_filter($filter_name, [$callback_data['function'][0], $method_name], $priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新初始化 WPAvatar 的 Cravatar 过滤器,使用更高的优先级
|
||||
*/
|
||||
private static function reinitialize_wpavatar_filters() {
|
||||
if (wpavatar_get_option('wpavatar_enable_cravatar', true)) {
|
||||
// 使用高优先级再次添加过滤器
|
||||
add_filter('um_user_avatar_url_filter', ['\WPAvatar\Cravatar', 'replace_avatar_url'], 9999);
|
||||
add_filter('bp_gravatar_url', ['\WPAvatar\Cravatar', 'replace_avatar_url'], 9999);
|
||||
add_filter('user_profile_picture_description', ['\WPAvatar\Cravatar', 'modify_profile_picture_description'], 9999);
|
||||
|
||||
// 确保 get_avatar_url 过滤器的优先级高于其他插件
|
||||
remove_filter('get_avatar_url', ['\WPAvatar\Cravatar', 'get_avatar_url'], 999);
|
||||
add_filter('get_avatar_url', ['\WPAvatar\Cravatar', 'get_avatar_url'], 9999, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理界面兼容性通知
|
||||
*/
|
||||
public static function admin_compatibility_notice() {
|
||||
$screen = get_current_screen();
|
||||
if ($screen && $screen->id === 'settings_page_wpavatar-settings') {
|
||||
echo '<div class="notice notice-info is-dismissible">';
|
||||
echo '<p>检测到文派叶子(WPCY.COM)插件,WPAvatar 生态组件兼容补丁已生效,确保文派头像设置优先。</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
96
wpavatar.php
96
wpavatar.php
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: WPAvatar
|
||||
* Version: 1.8.1
|
||||
* Version: 1.9.2
|
||||
* Plugin URI: https://wpavatar.com/download
|
||||
* Description: Replace Gravatar with Cravatar, a perfect replacement of Gravatar in China.
|
||||
* Author: WPfanyi
|
||||
|
@ -13,7 +13,7 @@
|
|||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
define('WPAVATAR_VERSION', '1.8.0');
|
||||
define('WPAVATAR_VERSION', '1.9.2');
|
||||
define('WPAVATAR_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||
define('WPAVATAR_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||
define('WPAVATAR_CACHE_DIR', WP_CONTENT_DIR . '/uploads/cravatar');
|
||||
|
@ -45,6 +45,7 @@ if (!file_exists(WPAVATAR_PLUGIN_DIR . 'assets/images')) {
|
|||
wp_mkdir_p(WPAVATAR_PLUGIN_DIR . 'assets/images');
|
||||
}
|
||||
|
||||
// 检查必要的插件目录是否存在
|
||||
if (!file_exists(WPAVATAR_PLUGIN_DIR . 'includes')) {
|
||||
wp_mkdir_p(WPAVATAR_PLUGIN_DIR . 'includes');
|
||||
|
||||
|
@ -55,12 +56,20 @@ if (!file_exists(WPAVATAR_PLUGIN_DIR . 'includes')) {
|
|||
if (file_exists(WPAVATAR_PLUGIN_DIR . 'admin.php')) {
|
||||
copy(WPAVATAR_PLUGIN_DIR . 'admin.php', WPAVATAR_PLUGIN_DIR . 'includes/admin.php');
|
||||
}
|
||||
|
||||
// 创建营销组件文件
|
||||
if (file_exists(WPAVATAR_PLUGIN_DIR . 'marketing.php')) {
|
||||
$marketing_content = file_get_contents(WPAVATAR_PLUGIN_DIR . 'marketing.php');
|
||||
file_put_contents(WPAVATAR_PLUGIN_DIR . 'includes/marketing.php', $marketing_content);
|
||||
}
|
||||
}
|
||||
|
||||
// Include core files
|
||||
// 包含核心文件
|
||||
require_once WPAVATAR_PLUGIN_DIR . 'includes/core.php';
|
||||
require_once WPAVATAR_PLUGIN_DIR . 'includes/admin.php';
|
||||
require_once WPAVATAR_PLUGIN_DIR . 'includes/multisite.php';
|
||||
require_once WPAVATAR_PLUGIN_DIR . 'includes/marketing.php';
|
||||
require_once WPAVATAR_PLUGIN_DIR . 'includes/wpcy-compatibility.php';
|
||||
|
||||
// Register AJAX actions
|
||||
add_action('wp_ajax_wpavatar_purge_cache', 'wpavatar_purge_cache_ajax');
|
||||
|
@ -226,12 +235,18 @@ add_action('plugins_loaded', function () {
|
|||
\WPAvatar\Network::init();
|
||||
}
|
||||
|
||||
// Initialize compatibility layer
|
||||
\WPAvatar\Compatibility::init();
|
||||
|
||||
// Initialize core components
|
||||
\WPAvatar\Core::init();
|
||||
\WPAvatar\Cravatar::init();
|
||||
\WPAvatar\Cache::init();
|
||||
\WPAvatar\Shortcode::init();
|
||||
|
||||
// Initialize Marketing component
|
||||
\WPAvatar\Marketing::init();
|
||||
|
||||
// Initialize admin settings (will be conditionally disabled in multisite if network managed)
|
||||
if (is_admin()) {
|
||||
// Check if we should initialize settings in site admin
|
||||
|
@ -375,6 +390,12 @@ register_activation_hook(__FILE__, function() {
|
|||
add_option('wpavatar_shortcode_class', 'wpavatar');
|
||||
add_option('wpavatar_shortcode_shape', 'square');
|
||||
|
||||
// 添加营销组件默认设置
|
||||
add_option('wpavatar_commenters_count', 15);
|
||||
add_option('wpavatar_commenters_size', 45);
|
||||
add_option('wpavatar_users_count', 15);
|
||||
add_option('wpavatar_users_size', 40);
|
||||
|
||||
// Create cache directory
|
||||
wp_mkdir_p(WPAVATAR_CACHE_DIR);
|
||||
|
||||
|
@ -430,7 +451,12 @@ register_activation_hook(__FILE__, function() {
|
|||
'wpavatar_fallback_avatar',
|
||||
'wpavatar_shortcode_size',
|
||||
'wpavatar_shortcode_class',
|
||||
'wpavatar_shortcode_shape'
|
||||
'wpavatar_shortcode_shape',
|
||||
// 营销组件设置
|
||||
'wpavatar_commenters_count',
|
||||
'wpavatar_commenters_size',
|
||||
'wpavatar_users_count',
|
||||
'wpavatar_users_size'
|
||||
] as $option_name) {
|
||||
add_site_option($option_name, get_option($option_name));
|
||||
}
|
||||
|
@ -459,65 +485,3 @@ register_deactivation_hook(__FILE__, function() {
|
|||
// Clear scheduled events
|
||||
wp_clear_scheduled_hook('wpavatar_purge_cache');
|
||||
});
|
||||
|
||||
// 确保 WPAvatar 插件已激活
|
||||
add_action('plugins_loaded', function() {
|
||||
if (class_exists('WPAvatar\\Cravatar')) {
|
||||
// 添加兼容性过滤器,确保 WPAvatar 的优先级高于 WP-China-Yes
|
||||
add_action('after_setup_theme', function() {
|
||||
// 检查 WP-China-Yes 插件是否激活
|
||||
if (class_exists('WenPai\\ChinaYes\\Service\\Super') || defined('CHINA_YES_VERSION')) {
|
||||
// 移除 WP-China-Yes 的头像相关过滤器
|
||||
global $wp_filter;
|
||||
|
||||
$filters_to_check = [
|
||||
'get_avatar_url',
|
||||
'um_user_avatar_url_filter',
|
||||
'bp_gravatar_url',
|
||||
'user_profile_picture_description',
|
||||
'avatar_defaults'
|
||||
];
|
||||
|
||||
foreach ($filters_to_check as $filter_name) {
|
||||
if (isset($wp_filter[$filter_name])) {
|
||||
foreach ($wp_filter[$filter_name]->callbacks as $priority => $callbacks) {
|
||||
foreach ($callbacks as $callback_key => $callback_data) {
|
||||
if (is_array($callback_data['function']) &&
|
||||
is_object($callback_data['function'][0]) &&
|
||||
get_class($callback_data['function'][0]) === 'WenPai\\ChinaYes\\Service\\Super') {
|
||||
|
||||
$method_name = $callback_data['function'][1];
|
||||
remove_filter($filter_name, [$callback_data['function'][0], $method_name], $priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重新添加 WPAvatar 的过滤器,使用更高的优先级
|
||||
if (wpavatar_get_option('wpavatar_enable_cravatar', true)) {
|
||||
// 移除原有优先级的过滤器
|
||||
remove_filter('get_avatar_url', ['WPAvatar\\Cravatar', 'get_avatar_url'], 999);
|
||||
remove_filter('um_user_avatar_url_filter', ['WPAvatar\\Cravatar', 'replace_avatar_url'], 1);
|
||||
remove_filter('bp_gravatar_url', ['WPAvatar\\Cravatar', 'replace_avatar_url'], 1);
|
||||
|
||||
// 使用更高优先级重新添加
|
||||
add_filter('get_avatar_url', ['WPAvatar\\Cravatar', 'get_avatar_url'], 9999, 2);
|
||||
add_filter('um_user_avatar_url_filter', ['WPAvatar\\Cravatar', 'replace_avatar_url'], 9999);
|
||||
add_filter('bp_gravatar_url', ['WPAvatar\\Cravatar', 'replace_avatar_url'], 9999);
|
||||
add_filter('user_profile_picture_description', ['WPAvatar\\Cravatar', 'modify_profile_picture_description'], 9999);
|
||||
}
|
||||
|
||||
// 添加管理界面通知
|
||||
add_action('admin_notices', function() {
|
||||
$screen = get_current_screen();
|
||||
if ($screen && $screen->id === 'settings_page_wpavatar-settings') {
|
||||
echo '<div class="notice notice-info is-dismissible">';
|
||||
echo '<p>检测到文派叶子(WPCY.COM)插件,WPAvatar 生态组件兼容性补丁已生效,确保文派头像设置优先。</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 5);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue