Skip to content

Commit 3b10b06

Browse files
committed
add 'recommendtions ui' filter to debug tools & remove from playground
1 parent 707f951 commit 3b10b06

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

classes/utils/class-debug-tools.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ 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+
\add_action( 'init', [ $this, 'check_toggle_recommendations_ui' ] );
5051
if ( \defined( '\IS_PLAYGROUND_PREVIEW' ) && \constant( '\IS_PLAYGROUND_PREVIEW' ) === true ) {
5152
\add_action( 'init', [ $this, 'check_toggle_placeholder_demo' ] );
5253
}
5354

5455
// Initialize color customizer.
5556
$this->get_color_customizer();
57+
58+
\add_filter( 'progress_planner_tasks_show_ui', [ $this, 'filter_tasks_show_ui' ] );
5659
}
5760

5861
/**
@@ -86,6 +89,8 @@ public function add_toolbar_items( $admin_bar ) {
8689

8790
$this->add_toggle_migrations_submenu_item( $admin_bar );
8891

92+
$this->add_toggle_recommendations_ui_submenu_item( $admin_bar );
93+
8994
// Add color customizer item.
9095
$admin_bar->add_node(
9196
[
@@ -319,6 +324,27 @@ protected function add_toggle_migrations_submenu_item( $admin_bar ) {
319324
);
320325
}
321326

327+
/**
328+
* Add Toggle Recommendations UI submenu to the debug menu.
329+
*
330+
* @param \WP_Admin_Bar $admin_bar The WordPress admin bar object.
331+
* @return void
332+
*/
333+
protected function add_toggle_recommendations_ui_submenu_item( $admin_bar ) {
334+
$debug_enabled = \get_option( 'prpl_debug_recommendations_ui', false );
335+
$title = $debug_enabled ? '<span style="color: green;">Recommendations UI Enabled</span>' : '<span style="color: red;">Recommendations UI Disabled</span>';
336+
$href = \add_query_arg( 'prpl_toggle_recommendations_ui', '1', $this->current_url );
337+
338+
$admin_bar->add_node(
339+
[
340+
'id' => 'prpl-toggle-recommendations-ui',
341+
'parent' => 'prpl-debug',
342+
'title' => $title,
343+
'href' => $href,
344+
]
345+
);
346+
}
347+
322348
/**
323349
* Check and process the toggle migrations action.
324350
*
@@ -352,6 +378,39 @@ public function check_toggle_migrations() {
352378
exit;
353379
}
354380

381+
/**
382+
* Check and process the toggle recommendations UI action.
383+
*
384+
* Toggles the debug option if the appropriate query parameter is set
385+
* and user has required capabilities.
386+
*
387+
* @return void
388+
*/
389+
public function check_toggle_recommendations_ui() {
390+
if (
391+
! isset( $_GET['prpl_toggle_recommendations_ui'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
392+
$_GET['prpl_toggle_recommendations_ui'] !== '1' || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
393+
! \current_user_can( 'manage_options' )
394+
) {
395+
return;
396+
}
397+
398+
// Verify nonce for security.
399+
$this->verify_nonce();
400+
401+
// Toggle the debug option.
402+
$current_value = \get_option( 'prpl_debug_recommendations_ui', false );
403+
if ( $current_value ) {
404+
\delete_option( 'prpl_debug_recommendations_ui' );
405+
} else {
406+
\update_option( 'prpl_debug_recommendations_ui', true );
407+
}
408+
409+
// Redirect to the same page without the parameter.
410+
\wp_safe_redirect( \remove_query_arg( [ 'prpl_toggle_recommendations_ui', '_wpnonce' ] ) );
411+
exit;
412+
}
413+
355414
/**
356415
* Check and process the delete tasks action.
357416
*
@@ -671,4 +730,17 @@ public function get_color_customizer() {
671730
}
672731
return $color_customizer;
673732
}
733+
734+
/**
735+
* Filter the tasks show UI.
736+
*
737+
* @param bool $show_ui The show UI.
738+
* @return bool
739+
*/
740+
public function filter_tasks_show_ui( $show_ui ) {
741+
if ( \get_option( 'prpl_debug_recommendations_ui', false ) ) {
742+
return true;
743+
}
744+
return $show_ui;
745+
}
674746
}

classes/utils/class-playground.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Playground {
1818
public function __construct() {
1919
\add_action( 'init', [ $this, 'register_hooks' ], 9 );
2020
\add_action( 'plugins_loaded', [ $this, 'enable_debug_tools' ], 1 );
21-
\add_filter( 'progress_planner_tasks_show_ui', '__return_true' );
2221
\add_action( 'admin_footer', [ $this, 'inject_playground_js_patch' ] );
2322
\add_action( 'init', [ $this, 'disable_upgrade_tasks_popover' ], 101 );
2423
}

0 commit comments

Comments
 (0)