验证中...
Languages: PHP
Categories: Web开发技术
Latest update 2019-06-10 14:31
增强函数plus
Raw Copy
@include(TEMPLATEPATH.'/plus.php'); //增强函数
plus.php
Raw Copy
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
<?php
//@startSMTP邮箱设置
//if(!get_option("SmtpPwd")&&get_option("SmtpHost")):
//SMTP邮箱设置
function php_mail_smtp($phpmailer) {
$phpmailer->From = get_bloginfo ('admin_email') ; //发件人地址
$phpmailer->FromName = get_bloginfo('name'); //发件人昵称
$phpmailer->Host = 'smtp.qq.com'; //SMTP服务器地址
$phpmailer->Port = '465'; //SMTP邮件发送端口
$phpmailer->SMTPSecure = 'ssl';//SMTP加密方式(SSL/TLS)没有为空即可
$phpmailer->Username = get_bloginfo ('admin_email') ; //邮箱帐号
$phpmailer->Password = 'kqmzmboocrmdbcef'; //邮箱密码 'kqmzmboocrmdbcef'
$phpmailer->IsSMTP();
$phpmailer->SMTPAuth = true; //启用SMTPAuth服务
}
add_action('phpmailer_init', 'php_mail_smtp');
//endif;
@include(TEMPLATEPATH.'/wcu/wp-clean-up.php'); //数据库清理
//移除顶部多余信息
remove_action('wp_head', 'feed_links', 2);//文章和评论feed
remove_action('wp_head', 'feed_links_extra', 3);// 额外的feed,例如category, tag页
remove_action('wp_head', 'start_post_rel_link', 10, 0);// 开始篇
remove_action('wp_head', 'parent_post_rel_link', 10, 0);//前后文信息
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // 上、下篇.
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);//rel=pre
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);//短链接
remove_action('wp_head', 'index_rel_link'); //移除当前页面的索引
remove_action('wp_head', 'noindex',1); //索引和爬取方式
remove_action('wp_head', 'rel_canonical');//rel="canonical"
remove_action('wp_head', 'wp_generator');//版本信息
/*
remove_action('wp_head', 'rsd_link');//移除head中的rel="EditURI"
remove_action('wp_head', 'wlwmanifest_link');//移除head中的rel="wlwmanifest"
remove_action('wp_head', 'rsd_link');//rsd_link移除XML-RPC
*/
//remove_action('wp_head', 'locale_stylesheet');
//remove_action('wp_head', 'wp_enqueue_scripts', 1);//Javascript的调用
//remove_action('wp_head', 'wp_print_styles', 8);//载入css
//add_filter('xmlrpc_enabled','__return_false');//禁用xmlrpc
remove_action('wp_head', 'wp_resource_hints', 2 ); //dns-prefetch
remove_action('wp_head', 'wp_print_head_scripts', 9 );
//remove_action('template_redirect', 'wp_shortlink_header', 11, 0);
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
wp_deregister_script('l10n');
remove_action('wp_head', 'print_emoji_detection_script', 7);//禁止加载emoji
remove_action('wp_print_styles', 'print_emoji_styles' );//禁止加载emoji
add_filter('emoji_svg_url', '__return_false' );//禁止加载emoji
remove_action('wp_footer', 'wp_print_footer_scripts' ); //底部脚本
//移除wp-json链接
add_filter('rest_enabled', '_return_false');
add_filter('rest_jsonp_enabled', '_return_false');
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
//移除后台emoji
remove_action('admin_print_scripts','print_emoji_detection_script');
remove_action('admin_print_styles','print_emoji_styles');
remove_action('wp_head','print_emoji_detection_script', 7);
remove_action('wp_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');
//移除评论 Cookie 确认复选框
add_filter('comment_form_field_cookies','__return_false');
//默认记录评论 Cookie
add_action('set_comment_cookies','coffin_set_cookies',10,3);
function coffin_set_cookies( $comment, $user, $cookies_consent){
$cookies_consent = true;
wp_set_comment_cookies($comment, $user, $cookies_consent);
}
//屏蔽 WP 后台“显示选项”和“帮助”选项卡
function remove_screen_options(){ return false;}
//add_filter('screen_options_show_screen', 'remove_screen_options'); //显示选项
add_filter( 'contextual_help', 'wpse50723_remove_help', 999, 3 ); //帮助
function wpse50723_remove_help($old_help, $screen_id, $screen){
$screen->remove_help_tabs();
return $old_help;
}
/*
//屏蔽后台无用模块
function example_remove_dashboard_widgets() {
// Globalize the metaboxes array, this holds all the widgets for wp-admin
global $wp_meta_boxes;
// 以下这一行代码将删除 "快速发布" 模块
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
// 以下这一行代码将删除 "引入链接" 模块
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
// 以下这一行代码将删除 "插件" 模块
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
// 以下这一行代码将删除 "近期评论" 模块
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
// 以下这一行代码将删除 "近期草稿" 模块
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
// 以下这一行代码将删除 "WordPress 开发日志" 模块
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
// 以下这一行代码将删除 "其它 WordPress 新闻" 模块
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
// 以下这一行代码将删除 "概况" 模块
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
}
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );
*/
//屏蔽左上方LOGO
function annointed_admin_bar_remove() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);
//移除登录页面标题中的“ — WordPress”
add_filter('login_title', 'Lopin_remove_login_title', 10, 2);
function Lopin_remove_login_title($login_title, $title){ return $title.' &lsaquo; '.get_bloginfo('name'); }
//移除后台页面标题中的“ — WordPress”
add_filter('admin_title', 'Lopin_remove_admin_title', 10, 2);
function Lopin_remove_admin_title($admin_title, $title){ return $title.' &lsaquo; '.get_bloginfo('name'); }
//屏蔽后台页脚信息
function change_footer_admin () {return '';}
add_filter('admin_footer_text', 'change_footer_admin', 9999);
function change_footer_version() {return '';}
add_filter( 'update_footer', 'change_footer_version', 9999);
//删除后台子菜单
function remove_submenu() {
// 删除”设置”下面的子菜单”隐私”
remove_submenu_page('options-general.php', 'options-privacy.php');
// 删除”外观”下面的子菜单”编辑”
remove_submenu_page('themes.php', 'theme-editor.php');
}
if (is_admin()){
//删除子菜单
add_action('admin_init','remove_submenu');
}
if (version_compare( $GLOBALS['wp_version'], '5.0', '>' )) {
//换回经典编辑器tinymce
add_filter('use_block_editor_for_post','__return_false');
remove_action('wp_enqueue_scripts','wp_common_block_scripts_and_styles');
}
/*
//重置非管理员用户到首页
function redirect_non_admin_users() {
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( home_url() );
exit;
}
}
add_action( 'admin_init', 'redirect_non_admin_users' );
*/
//移除菜单的多余CSS选择器
function my_css_attributes_filter($var) {return is_array($var) ? array() : '';}
add_filter('nav_menu_css_class', 'my_css_attributes_filter',100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter',100, 1);
add_filter('page_css_class', 'my_css_attributes_filter',100, 1);
//其他功能优化
show_admin_bar(false);//禁用工具条
remove_action('publish_future_post','check_and_publish_future_post',10, 1); //文章定时发布任务
remove_filter('the_content', 'wptexturize');//禁用半角符号自动转换为全角
add_filter('create_fun_core', create_function('', 'return 1;'));//禁用 create_fun_core 函数:禁用图片裁剪功能
// 禁止自动生成 768px 缩略图
function shapeSpace_customize_image_sizes($sizes) { unset($sizes['medium_large']);return $sizes; }
// 禁用 srcset 属性
add_filter('max_srcset_image_width', create_function('', 'return 1;'));
//禁用文章自动保存,禁用文章修订版本
add_action('wp_print_scripts','disable_autosave');
add_filter( 'wp_revisions_to_keep', 'specs_wp_revisions_to_keep', 10, 2 );
function disable_autosave(){ wp_deregister_script('autosave'); }
function specs_wp_revisions_to_keep( $num, $post ) { return 0; }
// 移除不必要的存档页面
add_action('template_redirect', 'meks_remove_wp_archives');
function meks_remove_wp_archives(){ if(is_date()) { global $wp_query; $wp_query->set_404(); } }
// 删除文章时删除图片附件
add_action('before_delete_post', 'delete_post_and_attachments');
function delete_post_and_attachments($post_ID) {
global $wpdb;
//删除特色图片
$thumbnails = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' AND post_id = $post_ID" );
foreach ( $thumbnails as $thumbnail ) {
wp_delete_attachment( $thumbnail->meta_value, true );
}
//删除图片附件
$attachments = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_parent = $post_ID AND post_type = 'attachment'" );
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->ID, true );
}
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' AND post_id = $post_ID" );
}
// 文章发布时弹出确认发布对话框
add_action('admin_footer', 'confirm_publish');
$c_message = '请再次确认是否要发布这篇文章?';
function confirm_publish(){
global $c_message;
echo '<script type="text/javascript"><!--
var publish = document.getElementById("publish");
if (publish !== null) publish.onclick = function(){
return confirm("'.$c_message.'");
};
// --></script>';
}
//发布文章前必须选择分类(与Restrict Author Posting插件冲突)
add_action('admin_footer-post.php', 'choose_a_category_before_publish');
add_action('admin_footer-post-new.php', 'choose_a_category_before_publish');
function choose_a_category_before_publish(){
global $post_type;
if($post_type=='post'){
echo "<script>
jQuery(function($){
$('#publish, #save-post').click(function(e){
if($('#taxonomy-category input:checked').length==0){
alert('抱歉,发布文章前,请在右侧的分类目录下勾选一个分类并填写关键词和摘要(招聘概括)信息,否则无法发布。');
e.stopImmediatePropagation();
return false;
}else{
return true;
}
});
var publish_click_events = $('#publish').data('events').click;
if(publish_click_events){
if(publish_click_events.length>1){
publish_click_events.unshift(publish_click_events.pop());
}
}
if($('#save-post').data('events') != null){
var save_click_events = $('#save-post').data('events').click;
if(save_click_events){
if(save_click_events.length>1){
save_click_events.unshift(save_click_events.pop());
}
}
}
});
</script>";
}
}
// 网站后台文章新标签打开
global $pagenow;
if( $pagenow == 'post.php' ){//这里如果不加的话,就会后台一直 js 报错
function _admin_aritical_ctrlenter() {
echo '<script type="text/javascript">
var postlink = document.getElementById("edit-slug-box").getElementsByTagName("a");
for(var i=0;i<postlink.length;i++){ postlink[i].target = "_blank"; }
</script>';
};
add_action('admin_footer', '_admin_aritical_ctrlenter');
};
//新标签打开顶部网站链接
add_action('admin_footer', '_admin_site_ctrlenter');
function _admin_site_ctrlenter() {
echo '<script type="text/javascript">
var sitelink = document.getElementById("wp-admin-bar-site-name").getElementsByClassName("ab-item");
for(var i=0;i<sitelink.length;i++){ sitelink[i].target = "_blank"; }
</script>';
};
//只显示自己上传的文件
function my_upload_media( $wp_query_obj ) {
global $current_user, $pagenow;
if( !is_a( $current_user, 'WP_User') )
return;
if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
return;
if( !current_user_can( 'manage_options' ) && !current_user_can('manage_media_library') )
$wp_query_obj->set('author', $current_user->ID );
return;
}
add_action('pre_get_posts','my_upload_media');
function my_media_library( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
if ( !current_user_can( 'manage_options' ) && !current_user_can( 'manage_media_library' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'my_media_library' );
// 禁止Ping自己的博客
add_action( 'pre_ping', 'no_self_ping' );
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link ){
if ( 0 === strpos( $link, $home ) ){
unset($links[$l]);
}
}
}
//搜索功能
//与模板分类冲突
//修改搜索结果的链接
function redirect_search() {
if (is_search() && !empty($_GET['s'])) {
wp_redirect(home_url('/search/').urlencode(get_query_var('s')));
exit();
}
}
add_action('template_redirect', 'redirect_search' );
//分类搜索
/*
function return_only_selected_category( $query ) {
//is_search判断搜索页面 !is_admin排除后台 $query->is_main_query()只影响主循环
if ( is_search() && !is_admin() && $query->is_main_query() ){
//有cat值传入
if(isset($_GET['cat'])){
$term_id = (int)$_GET['cat']; //处理分类参数
if( $term_id ){
//分类查询的参数
$tax_query = array(
array(
'taxonomy'=>'category', //可换为自定义分类法
'field'=>'term_id',
'operator'=>'IN',
'terms'=>array($term_id)
)
);
$query->set( 'tax_query', $tax_query );
}
}
}
return $query;
}
add_filter('pre_get_posts', 'return_only_selected_category');
*/
//@start压缩代码
//压缩前端html代码
if(!current_user_can('manage_options') || strpos($_SERVER['REQUEST_URI'],'robots.txt')!==false || strpos($_SERVER['REQUEST_URI'],'.xml')!==false ) :
function wp_compress_html(){
function wp_compress_html_main ($buffer){
$initial=strlen($buffer);
$buffer=explode("<!--wp-compress-html-->", $buffer);
$count=count ($buffer);
for ($i = 0; $i <= $count; $i++){
if (stristr($buffer[$i], '<!--wp-compress-html no compression-->')) {
$buffer[$i]=(str_replace("<!--wp-compress-html no compression-->", " ", $buffer[$i]));
} else {
$buffer[$i]=(str_replace("\t", " ", $buffer[$i]));
$buffer[$i]=(str_replace("\n\n", "\n", $buffer[$i]));
$buffer[$i]=(str_replace("\n", "", $buffer[$i]));
$buffer[$i]=(str_replace("\r", "", $buffer[$i]));
while (stristr($buffer[$i], ' ')) {
$buffer[$i]=(str_replace(" ", " ", $buffer[$i]));
}
}
$buffer_out.=$buffer[$i];
}
$final=strlen($buffer_out);
$savings=($initial-$final)/$initial*100;
$savings=round($savings, 2);
$buffer_out.="\n<!--压缩前的大小: $initial bytes; 压缩后的大小: $final bytes; 节约:$savings% -->";
return $buffer_out;
}
//WordPress后台不压缩
if ( !is_admin() ) {
ob_start("wp_compress_html_main");
}
}
add_action('init', 'wp_compress_html');
//当检测到文章内容中有代码标签时文章内容不会被压缩
function unCompress($content) {
if( preg_match_all('/(language-|<\/pre>)/i', $content, $matches)||preg_match_all('/(crayon-|<\/pre>)/i', $content, $matches) ){
$content = '<!--wp-compress-html--><!--wp-compress-html no compression-->'.$content;
$content.= '<!--wp-compress-html no compression--><!--wp-compress-html-->';
}
return $content;
}
add_filter( "the_content", "unCompress");
endif;
//@end压缩代码
//@start登陆提醒
//if(!get_option("LoginNotify")):
//函数作用:有登录wp后台就会email通知博主
/*
function wp_login_notify() {
date_default_timezone_set('PRC');
$admin_email = get_bloginfo ('admin_email');
$to = $admin_email;
$subject = '你的博客空间登录提醒';
$message = '<p>你好!你的博客空间(' . get_option("blogname") . ')有登录!</p>' .
'<p>请确定是您自己的登录,以防别人攻击!登录信息如下:</p>' .
'<p>登录名:' . $_POST['log'] . '<p>' .
'<p>登录密码:' . $_POST['pwd'] . '<p>' .
'<p>登录时间:' . date("Y-m-d H:i:s") . '<p>' .
'<p>登录IP:' . $_SERVER['REMOTE_ADDR'] . '<p>';
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
}
add_action('wp_login', 'wp_login_notify');
*/
//函数作用:有错误登录wp后台就会email通知博主
function wp_login_failed_notify() {
date_default_timezone_set('PRC');
$admin_email = get_bloginfo ('admin_email');
$to = $admin_email;
$subject = '你的博客空间登录错误警告';
$message = '<p>你好!你的博客空间(' . get_option("blogname") . ')有登录错误!</p>' .
'<p>请确定是您自己的登录失误,以防别人攻击!登录信息如下:</p>' .
'<p>登录名:' . $_POST['log'] . '<p>' .
'<p>登录密码:' . $_POST['pwd'] . '<p>' .
'<p>登录时间:' . date("Y-m-d H:i:s") . '<p>' .
'<p>登录IP:' . $_SERVER['REMOTE_ADDR'] . '<p>';
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
}
add_action('wp_login_failed', 'wp_login_failed_notify');
//endif;
//@end登陆提醒
//@start语法高亮脚本
//if(get_option("PrismScript")):
//语法高亮脚本
function add_prism_style() {
if(is_page()||is_single()){
echo '<link rel="stylesheet" id="prismCSS" type="text/css" href="'.get_stylesheet_directory_uri().'/css/prism.css" media="all" />';
}
}
function add_prism_scripts() {
if(is_page()||is_single()){
wp_register_script('prismJS',get_stylesheet_directory_uri() . '/js/prism.js');
wp_enqueue_script('prismJS', false, array(), false, true);
}
}
add_action( 'wp_head', 'add_prism_style',10);
add_action('wp_enqueue_scripts', 'add_prism_scripts',999);
//后台可视化编辑器
function spces_code_plugin() {
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
return;
}
if ( get_user_option('rich_editing') == 'true' ) {
add_filter( 'mce_external_plugins', 'specs_mce_external_plugins_filter' );
add_filter( 'mce_buttons', 'specs_mce_buttons_filter' );
}
}
add_action('admin_head', 'spces_code_plugin');
function specs_mce_external_plugins_filter($plugin_array) {
$plugin_array['specs_code_plugin'] = get_template_directory_uri() . '/js/mce_code_plugin.js';
return $plugin_array;
}
function specs_mce_buttons_filter($buttons) {
array_push($buttons, 'specs_code_plugin');
return $buttons;
}
//endif;
//@end语法高亮脚本
//@start防止邮箱采集
//if(!get_option("EmailSecurity")):
//防止邮箱采集
function security_remove_emails($content) {
$pattern = '/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})/i';
$fix = preg_replace_callback($pattern, "security_remove_emails_logic", $content);
return $fix;
}
function security_remove_emails_logic($result) {
return antispambot($result[1]);
}
add_filter( 'the_content', 'security_remove_emails', 20 );
add_filter( 'comment_text', 'security_remove_emails', 20 );
//endif;
//@end防止邮箱采集
//@start移除后台隐私策略页
//if(!get_option("PrivacyPage")):
//移除后台隐私策略页
add_action('admin_menu', function (){
global $menu, $submenu;
// 移除设置菜单下的隐私子菜单。
unset($submenu['options-general.php'][45]);
// 移除工具彩带下的相关页面
remove_action( 'admin_menu', '_wp_privacy_hook_requests_page' );
remove_filter( 'wp_privacy_personal_data_erasure_page', 'wp_privacy_process_personal_data_erasure_page', 10, 5 );
remove_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 );
remove_filter( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
remove_filter( 'wp_privacy_personal_data_erased', '_wp_privacy_send_erasure_fulfillment_notification', 10 );
// Privacy policy text changes check.
remove_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'text_change_check' ), 100 );
// Show a "postbox" with the text suggestions for a privacy policy.
remove_action( 'edit_form_after_title', array( 'WP_Privacy_Policy_Content', 'notice' ) );
// Add the suggested policy text from WordPress.
remove_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'add_suggested_content' ), 1 );
// Update the cached policy info when the policy page is updated.
remove_action( 'post_updated', array( 'WP_Privacy_Policy_Content', '_policy_page_updated' ) );
},9);
//endif;
//@end移除后台隐私策略页
//@start外链跳转內链
//文章外链跳转伪静态版
add_filter('the_content','link_jump',999);//文章内容
function link_jump($content){
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff|webp)/i',$val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$val)){
$content=str_replace("href=\"$val\"", "href=\"".home_url()."/goto/".base64_encode($val)."\" rel=\"nofollow\"",$content);
}
}
}
return $content;
}
//@end外链跳转內链
//@start防止垃圾评论
//屏蔽关键词,email,url,ip
function Shield_fuckspam($comment) {
if (wp_blacklist_check($comment['comment_author'], $comment['comment_author_email'], $comment['comment_author_url'], $comment['comment_content'], $comment['comment_author_IP'], $comment['comment_agent'])) {
header("Content-type: text/html; charset=utf-8");
err(__('不好意思,您的评论违反评论规则'));
} else {
return $comment;
}
}
add_filter('preprocess_comment', 'Shield_fuckspam');
//屏蔽日文英文评论
function refused_spam_comments($comment_data) {
$pattern = '/[一-龥]/u';
$jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u';
if (!preg_match($pattern, $comment_data['comment_content'])) {
err(__('来一波汉字吧,苦逼的站长只认识汉字!You should type some Chinese word!'));
}
if (preg_match($jpattern, $comment_data['comment_content'])) {
err(__('原谅站长吧,这货只听得懂岛国神片的一两句雅蠛蝶 Japanese Get out!日本语出て行け! You should type some Chinese word!'));
}
return ($comment_data);
}
add_filter('preprocess_comment', 'refused_spam_comments');
//屏蔽昵称和评论里面添加链接
function Shield_link($comment_data) {
$links = '/http:\/\/|https:\/\/|www\./u';
if (preg_match($links, $comment_data['comment_author']) || preg_match($links, $comment_data['comment_content'])) {
err(__('别啊,昵称和评论里面添加链接会怀孕的哟!!'));
}
return ($comment_data);
}
add_filter('preprocess_comment', 'Shield_link');
//限制评论字数
function limit_comment_length( $commentdata ) {
$minCommentlength = 10; //最少字数限制
$maxCommentlength = 10000; //最多字数限制
$pointCommentlength = mb_strlen($commentdata['comment_content'],'UTF8'); //mb_strlen 1个中文字符当作1个长度
if ( $pointCommentlength < $minCommentlength ){
header("Content-type: text/html; charset=utf-8");
wp_die('抱歉,您的评论太短了,请至少输入' . $minCommentlength .'个字(已输入'. $pointCommentlength .'个字)');
exit;
}
if ( $pointCommentlength > $maxCommentlength ){
header("Content-type: text/html; charset=utf-8");
wp_die('抱歉,您的评论太长了,请少于' . $maxCommentlength .'个字(已输入'. $pointCommentlength .'个字)');
exit;
}
return $commentdata;
}
add_filter( 'preprocess_comment', 'limit_comment_length' );
//@end防止垃圾评论
//@start禁止发布相同标题内容
// 发表文章页面,前端抓取标题并使用AJAX发送请求
add_action( 'admin_print_footer_scripts', 'duplicate_titles_enqueue_scripts', 100 );
function duplicate_titles_enqueue_scripts() {
?>
<script>
jQuery(function($){
function checkTitleAjax(title, id,post_type) {
var data = {
action: 'title_checks',
post_title: title,
post_type: post_type,
post_id: id
};
$.post(ajaxurl, data, function(response) {
$('#message').remove();
$('#poststuff').prepend('<div id=\"message\" class=\"updated below-h2 fade \"><p>'+response+'</p></div>');
});
};
$('#title').change(function() {
var title = $('#title').val();
var id = $('#post_ID').val();
var post_type = $('#post_type').val();
checkTitleAjax(title, id,post_type);
});
});
</script>
<?php
}
// 接收前端ajax参数
add_action('wp_ajax_title_checks', 'duplicate_title_checks_callback');
function duplicate_title_checks_callback(){
global $wpdb;
$title = $_POST['post_title'];
$post_id = $_POST['post_id'];
$titles = "SELECT post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
AND post_title = '{$title}' AND ID != {$post_id} ";
$results = $wpdb->get_results($titles);
if($results) {
echo "<span style='color:red'>". _( '此标题已存在,请换一个标题!' , '' ) ." </span>";
} else {
echo '<span style="color:green">'._('恭喜,此标题未与其他文章标题重复!' , '').'</span>';
}
die();
}
// 检测后端标题并且避免同名文章更新草稿
add_action( 'publish_post','duplicate_titles_wallfa_bc' ) ;
function duplicate_titles_wallfa_bc( $post ){
global $wpdb ;
$title = $_POST['post_title'] ;
$post_id = $post ;
$wtitles = "SELECT post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
AND post_title = '{$title}' AND ID != {$post_id} " ;
$wresults = $wpdb->get_results( $wtitles ) ;
if ( $wresults ){
$wpdb->update( $wpdb->posts, array( 'post_status' =>
'draft' ), array( 'ID' => $post ) ) ;
$arr_params = array( 'message' => '10', 'wallfaerror' => '1' ) ;
$location = add_query_arg( $arr_params , get_edit_post_link( $post , 'url' ) ) ;
wp_redirect( $location ) ;
exit ;
}
}
/// 文章提交更新后的提示
add_action( 'admin_notices', 'not_published_error_notice' );
function not_published_error_notice() {
if(isset($_GET['wallfaerror']) == 1 ){
?>
<div class="updated">
<p style='color:red' ><?php _e('貌似已经存在相同标题的文章,若您使用了文章别名作为固定链接,则可以通过修改本文的固定链接来使标题不再重复!' , '') ?></p>
</div>
<?php
}
}
//@end禁止发布相同标题内容
/*用户只能看见自己发布的文章*/
function mypo_parse_query_useronly( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
if ( !current_user_can( 'manage_options' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'mypo_parse_query_useronly' );
/*用户只能看见自己发布的文章*/
//@start防止镜像
//if(!get_option("DenyMirrored")):
//防止WordPress站点被恶意镜像,请修改$currentDomain代码中的网址
add_action('wp_footer','deny_mirrored_websites',1000);
function deny_mirrored_websites(){
$currentDomain = $_SERVER['HTTP_HOST'];
echo '<img style="display:none" src=" " onerror=\'var str1="'.$currentDomain.'"; str2="docu"+"ment.loca"+"tion.host"; str3=eval(str2);if( str1!=str3 && str3!="cache.baiducontent.com" && str3!="webcache.googleusercontent.com" && str3!="c.360webcache.com" && str3!="cncc.bingj.com" && str3!="snapshot.sogoucdn.com" && str3!="baidu.com" && str3!="sogou.com" && str3!="sogo.com" && str3!="bing.cn" && str3!="goole.com" && str3!="goole.com.hk" && str3!="goole.cn" && str3!="sm.cn" && str3!="sm-tc.cn" ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "\"' . $currentDomain .'\"" + ")"; eval(do_action) }\' />';
}
//endif;
//@end防止镜像
?>
注意事项:需要自定义的地方和不用的部分请对照修改和删除
Raw Copy
//SMTP邮箱设置 处启用的是管理员登陆邮箱,smtp参数请对照提供商提供的修改
//默认移除了日期存档页,需要的请注释掉以下两行
add_action('template_redirect', 'meks_remove_wp_archives');
function meks_remove_wp_archives(){ if(is_date()) { global $wp_query; $wp_query->set_404(); } }
//语法高亮脚本需要对应的css和js,放到相关目录即可
//编辑器去掉了默认的古腾堡和默认对应增强的功能,如需要这些,自己修改或者注释掉以下几行代码
if (version_compare( $GLOBALS['wp_version'], '5.0', '>' )) {
//换回经典编辑器tinymce
add_filter('use_block_editor_for_post','__return_false');
remove_action('wp_enqueue_scripts','wp_common_block_scripts_and_styles');
}
justnews_plus.zip

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close