-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANET-7648: Added opt-in archive notice on old posts (#2445)
- Add new feature flag - Add new default content - Pass content to the twig template - Add styles and clean code - Show or hide notice based on the date - Improve code logic - Add migration script - Fix lint issues - Fix php test
- Loading branch information
Showing
9 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace P4\MasterTheme\Features; | ||
|
||
use P4\MasterTheme\Feature; | ||
|
||
/** | ||
* @see description(). | ||
*/ | ||
class OldPostsArchiveNotice extends Feature | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function id(): string | ||
{ | ||
return 'old_posts_archive_notice'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected static function name(): string | ||
{ | ||
return __('Old Posts Archive notice', 'planet4-master-theme-backend'); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected static function description(): string | ||
{ | ||
return __( | ||
// phpcs:ignore Generic.Files.LineLength.MaxExceeded | ||
'Displays a notice on top of old Posts.<br>Adjust its behavior and text through <a href="/wp-admin/admin.php?page=planet4_settings_defaults_content" href="_self">Defaults content settings.</a>', | ||
'planet4-master-theme-backend' | ||
); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function show_toggle_production(): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?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 M034PrePopulateOldPostsArchiveNotice 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 | ||
{ | ||
$cutoff = '10'; | ||
$title = 'Oldies But Goodies Alert!'; | ||
$description = "Hey there! Just a quick note: the stuff you're browsing through is mostly for nostalgia and archival kicks. So, before you go basing any big decisions on what you find here, maybe double-check with some fresher content."; // phpcs:ignore Generic.Files.LineLength.MaxExceeded | ||
$button = 'Read the latest from ' . get_bloginfo('name'); | ||
$prefix = 'old_posts_archive_notice_'; | ||
|
||
$options = get_option('planet4_options'); | ||
|
||
if (!$options) { | ||
echo "Error with migration M034PrePopulateOldPostsArchiveNotice. P4 options not found.\n"; // phpcs:ignore | ||
return; | ||
} | ||
|
||
$options[ $prefix . 'cutoff' ] = $cutoff; | ||
$options[ $prefix . 'title' ] = $title; | ||
$options[ $prefix . 'description' ] = $description; | ||
$options[ $prefix . 'button' ] = $button; | ||
|
||
$result = update_option('planet4_options', $options); | ||
|
||
if ($result) { | ||
echo "Migration M034PrePopulateOldPostsArchiveNotice successful\n"; // phpcs:ignore | ||
} else { | ||
echo "Error with migration M034PrePopulateOldPostsArchiveNotice. P4 options could not be updated.\n"; // phpcs:ignore | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters