mirror of
https://github.com/WenPai-org/wpavatar.git
synced 2025-08-17 09:51:08 +08:00
清理文件
This commit is contained in:
parent
3faa95616c
commit
2ae43de934
2 changed files with 0 additions and 221 deletions
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* WPAvatar 兼容性修复
|
||||
*
|
||||
* 用于处理与 WP-China-Yes 插件的兼容性问题
|
||||
*/
|
||||
|
||||
namespace WPAvatar;
|
||||
|
||||
class Compatibility {
|
||||
/**
|
||||
* 初始化兼容性修复
|
||||
*/
|
||||
public static function init() {
|
||||
// 在所有插件加载后、主题初始化前运行
|
||||
add_action('after_setup_theme', [__CLASS__, 'handle_wp_china_yes_compatibility'], 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理与 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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 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>';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
Name: Cravatar
|
||||
URI: https://cravatar.com
|
||||
License: GPL-2.0+
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
*/
|
||||
|
||||
|
||||
|
||||
if (!function_exists('get_cravatar_url')) {
|
||||
/**
|
||||
* Replace Gravatar with Cravatar
|
||||
*
|
||||
* Cravatar is the perfect alternative to Gravatar in China, you can update your avatar at https://cn.cravatar.com.
|
||||
*/
|
||||
function get_cravatar_url($url)
|
||||
{
|
||||
$sources = array(
|
||||
'www.gravatar.com',
|
||||
'0.gravatar.com',
|
||||
'1.gravatar.com',
|
||||
'2.gravatar.com',
|
||||
'secure.gravatar.com',
|
||||
'cn.gravatar.com',
|
||||
'gravatar.com',
|
||||
);
|
||||
return str_replace($sources, 'cn.cravatar.com', $url);
|
||||
}
|
||||
|
||||
if (get_option('wpavatar_enable_cravatar', '0') == '1') {
|
||||
add_filter('um_user_avatar_url_filter', 'get_cravatar_url', 1);
|
||||
add_filter('bp_gravatar_url', 'get_cravatar_url', 1);
|
||||
add_filter('get_avatar_url', 'get_cravatar_url', 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('set_defaults_for_cravatar')) {
|
||||
/**
|
||||
* Replace default avatar with Cravatar in Discussion Settings
|
||||
*/
|
||||
function set_defaults_for_cravatar($avatar_defaults)
|
||||
{
|
||||
$avatar_defaults['gravatar_default'] = __('Cravatar Logo', 'wpavatar');
|
||||
return $avatar_defaults;
|
||||
}
|
||||
|
||||
if (get_option('wpavatar_enable_cravatar', '0') == '1') {
|
||||
add_filter('avatar_defaults', 'set_defaults_for_cravatar', 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('set_user_profile_picture_for_cravatar')) {
|
||||
/**
|
||||
* Replace avatar upload link in user profile
|
||||
*/
|
||||
function set_user_profile_picture_for_cravatar()
|
||||
{
|
||||
return '<a href="https://cravatar.com" target="_blank" rel="noopener">'.__('You can update your profile picture at cn.cravatar.com', 'wpavatar').'</a>';
|
||||
}
|
||||
|
||||
if (get_option('wpavatar_enable_cravatar', '0') == '1') {
|
||||
add_filter('user_profile_picture_description', 'set_user_profile_picture_for_cravatar', 1);
|
||||
}
|
||||
}
|
||||
|
||||
add_action('admin_menu', 'wpavatar_create_settings_page');
|
||||
|
||||
function wpavatar_create_settings_page()
|
||||
{
|
||||
add_options_page(
|
||||
__('Avatar Settings', 'wpavatar'),
|
||||
__('Avatar', 'wpavatar'),
|
||||
'manage_options',
|
||||
'wpavatar-settings',
|
||||
'wpavatar_render_settings_page'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function wpavatar_render_settings_page()
|
||||
{
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
||||
<h2><?php _e( 'WordPress Avatar Settings', 'wpavatar' ); ?></h2>
|
||||
<p><?php _e( 'Cravatar is the perfect alternative to Gravatar in China, you can update your avatar at', 'wpavatar' ); ?> <a href="https://cravatar.com" target="_blank" rel="noopener">Cravatar.com</a>.</p>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields('wpavatar_settings'); ?>
|
||||
<?php do_settings_sections('wpavatar-settings'); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Enable Cravatar', 'wpavatar'); ?></th>
|
||||
<td>
|
||||
<?php $enable_cravatar = get_option('wpavatar_enable_cravatar', '1'); ?>
|
||||
<label><input type="radio" name="wpavatar_enable_cravatar" value="1" <?php checked($enable_cravatar, '1'); ?>> <?php _e('Yes', 'wpavatar'); ?></label>
|
||||
<label><input type="radio" name="wpavatar_enable_cravatar" value="0" <?php checked($enable_cravatar, '0'); ?>> <?php _e('No', 'wpavatar'); ?></label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php submit_button(__('Save Changes', 'wpavatar')); ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action('admin_init', 'wpavatar_register_settings');
|
||||
|
||||
function wpavatar_register_settings()
|
||||
{
|
||||
register_setting('wpavatar_settings', 'wpavatar_enable_cravatar', 'absint');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue