wordpress4.4 优化wp-json链接、embeds功能

  1. add_filter('rest_enabled', '_return_false');
  2. add_filter('rest_jsonp_enabled', '_return_false');
  3. remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
  4. remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
  1. function disable_embeds_init() {
  2. global $wp;
  3. $wp->public_query_vars = array_diff( $wp->public_query_vars, array( 'embed', ) );
  4. remove_action( 'rest_api_init', 'wp_oembed_register_route' );
  5. add_filter( 'embed_oembed_discover', '__return_false' );
  6. remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
  7. remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
  8. remove_action( 'wp_head', 'wp_oembed_add_host_js' );
  9. add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );
  10. add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' ); }
  11. add_action( 'init', 'disable_embeds_init', 9999 );
  12. function disable_embeds_tiny_mce_plugin( $plugins ) { return array_diff( $plugins, array( 'wpembed' ) ); }
  13. function disable_embeds_rewrites( $rules ) { foreach ( $rules as $rule => $rewrite ) { if ( false !== strpos( $rewrite, 'embed=true' ) ) { unset( $rules[ $rule ] ); } }
  14. return $rules; }
  15. function disable_embeds_remove_rewrite_rules() { add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' ); flush_rewrite_rules(); }
  16. register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );
  17. function disable_embeds_flush_rewrite_rules() { remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' ); flush_rewrite_rules(); }
  18. register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );

每一次更新wordpress版本都会多出一些东西,例如之前的emoji,并且都在页面上输入内容,或多或少都会影响速度,我们博客基本就是更新下文章而已,搞的太负责了未免多此一举,用不上就干掉REST API和embeds,为了用户体验,让网站更快的展示我们码的字就OK了。


发布日期:

所属分类: Wordpress, Wordpress 综合 标签: