From 84e6cae49905c7c081696bcb991d8399e2b479c6 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Tue, 12 Sep 2017 23:03:27 -0700 Subject: [PATCH] Reduce duplication --- includes/class-delete-all.php | 10 ++++++---- includes/class-move-to-trash.php | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/includes/class-delete-all.php b/includes/class-delete-all.php index dc540b5..2f1da5e 100644 --- a/includes/class-delete-all.php +++ b/includes/class-delete-all.php @@ -14,14 +14,16 @@ class Delete_All { /** * Class constants */ + const ACTION = 'delete_all'; + const ADMIN_NOTICE_KEY = 'bulk_edit_cron_offload_deleted_all'; /** * Register this bulk process' hooks */ public static function register_hooks() { - add_action( Main::build_hook( 'delete_all' ), array( __CLASS__, 'process' ) ); - add_action( Main::build_cron_hook( 'delete_all' ), array( __CLASS__, 'process_via_cron' ) ); + add_action( Main::build_hook( self::ACTION ), array( __CLASS__, 'process' ) ); + add_action( Main::build_cron_hook( self::ACTION ), array( __CLASS__, 'process_via_cron' ) ); add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) ); add_filter( 'posts_where', array( __CLASS__, 'hide_posts_pending_delete' ), 999, 2 ); @@ -39,7 +41,7 @@ class Delete_All { */ public static function process( $vars ) { // Special keys are used to trigger this request, and we need to remove them on redirect. - $extra_keys = array( 'delete_all', 'delete_all2' ); + $extra_keys = array( self::ACTION, self::ACTION . '2' ); $action_scheduled = self::action_next_scheduled( $vars->post_type ); @@ -224,7 +226,7 @@ class Delete_All { foreach ( $action_instances as $instance => $instance_args ) { $vars = array_shift( $instance_args['args'] ); - if ( 'delete_all' === $vars->action && $post_type === $vars->post_type ) { + if ( self::ACTION === $vars->action && $post_type === $vars->post_type ) { return array( 'timestamp' => $timestamp, 'args' => $vars, diff --git a/includes/class-move-to-trash.php b/includes/class-move-to-trash.php index edcd11e..3350e81 100644 --- a/includes/class-move-to-trash.php +++ b/includes/class-move-to-trash.php @@ -14,14 +14,16 @@ class Move_To_Trash { /** * Class constants */ + const ACTION = 'trash'; + const ADMIN_NOTICE_KEY = 'bulk_edit_cron_offload_move_to_trash'; /** * Register this bulk process' hooks */ public static function register_hooks() { - add_action( Main::build_hook( 'trash' ), array( __CLASS__, 'process' ) ); - add_action( Main::build_cron_hook( 'trash' ), array( __CLASS__, 'process_via_cron' ) ); + add_action( Main::build_hook( self::ACTION ), array( __CLASS__, 'process' ) ); + add_action( Main::build_cron_hook( self::ACTION ), array( __CLASS__, 'process_via_cron' ) ); add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) ); add_filter( 'posts_where', array( __CLASS__, 'hide_posts_pending_move' ), 999, 2 ); @@ -187,7 +189,7 @@ class Move_To_Trash { foreach ( $action_instances as $instance => $instance_args ) { $vars = array_shift( $instance_args['args'] ); - if ( 'trash' === $vars->action && $post_type === $vars->post_type ) { + if ( self::ACTION === $vars->action && $post_type === $vars->post_type ) { if ( $post_status === $vars->post_status || 'all' === $vars->post_status || 'all' === $post_status ) { $ids[] = array( 'timestamp' => $timestamp, -- GitLab