@@ -47,6 +47,9 @@ public function __construct() {
4747 \add_action ( 'init ' , [ $ this , 'check_delete_badges ' ] );
4848 \add_action ( 'init ' , [ $ this , 'check_toggle_migrations ' ] );
4949 \add_action ( 'init ' , [ $ this , 'check_delete_single_task ' ] );
50+ if ( \defined ( '\IS_PLAYGROUND_PREVIEW ' ) && \constant ( '\IS_PLAYGROUND_PREVIEW ' ) === true ) {
51+ \add_action ( 'init ' , [ $ this , 'check_toggle_placeholder_demo ' ] );
52+ }
5053
5154 // Add filter to modify the maximum number of suggested tasks to display.
5255 \add_filter ( 'progress_planner_suggested_tasks_max_items_per_category ' , [ $ this , 'check_show_all_suggested_tasks ' ] );
@@ -105,6 +108,8 @@ public function add_toolbar_items( $admin_bar ) {
105108 'href ' => \admin_url ( 'admin.php?page=progress-planner-color-customizer ' ),
106109 ]
107110 );
111+
112+ $ this ->add_placeholder_demo_submenu_item ( $ admin_bar );
108113 }
109114
110115 /**
@@ -631,6 +636,65 @@ public function check_delete_single_task() {
631636 exit ;
632637 }
633638
639+ /**
640+ * Add Placeholder Demo submenu to the debug menu.
641+ *
642+ * @param \WP_Admin_Bar $admin_bar The WordPress admin bar object.
643+ * @return void
644+ */
645+ protected function add_placeholder_demo_submenu_item ( $ admin_bar ) {
646+ $ demo_enabled = isset ( $ _COOKIE ['prpl_placeholder_demo ' ] ) && '1 ' === $ _COOKIE ['prpl_placeholder_demo ' ];
647+ $ title = $ demo_enabled ? '<span style="color: green;">Placeholder Demo Enabled</span> ' : '<span style="color: red;">Placeholder Demo Disabled</span> ' ;
648+ $ href = \add_query_arg ( 'prpl_toggle_placeholder_demo ' , '1 ' , $ this ->current_url );
649+
650+ $ admin_bar ->add_node (
651+ [
652+ 'id ' => 'prpl-placeholder-demo ' ,
653+ 'parent ' => 'prpl-debug ' ,
654+ 'title ' => $ title ,
655+ 'href ' => $ href ,
656+ ]
657+ );
658+ }
659+
660+ /**
661+ * Check and process the toggle placeholder demo action.
662+ *
663+ * Toggles the placeholder demo cookie if the appropriate query parameter is set
664+ * and user has required capabilities.
665+ *
666+ * @return void
667+ */
668+ public function check_toggle_placeholder_demo () {
669+ if (
670+ ! isset ( $ _GET ['prpl_toggle_placeholder_demo ' ] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
671+ $ _GET ['prpl_toggle_placeholder_demo ' ] !== '1 ' || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
672+ ! \current_user_can ( 'manage_options ' )
673+ ) {
674+ return ;
675+ }
676+
677+ // Verify nonce for security.
678+ $ this ->verify_nonce ();
679+
680+ // Toggle the cookie.
681+ $ current_value = isset ( $ _COOKIE ['prpl_placeholder_demo ' ] ) && '1 ' === $ _COOKIE ['prpl_placeholder_demo ' ];
682+ if ( $ current_value ) {
683+ \setcookie ( 'prpl_placeholder_demo ' , '0 ' , \time () - 3600 , \COOKIEPATH , \COOKIE_DOMAIN ); // @phpstan-ignore-line constant.notFound
684+ } else {
685+ \setcookie ( 'prpl_placeholder_demo ' , '1 ' , \time () + ( 30 * DAY_IN_SECONDS ), \COOKIEPATH , \COOKIE_DOMAIN ); // @phpstan-ignore-line constant.notFound
686+ }
687+
688+ // Clear cache since branding data is cached.
689+ if ( \function_exists ( 'progress_planner ' ) ) {
690+ \progress_planner ()->get_utils__cache ()->delete_all ();
691+ }
692+
693+ // Redirect to the same page without the parameter.
694+ \wp_safe_redirect ( \remove_query_arg ( [ 'prpl_toggle_placeholder_demo ' , '_wpnonce ' ] ) );
695+ exit ;
696+ }
697+
634698 /**
635699 * Get color customizer instance.
636700 *
0 commit comments