//后台字体切换雅黑
function geekzu_admin_font(){
echo'<style>*{font-family:"Microsoft YaHei";}</style>';
}
add_action('admin_head', 'geekzu_admin_font');
//友情链接
add_filter( 'pre_option_link_manager_enabled', '__return_true' );
//判断当前文章是否被百度收录,若没有被收录则可点击提交至百度,加速收录!(此插件在文章页面仅管理员可见)
function d4v($url){
$url='
http://www.baidu.com/s?wd='.$url; $curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$rs=curl_exec($curl);
curl_close($curl);
if(!strpos($rs,'没有找到')){
return 1;
}else{
return 0;
}
}
add_filter( 'the_content', 'baidu_submit' );
function baidu_submit( $content ) {
if( is_single() && current_user_can( 'manage_options') )
if(d4v(get_permalink()) == 1)
$content="<p align=right>本文百度已收录!</p>".$content;
else
$content="<p align=right><b><a style=color:red target=_blank href=
http://zhanzhang.baidu.com/sitesubmit/index?sitename=".get_permalink().">百度未收录!点击此处提交</a></b>(仅管理员可见)</p>".$content;
return $content;
}
//防采集
$ua = $_SERVER['HTTP_USER_AGENT'];
$now_ua = array('FeedDemon ','ZmEu','Indy Library','oBot','jaunty'); //将恶意USER_AGENT存入数组
if(!$ua) { //禁止空USER_AGENT,dedecms等主流采集程序都是空USER_AGENT,部分sql注入工具也是空USER_AGENT
header("Content-type: text/html; charset=utf-8");
wp_die('请勿采集,因为采集的站长木JJ!
www.geekzu.cn');
}else{
foreach($now_ua as $value )
if(eregi($value,$ua)) {
header("Content-type: text/html; charset=utf-8");
wp_die('请勿采集本站,因为采集的站长木JJ!
www.geekzu.cn');
}
}
//移除头部多余信息
remove_action('wp_head','wp_generator'); //禁止在head泄露wordpress版本号
remove_action('wp_head','rsd_link'); //移除head中的rel="EditURI"
remove_action('wp_head','wlwmanifest_link'); //移除head中的rel="wlwmanifest"
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 ); //rel=shortlink
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );//rel='prev' rel='next'
remove_action('wp_head', 'rel_canonical' );//rel='canonical'
//移除wp近期评论加载样式
function remove_recent_comments_style() {
global $wp_widget_factory;
remove_action( 'wp_head' , array( $wp_widget_factory -> widgets['WP_Widget_Recent_Comments'] , 'recent_comments_style' ) );
}
add_action( 'widgets_init' , 'remove_recent_comments_style' );
// 开启支持 文章形式
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
//头像中转极客族公共加速服务 解决被墙问题
function get_ssl_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img class="avatar avatar-$2" src="//
sdn.geekzu.org/avatar/$1?s=$2" alt="" width="$2" height="$2" />',$avatar);
return $avatar;
}
add_filter('get_avatar', 'get_ssl_avatar');
//禁用半角符号自动转换为全角
remove_filter('the_content', 'wptexturize');
// 禁止全英文和日文评论
function GeekZu_comment_post( $incoming_comment ) {
$pattern = '/[一-龥]/u';
$jpattern ='/[ぁ-ん]+|[ァ-ヴ]+/u';
if(!preg_match($pattern, $incoming_comment['comment_content'])) {
err( "评论请用天朝语言 Comments must include the Chinese(like“你好”)" );
}
if(preg_match($jpattern, $incoming_comment['comment_content'])){
err( "日本人滚一边玩儿蛋去!Japanese Get out!日本語出て行け!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'GeekZu_comment_post');
//禁用Open Sans
class Disable_Google_Fonts {
public function __construct() {
add_filter( 'gettext_with_context', array( $this, 'disable_open_sans' ), 888, 4 );
}
public function disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
}
$disable_google_fonts = new Disable_Google_Fonts;
add_filter('content_save_pre', 'auto_save_image');
function auto_save_image($content) {
$upload_path = '';
$upload_url_path = get_bloginfo('url');