Skip to content

Commit 82aab1a

Browse files
committed
update debug tool - delete task
1 parent 16e8d01 commit 82aab1a

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

classes/utils/class-debug-tools.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function __construct() {
4646
\add_action( 'init', [ $this, 'check_delete_licenses' ] );
4747
\add_action( 'init', [ $this, 'check_delete_badges' ] );
4848
\add_action( 'init', [ $this, 'check_toggle_migrations' ] );
49+
\add_action( 'init', [ $this, 'check_delete_single_task' ] );
4950

5051
// Add filter to modify the maximum number of suggested tasks to display.
5152
\add_filter( 'progress_planner_suggested_tasks_max_items_per_category', [ $this, 'check_show_all_suggested_tasks' ] );
@@ -251,11 +252,25 @@ protected function add_suggested_tasks_submenu_item( $admin_bar ) {
251252
$title .= ' ' . $until;
252253
}
253254

255+
// Add delete button.
256+
$delete_url = add_query_arg(
257+
[
258+
'prpl_delete_single_task' => $task['task_id'],
259+
'_wpnonce' => wp_create_nonce( 'prpl_debug_tools' ),
260+
],
261+
$this->current_url
262+
);
263+
254264
$admin_bar->add_node(
255265
[
256266
'id' => 'prpl-suggested-' . $key . '-' . $title,
257267
'parent' => 'prpl-suggested-' . $key,
258-
'title' => $title,
268+
'title' => $title . ' <a href="' . esc_url( $delete_url ) . '" style="color: #dc3232; display: inline-block; margin-left: 5px; text-decoration: none;">×</a>',
269+
// 'href' => $delete_url,
270+
'meta' => [
271+
'title' => 'Delete this task',
272+
'html' => '',
273+
],
259274
]
260275
);
261276
}
@@ -615,4 +630,33 @@ protected function verify_nonce() {
615630
wp_die( esc_html__( 'Security check failed', 'progress-planner' ) );
616631
}
617632
}
633+
634+
/**
635+
* Check and process the delete single task action.
636+
*
637+
* Deletes a single task if the appropriate query parameter is set
638+
* and user has required capabilities.
639+
*
640+
* @return void
641+
*/
642+
public function check_delete_single_task() {
643+
if (
644+
! isset( $_GET['prpl_delete_single_task'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
645+
! current_user_can( 'manage_options' )
646+
) {
647+
return;
648+
}
649+
650+
// Verify nonce for security.
651+
$this->verify_nonce();
652+
653+
$task_id = sanitize_text_field( wp_unslash( $_GET['prpl_delete_single_task'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
654+
655+
// Delete the task.
656+
\progress_planner()->get_suggested_tasks()->delete_task( $task_id );
657+
658+
// Redirect to the same page without the parameter.
659+
wp_safe_redirect( remove_query_arg( [ 'prpl_delete_single_task', '_wpnonce' ] ) );
660+
exit;
661+
}
618662
}

0 commit comments

Comments
 (0)