<!--以下代码为主题目录下functions.php文件内代码!-->
// 彻底关闭自动更新
add_filter('automatic_updater_disabled', '__return_true');
// 关闭更新检查定时作业
remove_action('init', 'wp_schedule_update_checks');
// 移除已有的版本检查定时作业
wp_clear_scheduled_hook('wp_version_check');
// 移除已有的插件更新定时作业
wp_clear_scheduled_hook('wp_update_plugins');
// 移除已有的主题更新定时作业
wp_clear_scheduled_hook('wp_update_themes');
// 移除已有的自动更新定时作业
wp_clear_scheduled_hook('wp_maybe_auto_update');
// 移除后台内核更新检查
remove_action( 'admin_init', '_maybe_update_core' );
// 移除后台插件更新检查
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
// 移除后台主题更新检查
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'load-update-core.php', 'wp_update_themes' );
remove_action( 'admin_init', '_maybe_update_themes' );
// 移除WP-JSON链接
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
remove_action( 'template_redirect', 'rest_output_link_header', 11 );
// 禁止后台显示升级核心提示
add_filter('pre_site_transient_update_core', create_function('$a', "return null;"));
// 禁止后台显示插件升级提示
add_filter('pre_site_transient_update_plugins', create_function('$a', "return null;"));
// 禁止后台显示主题升级提示
add_filter('pre_site_transient_update_themes', create_function('$a', "return null;"));
// 把fonts.googleapis.com替换为fonts.useso.com
function bf_google_font($content)
{
return str_replace('fonts.googleapis.com', 'fonts.useso.com', $content);
return str_replace('ajax.googleapis.com', 'ajax.useso.com', $content);
}
// 关闭WordPress的XML-RPC功能(建议清空网站根目录下下xmlrpc.php内容)
add_filter('xmlrpc_enabled', '__return_false');
// 关闭XML-RPC 的 pingback端口
add_filter('xmlrpc_methods', 'remove_xmlrpc_pingback_ping');
function remove_xmlrpc_pingback_ping( $methods ) {
unset( $methods['pingback.ping'] );
return $methods;
}
// 禁止后台加载谷歌字体
function wp_remove_open_sans_from_wp_core() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
wp_enqueue_style('open-sans','');
}
add_action( 'init', 'wp_remove_open_sans_from_wp_core' );
// 禁用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;
// 禁用 WordPress 的 JSON REST API
add_filter('json_enabled', '__return_false');
add_filter('json_jsonp_enabled', '__return_false');
// 阻止WordPress的PingBack端口
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
// 屏蔽XML-RPC(pingback)功能,阻止pingback端口
add_filter('xmlrpc_enabled', '__return_false');
add_filter('xmlrpc_methods', 'remove_xmlrpc_pingback_ping');
function remove_xmlrpc_pingback_ping( $methods ) {
unset( $methods['pingback.ping'] );
return $methods;
}
// 通过多说服务器加速Gravatar头像
function mytheme_get_avatar($avatar) {
$avatar = str_replace(array("www.gravatar.com","0.gravatar.com"
WordPress程序/functions.php收集整理的各种自定义优化代码分享
最新推荐文章于 2022-01-03 20:40:49 发布