1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-06-15 20:15:12 +02:00

修改函数名

This commit is contained in:
云落 2020-01-27 12:06:36 +08:00
parent 909933f92d
commit 59a16c642d
8 changed files with 116 additions and 90 deletions

View file

@ -128,24 +128,44 @@ $gdk_options = [
'std' => '|' 'std' => '|'
], ],
[ [
'name' => '自动内链', 'name' => '文章自动内链',
'desc' => '启用', 'desc' => '该功能会将文章中与标签匹配的文字自动添加标签链接,如果是纯文字的内容建议打开,默认禁用',
'id' => 'git_autolink_b', 'id' => 'gdk_tag_link',
'type' => 'checkbox' 'type' => 'radio',
], 'options' => [
[ '0' => '禁用',
'name' => '关键词出现数目', '1' => '开启'
'desc' => '文章中少于这个数字的关键词将不自动内链默认是1即全部链接', ],
'id' => 'git_autolink_1', 'std' => '0'
'type' => 'number',
'std' => 1
], ],
[ [
'name' => '关键词链接次数', 'name' => '关键词链接次数',
'desc' => '文章中最多链接的次数,默认是6', 'desc' => '文章中最多链接的次数,默认是5',
'id' => 'git_autolink_2', 'id' => 'gdk_tag_num',
'type' => 'number', 'type' => 'number',
'std' => 6 'std' => 5
],
[
'name' => 'Robots.txt 优化',
'desc' => '该功能会自动生成一个虚拟Robots.txt文件,和真实文件效果一样的,默认开启',
'id' => 'gdk_robots',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '网站地图 sitemap_xml',
'desc' => '该功能会自动生成网站地图链接:域名/sitemap_xml,开启后建议更新固定链接一次,默认开启',
'id' => 'gdk_sitemap_xml',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
], ],
[ [
'name' => '图片自动添加alt以及title', 'name' => '图片自动添加alt以及title',

View file

@ -30,7 +30,7 @@ function gdk_update_options() {
gdk_update_options(); gdk_update_options();
//获取设置选项 //获取设置选项
function gdk_get_option($id, $returnDefault = false) { function gdk_option($id, $returnDefault = false) {
global $gdk_default_options, $gdk_current_options; global $gdk_default_options, $gdk_current_options;
return stripslashes( $returnDefault ? $gdk_default_options[$id] : $gdk_current_options[$id] ); return stripslashes( $returnDefault ? $gdk_default_options[$id] : $gdk_current_options[$id] );
} }
@ -92,7 +92,7 @@ switch ( $type ) {
case 'text': case 'text':
?> ?>
<label> <label>
<input name="<?php echo $id; ?>" class="regular-text" id="<?php echo $id; ?>" type="text" value="<?php echo esc_attr(gdk_get_option( $id )) ?>" /> <input name="<?php echo $id; ?>" class="regular-text" id="<?php echo $id; ?>" type="text" value="<?php echo esc_attr(gdk_option( $id )) ?>" />
</label> </label>
<p class="description"><?php echo $option['desc']; ?></p> <p class="description"><?php echo $option['desc']; ?></p>
<?php <?php
@ -100,7 +100,7 @@ switch ( $type ) {
case 'number': case 'number':
?> ?>
<label> <label>
<input name="<?php echo $id; ?>" class="small-text" id="<?php echo $id; ?>" type="number" value="<?php echo esc_attr(gdk_get_option( $id )) ?>" /> <input name="<?php echo $id; ?>" class="small-text" id="<?php echo $id; ?>" type="number" value="<?php echo esc_attr(gdk_option( $id )) ?>" />
<span class="description"><?php echo $option['desc']; ?></span> <span class="description"><?php echo $option['desc']; ?></span>
</label> </label>
<?php <?php
@ -108,7 +108,7 @@ switch ( $type ) {
case 'textarea': case 'textarea':
?> ?>
<p><label for="<?php echo $id; ?>"><?php echo $option['desc']; ?></label></p> <p><label for="<?php echo $id; ?>"><?php echo $option['desc']; ?></label></p>
<p><textarea name="<?php echo $id; ?>" id="<?php echo $id; ?>" rows="10" cols="50" class="large-text code"><?php echo esc_textarea(gdk_get_option( $id )) ?></textarea></p> <p><textarea name="<?php echo $id; ?>" id="<?php echo $id; ?>" rows="10" cols="50" class="large-text code"><?php echo esc_textarea(gdk_option( $id )) ?></textarea></p>
<?php <?php
break; break;
case 'radio': case 'radio':
@ -116,7 +116,7 @@ switch ( $type ) {
<fieldset> <fieldset>
<?php foreach ($option['options'] as $val => $name) : ?> <?php foreach ($option['options'] as $val => $name) : ?>
<label> <label>
<input type="radio" name="<?php echo $id; ?>" id="<?php echo $id . '_' . $val; ?>" value="<?php echo $val; ?>" <?php checked( gdk_get_option( $id ), $val); ?>> <input type="radio" name="<?php echo $id; ?>" id="<?php echo $id . '_' . $val; ?>" value="<?php echo $val; ?>" <?php checked( gdk_option( $id ), $val); ?>>
<?php echo $name; ?> <?php echo $name; ?>
</label> </label>
<?php endforeach; ?> <?php endforeach; ?>
@ -127,7 +127,7 @@ switch ( $type ) {
case 'checkbox': case 'checkbox':
?> ?>
<label> <label>
<input type='checkbox' name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="1" <?php echo checked(gdk_get_option($id)); ?> /> <input type='checkbox' name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="1" <?php echo checked(gdk_option($id)); ?> />
<span><?php echo $option['desc']; ?></span> <span><?php echo $option['desc']; ?></span>
</label> </label>
<?php <?php
@ -135,7 +135,7 @@ switch ( $type ) {
case 'checkboxs': case 'checkboxs':
?> ?>
<fieldset> <fieldset>
<?php $checkboxValues = gdk_get_option( $id ); <?php $checkboxValues = gdk_option( $id );
if ( !is_array($checkboxValues) ) $checkboxValues = []; if ( !is_array($checkboxValues) ) $checkboxValues = [];
foreach ( $option['options'] as $id => $name ) : ?> foreach ( $option['options'] as $id => $name ) : ?>
<label> <label>
@ -150,7 +150,7 @@ switch ( $type ) {
default: default:
?> ?>
<label> <label>
<input name="<?php echo $id; ?>" class="regular-text" id="<?php echo $id; ?>" type="<?php echo $type; ?>" value="<?php echo esc_attr(gdk_get_option( $id )) ?>" /> <input name="<?php echo $id; ?>" class="regular-text" id="<?php echo $id; ?>" type="<?php echo $type; ?>" value="<?php echo esc_attr(gdk_option( $id )) ?>" />
</label> </label>
<p class="description"><?php echo $option['desc']; ?></p> <p class="description"><?php echo $option['desc']; ?></p>
<?php <?php

View file

@ -2,7 +2,7 @@
//头像解决方案 //头像解决方案
function gdk_switch_get_avatar( $avatar ) { function gdk_switch_get_avatar( $avatar ) {
switch (gdk_get_option('gdk_switch_get_avatar')) { switch (gdk_option('gdk_switch_get_avatar')) {
case 1: case 1:
$avatarsrc = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg'; $avatarsrc = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg';
$avatar = "<img src=$avatarsrc class='avatar rand_avatar photo' />"; $avatar = "<img src=$avatarsrc class='avatar rand_avatar photo' />";

View file

@ -3,7 +3,7 @@
//禁用新版编辑器 //禁用新版编辑器
if(gdk_get_option('gdk_diasble_gutenberg')){ if(gdk_option('gdk_diasble_gutenberg')){
add_filter('use_block_editor_for_post', '__return_false'); add_filter('use_block_editor_for_post', '__return_false');
remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
} }
@ -12,7 +12,7 @@ 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 无关紧要的代码 //移除 WP_Head 无关紧要的代码
if(gdk_get_option('gdk_diasble_head_useless')){ if(gdk_option('gdk_diasble_head_useless')){
remove_action('wp_head', 'wp_generator'); //删除 head 中的 WP 版本号 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) { 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($action, 'the_generator');
@ -37,7 +37,7 @@ if(gdk_get_option('gdk_diasble_head_useless')){
/** 开始关闭WordPress更新 **/ /** 开始关闭WordPress更新 **/
if (gdk_get_option('gdk_diasble_wp_update')) { if (gdk_option('gdk_diasble_wp_update')) {
add_filter('automatic_updater_disabled', '__return_true'); add_filter('automatic_updater_disabled', '__return_true');
remove_action('init', 'wp_schedule_update_checks'); remove_action('init', 'wp_schedule_update_checks');
wp_clear_scheduled_hook('wp_version_check'); wp_clear_scheduled_hook('wp_version_check');
@ -62,7 +62,7 @@ remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12); add_filter( 'the_content', 'wpautop' , 12);
//禁用emoji功能 //禁用emoji功能
if (gdk_get_option('gdk_disable_emojis')) { if (gdk_option('gdk_disable_emojis')) {
function gdk_disable_emojis_link() { function gdk_disable_emojis_link() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
@ -83,14 +83,14 @@ if (gdk_get_option('gdk_disable_emojis')) {
//禁用 XML-RPC 接口 //禁用 XML-RPC 接口
if (gdk_get_option('gdk_disable_xmlrpc')) { if (gdk_option('gdk_disable_xmlrpc')) {
add_filter('xmlrpc_enabled', '__return_false'); add_filter('xmlrpc_enabled', '__return_false');
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd'); remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
} }
//禁用日志修订功能 //禁用日志修订功能
if (gdk_get_option('gdk_disable_revision')) { if (gdk_option('gdk_disable_revision')) {
function gdk_disable_post_revisions() { function gdk_disable_post_revisions() {
foreach ( get_post_types() as $post_type ) { foreach ( get_post_types() as $post_type ) {
remove_post_type_support( $post_type, 'revisions' ); remove_post_type_support( $post_type, 'revisions' );
@ -100,7 +100,7 @@ if (gdk_get_option('gdk_disable_revision')) {
} }
//彻底关闭 pingback //彻底关闭 pingback
if (gdk_get_option('gdk_disable_trackbacks')) { if (gdk_option('gdk_disable_trackbacks')) {
add_filter('xmlrpc_methods', 'gdk_xmlrpc_methods'); add_filter('xmlrpc_methods', 'gdk_xmlrpc_methods');
function gdk_xmlrpc_methods($methods) { function gdk_xmlrpc_methods($methods) {
unset($methods['system.multicall']); unset($methods['system.multicall']);
@ -115,7 +115,7 @@ if (gdk_get_option('gdk_disable_trackbacks')) {
} }
//国内更新word press加速 //国内更新word press加速
if (gdk_get_option('gdk_porxy_update') && !gdk_get_option('gdk_diasble_wp_update')) { if (gdk_option('gdk_porxy_update') && !gdk_option('gdk_diasble_wp_update')) {
add_filter('site_transient_update_core',function($value) { add_filter('site_transient_update_core',function($value) {
foreach($value->updates as &$update) { foreach($value->updates as &$update) {
if($update->locale == 'zh_CN') { if($update->locale == 'zh_CN') {

View file

@ -28,7 +28,7 @@ add_action( 'wp', 'gdk_prevent_script_injection' );
} }
} }
if(gdk_get_option('gdk_lock_login')){ if(gdk_option('gdk_lock_login')){
if ( ! class_exists( 'GDK_Limit_Login_Attempts' ) ) { if ( ! class_exists( 'GDK_Limit_Login_Attempts' ) ) {
class GDK_Limit_Login_Attempts { class GDK_Limit_Login_Attempts {
var $failed_login_limit = 3; var $failed_login_limit = 3;
@ -38,8 +38,8 @@ if(gdk_get_option('gdk_lock_login')){
var $transient_name = 'attempted_login'; var $transient_name = 'attempted_login';
//Transient used //Transient used
public function __construct() { public function __construct() {
$failed_login_limit = gdk_get_option('gdk_failed_login_limit'); $failed_login_limit = gdk_option('gdk_failed_login_limit');
$lockout_duration = gdk_get_option('gdk_lockout_duration'); $lockout_duration = gdk_option('gdk_lockout_duration');
add_filter( 'authenticate', array( $this, 'check_attempted_login' ), 30, 3 ); add_filter( 'authenticate', array( $this, 'check_attempted_login' ), 30, 3 );
add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 ); add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 );
} }

View file

@ -1,5 +1,56 @@
<?php <?php
//加载网站地图xml
if(gdk_option('gdk_sitemap_xml')){
include('sitemap-xml.php');
}
//robots.txt优化功能
if(gdk_option('gdk_robots')){
add_filter('robots_txt', 'gdk_robots_txt', 10, 2);
function gdk_robots_txt($robotext)
{
if(gdk_option('gdk_sitemap_xml')){
$sitemap = 'Sitemap: ' . home_url('/sitemap.xml');
} else {
$sitemap = '';
}
$robotext = "User-agent: *
Disallow: /wp-admin/
Disallow: /wp-content/plugins/
Disallow: /wp-includes/
Disallow: /*/trackback
Disallow: /feed
Disallow: /*/feed
Disallow: /attachment/
Disallow: /wp-content/themes/
{$sitemap}";
return $robotext;
}
}
//文章自动内链
if(gdk_option('gdk_tag_link')){
function gdk_tag_link($content)
{
$post_tags = get_the_tags();
if ($post_tags) {
foreach ($post_tags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), '查看更多关于%s的文章').'">'.addcslashes($cleankeyword, '$').'</a>';
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
$content = preg_replace($regEx, $url, $content, gdk_option('gdk_tag_num') ?? 5);
}
}
return $content;
}
add_filter('the_content', 'gdk_tag_link', 1);
}
//给外部链接加上跳转 //给外部链接加上跳转
function git_go_url($content){ function git_go_url($content){

View file

@ -11,7 +11,7 @@ function sitemap_xml_flush_rules(){
// 添加自定义URL重写 // 添加自定义URL重写
function sitemap_xml_custom_rewrite_rule() { function sitemap_xml_custom_rewrite_rule() {
add_rewrite_rule('^sitemap(.*?)\.xml$','index.php?sitemap=nice$matches[1]','top'); add_rewrite_rule('^sitemap(.*?)\.xml$','index.php?sitemap=gdk$matches[1]','top');
} }
function sitemap_xml_insert_query_vars( $vars ){ function sitemap_xml_insert_query_vars( $vars ){
@ -32,7 +32,7 @@ function sitemap_xml_api_handlers( $template ){
$hook = explode('-', get_query_var( 'sitemap' ) ); $hook = explode('-', get_query_var( 'sitemap' ) );
if( isset( $hook[0] ) && $hook[0] === 'nice' ){ if( isset( $hook[0] ) && $hook[0] === 'gdk' ){
if( isset( $hook[1] ) ){ if( isset( $hook[1] ) ){
status_header(404); status_header(404);
@ -42,11 +42,11 @@ function sitemap_xml_api_handlers( $template ){
exit; exit;
} }
$sitemap = get_transient('nice-sitemap'); $sitemap = get_transient('gdk-sitemap');
if( false === $sitemap || empty( $sitemap ) ){ if( false === $sitemap || empty( $sitemap ) ){
$sitemap = nc_create_sitemap(); $sitemap = gdk_create_sitemap();
set_transient( 'nice-sitemap', $sitemap ); set_transient( 'gdk-sitemap', $sitemap );
} }
header("Content-type: text/xml"); header("Content-type: text/xml");
@ -63,7 +63,7 @@ add_filter( 'redirect_canonical', 'sitemap_xml_cancel_redirect' );
add_action( 'wp_loaded', 'sitemap_xml_flush_rules' ); add_action( 'wp_loaded', 'sitemap_xml_flush_rules' );
add_filter( 'template_include', 'sitemap_xml_api_handlers', 99 ); add_filter( 'template_include', 'sitemap_xml_api_handlers', 99 );
function nc_create_sitemap() { function gdk_create_sitemap() {
if ( str_replace( '-', '', get_option( 'gmt_offset' ) ) < 10 ) { if ( str_replace( '-', '', get_option( 'gmt_offset' ) ) < 10 ) {
$tempo = '-0' . str_replace( '-', '', get_option( 'gmt_offset' ) ); $tempo = '-0' . str_replace( '-', '', get_option( 'gmt_offset' ) );
@ -100,9 +100,9 @@ function nc_create_sitemap() {
return $sitemap; return $sitemap;
} }
function nc_clear_sitemap_cache(){ function gdk_clear_sitemap_cache(){
delete_transient( 'nice-sitemap' ); delete_transient( 'gdk-sitemap' );
} }
add_action("publish_post", "nc_clear_sitemap_cache"); add_action("publish_post", "gdk_clear_sitemap_cache");
add_action("publish_page", "nc_clear_sitemap_cache"); add_action("publish_page", "gdk_clear_sitemap_cache");
add_action( "save_post", "nc_clear_sitemap_cache" ); add_action( "save_post", "gdk_clear_sitemap_cache" );

View file

@ -44,53 +44,8 @@ if ($others_seo['auto_nofollow']) {
endif; endif;
} }
if ($others_seo['auto_tag_link_switcher']) {
if (!function_exists('nc_tag_link')):
function nc_tag_link($content)
{
$post_tags = get_the_tags();
if ($post_tags) {
foreach ($post_tags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), __('View all posts in %s')).'">'.addcslashes($cleankeyword, '$').'</a>';
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
$content = preg_replace($regEx, $url, $content, $others_seo['auto_tag_link_switcher_limit'] ?? 5);
}
}
return $content;
}
add_filter('the_content', 'nc_tag_link', 1);
endif;
}
if ($general_options['improve_robots_txt']) {
if (!function_exists('nc_robots_txt')):
add_filter('robots_txt', 'nc_robots_txt', 10, 2);
function nc_robots_txt($robotext)
{
if (isset($GLOBALS['nice_sitemap_xml'])) {
$sitemap = 'Sitemap: ' . home_url('/sitemap.xml');
} else {
$sitemap = '';
}
$robotext = "User-agent: *
Disallow: /wp-admin/
Disallow: /wp-content/plugins/
Disallow: /wp-includes/
Disallow: /*/trackback
Disallow: /feed
Disallow: /*/feed
Disallow: /attachment/
Disallow: /wp-content/themes/
{$sitemap}";
return $robotext;
}
endif;
}
if (isset($others_seo['baidu_submit']) && $others_seo['baidu_submit']) { if (isset($others_seo['baidu_submit']) && $others_seo['baidu_submit']) {
add_action('post_updated', 'nc_baidu_submit'); add_action('post_updated', 'nc_baidu_submit');