From 3c4fc0d9e8cfa34c2ec56b328537cffc2ba8d9e2 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Fri, 15 Sep 2017 17:44:52 -0700 Subject: [PATCH] Trait to share stripping of initial redirect args --- bulk-actions-cron-offload.php | 1 + includes/class-main.php | 6 ++++++ includes/trait-bulk-actions.php | 17 +++++------------ includes/trait-remove-one-time-args.php | 25 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 includes/trait-remove-one-time-args.php diff --git a/bulk-actions-cron-offload.php b/bulk-actions-cron-offload.php index 3431ffc..1565e26 100644 --- a/bulk-actions-cron-offload.php +++ b/bulk-actions-cron-offload.php @@ -15,6 +15,7 @@ namespace Automattic\WP\Bulk_Actions_Cron_Offload; // Plugin dependencies. +require __DIR__ . '/includes/trait-remove-one-time-args.php'; require __DIR__ . '/includes/trait-bulk-actions.php'; require __DIR__ . '/includes/utils.php'; diff --git a/includes/class-main.php b/includes/class-main.php index 1eb93b1..8a24a43 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -11,6 +11,11 @@ namespace Automattic\WP\Bulk_Actions_Cron_Offload; * Class Main */ class Main { + /** + * Strip notice arguments after the initial redirect + */ + use Remove_One_Time_Args; + /** * Prefix for bulk-process hook invoked by request-specific classes */ @@ -36,6 +41,7 @@ class Main { add_action( 'load-edit.php', array( __CLASS__, 'intercept' ) ); add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) ); + add_filter( 'removable_query_args', array( __CLASS__, 'remove_notice_arg' ) ); } /** diff --git a/includes/trait-bulk-actions.php b/includes/trait-bulk-actions.php index a504c2b..a5d99c6 100644 --- a/includes/trait-bulk-actions.php +++ b/includes/trait-bulk-actions.php @@ -11,6 +11,11 @@ namespace Automattic\WP\Bulk_Actions_Cron_Offload; * Trait Bulk_Actions */ trait Bulk_Actions { + /** + * Strip notice arguments after the initial redirect + */ + use Remove_One_Time_Args; + /** * Register this bulk process' hooks */ @@ -174,16 +179,4 @@ trait Bulk_Actions { return $where; } - - /** - * Strip the custom notice key, otherwise it turns up in pagination and other unwanted places. - * - * @param array $args Array of one-time query args. - * @return array - */ - public static function remove_notice_arg( $args ) { - $args[] = self::ADMIN_NOTICE_KEY; - - return $args; - } } diff --git a/includes/trait-remove-one-time-args.php b/includes/trait-remove-one-time-args.php new file mode 100644 index 0000000..547dc3f --- /dev/null +++ b/includes/trait-remove-one-time-args.php @@ -0,0 +1,25 @@ +<?php +/** + * Strip one-time arguments after redirects + * + * @package Bulk_Actions_Cron_Offload + */ + +namespace Automattic\WP\Bulk_Actions_Cron_Offload; + +/** + * Trait Remove_One_Time_Args + */ +trait Remove_One_Time_Args { + /** + * Strip the custom notice key, otherwise it turns up in pagination and other unwanted places. + * + * @param array $args Array of one-time query args. + * @return array + */ + public static function remove_notice_arg( $args ) { + $args[] = self::ADMIN_NOTICE_KEY; + + return $args; + } +} -- GitLab