删除Elementor Page Builder之后清理WordPress数据库

从WordPress删除插件时,数据库中可能会剩下很多东西,这使数据库不必要地变大,甚至可能减慢查询速度。删除插件后清理WordPress数据库始终是一个好习惯。最近将一个客户网站启用非常轻量的GeneratePress主题,并决定将页面构建插件Elementor改为相对轻量的Beaver Builder,自然而然地需要理数据库。

本文将介绍删除Elementor插件后,以从options、postmeta、usermeta、posts表中删除剩余的数据。

主要包含以下内容:

  • 删除Elementor插件和文件
  • 删除Elementor文章类型
  • 删除Elementor分类
  • 从usermeta和postmeta删除Elementor meta_keys
  • 从wp_options删除Elementor选项

删除Elementor插件和文件

以下使用WP-CLI,执行以下命令删除Elementor插件:

wp plugin delete elementor --allow-root
wp plugin delete elementor-pro --allow-root

删除Elementor上传文件夹

rm -rf wp-content/uploads/elementor

删除Elementor文章类型

列出文章类型,并查看Elementor是否在其中

wp post-type list --allow-root | grep elementor

在这里我没找到相关信息。下面开始查找数据库:

wp db query "SELECT DISTINCT(post_type) FROM $(wp db prefix --allow-root)posts" --allow-root

elementor_library post类型在这里!

+---------------------+
| post_type           |
+---------------------+
| amn_exact-metrics   |
| attachment          |
| custom_css          |
| customize_changeset |
| download            |
| edd_log             |
| edd_payment         |
| elementor_library   |
| gp_elements         |
| nav_menu_item       |
| oembed_cache        |
| page                |
| post                |
| pretty-link         |
| revision            |
| wpcf7_contact_form  |
+---------------------+

现在可以删除所有elementor_library post了

先列出它们:

wp post list --post_type=elementor_library --post_status=draft,revision,publish --allow-root

输出:

+-----+---------------------+---------------------+---------------------+-------------+
| ID  | post_title          | post_name           | post_date           | post_status |
+-----+---------------------+---------------------+---------------------+-------------+
| 217 | Default Kit         | default-kit         | 2020-03-08 00:05:51 | publish     |
| 112 | WP css2js Minify    | wp-css2js-minify    | 2016-12-10 22:13:29 | publish     |
| 64  | Works with template | works-with-template | 2016-10-30 20:02:04 | publish     |
| 18  | Home Final Final    | home-final-final    | 2016-10-26 13:52:42 | publish     |
+-----+---------------------+---------------------+---------------------+-------------+

为了删除这些,必须使用--force,否则将出现以下错误:

Warning: Posts of type 'elementor_library' do not support being sent to trash.
Please use the --force flag to skip trash and delete them permanently.

使用WP-CLI删除elementor_library所有文章的命令:

wp post delete $(wp post list --post_type=elementor_library --post_status=draft,revision,publish --allow-root --skip-plugins --format=ids) --force --allow-root

应该看到类似这样的输出:

Success: Deleted post 217.
Success: Deleted post 112.
Success: Deleted post 64.
Success: Deleted post 18.

删除Elementor分类

在搜索数据库时,我发现分类表中有Elementor引用,因此请确认你也有这些引用!

这是在数据库中搜索elementor字符串的结果。

wp_posts:post_type
18:elementor_library
wp_posts:post_type
64:elementor_library
wp_posts:post_type
112:elementor_library
wp_posts:post_type
217:elementor_library
wp_term_taxonomy:taxonomy
5:elementor_library_type
wp_term_taxonomy:taxonomy
6:elementor_library_type

计算分类表中的Elementor行数:

wp db query "SELECT COUNT(*) AS ElementorTaxonomy FROM $(wp db prefix --allow-root)term_taxonomy WHERE taxonomy LIKE '%elementor%'" --allow-root

输出:

+-------------------+
| ElementorTaxonomy |
+-------------------+
|                 2 |
+-------------------+

现在可以删除这些了

wp db query "DELETE FROM $(wp db prefix --allow-root)term_taxonomy WHERE taxonomy LIKE '%elementor%'" --allow-root

清理Elementor postmeta

列出postmeta包含字符串elementor的表:

wp db query "SELECT DISTINCT(meta_key) FROM $(wp db prefix --allow-root)postmeta" --allow-root | grep elementor

输出:

_elementor_data
_elementor_edit_mode
_elementor_template_type
_elementor_version
_elementor_conditions
_elementor_page_settings
_elementor_pro_version
_elementor_template_widget_type
_elementor_global_widget_included_posts
_elementor_template_sub_type
_elementor_popup_display_settings
_elementor_source_image_hash
_elementor_controls_usage
_elementor_css

计算一下有多少Elementor Postmeta:

wp db query "SELECT COUNT(*) AS ElementorPostMeta FROM $(wp db prefix --allow-root)postmeta WHERE meta_key LIKE '%elementor%'" --allow-root

输出:

+-------------------+
| ElementorPostMeta |
+-------------------+
|                52 |
+-------------------+

删除所有Elementor postmeta条目

wp db query "DELETE FROM $(wp db prefix --allow-root)postmeta WHERE meta_key LIKE '%elementor%'" --allow-root

清理Elementor usermeta

wp db query "SELECT DISTINCT(meta_key) FROM wp_usermeta" --allow-root | grep elementor

输出:

elementor_introduction
elementor_admin_notices
wp_elementor_connect_common_data

计算行数:

wp db query "SELECT COUNT(*) AS ElementorUserMeta FROM $(wp db prefix --allow-root)usermeta WHERE meta_key LIKE '%elementor%'" --allow-root

输出:

+-------------------+
| ElementorUserMeta |
+-------------------+
|                 2 |
+-------------------+

清理:

wp db query "DELETE FROM $(wp db prefix --allow-root)usermeta WHERE meta_key LIKE '%elementor%'" --allow-root

清理Elementor选项(Options)

检查网站上自动加载的数据量,越少越好!

+-----------------------+---------+--------------------------------------------------------------------+
| name                  | status  | message                                                            |
+-----------------------+---------+--------------------------------------------------------------------+
| autoload-options-size | success | Autoloaded options size (116.58kb) is less than threshold (900kb). |
+-----------------------+---------+--------------------------------------------------------------------+

列出属于Elementor的选项

wp option list --field=option_name --allow-root | grep elementor

输出:

elementor_active_kit
elementor_allow_svg
elementor_allow_tracking
elementor_beta
elementor_clear_cache
elementor_connect_site_key
elementor_container_width
elementor_controls_usage
elementor_cpt_support
elementor_css_print_method
elementor_custom_icon_sets_config
elementor_default_generic_fonts
elementor_disable_color_schemes
elementor_disable_typography_schemes
elementor_edit_buttons
elementor_editor_break_lines
elementor_enable_inspector
elementor_exclude_user_roles
elementor_font_awesome_pro_kit_id
elementor_fonts_manager_fonts
elementor_fonts_manager_font_types
_elementor_general_settings
_elementor_global_css
elementor_global_image_lightbox
elementor_icon_manager_needs_update
_elementor_installed_time
elementor_library_category_children
elementor_load_fa4_shim
elementor_log
elementor_maintenance_mode_exclude_mode
elementor_maintenance_mode_exclude_roles
elementor_maintenance_mode_mode
elementor_maintenance_mode_template_id
elementor_page_title_selector
elementor_pro_activecampaign_api_key
elementor_pro_activecampaign_api_url
elementor_pro_convertkit_api_key
elementor_pro_donreach_api_key
elementor_pro_donreach_api_url
elementor_pro_drip_api_token
elementor_pro_facebook_app_id
elementor_pro_getresponse_api_key
_elementor_pro_installed_time
elementor_pro_license_key
elementor_pro_mailchimp_api_key
elementor_pro_mailerlite_api_key
elementor_pro_recaptcha_secret_key
elementor_pro_recaptcha_site_key
elementor_pro_recaptcha_v3_secret_key
elementor_pro_recaptcha_v3_site_key
elementor_pro_recaptcha_v3_threshold
elementor_pro_theme_builder_conditions
elementor_pro_tracker_notice
elementor_pro_upgrades
elementor_pro_version
elementor_remote_info_feed_data
elementor_remote_info_library
elementor_remote_info_templates_data
elementor_replace_url
elementor_reset_api_data
elementor_rollback
elementor_rollback_pro
elementor_rollback_pro_separator
elementor_scheme_color
elementor_scheme_color-picker
_elementor_scheme_last_updated
elementor_scheme_typography
_elementor_settings_update_time
elementor_space_between_widgets
elementor_stretched_section_container
elementor_tracker_last_send
elementor_tracker_notice
elementor_typekit-kit-id
elementor_upgrades
elementor_use_mini_cart_template
elementor_validate_api_data
elementor_version
elementor_viewport_lg
elementor_viewport_md
plugin_last_upgraded_date_elementor
plugin_last_upgraded_date_elementor-pro-elementor-pro-php
plugin_last_upgraded_version_elementor
plugin_last_upgraded_version_elementor-pro-elementor-pro-php
widget_elementor-library

计算行数:

wp db query "SELECT COUNT(*) AS ElementorOptions FROM $(wp db prefix --allow-root)options WHERE option_name LIKE '%elementor%'" --allow-root

输出:

+------------------+
| ElementorOptions |
+------------------+
|               79 |
+------------------+

从wp_options表中删除所有Elementor设置:

wp db query "DELETE FROM $(wp db prefix --allow-root)options WHERE option_name LIKE '%elementor%'" --allow-root

清理脚本

这是以上所有步骤的脚本,用于清理删除Elementor插件后清理WordPress数据库。

#!/usr/bin/env/bash
# Purpose - clean Elementor leftover database rows from WordPress
# Mike from https://zhanzhangb.com

# deactivate and delete
wp plugin deactivate elementor --allow-root
wp plugin deactivate elementor-pro --allow-root
wp plugin delete elementor --allow-root
wp plugin delete elementor-pro --allow-root

# clean up leftover Elementor uploads
rm -rf wp-content/uploads/elementor

# taxonomy

wp db query "DELETE FROM $(wp db prefix --allow-root)term_taxonomy WHERE taxonomy LIKE '%elementor%'" --allow-root

# custom post types
wp post delete $(wp post list --post_type=elementor_library --post_status=draft,revision,publish --allow-root --skip-plugins --format=ids) --force --allow-root

# postmeta
wp db query "DELETE FROM $(wp db prefix --allow-root)postmeta WHERE meta_key LIKE '%elementor%'" --allow-root

# usermeta

wp db query "DELETE FROM $(wp db prefix --allow-root)usermeta WHERE meta_key LIKE '%elementor%'" --allow-root

# options
wp db query "DELETE FROM $(wp db prefix --allow-root)options WHERE option_name LIKE '%elementor%'" --allow-root

WP-CLI安装使用教程请阅读:https://www.zhanzhangb.com/1664.html

留下评论