makers99/wp-cli-db-export-clean
Composer 安装命令:
composer require makers99/wp-cli-db-export-clean
包简介
A WP-CLI command `wp db export-clean` to create a database dump without sensitive customer/user data.
关键字:
README 文档
README
Adds the WP-CLI command wp db export-clean to create a MySQL database dump
without sensitive data related to customers and optionally API secrets/credentials,
while retaining all administrative users and their related data.
Revisions are excluded as well to minimize the dump file size.
Quick links: Usage | Integration | Installation | Support
Usage
wp db export-clean [<filepath>] [--remove-keys]
Arguments
The command accepts the result filename as argument. If omitted, it defaults to
./clean.sql.
Options
| Option | Description | Default |
|---|---|---|
--remove-keys |
Additionally remove options containing license keys and API credentials during dump. | false |
Examples
-
Create clean database dump in
./clean.sql:$ wp db export-clean -
Create clean database dump in the user's home directory:
$ wp db export-clean ~/clean.sql -
Exclude plugin license keys and API keys in the clean database dump – useful when working with plugin vendor support or unknown freelancers:
$ wp db export-clean --remove-keys
Integration
Supported plugins
- WordPress Core (keeping only posts and comments from retained users, omitting revisions, transients and caches)
- WooCommerce (only orders from retained users, omitting scheduled actions and sessions)
- WooCommerce Subscriptions (only subscriptions from retained users)
- Gravityforms (omitting revisions, entries, and statistics)
- wp-lister-amazon, wp-lister-ebay (omitting feeds, jobs, logs)
- Yoast wordpress-seo (omitting index tracking, migrations, links)
Placing the filter hooks
wp db export-clean runs directly after WordPress is loaded (like wp db export), which means that only wp-config.php and plugins are loaded but WordPress is not bootstrapped with init hooks. You can place your hooks into a must-use plugin; for example:
wp-content/mu-plugins/wp-cli-db-export-clean.php:
<?php /* Plugin Name: wp db export-clean Customizations Version: 1.0.0 Description: Includes test users in the clean database dump. */ add_filter('wp-db-export-clean/allowed-emails', function ($allowed_emails) { return array_unique(array_merge($allowed_emails, [ 'test@example.com', ])); });
Including more users in the database export
wp db export-clean only includes users having the role Administrator by default. Use the filter hook 'wp-db-export-clean/allowed-emails' to include more users in the database dump:
/** * Customizes list of email addresses to retain in clean database dump. * * @return array * An array whose items are email addresses to keep. */ add_filter('wp-db-export-clean/allowed-emails', function ($allowed_emails) { global $wpdb; $users = $wpdb->get_col( $wpdb->prepare("SELECT u.user_email FROM {$wpdb->prefix}users u WHERE u.user_email LIKE '%%%s'", '@example.com') ); return array_unique(array_merge($allowed_emails, $users)); });
In addition, you can include users by ID:
/** * Customizes list of user IDs to retain in clean database dump. * * @return array * An array whose items are user IDs to keep. */ add_filter('wp-db-export-clean/allowed-user-ids', function ($allowedUserIds) { $allowedUserIds[] = 123; $allowedUserIds[] = 456; return array_unique($allowedUserIds); });
Including more WooCommerce orders or subscriptions in the database export
/** * Customizes list of shop order/subscription IDs to retain in clean database dump. * * @return array * An array whose items are shop_order IDs to keep. */ add_filter('wp-db-export-clean/allowed-order-ids', function ($allowedOrderIds) { $allowedOrderIds[] = 123456; return array_unique($allowedOrderIds); });
Excluding more/custom data in the database export
Implement the following filter hook to customize the where conditions for all tables.
/** * Customizes select query conditions for each table in clean database dump. * * @return array * An array whose keys are table names and whose values are SQL WHERE clause conditions. */ add_filter('wp-db-export-clean/table-wheres', function ($tableWheres) { global $wpdb; $tableWheres = array_merge($tableWheres, [ "{$wpdb->prefix}my_log" => '1 = 0', "{$wpdb->prefix}my_userdata" => "user_id IN ({$allowedUserIds})", ]); return $tableWheres; });
Excluded licenses and API keys
When passing the --remove-keys option, the following plugins are currently supported:
- WooCommerce (PayPal)
- WooCommerce PayPal Plus
- WooCommerce PayPal Express Checkout (woocommerce-gateway-paypal-express-checkout)
- wp-lister-amazon
- wp-lister-ebay
- Gravityforms
- WooThemes (wp-all-import, wp-all-export)
- Optimus
- Elementor
- SearchWP
- Gravityforms Zero Spam
- WooCommerce Amazon Payments
Installation
Install as package
- To install the latest version of this package for the current user:
wp package install makers99/wp-cli-db-export-clean
Install as Git submodule
-
Add the package as submodule.
git submodule add --name wp-cli-db-export-clean git@github.com:makers99/wp-cli-db-export-clean.git .wp-cli/packages/db-export-clean
-
Register the command for early WP-CLI bootstrap.
echo -e "require:\n - .wp-cli/packages/db-export-clean/package.php" >> wp-cli.yml
Or manually:
vi wp-cli.yml
require: - .wp-cli/packages/db-export-clean/plugin.php
Install with Composer
-
Install the package with Composer.
composer config repositories.wp-cli-db-export-clean git https://github.com/makers99/wp-cli-db-export-clean.git composer require makers99/wp-cli-db-export-clean:dev-master
Note: Do not use
--devto install asrequire-dev, because export-clean is typically used in production. -
Register the command for early WP-CLI bootstrap.
echo -e "require:\n - vendor/makers99/wp-cli-db-export-clean/package.php" >> wp-cli.yml
Or manually:
vi wp-cli.yml
require: - vendor/makers99/wp-cli-db-export-clean/package.php
Support
MySQL errors during export
Add to wp-cli.yml in your site root folder:
db export: max-allowed-packet: 1G
Come create with us!
Originally authored by Bogdan Arizancu and Daniel Kudwien.
makers99/wp-cli-db-export-clean 适用场景与选型建议
makers99/wp-cli-db-export-clean 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 445 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「security」 「dump」 「mysql」 「deploy」 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 makers99/wp-cli-db-export-clean 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 makers99/wp-cli-db-export-clean 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 makers99/wp-cli-db-export-clean 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package will add the `dd` and `dump` helpers to your Phalcon application.
Dibi is Database Abstraction Library for PHP
Simple Twig extension improving templates debugging
nice output for debug functions for PHP 5.3
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 445
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2023-03-17
