diff --git a/assets/src/scss/pages/post/_post.scss b/assets/src/scss/pages/post/_post.scss index b0df29682b..bcc0c6e779 100644 --- a/assets/src/scss/pages/post/_post.scss +++ b/assets/src/scss/pages/post/_post.scss @@ -99,3 +99,30 @@ .post-tags { margin-bottom: $sp-2; } + +.single-post-old-posts-archive-notice { + background-color: var(--beige-100); + padding: $sp-3; + margin-top: $sp-3; + + @include medium-and-up { + padding: $sp-3 $sp-8; + } + + a { + margin: 0 auto; + display: block; + width: fit-content; + } + + h4 { + text-align: center; + margin: 0; + } + + p { + font-size: var(--font-size-m--font-family-secondary); + line-height: var(--line-height-m--font-family-secondary); + margin: $sp-3 0; + } +} diff --git a/single.php b/single.php index e3ba3152a5..9f0ecebe13 100755 --- a/single.php +++ b/single.php @@ -48,6 +48,7 @@ $context['post_categories'] = implode(', ', $post->categories()); // We need the explode because we want to remove "+00:00" at the end of the string. $context['page_date'] = explode('+', get_the_date('c', $post->ID))[0]; +$context['old_posts_archive_notice'] = $post->get_old_posts_archive_notice(); Context::set_og_meta_fields($context, $post); Context::set_campaign_datalayer($context, $page_meta_data); diff --git a/src/Features/OldPostsArchiveNotice.php b/src/Features/OldPostsArchiveNotice.php new file mode 100644 index 0000000000..9274620166 --- /dev/null +++ b/src/Features/OldPostsArchiveNotice.php @@ -0,0 +1,47 @@ +Adjust its behavior and text through Defaults content settings.', + 'planet4-master-theme-backend' + ); + } + + /** + * @inheritDoc + */ + public static function show_toggle_production(): bool + { + return true; + } +} diff --git a/src/Migrations/M034PrePopulateOldPostsArchiveNotice.php b/src/Migrations/M034PrePopulateOldPostsArchiveNotice.php new file mode 100644 index 0000000000..a0a6a82275 --- /dev/null +++ b/src/Migrations/M034PrePopulateOldPostsArchiveNotice.php @@ -0,0 +1,49 @@ +id); + $options = get_option('planet4_options'); + $notice_cutoff = isset($options[$prefix . 'cutoff']) ? $options[$prefix . 'cutoff'] : null; + $activate = OldPostsArchiveNotice::is_active(); + + if ($options && $post_date && $notice_cutoff && $activate) { + $post_publish_year = (int) date('Y', strtotime($post_date)); + $current_year = (int) date('Y'); + + return array( + "show_notice" => ($current_year - $post_publish_year) >= (int) $notice_cutoff, + "title" => $options[$prefix . 'title'] ?? '', + "description" => $options[$prefix . 'description'] ?? '', + "button" => $options[$prefix . 'button'] ?? '', + ); + } + + return array( + "show_notice" => false, + "title" => '', + "description" => '', + "button" => '', + ); + } } diff --git a/src/Settings.php b/src/Settings.php index 21eb1ecb20..86498d0aa0 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -173,6 +173,31 @@ public function __construct() 'media_buttons' => false, ], ], + + [ + 'name' => __('Old Posts Archive notice cutoff years', 'planet4-master-theme-backend'), + 'id' => 'old_posts_archive_notice_cutoff', + 'type' => 'text', + 'desc' => __('Condition to determine when to show the notice, in years.
Any Post older than that will have the notice displayed on the top.', 'planet4-master-theme-backend'), + ], + + [ + 'name' => __('Old Posts Archive notice title', 'planet4-master-theme-backend'), + 'id' => 'old_posts_archive_notice_title', + 'type' => 'text', + ], + + [ + 'name' => __('Old Posts Archive notice description', 'planet4-master-theme-backend'), + 'id' => 'old_posts_archive_notice_description', + 'type' => 'textarea', + ], + + [ + 'name' => __('Old Posts Archive button text', 'planet4-master-theme-backend'), + 'id' => 'old_posts_archive_notice_button', + 'type' => 'text', + ], ], ], 'planet4_settings_cookies_text' => [ diff --git a/src/Settings/Features.php b/src/Settings/Features.php index 5454739ba3..b92ae99d17 100644 --- a/src/Settings/Features.php +++ b/src/Settings/Features.php @@ -11,6 +11,7 @@ use P4\MasterTheme\Features\LazyYoutubePlayer; use P4\MasterTheme\Features\RedirectRedirectPages; use P4\MasterTheme\Features\Planet4Blocks; +use P4\MasterTheme\Features\OldPostsArchiveNotice; use P4\MasterTheme\Loader; use P4\MasterTheme\Settings; use CMB2; @@ -99,6 +100,7 @@ public static function all_features(): array LazyYoutubePlayer::class, RedirectRedirectPages::class, Planet4Blocks::class, + OldPostsArchiveNotice::class, // Dev only. DisableDataSync::class, diff --git a/templates/single.twig b/templates/single.twig index f328585bbc..fe1f62adff 100644 --- a/templates/single.twig +++ b/templates/single.twig @@ -79,6 +79,22 @@ {% include "blocks/share_buttons.twig" with {social:post.share_meta, utm_medium: 'share'} %} + + {% if old_posts_archive_notice.show_notice %} +
+ {% if ( old_posts_archive_notice.title ) %} +

{{ old_posts_archive_notice.title|e('wp_kses_post')|raw }}

+ {% endif %} + {% if ( old_posts_archive_notice.description ) %} +

{{ old_posts_archive_notice.description|e('wp_kses_post')|raw }}

+ {% endif %} + {% if ( old_posts_archive_notice.button ) %} + + {{ old_posts_archive_notice.button|e('wp_kses_post')|raw }} + + {% endif %} +
+ {% endif %}