Tooling
Jetpack

Jetpack

WordPress.com VIP includes Automattic's Jetpack plugin in their mu-plugins and PMC uses several of Jetpack's features. Some, like Instagram embeds, require a Jetpack connection to work in our local environment.

Connecting Jetpack in a local environment

  1. Install and configure ngrok (preferably via Homebrew): https://ngrok (opens in a new tab). com/download

  2. Start an ngrok tunnel:

    ngrok http https://nova.test:443 --host-header nova.test

    Replace nova.test with the domain name of the local site you're working on.

  3. Copy the ngrok URL shown next to the "Forwarding" section, eg https://be29-1-1-1-1.ngrok-free.app

  4. Add the following constants to wp-config.php, replacing the values with the URL copied in the previous step:

    define( 'WP_HOME', 'https://be29-1-1-1-1.ngrok-free.app' );
    define( 'WP_SITEURL', 'https://be29-1-1-1-1.ngrok-free.app' );
  5. If you need to test a specific Jetpack version that isn't the version used in your local environment, add the following constant to wp-config.php:

    define( 'VIP_JETPACK_PINNED_VERSION', '12.5' );
  6. Force Jetpack to ignore any signals that your local environment is a staging site, or that it's offline, by adding the following to wp-content/client-mu-plugins/local-dev.php:

    <?php
    add_filter( 'jetpack_offline_mode', '__return_false' );
  7. Log in to WordPress using the ngrok URL and go to the Jetpack admin page to start the connection process.

  8. Complete whatever testing required a Jetpack connection.

Cleaning up

  1. Disconnect Jetpack, either via the Jetpack admin page, or via WP-CLI:
    wp jetpack disconnect blog
  2. Terminate the ngrok tunnel.
  3. Remove or comment out the constants added to wp-config.php.
  4. Remove or comment out the filter added to wp-content/client-mu-plugins/local-dev.php.