因为经常要用到,所以在这里记录一下。
//清理wp_postmeta数据表,删除文章Meta标签 DELETE FROM wp_postmeta WHERE meta_key = '_edit_lock'; DELETE FROM wp_postmeta WHERE meta_key = '_edit_last'; //自动保存草稿 DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)WHERE a.post_type ='revision' //删除WordPress未使用标签垃圾数据 SELECT * FROM wp_terms wt INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id INNER JOIN wp_term_relationships wtr ON wtr.term_taxonomy_id=wtt.term_taxonomy_id LEFT JOIN wp_posts wp ON wp.ID=wtr.object_id WHERE taxonomy='post_tag' AND ID IS null AND NOT EXISTS(SELECT * From wp_terms wt2 INNER JOIN wp_term_taxonomy wtt2 ON wt2.term_id=wtt2.term_id WHERE wtt2.parent=wt.term_id) ORDER BY name;
remove_action( 'wp_head', 'rsd_link' ); //移除离线编辑器开放接口remove_action( 'wp_head', 'wlwmanifest_link' ); //移除离线编辑器开放接口//remove_action( 'wp_head', 'index_rel_link' ); //去除本页唯一链接信息remove_action( 'wp_head', 'wp_generator' ); //移除WordPress版本remove_action( 'wp_head', 'wp_resource_hints', 2 );//禁止加载s.w.orgremove_action( 'wp_head', 'feed_links', 2 );//移除feedremove_action( 'wp_head', 'feed_links_extra', 3);//移除feedremove_action( 'wp_head', 'wp_shortlink_wp_head' );//移除短连接remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0);//相邻的postsrel-linkremove_filter( 'the_content', 'wptexturize');//取消内容中字符转义//remove_filter('the_excerpt', 'wptexturize');//取消摘要转义//remove_filter('comment_text', 'wptexturize');//取消评论转义add_filter( 'run_wptexturize', '__return_false' );//禁止 WordPress 网站title中的 “-” 被转义add_filter('show_admin_bar', '__return_false', 9999);//删除最顶部的管理横条//remove_action( 'wp_head', 'wp_enqueue_scripts', 1 ); //Javascript的调用/** 禁用自动保存 */add_action('wp_print_scripts', 'qgg_not_autosave');function qgg_not_autosave() { wp_deregister_script('autosave');}//禁止加载WP自带的jquery.jsif ( !is_admin() ) { // 后台不禁止function my_init_method() {wp_deregister_script( 'jquery' ); // 取消原有的 jquery 定义}add_action('init', 'my_init_method');}wp_deregister_script( 'l10n' );add_filter( 'wp_revisions_to_keep', 'specs_wp_revisions_to_keep', 10, 2 );//关闭Wordpress中的修订功能//add_filter('comment_form_field_cookies','__return_false');//移除评论隐私Cookie 确认存储勾选框add_filter( 'add_image_size', create_function( '', 'return 1;' ) );//彻底禁止缩略图裁剪remove_action( 'wp_head', 'locale_stylesheet' );//remove_action('publish_future_post','check_and_publish_future_post',10, 1 );//发布未来的日志,检查并发布未来的日志//remove_action( 'wp_head', 'noindex', 1 );//暂时不明//remove_action( 'wp_head', 'wp_print_styles', 8 );//载入cssremove_action( 'wp_head', 'wp_print_head_scripts', 9 );//载入JS//remove_action( 'wp_head', 'rel_canonical' );//移除Canonical标记remove_action( 'wp_footer', 'wp_print_footer_scripts' );//强制所有脚本进入WordPress中的wp_footerremove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );//屏蔽WP产生的rel=shortlink头部信息remove_action( 'template_redirect','rest_output_link_header', 11, 0 );//屏蔽WP自带API产生的头部信息//清除前后文信息remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // Removes the prev linkremove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // Removes the start linkremove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Removes the relational links for the posts adjacent to the current post.//屏蔽gravatar,调用多说缓存图片function duoshuo_avatar($avatar) {$avatar = str_replace(array("www.gravatar.com","0.gravatar.com","1.gravatar.com","2.gravatar.com"),"gravatar.duoshuo.com",$avatar);return $avatar;}add_filter( 'get_avatar', 'duoshuo_avatar', 10, 3 );//屏蔽谷歌文字代码1if (!function_exists('remove_wp_open_sans')) : function remove_wp_open_sans() { wp_deregister_style( 'open-sans' ); wp_register_style( 'open-sans', false ); } add_action('wp_enqueue_scripts', 'remove_wp_open_sans'); // Uncomment below to remove from admin // add_action('admin_enqueue_scripts', 'remove_wp_open_sans');endif;//屏蔽谷歌文字代码2function remove_open_sans() { wp_deregister_style( 'open-sans' ); wp_register_style( 'open-sans', false ); wp_enqueue_style('open-sans','');}add_action( 'init', 'remove_open_sans' ); //移除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 );// 移除头部 wp-json 标签和 HTTP header 中的 linkremove_action('template_redirect', 'rest_output_link_header', 11 );// 屏蔽登录错误提示function no_errors_please(){return '账号或者密码不正确,请重新输入!';}add_filter( 'login_errors', 'no_errors_please' );//禁止生成多张微略图add_filter( 'intermediate_image_sizes', function( $sizes ){ return array_filter( $sizes, function( $val ) { return 'medium_large' !== $val; // Filter out 'medium_large' } );} );//禁止加载wp-embeds.mins.jsfunction disable_embeds_init() { /* @var WP $wp */ global $wp; // Remove the embed query var. $wp->public_query_vars = array_diff( $wp->public_query_vars, array( 'embed', ) ); // Remove the REST API endpoint. remove_action( 'rest_api_init', 'wp_oembed_register_route' ); // Turn off add_filter( 'embed_oembed_discover', '__return_false' ); // Don't filter oEmbed results. remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 ); // Remove oEmbed discovery links. remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // Remove oEmbed-specific JavaScript from the front-end and back-end. remove_action( 'wp_head', 'wp_oembed_add_host_js' ); add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' ); // Remove all embeds rewrite rules. add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );} add_action( 'init', 'disable_embeds_init', 9999 ); /** * Removes the 'wpembed' TinyMCE plugin. * * @since 1.0.0 * * @param array $plugins List of TinyMCE plugins. * @return array The modified list. */function disable_embeds_tiny_mce_plugin( $plugins ) { return array_diff( $plugins, array( 'wpembed' ) );}/** * Remove all rewrite rules related to embeds. * * @since 1.2.0 * * @param array $rules WordPress rewrite rules. * @return array Rewrite rules without embeds rules. */function disable_embeds_rewrites( $rules ) { foreach ( $rules as $rule => $rewrite ) { if ( false !== strpos( $rewrite, 'embed=true' ) ) { unset( $rules[ $rule ] ); } } return $rules;}/** * Remove embeds rewrite rules on plugin activation. * * @since 1.2.0 */function disable_embeds_remove_rewrite_rules() { add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' ); flush_rewrite_rules();} register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );/** * Flush rewrite rules on plugin deactivation. * * @since 1.2.0 */function disable_embeds_flush_rewrite_rules() { remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' ); flush_rewrite_rules();}register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );//去除分类标志代码add_action( 'load-themes.php', 'no_category_base_refresh_rules');add_action('created_category', 'no_category_base_refresh_rules');add_action('edited_category', 'no_category_base_refresh_rules');add_action('delete_category', 'no_category_base_refresh_rules');function no_category_base_refresh_rules() { global $wp_rewrite; $wp_rewrite -> flush_rules();}// register_deactivation_hook(__FILE__, 'no_category_base_deactivate');// function no_category_base_deactivate() {// remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');// // We don't want to insert our custom rules again// no_category_base_refresh_rules();// }// Remove category baseadd_action('init', 'no_category_base_permastruct');function no_category_base_permastruct() { global $wp_rewrite, $wp_version; if (version_compare($wp_version, '3.4', '<')) { // For pre-3.4 support $wp_rewrite -> extra_permastructs['category'][0] = '%category%'; } else { $wp_rewrite -> extra_permastructs['category']['struct'] = '%category%'; }}// Add our custom category rewrite rulesadd_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');function no_category_base_rewrite_rules($category_rewrite) { //var_dump($category_rewrite); // For Debugging $category_rewrite = array(); $categories = get_categories(array('hide_empty' => false)); foreach ($categories as $category) { $category_nicename = $category -> slug; if ($category -> parent == $category -> cat_ID)// recursive recursion $category -> parent = 0; elseif ($category -> parent != 0) $category_nicename = get_category_parents($category -> parent, false, '/', true) . $category_nicename; $category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; $category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]'; $category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]'; } // Redirect support from Old Category Base global $wp_rewrite; $old_category_base = get_option('category_base') ? get_option('category_base') : 'category'; $old_category_base = trim($old_category_base, '/'); $category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]'; //var_dump($category_rewrite); // For Debugging return $category_rewrite;}// Add 'category_redirect' query variableadd_filter('query_vars', 'no_category_base_query_vars');function no_category_base_query_vars($public_query_vars) { $public_query_vars[] = 'category_redirect'; return $public_query_vars;}// Redirect if 'category_redirect' is setadd_filter('request', 'no_category_base_request');function no_category_base_request($query_vars) { //print_r($query_vars); // For Debugging if (isset($query_vars['category_redirect'])) { $catlink = trailingslashit(get_option('home')) . user_trailingslashit($query_vars['category_redirect'], 'category'); status_header(301); header("Location: $catlink"); exit(); } return $query_vars;}/** * WordPress禁止某些用户账号登录插件源码分析,及WordPress用户黑名单插件“盘他”下载 * https://www.dujin.org/12560.html *///在资料页面添加选项function dj_rc_admin_init(){ // 编辑用户资料 add_action( 'edit_user_profile', 'dj_rc_edit_user_profile' ); add_action( 'edit_user_profile_update', 'dj_rc_edit_user_profile_update' );}add_action('admin_init', 'dj_rc_admin_init' );//在个人资料页面添加一个复选框function dj_rc_edit_user_profile() { if ( !current_user_can( 'edit_users' ) ) { return; } global $user_id; // 用户不能禁止自己 $current_user = wp_get_current_user(); $current_user_id = $current_user->ID; if ( $current_user_id == $user_id ) { return; } ?> <h3>权限设置</h3> <table class="form-table"> <tr> <th scope="row">禁止用户登录</th> <td><label for="dj_rc_ban"><input name="dj_rc_ban" type="checkbox" id="dj_rc_ban" <?php if (dj_rc_is_user_banned( $user_id )){echo 'checked="checked"';} ?> /> 勾起来,盘Ta,什么玩意儿……</label></td> </tr> </table> <?php}//添加一个函数来将这个选项的值保存到数据库中function dj_rc_edit_user_profile_update() { if ( !current_user_can( 'edit_users' ) ) { return; } global $user_id; // 用户不能禁止自己 $current_user = wp_get_current_user(); $current_user_id = $current_user->ID; if ( $current_user_id == $user_id ) { return; } // 锁定 if( isset( $_POST['dj_rc_ban'] ) && $_POST['dj_rc_ban'] = 'on' ) { dj_rc_ban_user( $user_id ); } else { // 解锁 dj_rc_unban_user( $user_id ); }}//禁止用户function dj_rc_ban_user( $user_id ) { $old_status = dj_rc_is_user_banned( $user_id ); // 更新状态 if ( !$old_status ) { update_user_option( $user_id, 'dj_rc_banned', true, false ); }}//解禁用户function dj_rc_unban_user( $user_id ) { $old_status = dj_rc_is_user_banned( $user_id ); // 更新状态 if ( $old_status ) { update_user_option( $user_id, 'dj_rc_banned', false, false ); }}//判断用户是否被禁止function dj_rc_is_user_banned( $user_id ) { return get_user_option( 'dj_rc_banned', $user_id, false );}//阻止已禁止的用户登录function dj_rc_authenticate_user( $user ) { if ( is_wp_error( $user ) ) { return $user; } // 如果用户被禁止,则返回错误提示,这里是显示给登录用户看的,错误提示可根据自己的喜好修改。 $banned = get_user_option( 'dj_rc_banned', $user->ID, false ); if ( $banned ) { return new WP_Error( 'dj_rc_banned', __('抱歉,您已被禁止登录!请联系站长解禁。', 'rc') ); } return $user;}//将该函数挂载到 wp_authenticate_user 钩子add_filter( 'wp_authenticate_user', 'dj_rc_authenticate_user', 1 );/* *Wordpress文章关键词自动添加内链链接代码 *///连接数量 $match_num_from = 1; //一个关键字少于多少不替换 $match_num_to = 1; //一个关键字最多替换次数 //连接到WordPress的模块 add_filter('the_content','tag_link',1); //按长度排序 function tag_sort($a, $b){ if ( $a->name == $b->name ) return 0; return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1; } //改变标签关键字 function tag_link($content){ global $match_num_from,$match_num_to; $posttags = get_the_tags(); if ($posttags) { usort($posttags, "tag_sort"); foreach($posttags as $tag) { $link = get_tag_link($tag->term_id); $keyword = $tag->name; //连接代码 $cleankeyword = stripslashes($keyword); $url = "<a href=\"$link\" title=\"".str_replace('%s',addcslashes($cleankeyword, '$'),__('查看所有文章关于 %s'))."\""; //$url .= 'target="_blank"'; $url .= ">".addcslashes($cleankeyword, '$')."</a>"; $limit = rand($match_num_from,$match_num_to); //不连接的代码 $content = preg_replace( '|(<a[^>]+>)(.*)('.$ex_word.')(.*)(</a[^>]*>)|U'.$case, '$1$2%&&&&&%$4$5', $content); $content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2%&&&&&%$4$5', $content); $cleankeyword = preg_quote($cleankeyword,'\''); $regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case; $content = preg_replace($regEx,$url,$content,$limit); $content = str_replace( '%&&&&&%', stripslashes($ex_word), $content); } } return $content; }//支持WebP格式上传function bzg_filter_mime_types( $array ) { $array['webp'] = 'image/webp'; return $array;}add_filter( 'mime_types', 'bzg_filter_mime_types', 10, 1 );//支持WebP格式媒体库显示function bzg_file_is_displayable_image($result, $path) { $info = @getimagesize( $path ); if($info['mime'] == 'image/webp') { $result = true; } return $result;}add_filter( 'file_is_displayable_image', 'bzg_file_is_displayable_image', 10, 2 );//自定义上传if(get_option('upload_path')=='wp-content/uploads' || get_option('upload_path')==null) { update_option('upload_path',WP_CONTENT_DIR.'/uploads');}//上传文件重命名add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );function custom_upload_filter( $file ){ $info = pathinfo($file['name']); $ext = '.' . $info['extension']; $md5 = md5($file['name']); $file['name'] = $md5.$ext; return $file;}//禁止EMOJIremove_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_action('embed_head','print_emoji_detection_script');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( 'emoji_svg_url','__return_false' );
<?php/* wordpress选择性优化总结 更新时间:2019.11.6 更新地址:https://www.jingxialai.com/2402.html *///1-删除谷歌字体if (!function_exists('remove_wp_open_sans')) : function remove_wp_open_sans() { wp_deregister_style( 'open-sans' ); wp_register_style( 'open-sans', false );}// 前台删除Google字体CSSadd_action('wp_enqueue_scripts', 'remove_wp_open_sans');// 后台删除Google字体CSSadd_action('admin_enqueue_scripts', 'remove_wp_open_sans');endif;//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-禁用feedfunction 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' );//去除评论feedremove_action( 'wp_head', 'feed_links_extra', 3 );//去除文章feedremove_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' );//移除后面文章的urlremove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );//移除最开始文章的urlremove_action( 'wp_head', 'start_post_rel_link', 10, 0 );//自动生成的短链接remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );//移除相邻文章的urlremove_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与Trackbackadd_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'); //28-百度主动推送 if(!function_exists('Baidu_Submit')) { function Baidu_Submit($post_ID) { $WEB_TOKEN = '你的百度密钥'; $WEB_DOMAIN = get_option('home'); if(get_post_meta($post_ID,'Baidusubmit',true) == 1) return; $url = get_permalink($post_ID); $api = 'http://data.zz.baidu.com/urls?site='.$WEB_DOMAIN.'&token='.$WEB_TOKEN; $request = new WP_Http; $result = $request->request( $api , array( 'method' => 'POST', 'body' => $url , 'headers' => 'Content-Type: text/plain') ); $result = json_decode($result['body'],true); if (array_key_exists('success',$result)) { add_post_meta($post_ID, 'Baidusubmit', 1, true); } } add_action('publish_post', 'Baidu_Submit', 0); }
整理自:https://www.mangdian.com/networknotes/40.html