|
WordPress 中文版是全球广泛使用的免费开源网站博客程序。
WordPress 最新版是一种采用 PHP 语言开发的博客平台,用户可以在支持 PHP 和 MySQL 数据库 的服务器上架设自己的网站,也可以把 WordPress 当作博客到大型网站的内容管理系统(CMS)。
WordPress 程序是免费的开源项目,在 GNU 通用公共许可证下授权发布。
新版变化
WordPress v6.0.2
wordpress.org/news/
WordPress 新版必备优化代码
<!--添加优化代码到主题目录functions.php文件-->/*彻底关闭自动更新(核心程序/主题/插件/翻译自动更新*/add_filter(&#39;automatic_updater_disabled&#39;, &#39;__return_true&#39;);/*关闭更新检查定时作业*/remove_action(&#39;init&#39;, &#39;wp_schedule_update_checks&#39;);/*移除已有的版本检查定时作业*/wp_clear_scheduled_hook(&#39;wp_version_check&#39;);/*移除已有的插件更新定时作业*/wp_clear_scheduled_hook(&#39;wp_update_plugins&#39;);/*移除已有的主题更新定时作业*/wp_clear_scheduled_hook(&#39;wp_update_themes&#39;);/*移除已有的自动更新定时作业*/wp_clear_scheduled_hook(&#39;wp_maybe_auto_update&#39;);/*移除后台内核更新检查*/remove_action( &#39;admin_init&#39;, &#39;_maybe_update_core&#39; );/*移除后台插件更新检查*/remove_action( &#39;load-plugins.php&#39;, &#39;wp_update_plugins&#39; );remove_action( &#39;load-update.php&#39;, &#39;wp_update_plugins&#39; );remove_action( &#39;load-update-core.php&#39;, &#39;wp_update_plugins&#39; );remove_action( &#39;admin_init&#39;, &#39;_maybe_update_plugins&#39; );/*移除后台主题更新检查*/remove_action( &#39;load-themes.php&#39;, &#39;wp_update_themes&#39; );remove_action( &#39;load-update.php&#39;, &#39;wp_update_themes&#39; );remove_action( &#39;load-update-core.php&#39;, &#39;wp_update_themes&#39; );remove_action( &#39;admin_init&#39;, &#39;_maybe_update_themes&#39; );/*关闭程序更新提示*/add_filter( &#39;pre_site_transient_update_core&#39;, function($a){ return null; });/*关闭插件更新提示*/add_filter(&#39;pre_site_transient_update_plugins&#39;, function($a){return null;});/*关闭主题更新提示*/add_filter(&#39;pre_site_transient_update_themes&#39;, function($a){return null;});//关闭WordPress的XML-RPC功能add_filter(&#39;xmlrpc_enabled&#39;, &#39;__return_false&#39;);/* 关闭XML-RPC的pingback端口 */add_filter( &#39;xmlrpc_methods&#39;, &#39;remove_xmlrpc_pingback_ping&#39; );function remove_xmlrpc_pingback_ping( $methods ) {unset( $methods[&#39;pingback.ping&#39;] );return $methods;}//禁用 pingbacks, enclosures, trackbacksremove_action( &#39;do_pings&#39;, &#39;do_all_pings&#39;, 10 );//去掉 _encloseme 和 do_ping 操作remove_action( &#39;publish_post&#39;,&#39;_publish_post_hook&#39;,5 );/* 禁止加载s.w.org获取表情和头像 */remove_action(&#39;wp_head&#39;, &#39;print_emoji_detection_script&#39;, 7 );remove_action(&#39;admin_print_scripts&#39;,&#39;print_emoji_detection_script&#39;);remove_action(&#39;wp_print_styles&#39;, &#39;print_emoji_styles&#39;);remove_action(&#39;admin_print_styles&#39;, &#39;print_emoji_styles&#39;);function remove_dns_prefetch( $hints, $relation_type ) {if ( &#39;dns-prefetch&#39; === $relation_type ) {return array_diff( wp_dependencies_unique_hosts(), $hints );}return $hints;}add_filter( &#39;wp_resource_hints&#39;, &#39;remove_dns_prefetch&#39;, 10, 2 );/* 完全禁止REST API、移除wp-json链接 */function lerm_disable_rest_api( $access ) { return new WP_Error( &#39;Stop!&#39;, &#39;Soooooryyyy&#39;, array( &#39;status&#39; => 403, ) );}add_filter( &#39;rest_authentication_errors&#39;, &#39;lerm_disable_rest_api&#39; );remove_action( &#39;wp_head&#39;, &#39;rest_output_link_wp_head&#39;, 10 );/* 禁止查询网站静态资源连接版本字符 */function _remove_script_version ( $src ){ $parts = explode( &#39;?&#39;, $src ); return $parts[0];}add_filter( &#39;script_loader_src&#39;, &#39;_remove_script_version&#39;, 15, 1 );add_filter( &#39;style_loader_src&#39;, &#39;_remove_script_version&#39;, 15, 1 );/* 移除前端网页源代码内的头部冗余代码 */remove_action( &#39;wp_head&#39;, &#39;feed_links_extra&#39;, 3 ); remove_action( &#39;wp_head&#39;, &#39;rsd_link&#39; ); remove_action( &#39;wp_head&#39;, &#39;wlwmanifest_link&#39; ); remove_action( &#39;wp_head&#39;, &#39;index_rel_link&#39; ); remove_action( &#39;wp_head&#39;, &#39;start_post_rel_link&#39;, 10, 0 ); remove_action( &#39;wp_head&#39;, &#39;wp_generator&#39; ); /* 禁止新版文章编辑器加载前端样式 */function wpassist_remove_block_library_css(){ wp_dequeue_style( &#39;wp-block-library&#39; );} remove_action( &#39;wp_enqueue_scripts&#39;, &#39;wp_common_block_scripts_and_styles&#39; );add_action( &#39;wp_enqueue_scripts&#39;, &#39;wpassist_remove_block_library_css&#39; );/* 移除新版本站点健康状态面板和菜单项 */add_action( &#39;admin_menu&#39;, &#39;remove_site_health_menu&#39; ); function remove_site_health_menu(){remove_submenu_page( &#39;tools.php&#39;,&#39;site-health.php&#39; ); }/* 禁用5.5版后自带的XML站点地图 */add_filter( &#39;wp_sitemaps_enabled&#39;, &#39;__return_false&#39; );/* 移除前后台顶部工具栏指定菜单 */function admin_bar_item ( WP_Admin_Bar $admin_bar ) { $admin_bar->remove_menu(&#39;wp-logo&#39;); //移动wp的logo $admin_bar->remove_menu(&#39;site-name&#39;); //移动站点名称 $admin_bar->remove_menu(&#39;updates&#39;); //移动更新提示 $admin_bar->remove_menu(&#39;comments&#39;); //移动评论提示 /*$admin_bar->remove_menu(&#39;new-content&#39;); //移除新建按钮 */ }add_action( &#39;admin_bar_menu&#39;, &#39;admin_bar_item&#39;, 500 );//移除后台仪表盘站点健康状态面板add_action(&#39;wp_dashboard_setup&#39;, &#39;remove_site_health_dashboard_widget&#39;);function remove_site_health_dashboard_widget(){ remove_meta_box(&#39;dashboard_site_health&#39;, &#39;dashboard&#39;, &#39;normal&#39;);}//移除后台仪表盘菜单:站点健康状态add_action( &#39;admin_menu&#39;, &#39;remove_site_health_menu&#39; ); function remove_site_health_menu(){ remove_submenu_page( &#39;tools.php&#39;,&#39;site-health.php&#39; ); }//移除后台仪表盘菜单:活动、新闻function bzg_remove_dashboard_widgets() { global $wp_meta_boxes; #移除 &quot;活动&quot; unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;normal&#39;][&#39;core&#39;][&#39;dashboard_activity&#39;]); #移除 &quot;WordPress 新闻&quot; unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;side&#39;][&#39;core&#39;][&#39;dashboard_primary&#39;]);}add_action(&#39;wp_dashboard_setup&#39;, &#39;bzg_remove_dashboard_widgets&#39; );//移除后台仪表盘菜单:帮助function bzg_remove_help() { get_current_screen()->remove_help_tabs();}add_action(&#39;admin_head&#39;, &#39;bzg_remove_help&#39;);//移除后台页面title标题的wordpress后缀add_filter(&#39;admin_title&#39;, &#39;delAdminTitle&#39;, 10, 2);function delAdminTitle($admin_title, $title){ return $title.&#39; ‹ &#39;.get_bloginfo(&#39;name&#39;);}//移除登陆页面title标题的wordpress后缀add_filter(&#39;login_title&#39;, &#39;remove_login_title&#39;, 10, 2);function remove_login_title($login_title, $title){ return $title.&#39; ‹ &#39;.get_bloginfo(&#39;name&#39;);}/* 彻底禁止4.4+版之后响应式图片功能及缩略图裁剪功能*/// 禁止生成图像尺寸function zm_customize_image_sizes( $sizes ){ unset( $sizes[ &#39;thumbnail&#39; ]); unset( $sizes[ &#39;medium&#39; ]); unset( $sizes[ &#39;medium_large&#39; ] ); unset( $sizes[ &#39;large&#39; ]); unset( $sizes[ &#39;full&#39; ] ); unset( $sizes[&#39;1536x1536&#39;] ); unset( $sizes[&#39;2048x2048&#39;] ); return $sizes;} add_filter( &#39;intermediate_image_sizes_advanced&#39;, &#39;zm_customize_image_sizes&#39; ); // 禁止缩放图片尺寸add_filter(&#39;big_image_size_threshold&#39;, &#39;__return_false&#39;); // 禁止生成其它图像尺寸function shapeSpace_disable_other_image_sizes() { // 禁止通过set_post_thumbnail_size()函数生成的图片尺寸 remove_image_size(&#39;post-thumbnail&#39;); // 禁止添加其它图像尺寸 remove_image_size(&#39;another-size&#39;);}add_action(&#39;init&#39;, &#39;shapeSpace_disable_other_image_sizes&#39;);//切换经典文章编辑器(v5.x开始默认古腾堡编辑器)add_filter(&#39;use_block_editor_for_post&#39;, &#39;__return_false&#39;);//替换评论用户头像链接为国内镜像加速访问add_filter(&#39;get_avatar&#39;, function ($avatar) {return str_replace([&#39;www.gravatar.com/avatar/&#39;,&#39;0.gravatar.com/avatar/&#39;,&#39;1.gravatar.com/avatar/&#39;,&#39;2.gravatar.com/avatar/&#39;,&#39;secure.gravatar.com/avatar/&#39;,&#39;cn.gravatar.com/avatar/&#39;], &#39;cravatar.cn/&#39;, $avatar);});//取消内容转义remove_filter(&#39;the_content&#39;, &#39;wptexturize&#39;);//取消摘要转义remove_filter(&#39;the_excerpt&#39;, &#39;wptexturize&#39;);//取消评论转义remove_filter(&#39;comment_text&#39;, &#39;wptexturize&#39;);//禁止转义引号字符remove_filter(&#39;the_content&#39;, &#39;wptexturize&#39;); // 禁止英文引号转义为中文引号//文章插入图片自动移除 img 的 width、height、class 属性;add_filter( &#39;post_thumbnail_html&#39;, &#39;fanly_remove_images_attribute&#39;, 10 );add_filter( &#39;image_send_to_editor&#39;, &#39;fanly_remove_images_attribute&#39;, 10 );function fanly_remove_images_attribute( $html ) { //$html = preg_replace( &#39;/(width|height)=&quot;\d*&quot;\s/&#39;, &quot;&quot;, $html ); $html = preg_replace( &#39;/width=&quot;(\d*)&quot;\s+height=&quot;(\d*)&quot;\s+class=&quot;[^&quot;]*&quot;/&#39;, &quot;&quot;, $html ); $html = preg_replace( &#39;/ /&#39;, &quot;&quot;, $html ); return $html;}//自适应图片删除width和heightfunction ludou_remove_width_height_attribute($content){ preg_match_all(&#39;/<[img|IMG].*?src=[\&#39;|&quot;](.*?(?:[\.gif|\.jpg|\.png\.webp]))[\&#39;|&quot;].*?[\/]?>/&#39;, $content, $images); if(!empty($images)) { foreach($images[0] as $index => $value){ $new_img = preg_replace(&#39;/(width|height)=&quot;\d*&quot;\s/&#39;, &quot;&quot;, $images[0][$index]); $content = str_replace($images[0][$index], $new_img, $content); } } return $content;}//判断是否是移动设备浏览if(wp_is_mobile()) { #删除文章内容中img的width和height属性 add_filter(&#39;the_content&#39;, &#39;ludou_remove_width_height_attribute&#39;, 99);}/* 删除文章时删除图片附件 */function delete_post_and_attachments($post_ID) {global $wpdb;#删除特色图片$thumbnails = $wpdb->get_results( &quot;SELECT * FROM $wpdb->postmeta WHERE meta_key = &#39;_thumbnail_id&#39; AND post_id = $post_ID&quot; );foreach ( $thumbnails as $thumbnail ) {wp_delete_attachment( $thumbnail->meta_value, true );}#删除图片附件$attachments = $wpdb->get_results( &quot;SELECT * FROM $wpdb->posts WHERE post_parent = $post_ID AND post_type = &#39;attachment&#39;&quot; );foreach ( $attachments as $attachment ) {wp_delete_attachment( $attachment->ID, true );}$wpdb->query( &quot;DELETE FROM $wpdb->postmeta WHERE meta_key = &#39;_thumbnail_id&#39; AND post_id = $post_ID&quot; );}add_action(&#39;before_delete_post&#39;, &#39;delete_post_and_attachments&#39;);系统要求
WordPress 5.x 以上版本最低运行需求:
- PHP 7.0 或更高版,建议 PHP 7.2 稳定版
- MySQL 5.6 或更高版,建议用 5.6 稳定版
下载地址
https://cn.wordpress.org/download/releases
https://cn.wordpress.org/wordpress-6.0.2-zh_CN.zip
https://cn.wordpress.org/wordpress-6.0.2-zh_CN.tar.gz
zip |
|