Skip to content

Commit

Permalink
PLANET-7532 Retire unused feature flags
Browse files Browse the repository at this point in the history
- Remove "Purge Cloudflare HTML cache on feature changes".
- Removed now obsolete hooks triggered on saving a feature flag.
- Remove "WordPress template editor".
- Add migration to clean up those options from database.

---

Ref: https://jira.greenpeace.org/browse/PLANET-7532
  • Loading branch information
comzeradd committed May 28, 2024
1 parent 1256386 commit c5985de
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 140 deletions.
38 changes: 0 additions & 38 deletions src/Features/Dev/WPTemplateEditor.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/Features/PurgeOnFeatureChanges.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/MasterSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace P4\MasterTheme;

use P4\MasterTheme\Features\Dev\CoreBlockPatterns;
use P4\MasterTheme\Features\Dev\WPTemplateEditor;
use P4\MasterTheme\Features\LazyYoutubePlayer;
use Timber\Timber;
use Timber\Site as TimberSite;
Expand Down Expand Up @@ -105,10 +104,6 @@ protected function hooks(): void
{
add_theme_support('post-thumbnails');
add_theme_support('menus');
if (!WPTemplateEditor::is_active()) {
// Enable Full Site Editing.
remove_theme_support('block-templates');
}
if (!CoreBlockPatterns::is_active()) {
// Disable WP Block Patterns.
remove_theme_support('core-block-patterns');
Expand Down
28 changes: 28 additions & 0 deletions src/Migrations/M029RemoveTemplateEditorOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace P4\MasterTheme\Migrations;

use P4\MasterTheme\MigrationRecord;
use P4\MasterTheme\MigrationScript;

/**
* Remove the WordPress template editor option from Planet 4 Features.
*/
class M029RemoveTemplateEditorOption extends MigrationScript
{
/**
* Perform the actual migration.
*
* @param MigrationRecord $record Information on the execution, can be used to add logs.
* phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter -- interface implementation
*/
protected static function execute(MigrationRecord $record): void
{
// Template editor feature flag.
$features = get_option('planet4_features');
unset($features[ 'wp_template_editor' ]);
update_option('planet4_features', $features);
}
}
28 changes: 28 additions & 0 deletions src/Migrations/M030RemovePurgeOnFeatureChangeOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace P4\MasterTheme\Migrations;

use P4\MasterTheme\MigrationRecord;
use P4\MasterTheme\MigrationScript;

/**
* Remove the Purge on feature change option from Planet 4 Features.
*/
class M030RemovePurgeOnFeatureChangeOption extends MigrationScript
{
/**
* Perform the actual migration.
*
* @param MigrationRecord $record Information on the execution, can be used to add logs.
* phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter -- interface implementation
*/
protected static function execute(MigrationRecord $record): void
{
// Purge on feature change feature flag.
$features = get_option('planet4_features');
unset($features[ 'purge_on_feature_changes' ]);
update_option('planet4_features', $features);
}
}
4 changes: 4 additions & 0 deletions src/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use P4\MasterTheme\Migrations\M026ReplaceDeprecatedColorsFromContent;
use P4\MasterTheme\Migrations\M027RemoveListingPageGridViewOption;
use P4\MasterTheme\Migrations\M028MovePageHeaderSideBarOptions;
use P4\MasterTheme\Migrations\M029RemoveTemplateEditorOption;
use P4\MasterTheme\Migrations\M030RemovePurgeOnFeatureChangeOption;

/**
* Run any new migration scripts and record results in the log.
Expand Down Expand Up @@ -77,6 +79,8 @@ public static function migrate(): void
M026ReplaceDeprecatedColorsFromContent::class,
M027RemoveListingPageGridViewOption::class,
M028MovePageHeaderSideBarOptions::class,
M029RemoveTemplateEditorOption::class,
M030RemovePurgeOnFeatureChangeOption::class,
];

// Loop migrations and run those that haven't run yet.
Expand Down
50 changes: 0 additions & 50 deletions src/Settings/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

namespace P4\MasterTheme\Settings;

use P4\MasterTheme\CloudflarePurger;
use P4\MasterTheme\Features\CloudflareDeployPurge;
use P4\MasterTheme\Features\Dev\AllowAllBlocks;
use P4\MasterTheme\Features\Dev\BetaBlocks;
use P4\MasterTheme\Features\Dev\CoreBlockPatterns;
use P4\MasterTheme\Features\Dev\DisableDataSync;
use P4\MasterTheme\Features\Dev\WPTemplateEditor;
use P4\MasterTheme\Features\EngagingNetworks;
use P4\MasterTheme\Features\LazyYoutubePlayer;
use P4\MasterTheme\Features\PurgeOnFeatureChanges;
use P4\MasterTheme\Features\RedirectRedirectPages;
use P4\MasterTheme\Features\Planet4Blocks;
use P4\MasterTheme\Loader;
Expand All @@ -25,11 +22,6 @@ class Features
{
public const OPTIONS_KEY = 'planet4_features';

/**
* @var bool Purge Cloudflare cache on save
*/
public static bool $purge_cloudflare = false;

/**
* Register current options status before processing, to detect any change later.
*
Expand Down Expand Up @@ -104,15 +96,13 @@ public static function all_features(): array
return [
EngagingNetworks::class,
CloudflareDeployPurge::class,
PurgeOnFeatureChanges::class,
LazyYoutubePlayer::class,
RedirectRedirectPages::class,
Planet4Blocks::class,

// Dev only.
DisableDataSync::class,
BetaBlocks::class,
WPTemplateEditor::class,
CoreBlockPatterns::class,
AllowAllBlocks::class,
];
Expand Down Expand Up @@ -153,27 +143,12 @@ public static function is_active(string $name): bool
*/
public static function hooks(): void
{
// On field save.
add_action(
'cmb2_options-page_process_fields_' . Settings::METABOX_ID,
[ self::class, 'on_pre_process' ],
10,
2
);

add_action(
'cmb2_save_field',
[ self::class, 'on_field_save' ],
10,
4
);
// After all fields are saved.
add_action(
'cmb2_save_options-page_fields_' . Settings::METABOX_ID,
[ self::class, 'on_features_saved' ],
10,
4
);
}

/**
Expand Down Expand Up @@ -206,29 +181,4 @@ function ($f) use ($cmb) {
)
);
}

/**
* Hook running after field is saved
*/
public static function on_field_save(): void
{
// This requires a toggle because we may be hitting a sort of rate limit from the deploy purge alone.
// For now it's better to leave this off on test instances, to avoid purges failing on production because we hit
// the rate limit.
if (! PurgeOnFeatureChanges::is_active()) {
return;
}
}

/**
* Hook running after all features are saved
*/
public static function on_features_saved(): void
{
if (!self::$purge_cloudflare) {
return;
}

is_plugin_active('cloudflare/cloudflare.php') && ( new CloudflarePurger() )->purge_all();
}
}

0 comments on commit c5985de

Please sign in to comment.