网络收集!!!!!!!!!!!!!!!!!
//2-删除表情脚本
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');
//3-页面链接添加html后缀(有的主题默认)
add_action('init', 'html_page_permalink', -1);
function html_page_permalink() {
global $wp_rewrite;
if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')) {
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
}
}
//4-首页禁止wp-block-library(古腾堡编辑器,下面是用的页面主页)
add_action( 'wp_print_styles', 'wpblocklibrary', 100 );
function wpblocklibrary() {
if ( is_page('home') ) {
wp_deregister_style( 'wp-block-library' );
wp_deregister_style( 'wp-block-library-theme' );
}
}
//5-禁用XML-RPC(第三方接口)
add_filter('xmlrpc_enabled', '__return_false');
//6-禁用REST API(有的主题需要调用)
add_filter('rest_enabled', '_return_false');
add_filter('rest_jsonp_enabled', '_return_false');
add_filter( 'rest_authentication_errors', function( $access ) {
return new WP_Error( 'rest_cannot_acess', 'REST API已关闭', array( 'status' => 403 ) );
});
//7-禁止加载wp-embed.min.js(有的主题需要调用)
function my_deregister_scripts(){
wp_dequeue_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
//8-除后台之外删除静态资源的查询字符串
function j_remove_script_version( $src ) {
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', 'j_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'j_remove_script_version', 15, 1 );
//9-js和cssver参数
if(!function_exists('cwp_remove_script_version')) {
function cwp_remove_script_version( $src ) {
return remove_query_arg( 'ver', $src );
}
add_filter( 'script_loader_src', 'cwp_remove_script_version' );
add_filter( 'style_loader_src', 'cwp_remove_script_version' );
}
//10-禁用auto-embeds加载外链视频封面
remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
//11-禁用feed
function disable_feed() {
wp_die( '本站不提供feed。<script>location.href="'.bloginfo('url').'";</script>' );
}
add_action('do_feed', 'disable_feed', 1);
add_action('do_feed_rdf', 'disable_feed', 1);
add_action('do_feed_rss', 'disable_feed', 1);
add_action('do_feed_rss2', 'disable_feed', 1);
add_action('do_feed_atom', 'disable_feed', 1);
//12-取消内容转义
$qmr_work_tags = array(
'the_title', // 标题
'the_content', // 内容 *
'the_excerpt', // 摘要 *
'single_post_title', // 单篇文章标题
'comment_author', // 评论作者
'comment_text', // 评论内容 *
'bloginfo', // 博客信息
'wp_title', // 网站标题
'term_description', // 项目描述
'category_description', // 分类描述
'widget_title', // 小工具标题
'widget_text' // 小工具文本
);
foreach ( $qmr_work_tags as $qmr_work_tag ) {
remove_filter ($qmr_work_tag, 'wptexturize');
}
/*13-整体移除页面还会显示的*/
// 移除 REST API 端点
remove_action( 'rest_api_init', 'wp_oembed_register_route' );
// 禁用 oEmbed 自动发现功能
add_filter( 'embed_oembed_discover', '__return_false' );
// 不要过滤 oEmbed 结果
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
// 移除 oEmbed 发现链接
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
// 移除 oEmbed 使用的 JavaScript 文件
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
//移除加载
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
//移除WordPress版本
remove_action( 'wp_head', 'wp_generator' );
//去除评论feed
remove_action( 'wp_head', 'feed_links_extra', 3 );
//去除文章feed
remove_action( 'wp_head', 'feed_links', 2 );
//屏蔽API产生的信息
remove_action( 'template_redirect', 'rest_output_link_header', 11 );
//屏蔽rel=shortlink信息
remove_action( 'template_redirect','wp_shortlink_header', 11, 0);
//离线编辑器接口
remove_action( 'wp_head', 'rsd_link' );
//Windows Live Writer接口
remove_action( 'wp_head', 'wlwmanifest_link' );
//移除当前页面的索引
remove_action( 'wp_head', 'index_rel_link' );
//移除后面文章的url
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
//移除最开始文章的url
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
//自动生成的短链接
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
//移除相邻文章的url
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
// 移除检查当前页面的检测(以下也可以不用加)
remove_filter('rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4);
remove_filter('oembed_response_data', 'get_oembed_response_data_rich', 10, 4);
/*整体移除页面还会显示的 end*/
//14-移除comment-reply.min.js(如果不用评论)
function crunchify_clean_header_hook() {
wp_deregister_script( 'comment-reply' );
}
add_action('init','crunchify_clean_header_hook');
//15-移除jquery-migrate.min.js(兼容老jquery库,有的主题默认不启用)
function isa_remove_jquery_migrate( &$scripts ) {
if( !is_admin() ) {
$scripts->remove( 'jquery' );
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
}
}
add_filter( 'wp_default_scripts', 'isa_remove_jquery_migrate' );
//16-禁用cron(定时任务)
define('DISABLE_WP_CRON', true);
//17-文章修订(建议还是保留不用全部关闭)
define('AUTOSAVE_INTERVAL', 300); // 时间间隔
define('WP_POST_REVISIONS', false);
//限制数量
define('AUTOSAVE_INTERVAL', 300); // 时间间隔
define('WP_POST_REVISIONS', 2);//修订2次
define('EMPTY_TRASH_DAYS', 3);//3天后自动清空
//18-彻底禁用Pingback与Trackback
add_filter('wp_headers', function($headers, $wp_query){
if(isset($headers['X-Pingback'])){
unset($headers['X-Pingback']);
}
return $headers;
}, 11, 2);
add_filter('pre_option_enable_xmlrpc', function($state){
return '0';
});
add_action('wp', function(){
remove_action('wp_head', 'rsd_link');
}, 9);
add_filter('bloginfo_url', function($output, $property){
return ($property == 'pingback_url') ? null : $output;
}, 11, 2);
add_action('xmlrpc_call', function($method){
if($method != 'pingback.ping') return;
wp_die(
'Pingback functionality is disabled on this Blog.',
'Pingback Disabled!',
array('response' => 403)
);
});
//19-删除XFN (XHTML Friends Network) Profile 链接 和 Pingback URL
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
//找到header.php删了就行
/*后台优化*/
//20-禁用后台右上角帮助
add_action('in_admin_header', function(){
global $current_screen;
$current_screen->remove_help_tabs();
});
//21-禁用后台右上角选项
add_action('in_admin_header', function(){
add_filter('screen_options_show_screen', '__return_false');
add_filter('hidden_columns', '__return_empty_array');
});
//22-禁用Admin Bar(登录之后顶部栏)
add_filter( 'show_admin_bar', '__return_false' );
//23-屏蔽后台页脚WordPress版本信息
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);
//24-隐藏后台标题中的“—— WordPress”
add_filter('admin_title', 'zm_custom_admin_title', 10, 2);
function zm_custom_admin_title($admin_title, $title){
return $title.' ‹ '.get_bloginfo('name');
}
//25-隐藏登录页面标题中的“WordPress”
add_filter('login_title', 'zm_custom_login_title', 10, 2);
function zm_custom_login_title($login_title, $title){
return $title.' ‹ '.get_bloginfo('name');
}
//26-隐藏左上角WordPress标志
function hidden_admin_bar_remove() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'hidden_admin_bar_remove', 0);
//27-隐藏后台状态
function disable_dashboard_widgets() {
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
//近期评论
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal');
//近期草稿
remove_meta_box('dashboard_primary', 'dashboard', 'core');
//wordpress博客
remove_meta_box('dashboard_secondary', 'dashboard', 'core');
//其它新闻
remove_meta_box('dashboard_right_now', 'dashboard', 'core');
//wordpress概况
remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
//wordresss链入链接
remove_meta_box('dashboard_plugins', 'dashboard', 'core');
//链入插件
remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
//快速发布
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');
// 动态
}
add_action('admin_menu', 'disable_dashboard_widgets');