Skip to content

Staging

The wp staging pull CLI command synchronises selected production data — posts, postmeta, terms, options, and files — into a staging or local environment.

The command is registered by Modules\Staging\CLI\CommandsProvider and only runs when WP_ENV is development or staging.

Required environment variables

Variable Description
STAGING_PULL_SOURCE_TABLE_PREFIX DB table prefix of the source (production) database
STAGING_PULL_SOURCE_DB_NAME Source database name
STAGING_SHARED_DIR Absolute path to the staging shared folder
STAGING_PULL_SOURCE_SHARED_DIR Absolute path to the source shared folder
DB_NAME Target database name (standard WordPress)

Usage

wp staging pull

What gets copied

Database

Data How
Posts Truncate target tables, copy filtered post types from source
Postmeta Copy postmeta for all copied posts
Terms & taxonomies Drop and recreate wp_terms, wp_term_taxonomy, wp_term_relationships, wp_termmeta
Options Copy a specific allow-listed set of options
Cancellation reasons Clean and re-import cancellation_reason custom post type

Default post types copied:

nav_menu_item, shop_coupon, product, product_variation,
page, post, attachment, cancellation_reason, elementor_library

Options copied:

page_on_front, template, stylesheet, theme_mods_*, elementor_*

URL replacement

After copying, all occurrences of the production domain are replaced with the staging domain in:

  • wp_options table
  • wp_posts.post_content
  • Elementor serialised data (via wp elementor replace-urls)

Override replacements per table with:

add_filter('staging/db-replacements/wp_options', function (array $replacements): array {
    $replacements['https://old.example.com'] = 'https://new.example.com';
    return $replacements;
});

Files

Synced from STAGING_PULL_SOURCE_SHARED_DIR to STAGING_SHARED_DIR for these folders:

  • languages
  • uploads (with blacklist: dao-labels-bulk, csv_exports, elementor, etc.)

Lifecycle hooks

Hooks fire before and after each major operation:

staging/pull/posts/before      staging/pull/posts/after
staging/pull/postmeta/before   staging/pull/postmeta/after
staging/pull/terms/before      staging/pull/terms/after
staging/pull/options/before    staging/pull/options/after
staging/pull/files/before      staging/pull/files/after

Use them to add custom pre/post-processing:

add_action('staging/pull/posts/after', function () {
    // e.g. clear a custom cache after posts are replaced
});

Extending the pull

To copy additional post types:

// Hook into the command before it runs to modify the post_types array
add_filter('staging/pull/post-types', fn(array $types) => array_merge($types, ['my_post_type']));

Warning

This command truncates and overwrites tables in the target database. Never run it against production. Always verify WP_ENV is set correctly.