4.4 的两大特性反正在下是超级喜欢,REST API 让 WordPress 可以快捷地在移动端开发衍生产品或与其他项目融合;Embeds 加强了网站与网站之间的互通性。当然这只是一家之言,对于大多数博主来说还是显得多余些了……随手记录下禁用方法,希望对你有帮助。
https://www.mywpku.com/luna-based-on-lingonberry.html
方法一:使请求
http://www.example.com/wp-json/后返回错误代码
{"code":"rest_disabled","message":"The REST API is disabled on this site."}
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 );
与之前被去除的 「链接」 功能一样,WordPress 官方已经为我们铺好后路——直接安装启用即可,或是将下列代码加入 Functions.php:
function 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 oEmbed auto discovery. 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' );
在此插件中意外地发现了
composer.json,是否预示着 WordPress 今后将有大变动?拭目以待。