1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-05-13 11:46:57 +02:00

使用自己的简单方法

This commit is contained in:
云落 2020-01-26 01:54:41 +08:00
parent 03ed816d96
commit 728ab3ab54
11 changed files with 503 additions and 435 deletions

View file

@ -0,0 +1,177 @@
<?php
//本地头像
class gdk_local_avatars {
private $user_id_being_edited;
public function __construct() {
add_action('admin_init', array(
$this,
'admin_init'
));
add_action('show_user_profile', array(
$this,
'edit_user_profile'
));
add_action('edit_user_profile', array(
$this,
'edit_user_profile'
));
add_action('personal_options_update', array(
$this,
'edit_user_profile_update'
));
add_action('edit_user_profile_update', array(
$this,
'edit_user_profile_update'
));
add_filter('get_avatar', array(
$this,
'get_avatar'
) , 10, 5);
add_filter('avatar_defaults', array(
$this,
'avatar_defaults'
));
}
public function admin_init() {
register_setting('discussion', 'gdk_local_avatars_caps', array(
$this,
'sanitize_options'
));
add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', array(
$this,
'avatar_settings_field'
) , 'discussion', 'avatars');
}
public function avatar_settings_field($args) {
$options = get_option('gdk_local_avatars_caps');
?>
<label for="gdk_local_avatars_caps">
<input type="checkbox" name="gdk_local_avatars_caps" id="gdk_local_avatars_caps" value="1" <?php
checked($options['gdk_local_avatars_caps'], 1); ?>/>仅具有头像上传权限的用户具有设置本地头像权限(作者及更高等级角色)</label>
<?php
}
public function sanitize_options($input) {
$new_input['gdk_local_avatars_caps'] = empty($input['gdk_local_avatars_caps']) ? 0 : 1;
return $new_input;
}
public function get_avatar($avatar, $id_or_email, $size = 96, $default, $alt) {
if (is_numeric($id_or_email)) $user_id = (int)$id_or_email;
elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) $user_id = $user->ID;
elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) $user_id = (int)$id_or_email->user_id;
if (empty($user_id)) return $avatar;
$local_avatars = get_user_meta($user_id, 'simple_local_avatar', true);
if (empty($local_avatars) || empty($local_avatars['full'])) return $avatar;
$size = (int)$size;
if (empty($alt)) $alt = get_the_author_meta('display_name', $user_id);
if (empty($local_avatars[$size])) {
$upload_path = wp_upload_dir();
$avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']);
$image = wp_get_image_editor($avatar_full_path);
if (!is_wp_error($image)) {
$image->resize($size, $size, true);
$image_sized = $image->save();
}
$local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized['path']);
update_user_meta($user_id, 'simple_local_avatar', $local_avatars);
} elseif (substr($local_avatars[$size], 0, 4) != 'http') {
$local_avatars[$size] = home_url($local_avatars[$size]);
}
$author_class = is_author($user_id) ? ' current-author' : '';
$avatar = "<img alt='" . esc_attr($alt) . "' src='" . $local_avatars[$size] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
return apply_filters('simple_local_avatar', $avatar);
}
public function edit_user_profile($profileuser) {
?>
<h3>头像</h3>
<table class="form-table">
<tr>
<th><label for="basic-user-avatar">上传头像</label></th>
<td style="width: 50px;" valign="top">
<?php
echo get_avatar($profileuser->ID); ?>
</td>
<td>
<?php
$options = get_option('gdk_local_avatars_caps');
if (empty($options['gdk_local_avatars_caps']) || current_user_can('upload_files')) {
// Nonce security ftw
wp_nonce_field('simple_local_avatar_nonce', '_simple_local_avatar_nonce', false);
echo '<input type="file" name="basic-user-avatar" id="basic-local-avatar" /><br />';
if (empty($profileuser->simple_local_avatar)) {
echo '<span class="description">尚未设置本地头像,请点击“浏览”按钮上传本地头像</span>';
} else {
echo '<input type="checkbox" name="basic-user-avatar-erase" value="1" />移除本地头像<br />';
echo '<span class="description">如需要修改本地头像,请重新上传新头像。如需要移除本地头像,请选中上方的“移除本地头像”复选框并更新个人资料即可。<br/>移除本地头像后,将恢复使用 Gravatar 头像</span>';
}
} else {
if (empty($profileuser->simple_local_avatar)) {
echo '<span class="description">尚未设置本地头像,请在 Gravatar.com 网站设置头像</span>';
} else {
echo '<span class="description">你没有头像上传权限,如需要修改本地头像,请联系站点管理员</span>';
}
}
?>
</td>
</tr>
</table>
<script type="text/javascript">var form = document.getElementById('your-profile');form.encoding = 'multipart/form-data';form.setAttribute('enctype', 'multipart/form-data');</script>
<?php
}
public function edit_user_profile_update($user_id) {
if (!isset($_POST['_simple_local_avatar_nonce']) || !wp_verify_nonce($_POST['_simple_local_avatar_nonce'], 'simple_local_avatar_nonce')) return;
if (!empty($_FILES['basic-user-avatar']['name'])) {
$mimes = array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
);
if (!function_exists('wp_handle_upload')) require_once ABSPATH . 'wp-admin/includes/file.php';
$this->avatar_delete($user_id);
if (strstr($_FILES['basic-user-avatar']['name'], '.php')) wp_die('基于安全考虑 ".php" 格式文件禁止上传');
$this->user_id_being_edited = $user_id;
$avatar = wp_handle_upload($_FILES['basic-user-avatar'], array(
'mimes' => $mimes,
'test_form' => false,
'unique_filename_callback' => array(
$this,
'unique_filename_callback'
)
));
update_user_meta($user_id, 'simple_local_avatar', array(
'full' => $avatar['url']
));
} elseif (!empty($_POST['basic-user-avatar-erase'])) {
$this->avatar_delete($user_id);
}
}
public function avatar_defaults($avatar_defaults) {
remove_action('get_avatar', array(
$this,
'get_avatar'
));
return $avatar_defaults;
}
public function avatar_delete($user_id) {
$old_avatars = get_user_meta($user_id, 'simple_local_avatar', true);
$upload_path = wp_upload_dir();
if (is_array($old_avatars)) {
foreach ($old_avatars as $old_avatar) {
$old_avatar_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $old_avatar);
@unlink($old_avatar_path);
}
}
delete_user_meta($user_id, 'simple_local_avatar');
}
public function unique_filename_callback($dir, $name, $ext) {
$user = get_user_by('id', (int)$this->user_id_being_edited);
$name = $base_name = sanitize_file_name($user->ID . '_avatar');
$number = 1;
while (file_exists($dir . "/$name$ext")) {
$name = $base_name . '_' . $number;
$number++;
}
return $name . $ext;
}
}
$gdk_local_avatars = new gdk_local_avatars;

View file

@ -1,14 +0,0 @@
<?php
//require ( 'shortcode.php' );//短代码
include('plugin-options.php');//优化措施
//require ( 'avatar.php' );//头像功能
//require ( 'server.php' );//第三方服务
//require ( 'user.php' );//用户服务
//require ( 'seo.php' );//seo功能
//require ( 'email.php' );//邮箱功能

View file

@ -4,87 +4,106 @@
*/
$gdk_options = array(
'常规选项' => array(
array(
'name' => '滚动内容来源',
'desc' => '选择一个内容调用显示在顶部的滚动',
'id' => 'git_gun_b',
'优化选项' => array(
array(
'name' => '新版编辑器开关',
'desc' => '新版编辑器尚不成熟,很多主题不兼容,建议禁用',
'id' => 'gdk_diasble_gutenberg',
'type' => 'radio',
'options' => array(
'git_gun_shuo' => '调用说说标题',
'git_gun_tui' => '调用下方公告'
'1' => '禁用',
'0' => '开启'
),
'std' => 'git_gun_tui'
'std' => '1'
),
array(
'name' => '滚动公告栏',
'desc' => '最新消息显示在全站导航条下方,非常给力的推广位置',
'id' => 'git_tui',
'type' => 'textarea',
'std' => '<li>欢迎访问极客公园网站WordPress信息WordPress教程推荐使用最新版火狐浏览器和Chrome浏览器访问本网站欢迎加入极客公园<code><a target="_blank" href="https://gitcafe.net/go/qun"><i class="fa fa-qq"></i> QQ群</a></code></li><li>Git主题现已支持滚动公告栏功能兼容其他浏览器看到的就是咯在后台最新消息那里用li标签添加即可。</li><li>最新版Git主题已支持说说碎语功能可像添加文章一样直接添加说说新建说说页面即可最后重新保存固定连接<a target="_blank" href="https://gitcafe.net/shuo.html">演示地址</a></li><li>百度口碑求点赞啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊<a target="_blank" href="http://koubei.baidu.com/s/gitcafe.net">http://koubei.baidu.com/s/gitcafe.net</a></li><li>如果您觉得本站非常有看点那么赶紧使用Ctrl+D 收藏极客公园吧</li>'
),
array(
'name' => '友情链接页面',
'desc' => '只显示输入分类的链接id之间用英文逗号隔开建议只显示友情链接即可。',
'id' => 'git_linkpage_cat',
'type' => 'number'
),
array(
'name' => '列表Ajax下拉加载',
'desc' => '开启本选项之后网站会采用ajax方式下拉自动加载,默认只在传统blog列表页面生效,如果使用卡片式或者CMS,请关闭',
'id' => 'git_ajaxpager_b',
'type' => 'checkbox'
),
array(
'title' => '热门排行',
'type' => 'title'
),
array(
'name' => '开启',
'desc' => '【注意在开启3D幻灯片的时候是默认打开的无法关闭】',
'id' => 'hot_list_check',
'type' => 'checkbox'
),
array(
'name' => '排序根据',
'desc' => '选择一个参数作为排序的根据可以选择评论数目文章置顶置顶文章最多10篇',
'id' => 'git_hot_b',
'name' => '清理冗余头部代码开关',
'desc' => 'wordpress头部自带很多无用代码不安全且浪费建议禁用',
'id' => 'gdk_diasble_head_useless',
'type' => 'radio',
'options' => array(
'git_hot_comment' => '评论数目',
'git_hot_zd' => '文章置顶'
'1' => '禁用',
'0' => '开启'
),
'std' => 'git_hot_comment'
'std' => '1'
),
array(
'name' => '排行名称',
'desc' => '这里是显示在网站首页热门排行那里',
'id' => 'hot_list_title',
'type' => 'text',
'std' => '本周热门'
'name' => '禁用wordpress更新',
'desc' => 'wordpress更新会不时发送请求数据所以可以关闭wordpress更新包括主题插件和内核更新',
'id' => 'gdk_diasble_wp_update',
'type' => 'radio',
'options' => array(
'1' => '禁用',
'0' => '开启'
),
'std' => '1'
),
array(
'name' => '用户登录信息',
'desc' => '开启',
'id' => 'git_sign_b',
'type' => 'checkbox'
'name' => '禁用emojis功能',
'desc' => 'wordpress的emojis功能会加载国外资源那是网站速度所以建议禁用',
'id' => 'gdk_disable_emojis',
'type' => 'radio',
'options' => array(
'1' => '禁用',
'0' => '开启'
),
'std' => '1'
),
array(
'name' => '百度分享',
'desc' => '开启并且同时开启打赏功能支持https',
'id' => 'git_bdshare_b',
'type' => 'checkbox'
'name' => '禁用XML-RPC功能',
'desc' => '该功能有安全风险如果不使用wordpress的手机客户端或者第三方编辑器软件那么建议禁用',
'id' => 'gdk_disable_xmlrpc',
'type' => 'radio',
'options' => array(
'1' => '禁用',
'0' => '开启'
),
'std' => '1'
),
array(
'title' => '占位文本',
'type' => 'title'
'name' => '禁用文章版本功能',
'desc' => '该功能有会造成数据库体量暴增为了你的数据库考虑,建议禁用',
'id' => 'gdk_disable_revision',
'type' => 'radio',
'options' => array(
'1' => '禁用',
'0' => '开启'
),
'std' => '1'
),
array(
'name' => '搜索框',
'desc' => '占位文本',
'id' => 'git_search_placeholder',
'type' => 'text',
'std' => '输入内容并回车'
'name' => '禁用pingback功能',
'desc' => '该功能会增加垃圾评论的几率,建议禁用',
'id' => 'gdk_disable_trackbacks',
'type' => 'radio',
'options' => array(
'1' => '禁用',
'0' => '开启'
),
'std' => '1'
),
array(
'name' => 'wordpress更新中国加速',
'desc' => '该功能会帮助顺利更新wordpress突破429注意如果上面的wordpress禁用更新了此处设置无效建议开启',
'id' => 'gdk_porxy_update',
'type' => 'radio',
'options' => array(
'0' => '禁用',
'1' => '开启'
),
'std' => '1'
),
array(
'name' => '头像加速功能',
'desc' => '该功能会增加头像加载速度有随机头像V2EX头像镜像和七牛头像镜像默认选择随机头像',
'id' => 'gdk_switch_get_avatar',
'type' => 'radio',
'options' => array(
'1' => '随机头像',
'2' => 'V2EX头像镜像',
'3' => '七牛头像镜像',
),
'std' => '1'
),
array(
'name' => '评论',

View file

@ -11,18 +11,19 @@ $current_theme = wp_get_theme();
$gdk_default_options = [];
$gdk_options = [];
include('options-config.php');
$gdk_current_options = get_option('gdk_options_setup', []);
$gdk_current_options = get_option('gdk_options_setup');
function gdk_update_options() {
global $gdk_default_options, $gdk_options, $gdk_current_options;
foreach ($gdk_options as $panel) {
foreach ($panel as $option) {
$id = $option['id'];
$type = $option['type'];
$id = isset( $option['id'] ) ? $option['id'] : '';
$type = isset( $option['type'] ) ? $option['type'] : '';
$std = isset( $option['std'] ) ? $option['std'] : '';
if ( !$id ) continue;
$gdk_default_options[$id] = $option['std'];
$gdk_default_options[$id] = $std;
if ( isset($gdk_current_options[$id]) ) continue;
$gdk_current_options[$id] = isset( $option['std'] ) ? $option['std'] : '';
$gdk_current_options[$id] = $std;
}
}
}
@ -44,9 +45,9 @@ function gdk_options_page() {
<div class="wp-filter">
</div>
<?php
if ($_GET['update']) echo '<div class="updated"><p><strong>设置已保存。</strong></p></div>';
if ($_GET['reset']) echo '<div class="updated"><p><strong>设置已重置。</strong></p></div>';
if ($_GET['test']) echo '<div class="updated"><p><strong>如果您的邮箱收到测试邮件则证明您的SMTP设置是没问题的。</strong></p></div>';
if (isset($_GET['update'])) echo '<div class="updated"><p><strong>设置已保存。</strong></p></div>';
if (isset($_GET['reset'])) echo '<div class="updated"><p><strong>设置已重置。</strong></p></div>';
if (isset($_GET['test'])) echo '<div class="updated"><p><strong>如果您的邮箱收到测试邮件则证明您的SMTP设置是没问题的。</strong></p></div>';
?>
<div class="wp-filter">
@ -98,7 +99,6 @@ switch ( $type ) {
case 'number':
?>
<label>
<span class="description"><?php echo $option['before']; ?></span>
<input name="<?php echo $id; ?>" class="small-text" id="<?php echo $id; ?>" type="number" value="<?php echo esc_attr(gdk_get_option( $id )) ?>" />
<span class="description"><?php echo $option['desc']; ?></span>
</label>

29
functions/advanced.php Normal file
View file

@ -0,0 +1,29 @@
<?php
//头像解决方案
function gdk_switch_get_avatar( $avatar ) {
switch (gdk_get_option('gdk_switch_get_avatar')) {
case 1:
$avatarsrc = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg';
$avatar = "<img src=$avatarsrc class='avatar rand_avatar photo' />";
break;
case 2:
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//cdn.v2ex.com/gravatar/",$avatar);
break;
default:
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//dn-qiniu-avatar.qbox.me/avatar/",$avatar);
}
return $avatar;
}
add_filter('get_avatar', 'gdk_switch_get_avatar');
//fancybox图片灯箱效果
function fancybox($content) {
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\\/a>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="box" class="fancybox"$6>$7</a>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'fancybox');

View file

@ -2,196 +2,7 @@
//头像镜像
function get_ssl_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="https://cdn.v2ex.com/gravatar/$1?s=50" class="avatar avatar-$2">',$avatar);
return $avatar;
}
add_filter('get_avatar', 'get_ssl_avatar', 10, 3);
//随机头像
function local_random_avatar($avatar) {
$avatarsrc = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg';
$avatar = "<img src=$avatarsrc class='avatar rand_avatar photo' />";
return $avatar;
}
add_filter('get_avatar', 'local_random_avatar', 1, 5);
//本地头像
class simple_local_avatars {
private $user_id_being_edited;
public function __construct() {
add_action('admin_init', array(
$this,
'admin_init'
));
add_action('show_user_profile', array(
$this,
'edit_user_profile'
));
add_action('edit_user_profile', array(
$this,
'edit_user_profile'
));
add_action('personal_options_update', array(
$this,
'edit_user_profile_update'
));
add_action('edit_user_profile_update', array(
$this,
'edit_user_profile_update'
));
add_filter('get_avatar', array(
$this,
'get_avatar'
) , 10, 5);
add_filter('avatar_defaults', array(
$this,
'avatar_defaults'
));
}
public function admin_init() {
register_setting('discussion', 'simple_local_avatars_caps', array(
$this,
'sanitize_options'
));
add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', array(
$this,
'avatar_settings_field'
) , 'discussion', 'avatars');
}
public function avatar_settings_field($args) {
$options = get_option('simple_local_avatars_caps');
?>
<label for="simple_local_avatars_caps">
<input type="checkbox" name="simple_local_avatars_caps" id="simple_local_avatars_caps" value="1" <?php
checked($options['simple_local_avatars_caps'], 1); ?>/>仅具有头像上传权限的用户具有设置本地头像权限(作者及更高等级角色)</label>
<?php
}
public function sanitize_options($input) {
$new_input['simple_local_avatars_caps'] = empty($input['simple_local_avatars_caps']) ? 0 : 1;
return $new_input;
}
public function get_avatar($avatar, $id_or_email, $size = 96, $default, $alt) {
if (is_numeric($id_or_email)) $user_id = (int)$id_or_email;
elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) $user_id = $user->ID;
elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) $user_id = (int)$id_or_email->user_id;
if (empty($user_id)) return $avatar;
$local_avatars = get_user_meta($user_id, 'simple_local_avatar', true);
if (empty($local_avatars) || empty($local_avatars['full'])) return $avatar;
$size = (int)$size;
if (empty($alt)) $alt = get_the_author_meta('display_name', $user_id);
if (empty($local_avatars[$size])) {
$upload_path = wp_upload_dir();
$avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']);
$image = wp_get_image_editor($avatar_full_path);
if (!is_wp_error($image)) {
$image->resize($size, $size, true);
$image_sized = $image->save();
}
$local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized['path']);
update_user_meta($user_id, 'simple_local_avatar', $local_avatars);
} elseif (substr($local_avatars[$size], 0, 4) != 'http') {
$local_avatars[$size] = home_url($local_avatars[$size]);
}
$author_class = is_author($user_id) ? ' current-author' : '';
$avatar = "<img alt='" . esc_attr($alt) . "' src='" . $local_avatars[$size] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
return apply_filters('simple_local_avatar', $avatar);
}
public function edit_user_profile($profileuser) {
?>
<h3>头像</h3>
<table class="form-table">
<tr>
<th><label for="basic-user-avatar">上传头像</label></th>
<td style="width: 50px;" valign="top">
<?php
echo get_avatar($profileuser->ID); ?>
</td>
<td>
<?php
$options = get_option('simple_local_avatars_caps');
if (empty($options['simple_local_avatars_caps']) || current_user_can('upload_files')) {
// Nonce security ftw
wp_nonce_field('simple_local_avatar_nonce', '_simple_local_avatar_nonce', false);
echo '<input type="file" name="basic-user-avatar" id="basic-local-avatar" /><br />';
if (empty($profileuser->simple_local_avatar)) {
echo '<span class="description">尚未设置本地头像,请点击“浏览”按钮上传本地头像</span>';
} else {
echo '<input type="checkbox" name="basic-user-avatar-erase" value="1" />移除本地头像<br />';
echo '<span class="description">如需要修改本地头像,请重新上传新头像。如需要移除本地头像,请选中上方的“移除本地头像”复选框并更新个人资料即可。<br/>移除本地头像后,将恢复使用 Gravatar 头像</span>';
}
} else {
if (empty($profileuser->simple_local_avatar)) {
echo '<span class="description">尚未设置本地头像,请在 Gravatar.com 网站设置头像</span>';
} else {
echo '<span class="description">你没有头像上传权限,如需要修改本地头像,请联系站点管理员</span>';
}
}
?>
</td>
</tr>
</table>
<script type="text/javascript">var form = document.getElementById('your-profile');form.encoding = 'multipart/form-data';form.setAttribute('enctype', 'multipart/form-data');</script>
<?php
}
public function edit_user_profile_update($user_id) {
if (!isset($_POST['_simple_local_avatar_nonce']) || !wp_verify_nonce($_POST['_simple_local_avatar_nonce'], 'simple_local_avatar_nonce')) return;
if (!empty($_FILES['basic-user-avatar']['name'])) {
$mimes = array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
);
if (!function_exists('wp_handle_upload')) require_once ABSPATH . 'wp-admin/includes/file.php';
$this->avatar_delete($user_id);
if (strstr($_FILES['basic-user-avatar']['name'], '.php')) wp_die('基于安全考虑 ".php" 格式文件禁止上传');
$this->user_id_being_edited = $user_id;
$avatar = wp_handle_upload($_FILES['basic-user-avatar'], array(
'mimes' => $mimes,
'test_form' => false,
'unique_filename_callback' => array(
$this,
'unique_filename_callback'
)
));
update_user_meta($user_id, 'simple_local_avatar', array(
'full' => $avatar['url']
));
} elseif (!empty($_POST['basic-user-avatar-erase'])) {
$this->avatar_delete($user_id);
}
}
public function avatar_defaults($avatar_defaults) {
remove_action('get_avatar', array(
$this,
'get_avatar'
));
return $avatar_defaults;
}
public function avatar_delete($user_id) {
$old_avatars = get_user_meta($user_id, 'simple_local_avatar', true);
$upload_path = wp_upload_dir();
if (is_array($old_avatars)) {
foreach ($old_avatars as $old_avatar) {
$old_avatar_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $old_avatar);
@unlink($old_avatar_path);
}
}
delete_user_meta($user_id, 'simple_local_avatar');
}
public function unique_filename_callback($dir, $name, $ext) {
$user = get_user_by('id', (int)$this->user_id_being_edited);
$name = $base_name = sanitize_file_name($user->ID . '_avatar');
$number = 1;
while (file_exists($dir . "/$name$ext")) {
$name = $base_name . '_' . $number;
$number++;
}
return $name . $ext;
}
}
$simple_local_avatars = new simple_local_avatars;

View file

@ -3,7 +3,7 @@
//require ( 'shortcode.php' );//短代码
include('optimization.php');//优化措施
//require ( 'avatar.php' );//头像功能
include( 'advanced.php' );//头像功能
//require ( 'server.php' );//第三方服务

View file

@ -3,9 +3,146 @@
//禁用新版编辑器
if(gdk_get_option('gdk_diasble_gutenberg')){
add_filter('use_block_editor_for_post', '__return_false');
remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
}
// 友情链接扩展
add_filter('pre_option_link_manager_enabled', '__return_true');
add_filter('pre_option_link_manager_enabled', '__return_true');
//移除 WP_Head 无关紧要的代码
if(gdk_get_option('gdk_diasble_head_useless')){
remove_action('wp_head', 'wp_generator'); //删除 head 中的 WP 版本号
foreach (array('rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head') as $action) {
remove_action($action, 'the_generator');
}
remove_action('wp_head', 'rsd_link'); //删除 head 中的 RSD LINK
remove_action('wp_head', 'wlwmanifest_link'); //删除 head 中的 Windows Live Writer 的适配器?
remove_action('wp_head', 'feed_links_extra', 3); //删除 head 中的 Feed 相关的link
//remove_action( 'wp_head', 'feed_links', 2 );
remove_action('wp_head', 'index_rel_link'); //删除 head 中首页,上级,开始,相连的日志链接
remove_action('wp_head', 'parent_post_rel_link', 10);
remove_action('wp_head', 'start_post_rel_link', 10);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); //删除 head 中的 shortlink
remove_action('wp_head', 'rest_output_link_wp_head', 10); // 删除头部输出 WP RSET API 地址
remove_action('template_redirect', 'wp_shortlink_header', 11); //禁止短链接 Header 标签。
remove_action('template_redirect', 'rest_output_link_header', 11); // 禁止输出 Header Link 标签。
}
/** 开始关闭WordPress更新 **/
if (gdk_get_option('gdk_diasble_wp_update')) {
add_filter('automatic_updater_disabled', '__return_true');
remove_action('init', 'wp_schedule_update_checks');
wp_clear_scheduled_hook('wp_version_check');
wp_clear_scheduled_hook('wp_maybe_auto_update');
remove_action( 'admin_init', '_maybe_update_core' );
//禁用主题更新
wp_clear_scheduled_hook('wp_update_themes');
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'load-update-core.php', 'wp_update_themes' );
remove_action( 'admin_init', '_maybe_update_themes' );
// 禁用插件更新
wp_clear_scheduled_hook('wp_update_plugins');
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
}
//禁用自带p标签的
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);
//禁用emoji功能
if (gdk_get_option('gdk_disable_emojis')) {
function gdk_disable_emojis_link() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'gdk_disable_emojis_tinymce' );
}
add_action( 'init', 'gdk_disable_emojis_link' );
function gdk_disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) return array_diff( $plugins, array( 'wpemoji' ) );
return array();
}
}
//禁用 XML-RPC 接口
if (gdk_get_option('gdk_disable_xmlrpc')) {
add_filter('xmlrpc_enabled', '__return_false');
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
}
//禁用日志修订功能
if (gdk_get_option('gdk_disable_revision')) {
function gdk_disable_post_revisions() {
foreach ( get_post_types() as $post_type ) {
remove_post_type_support( $post_type, 'revisions' );
}
}
add_action( 'init', 'gdk_disable_post_revisions', 999 );
}
//彻底关闭 pingback
if (gdk_get_option('gdk_disable_trackbacks')) {
add_filter('xmlrpc_methods', 'gdk_xmlrpc_methods');
function gdk_xmlrpc_methods($methods) {
$methods['pingback.ping'] = '__return_false';
$methods['pingback.extensions.getPingbacks'] = '__return_false';
return $methods;
}
//禁用 pingbacks, enclosures, trackbacks
remove_action('do_pings', 'do_all_pings', 10);
//去掉 _encloseme 和 do_ping 操作。
remove_action('publish_post', '_publish_post_hook', 5);
}
//国内更新word press加速
if (gdk_get_option('gdk_porxy_update') && !gdk_get_option('gdk_diasble_wp_update')) {
add_filter('site_transient_update_core',function($value) {
foreach($value->updates as &$update) {
if($update->locale == 'zh_CN') {
$update->download = 'http://cn.wp101.net/latest-zh_CN.zip';
$update->packages->full = 'http://cn.wp101.net/latest-zh_CN.zip';
}
}
return $value;
}
);
}
function html_page_permalink() {
global $wp_rewrite;
if (!strpos($wp_rewrite->get_page_permastruct(), '.html')) {
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
}
}
add_action('init', 'html_page_permalink', -1);
//中文文件重命名
function gdk_upload_rename($file) {
$time = date("YmdHis");
$file['name'] = $time . "" . mt_rand(1, 100) . "." . pathinfo($file['name'], PATHINFO_EXTENSION);
return $file;
}
add_filter('wp_handle_upload_prefilter', 'gdk_upload_rename');

View file

@ -332,4 +332,54 @@ function nc_get_meta($key, $single = true) {
function nc_the_meta($key, $placeholder = '') {
echo nc_get_meta($key, true) ?: $placeholder;
}
function gdk_is_mobile() {
if (empty($_SERVER['HTTP_USER_AGENT'])) {
return false;
} elseif ((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') === false) // many mobile devices (all iPh, etc.)
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'NetType/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MQQBrowser') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'HUAWEI') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'TBS/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Mi') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false) {
return true;
} else {
return false;
}
}
if (function_exists('curl_init')) {
function curl_post($url, $postfields = '', $headers = '', $timeout = 20, $file = 0) {
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_NOBODY => false,
CURLOPT_POST => true,
CURLOPT_MAXREDIRS => 20,
CURLOPT_USERAGENT => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
CURLOPT_TIMEOUT => $timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0
);
if (is_array($postfields) && $file == 0) {
$options[CURLOPT_POSTFIELDS] = http_build_query($postfields);
} else {
$options[CURLOPT_POSTFIELDS] = $postfields;
}
curl_setopt_array($ch, $options);
if (is_array($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$result = curl_exec($ch);
$code = curl_errno($ch);
$msg = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return array(
'data' => $result,
'code' => $code,
'msg' => $msg,
'info' => $info
);
}
}

View file

@ -20,81 +20,16 @@ if (!function_exists('nc_admin_logo')):
add_action('login_head', 'nc_admin_logo');
endif;
//移除 WP_Head 无关紧要的代码
if ($general_options['remove_wp_head_useless']) {
remove_action('wp_head', 'wp_generator'); //删除 head 中的 WP 版本号
foreach (array('rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head') as $action) {
remove_action($action, 'the_generator');
}
remove_action('wp_head', 'rsd_link'); //删除 head 中的 RSD LINK
remove_action('wp_head', 'wlwmanifest_link'); //删除 head 中的 Windows Live Writer 的适配器?
remove_action('wp_head', 'feed_links_extra', 3); //删除 head 中的 Feed 相关的link
//remove_action( 'wp_head', 'feed_links', 2 );
remove_action('wp_head', 'index_rel_link'); //删除 head 中首页,上级,开始,相连的日志链接
remove_action('wp_head', 'parent_post_rel_link', 10);
remove_action('wp_head', 'start_post_rel_link', 10);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); //删除 head 中的 shortlink
remove_action('wp_head', 'rest_output_link_wp_head', 10); // 删除头部输出 WP RSET API 地址
remove_action('template_redirect', 'wp_shortlink_header', 11); //禁止短链接 Header 标签。
remove_action('template_redirect', 'rest_output_link_header', 11); // 禁止输出 Header Link 标签。
}
//禁用日志修订功能
if ($general_options['post_revision']) {
if (!function_exists('nc_disable_post_revisions')):
function nc_disable_post_revisions() {
foreach ( get_post_types() as $post_type ) {
remove_post_type_support( $post_type, 'revisions' );
}
}
add_action( 'init', 'nc_disable_post_revisions', 999 );
endif;
}
if (isset($general_options['core_update']) && $general_options['core_update']) {
add_filter('site_transient_update_core', 'nc_core_update_cdn');
function nc_core_update_cdn($value) {
foreach ($value->updates as &$update) {
$update->download = str_replace('downloads.wordpress.org', 'downloads.wordpress.org.nicetheme.xyz', $update->download);
$update->packages->full = str_replace('downloads.wordpress.org', 'downloads.wordpress.org.nicetheme.xyz', $update->packages->full);
}
return $value;
}
}
if ($general_options['disable_trackbacks']) {
//彻底关闭 pingback
if (!function_exists('nc_xmlrpc_methods')):
add_filter('xmlrpc_methods', 'nc_xmlrpc_methods');
function nc_xmlrpc_methods($methods)
{
$methods['pingback.ping'] = '__return_false';
$methods['pingback.extensions.getPingbacks'] = '__return_false';
return $methods;
}
endif;
//禁用 pingbacks, enclosures, trackbacks
remove_action('do_pings', 'do_all_pings', 10);
//去掉 _encloseme 和 do_ping 操作。
remove_action('publish_post', '_publish_post_hook', 5);
}
//禁用 XML-RPC 接口
if ($general_options['disable_xmlrpc']) {
add_filter('xmlrpc_enabled', '__return_false');
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
}
//禁用 Auto OEmbed
// if ($general_options['disable_auto_embeds']) {
@ -139,81 +74,5 @@ if ($general_options['gravatar_speedup']) {
endif;
}
if ($general_options['disable_emoji']) {
if (!function_exists('nc_disable_emojis')):
function nc_disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'nc_disable_emojis_tinymce' );
}
add_action( 'init', 'nc_disable_emojis' );
endif;
if (!function_exists('nc_disable_emojis_tinymce')):
function nc_disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) return array_diff( $plugins, array( 'wpemoji' ) );
return array();
}
endif;
}
if ($general_options['emoji_cdn']) {
if (!function_exists('nc_change_wp_emoji_baseurl')):
function nc_change_wp_emoji_baseurl() {
return set_url_scheme('//twemoji.maxcdn.com/2/72x72/');
}
add_action( 'emoji_url', 'nc_change_wp_emoji_baseurl' );
endif;
if (!function_exists('nc_change_wp_emoji_baseurl')):
function nc_change_wp_emoji_svgurl($url) {
return set_url_scheme('//twemoji.maxcdn.com/svg/');
}
add_filter('emoji_svg_url', 'nc_change_wp_emoji_svgurl');
endif;
}
if ($general_options['disable_wp_widgets']) {
if (!function_exists('nc_unregister_rss_widget')):
function nc_unregister_rss_widget(){
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Nav_Menu_Widget');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Recent_Comments');
}
add_action('widgets_init', 'nc_unregister_rss_widget');
endif;
}
if ($general_options['disable_core_update']) {
add_filter('automatic_updater_disabled', '__return_true');
remove_action('init', 'wp_schedule_update_checks');
wp_clear_scheduled_hook('wp_version_check');
wp_clear_scheduled_hook('wp_maybe_auto_update');
remove_action( 'admin_init', '_maybe_update_core' );
}
if ($general_options['disable_theme_update']) {
wp_clear_scheduled_hook('wp_update_themes');
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'load-update-core.php', 'wp_update_themes' );
remove_action( 'admin_init', '_maybe_update_themes' );
}
if ($general_options['disable_plugin_update']) {
wp_clear_scheduled_hook('wp_update_plugins');
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
}

View file

@ -26,20 +26,20 @@ define('NC_STORE_VER', '0.3.5');
define('NC_STORE_FILE', __FILE__);//插件入口文件
define('NC_BASE_URL', plugin_dir_url( __FILE__ ) );//插件目录url
define('NC_STORE_ROOT_PATH', plugin_dir_path( __FILE__ ) );//插件目录路径
include('library/nc-base/kernel/kernel.php');
include('library/nc-base/static-load.php');
include('library/nc-base/add-menu-page.php');
//include('library/nc-base/kernel/kernel.php');
//include('library/nc-base/static-load.php');
//include('library/nc-base/add-menu-page.php');
if (version_compare(PHP_VERSION, '7.2.26', '>=')) {
include('modules/field-group/Field_Group_Values.php');
include('modules/field-group/get_all_custom_field_meta.php');
//include('modules/field-group/Field_Group_Values.php');
//include('modules/field-group/get_all_custom_field_meta.php');
}
include('modules/base/main.php');
//include('modules/base/main.php');
include('framework/plugin-options.php');
include('functions/func_load.php');
include('framework/load.php');
function nc_store_pluggable_include() {
include( 'modules/pluggable/load.php' );