{"id":330,"date":"2022-05-25T18:01:03","date_gmt":"2022-05-25T10:01:03","guid":{"rendered":"https:\/\/blog.ppdd.vip\/?p=330"},"modified":"2022-05-25T18:01:03","modified_gmt":"2022-05-25T10:01:03","slug":"wordpress6-0-%e6%96%b0%e7%89%88%e5%bf%85%e5%a4%87%e4%bc%98%e5%8c%96%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/blog.ppdd.vip\/index.php\/2022\/05\/25\/wordpress6-0-%e6%96%b0%e7%89%88%e5%bf%85%e5%a4%87%e4%bc%98%e5%8c%96%e4%bb%a3%e7%a0%81\/","title":{"rendered":"WordPress6.0 \u65b0\u7248\u5fc5\u5907\u4f18\u5316\u4ee3\u7801"},"content":{"rendered":"<pre>WordPress6.0 \u65b0\u7248\u5fc5\u5907\u4f18\u5316\u4ee3\u7801\uff1a\n&lt;!--\u6dfb\u52a0\u4f18\u5316\u4ee3\u7801\u5230\u4e3b\u9898\u76ee\u5f55functions.php\u6587\u4ef6--&gt;\n\/*\u5f7b\u5e95\u5173\u95ed\u81ea\u52a8\u66f4\u65b0\uff08\u6838\u5fc3\u7a0b\u5e8f\/\u4e3b\u9898\/\u63d2\u4ef6\/\u7ffb\u8bd1\u81ea\u52a8\u66f4\u65b0*\/\nadd_filter('automatic_updater_disabled', '__return_true');\n\/*\u5173\u95ed\u66f4\u65b0\u68c0\u67e5\u5b9a\u65f6\u4f5c\u4e1a*\/\nremove_action('init', 'wp_schedule_update_checks');\n\/*\u79fb\u9664\u5df2\u6709\u7684\u7248\u672c\u68c0\u67e5\u5b9a\u65f6\u4f5c\u4e1a*\/\nwp_clear_scheduled_hook('wp_version_check');\n\/*\u79fb\u9664\u5df2\u6709\u7684\u63d2\u4ef6\u66f4\u65b0\u5b9a\u65f6\u4f5c\u4e1a*\/\nwp_clear_scheduled_hook('wp_update_plugins');\n\/*\u79fb\u9664\u5df2\u6709\u7684\u4e3b\u9898\u66f4\u65b0\u5b9a\u65f6\u4f5c\u4e1a*\/\nwp_clear_scheduled_hook('wp_update_themes');\n\/*\u79fb\u9664\u5df2\u6709\u7684\u81ea\u52a8\u66f4\u65b0\u5b9a\u65f6\u4f5c\u4e1a*\/\nwp_clear_scheduled_hook('wp_maybe_auto_update');\n\/*\u79fb\u9664\u540e\u53f0\u5185\u6838\u66f4\u65b0\u68c0\u67e5*\/\nremove_action( 'admin_init', '_maybe_update_core' );\n\/*\u79fb\u9664\u540e\u53f0\u63d2\u4ef6\u66f4\u65b0\u68c0\u67e5*\/\nremove_action( 'load-plugins.php', 'wp_update_plugins' );\nremove_action( 'load-update.php', 'wp_update_plugins' );\nremove_action( 'load-update-core.php', 'wp_update_plugins' );\nremove_action( 'admin_init', '_maybe_update_plugins' );\n\/*\u79fb\u9664\u540e\u53f0\u4e3b\u9898\u66f4\u65b0\u68c0\u67e5*\/\nremove_action( 'load-themes.php', 'wp_update_themes' );\nremove_action( 'load-update.php', 'wp_update_themes' );\nremove_action( 'load-update-core.php', 'wp_update_themes' );\nremove_action( 'admin_init', '_maybe_update_themes' );\n\/*\u5173\u95ed\u7a0b\u5e8f\u66f4\u65b0\u63d0\u793a*\/\nadd_filter( 'pre_site_transient_update_core', function($a){ return null; });\n\/*\u5173\u95ed\u63d2\u4ef6\u66f4\u65b0\u63d0\u793a*\/\nadd_filter('pre_site_transient_update_plugins', function($a){return null;});\n\/*\u5173\u95ed\u4e3b\u9898\u66f4\u65b0\u63d0\u793a*\/\nadd_filter('pre_site_transient_update_themes', function($a){return null;});\n\/\/\u5173\u95edWordPress\u7684XML-RPC\u529f\u80fd\nadd_filter('xmlrpc_enabled', '__return_false');\n\/* \u5173\u95edXML-RPC\u7684pingback\u7aef\u53e3 *\/\nadd_filter( 'xmlrpc_methods', 'remove_xmlrpc_pingback_ping' );\nfunction remove_xmlrpc_pingback_ping( $methods ) {\nunset( $methods['pingback.ping'] );\nreturn $methods;\n}\n\/\/\u7981\u7528 pingbacks, enclosures, trackbacks\nremove_action( 'do_pings', 'do_all_pings', 10 );\n\/\/\u53bb\u6389 _encloseme \u548c do_ping \u64cd\u4f5c\nremove_action( 'publish_post','_publish_post_hook',5 );\n\/* \u7981\u6b62\u52a0\u8f7ds.w.org\u83b7\u53d6\u8868\u60c5\u548c\u5934\u50cf *\/\nremove_action('wp_head', 'print_emoji_detection_script', 7 );\nremove_action('admin_print_scripts','print_emoji_detection_script');\nremove_action('wp_print_styles', 'print_emoji_styles');\nremove_action('admin_print_styles', 'print_emoji_styles');\nfunction remove_dns_prefetch( $hints, $relation_type ) {\nif ( 'dns-prefetch' === $relation_type ) {\nreturn array_diff( wp_dependencies_unique_hosts(), $hints );\n}\nreturn $hints;\n}\nadd_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );\n\/* \u5b8c\u5168\u7981\u6b62REST API\u3001\u79fb\u9664wp-json\u94fe\u63a5 *\/\nfunction lerm_disable_rest_api( $access ) {\n\treturn new WP_Error(\n\t\t'Stop!',\n\t\t'Soooooryyyy',\n\t\tarray(\n\t\t\t'status' =&gt; 403,\n\t\t)\n\t);\n}\nadd_filter( 'rest_authentication_errors', 'lerm_disable_rest_api' );\nremove_action( 'wp_head', 'rest_output_link_wp_head', 10 );\n\/* \u7981\u6b62\u67e5\u8be2\u7f51\u7ad9\u9759\u6001\u8d44\u6e90\u8fde\u63a5\u7248\u672c\u5b57\u7b26 *\/\nfunction _remove_script_version ( $src ){\n  $parts = explode( '?', $src );\n  return $parts[0];\n}\nadd_filter( 'script_loader_src', '_remove_script_version', 15, 1 );\nadd_filter( 'style_loader_src', '_remove_script_version', 15, 1 );\n\/* \u79fb\u9664\u524d\u7aef\u7f51\u9875\u6e90\u4ee3\u7801\u5185\u7684\u5934\u90e8\u5197\u4f59\u4ee3\u7801 *\/\nremove_action( 'wp_head', 'feed_links_extra', 3 ); \nremove_action( 'wp_head', 'rsd_link' ); \nremove_action( 'wp_head', 'wlwmanifest_link' ); \nremove_action( 'wp_head', 'index_rel_link' ); \nremove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); \nremove_action( 'wp_head', 'wp_generator' ); \n\/* \u7981\u6b62\u65b0\u7248\u6587\u7ae0\u7f16\u8f91\u5668\u52a0\u8f7d\u524d\u7aef\u6837\u5f0f *\/\nfunction wpassist_remove_block_library_css(){\n    wp_dequeue_style( 'wp-block-library' );\n} \nremove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );\nadd_action( 'wp_enqueue_scripts', 'wpassist_remove_block_library_css' );\n\/* \u79fb\u9664\u65b0\u7248\u672c\u7ad9\u70b9\u5065\u5eb7\u72b6\u6001\u9762\u677f\u548c\u83dc\u5355\u9879 *\/\nadd_action( 'admin_menu', 'remove_site_health_menu' ); \nfunction remove_site_health_menu(){\nremove_submenu_page( 'tools.php','site-health.php' ); \n}\n\/* \u7981\u75285.5\u7248\u540e\u81ea\u5e26\u7684XML\u7ad9\u70b9\u5730\u56fe *\/\nadd_filter( 'wp_sitemaps_enabled', '__return_false' );\n\/* \u79fb\u9664\u524d\u540e\u53f0\u9876\u90e8\u5de5\u5177\u680f\u6307\u5b9a\u83dc\u5355 *\/\nfunction admin_bar_item ( WP_Admin_Bar $admin_bar ) {\n\t$admin_bar-&gt;remove_menu('wp-logo'); \/\/\u79fb\u52a8wp\u7684logo\n\t$admin_bar-&gt;remove_menu('site-name'); \/\/\u79fb\u52a8\u7ad9\u70b9\u540d\u79f0\n\t$admin_bar-&gt;remove_menu('updates'); \/\/\u79fb\u52a8\u66f4\u65b0\u63d0\u793a\n\t$admin_bar-&gt;remove_menu('comments'); \/\/\u79fb\u52a8\u8bc4\u8bba\u63d0\u793a\n\t\/*$admin_bar-&gt;remove_menu('new-content');\t\/\/\u79fb\u9664\u65b0\u5efa\u6309\u94ae  *\/ \n}\nadd_action( 'admin_bar_menu', 'admin_bar_item', 500 );\n\/\/\u79fb\u9664\u540e\u53f0\u4eea\u8868\u76d8\u7ad9\u70b9\u5065\u5eb7\u72b6\u6001\u9762\u677f\nadd_action('wp_dashboard_setup', 'remove_site_health_dashboard_widget');\nfunction remove_site_health_dashboard_widget()\n{\n    remove_meta_box('dashboard_site_health', 'dashboard', 'normal');\n}\n\/\/\u79fb\u9664\u540e\u53f0\u4eea\u8868\u76d8\u83dc\u5355\uff1a\u7ad9\u70b9\u5065\u5eb7\u72b6\u6001\nadd_action( 'admin_menu', 'remove_site_health_menu' );\t\nfunction remove_site_health_menu(){\n\tremove_submenu_page( 'tools.php','site-health.php' ); \n}\n\/\/\u79fb\u9664\u540e\u53f0\u4eea\u8868\u76d8\u83dc\u5355\uff1a\u6d3b\u52a8\u3001\u65b0\u95fb\nfunction bzg_remove_dashboard_widgets() {\n\tglobal $wp_meta_boxes;\n\t#\u79fb\u9664 \"\u6d3b\u52a8\" \n\tunset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);\n\t#\u79fb\u9664 \"WordPress \u65b0\u95fb\" \n\tunset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);\n}\nadd_action('wp_dashboard_setup', 'bzg_remove_dashboard_widgets' );\n\/\/\u79fb\u9664\u540e\u53f0\u4eea\u8868\u76d8\u83dc\u5355\uff1a\u5e2e\u52a9\nfunction bzg_remove_help() {\n\tget_current_screen()-&gt;remove_help_tabs();\n}\nadd_action('admin_head', 'bzg_remove_help');\n\n\/\/\u79fb\u9664\u540e\u53f0\u9875\u9762title\u6807\u9898\u7684wordpress\u540e\u7f00\nadd_filter('admin_title', 'delAdminTitle', 10, 2);\nfunction delAdminTitle($admin_title, $title){\n    return $title.' \u2039 '.get_bloginfo('name');\n}\n\/\/\u79fb\u9664\u767b\u9646\u9875\u9762title\u6807\u9898\u7684wordpress\u540e\u7f00\nadd_filter('login_title', 'remove_login_title', 10, 2);\nfunction remove_login_title($login_title, $title){\n\treturn $title.' \u2039 '.get_bloginfo('name');\n}\n\/* \u5f7b\u5e95\u7981\u6b624.4+\u7248\u4e4b\u540e\u54cd\u5e94\u5f0f\u56fe\u7247\u529f\u80fd\u53ca\u7f29\u7565\u56fe\u88c1\u526a\u529f\u80fd*\/\n\/\/ \u7981\u6b62\u751f\u6210\u56fe\u50cf\u5c3a\u5bf8\nfunction zm_customize_image_sizes( $sizes ){\n\tunset( $sizes[ 'thumbnail' ]);\n\tunset( $sizes[ 'medium' ]);\n\tunset( $sizes[ 'medium_large' ] );\n\tunset( $sizes[ 'large' ]);\n\tunset( $sizes[ 'full' ] );\n\tunset( $sizes['1536x1536'] );\n\tunset( $sizes['2048x2048'] );\n\treturn $sizes;\n}\n \nadd_filter( 'intermediate_image_sizes_advanced', 'zm_customize_image_sizes' );\n \n\/\/ \u7981\u6b62\u7f29\u653e\u56fe\u7247\u5c3a\u5bf8\nadd_filter('big_image_size_threshold', '__return_false');\n \n\/\/ \u7981\u6b62\u751f\u6210\u5176\u5b83\u56fe\u50cf\u5c3a\u5bf8\nfunction shapeSpace_disable_other_image_sizes() {\t\n\t\/\/ \u7981\u6b62\u901a\u8fc7set_post_thumbnail_size()\u51fd\u6570\u751f\u6210\u7684\u56fe\u7247\u5c3a\u5bf8\n\tremove_image_size('post-thumbnail'); \n\t\/\/ \u7981\u6b62\u6dfb\u52a0\u5176\u5b83\u56fe\u50cf\u5c3a\u5bf8\n\tremove_image_size('another-size');\n}\nadd_action('init', 'shapeSpace_disable_other_image_sizes');\n\/\/\u5207\u6362\u7ecf\u5178\u6587\u7ae0\u7f16\u8f91\u5668\uff08v5.x\u5f00\u59cb\u9ed8\u8ba4\u53e4\u817e\u5821\u7f16\u8f91\u5668\uff09\nadd_filter('use_block_editor_for_post', '__return_false');\n\/\/\u66ff\u6362\u8bc4\u8bba\u7528\u6237\u5934\u50cf\u94fe\u63a5\u4e3a\u56fd\u5185\u955c\u50cf\u52a0\u901f\u8bbf\u95ee\nadd_filter('get_avatar', function ($avatar) {\nreturn str_replace([\n'www.gravatar.com\/avatar\/',\n'0.gravatar.com\/avatar\/',\n'1.gravatar.com\/avatar\/',\n'2.gravatar.com\/avatar\/',\n'secure.gravatar.com\/avatar\/',\n'cn.gravatar.com\/avatar\/'\n], 'cravatar.cn\/', $avatar);\n});\n\n\/\/\u53d6\u6d88\u5185\u5bb9\u8f6c\u4e49\nremove_filter('the_content', 'wptexturize');\n\/\/\u53d6\u6d88\u6458\u8981\u8f6c\u4e49\nremove_filter('the_excerpt', 'wptexturize');\n\/\/\u53d6\u6d88\u8bc4\u8bba\u8f6c\u4e49\nremove_filter('comment_text', 'wptexturize');\n\/\/\u7981\u6b62\u8f6c\u4e49\u5f15\u53f7\u5b57\u7b26\nremove_filter('the_content', 'wptexturize');    \/\/ \u7981\u6b62\u82f1\u6587\u5f15\u53f7\u8f6c\u4e49\u4e3a\u4e2d\u6587\u5f15\u53f7\n\n\/\/\u6587\u7ae0\u63d2\u5165\u56fe\u7247\u81ea\u52a8\u79fb\u9664 img \u7684 width\u3001height\u3001class \u5c5e\u6027\uff1b\nadd_filter( 'post_thumbnail_html', 'fanly_remove_images_attribute', 10 );\nadd_filter( 'image_send_to_editor', 'fanly_remove_images_attribute', 10 );\nfunction fanly_remove_images_attribute( $html ) {\n \/\/$html = preg_replace( '\/(width|height)=\"\\d*\"\\s\/', \"\", $html );\n $html = preg_replace( '\/width=\"(\\d*)\"\\s+height=\"(\\d*)\"\\s+class=\"[^\"]*\"\/', \"\", $html );\n $html = preg_replace( '\/  \/', \"\", $html );\n return $html;\n}\n\n\/\/\u81ea\u9002\u5e94\u56fe\u7247\u5220\u9664width\u548cheight\nfunction ludou_remove_width_height_attribute($content){\n  preg_match_all('\/&lt;[img|IMG].*?src=[\\'|\"](.*?(?:[\\.gif|\\.jpg|\\.png\\.webp]))[\\'|\"].*?[\\\/]?&gt;\/', $content, $images);\n  if(!empty($images)) {\n    foreach($images[0] as $index =&gt; $value){\n      $new_img = preg_replace('\/(width|height)=\"\\d*\"\\s\/', \"\", $images[0][$index]);\n      $content = str_replace($images[0][$index], $new_img, $content);\n    }\n  }\n  return $content;\n}\n\n\/\/\u5224\u65ad\u662f\u5426\u662f\u79fb\u52a8\u8bbe\u5907\u6d4f\u89c8\nif(wp_is_mobile()) {\n   #\u5220\u9664\u6587\u7ae0\u5185\u5bb9\u4e2dimg\u7684width\u548cheight\u5c5e\u6027\n   add_filter('the_content', 'ludou_remove_width_height_attribute', 99);\n}\n\n\/* \u5220\u9664\u6587\u7ae0\u65f6\u5220\u9664\u56fe\u7247\u9644\u4ef6 *\/\nfunction delete_post_and_attachments($post_ID) {\nglobal $wpdb;\n#\u5220\u9664\u7279\u8272\u56fe\u7247\n$thumbnails = $wpdb-&gt;get_results( \"SELECT * FROM $wpdb-&gt;postmeta WHERE meta_key = '_thumbnail_id' AND post_id = $post_ID\" );\nforeach ( $thumbnails as $thumbnail ) {\nwp_delete_attachment( $thumbnail-&gt;meta_value, true );\n}\n#\u5220\u9664\u56fe\u7247\u9644\u4ef6\n$attachments = $wpdb-&gt;get_results( \"SELECT * FROM $wpdb-&gt;posts WHERE post_parent = $post_ID AND post_type = 'attachment'\" );\nforeach ( $attachments as $attachment ) {\nwp_delete_attachment( $attachment-&gt;ID, true );\n}\n$wpdb-&gt;query( \"DELETE FROM $wpdb-&gt;postmeta WHERE meta_key = '_thumbnail_id' AND post_id = $post_ID\" );\n}\nadd_action('before_delete_post', 'delete_post_and_attachments');<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>WordPress6.0 \u65b0\u7248\u5fc5\u5907\u4f18\u5316\u4ee3\u7801\uff1a &lt;!&#8211;\u6dfb\u52a0\u4f18\u5316\u4ee3\u7801\u5230\u4e3b\u9898\u76ee\u5f55functions.php\u6587&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-330","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/comments?post=330"}],"version-history":[{"count":0,"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/posts\/330\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/media?parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/categories?post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ppdd.vip\/index.php\/wp-json\/wp\/v2\/tags?post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}