Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

97 set jetpack to staging on non production sites #98

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
.vscode
.DS_Store
.idea
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ This feature disables WordPress sticky posts entirely, including the ability to

This feature disables WordPress from sending or receiving trackbacks or pingbacks.

### `enabled_jetpack_safe_mode`

This feature ensures Jetpack is in safe mode where applicable (currently Pantheon only).

### `force_two_factor_authentication`

This feature forces users with `edit_posts` permissions to use two factor authentication (2fa) for their accounts.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Class file for Enable_Jetpack_Safe_Mode
*
* (c) Alley <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package wp-alleyvate
*/

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Types\Feature;

/**
* Enables Jetpack safe mode for non-production environments, currently only for Pantheon.
*/
final class Enable_Jetpack_Safe_Mode implements Feature {
/**
* Boot the feature.
*/
public function boot(): void {
if (
isset( $_ENV['PANTHEON_ENVIRONMENT'] ) &&
'live' !== $_ENV['PANTHEON_ENVIRONMENT']
) {
add_filter( 'jetpack_is_development_site', '__return_true' );
}
}
}
4 changes: 4 additions & 0 deletions src/alley/wp/alleyvate/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ function load(): void {
'disallow_file_edit',
new Features\Disallow_File_Edit(),
),
new Feature(
'enable_jetpack_safe_mode',
new Features\Enable_Jetpack_Safe_Mode(),
),
new Feature(
'login_nonce',
new Features\Login_Nonce(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Class file for Test_Enable_Jetpack_Safe_Mode
*
* (c) Alley <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package wp-alleyvate
*/

declare( strict_types=1 );

namespace Alley\WP\Alleyvate\Features;

use Mantle\Testkit\Test_Case;

/**
* Tests for the enabling of Jetpack safe mode.
*/
final class EnabledJetpackSafeModeTest extends Test_Case {

/**
* Feature instance.
*
* @var Enable_Jetpack_Safe_Mode
*/
private Enable_Jetpack_Safe_Mode $feature;

/**
* Set up.
*/
protected function setUp(): void {
parent::setUp();

$this->feature = new Enable_Jetpack_Safe_Mode();
}

/**
* Test that the feature enabled Jetpack safe mode.
*/
public function test_enable_jetpack_safe_mode(): void {
$this->assertFalse( apply_filters( 'jetpack_is_development_site', false ), 'jetpack_is_development_site should not be true prior to boot.' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$this->setEnvironment( 'test' );
$this->feature->boot();
$this->assertTrue( apply_filters( 'jetpack_is_development_site', false ), 'jetpack_is_development_site should be true after boot.' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
}

/**
* Set the current environment value.
*
* @param string $environment The environment name to use.
*/
protected function setEnvironment( string $environment ): void {
putenv( 'PANTHEON_ENVIRONMENT=' . $environment ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv
$_ENV['PANTHEON_ENVIRONMENT'] = $environment;
}
}
Loading