From 70d1433c77b2ec18ec86f26e1c416af74ab5cc3e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 24 Dec 2025 03:00:56 +0000 Subject: [PATCH] Add bulk enable/disable actions for popups Allow admins to enable or disable multiple popups at once from the All Popups list table using the Bulk Actions dropdown. Displays a success notice with the count of popups affected. --- classes/Admin/Popups.php | 121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/classes/Admin/Popups.php b/classes/Admin/Popups.php index 730d38704..c306e7b31 100644 --- a/classes/Admin/Popups.php +++ b/classes/Admin/Popups.php @@ -56,6 +56,11 @@ public static function init() { add_action( 'post_submitbox_misc_actions', [ __CLASS__, 'add_enabled_toggle_editor' ], 10, 1 ); + // Bulk actions for enabling/disabling popups. + add_filter( 'bulk_actions-edit-popup', [ __CLASS__, 'register_bulk_actions' ] ); + add_filter( 'handle_bulk_actions-edit-popup', [ __CLASS__, 'handle_bulk_actions' ], 10, 3 ); + add_action( 'admin_notices', [ __CLASS__, 'bulk_action_admin_notice' ] ); + add_filter( 'mce_buttons_2', [ __CLASS__, 'add_mce_buttons' ], 10, 1 ); add_filter( 'tiny_mce_before_init', [ __CLASS__, 'increase_available_font_sizes' ], 10, 1 ); } @@ -85,6 +90,122 @@ public static function add_enabled_toggle_editor( $post ) { is_valid() ) { + continue; + } + + $popup->update_meta( 'enabled', $enabled ); + ++$count; + } + + $redirect_url = add_query_arg( + [ + 'pum_bulk_action' => $action, + 'pum_bulk_count' => $count, + ], + $redirect_url + ); + + return $redirect_url; + } + + /** + * Displays an admin notice after bulk enable/disable actions. + * + * @since 1.21.4 + */ + public static function bulk_action_admin_notice() { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only, no action taken. + if ( empty( $_REQUEST['pum_bulk_action'] ) || empty( $_REQUEST['pum_bulk_count'] ) ) { + return; + } + + $screen = get_current_screen(); + + if ( ! $screen || 'edit-popup' !== $screen->id ) { + return; + } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only, no action taken. + $action = sanitize_key( wp_unslash( $_REQUEST['pum_bulk_action'] ) ); + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only, no action taken. + $count = intval( $_REQUEST['pum_bulk_count'] ); + + if ( 'pum_enable' === $action ) { + $message = sprintf( + /* translators: %d: Number of popups enabled. */ + _n( + '%d popup enabled.', + '%d popups enabled.', + $count, + 'popup-maker' + ), + $count + ); + } elseif ( 'pum_disable' === $action ) { + $message = sprintf( + /* translators: %d: Number of popups disabled. */ + _n( + '%d popup disabled.', + '%d popups disabled.', + $count, + 'popup-maker' + ), + $count + ); + } else { + return; + } + + printf( + '

%s

', + esc_html( $message ) + ); + } + /** * Adds the Popup ID right under the "Edit Popup" heading *