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
-
Install and configure
ngrok(preferably via Homebrew): https://ngrok (opens in a new tab). com/download -
Start an
ngroktunnel:ngrok http https://nova.test:443 --host-header nova.testReplace
nova.testwith the domain name of the local site you're working on. -
Copy the ngrok URL shown next to the "Forwarding" section, eg
https://be29-1-1-1-1.ngrok-free.app -
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' ); -
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' ); -
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' ); -
Log in to WordPress using the ngrok URL and go to the Jetpack admin page to start the connection process.
-
Complete whatever testing required a Jetpack connection.
Cleaning up
- Disconnect Jetpack, either via the Jetpack admin page, or via WP-CLI:
wp jetpack disconnect blog - Terminate the
ngroktunnel. - Remove or comment out the constants added to
wp-config.php. - Remove or comment out the filter added to
wp-content/client-mu-plugins/local-dev.php.