* @since 3.0.0 */ namespace Beyondwords\Wordpress\Component\Posts\BulkEdit; use Beyondwords\Wordpress\Core\Core; use Beyondwords\Wordpress\Core\CoreUtils; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; use Beyondwords\Wordpress\Plugin; /** * BulkEdit * * @since 3.0.0 */ class BulkEdit { /** * Init. * * @since 4.0.0 * @since 6.0.0 Make static. */ public static function init() { add_action('bulk_edit_custom_box', [self::class, 'bulkEditCustomBox'], 10, 2); add_action('wp_ajax_save_bulk_edit_beyondwords', [self::class, 'saveBulkEdit']); add_action('wp_loaded', function (): void { $postTypes = SettingsUtils::getCompatiblePostTypes(); if (is_array($postTypes)) { foreach ($postTypes as $postType) { add_filter("bulk_actions-edit-{$postType}", [self::class, 'bulkActionsEdit'], 10, 1); add_filter("handle_bulk_actions-edit-{$postType}", [self::class, 'handleBulkDeleteAction'], 10, 3); // phpcs:ignore Generic.Files.LineLength.TooLong add_filter("handle_bulk_actions-edit-{$postType}", [self::class, 'handleBulkGenerateAction'], 10, 3); // phpcs:ignore Generic.Files.LineLength.TooLong } } }); } /** * Adds the meta box container. * * @since 6.0.0 Make static. */ public static function bulkEditCustomBox($columnName, $postType) { if ($columnName !== 'beyondwords') { return; } $postTypes = SettingsUtils::getCompatiblePostTypes(); if (! in_array($postType, $postTypes)) { return; } wp_nonce_field('beyondwords_bulk_edit_nonce', 'beyondwords_bulk_edit'); ?>
getMessage(), $redirect); } // Add $generated & $failed query args into redirect $redirect = add_query_arg('beyondwords_bulk_generated', $generated, $redirect); $redirect = add_query_arg('beyondwords_bulk_failed', $failed, $redirect); // Add nonce to redirect url $nonce = wp_create_nonce('beyondwords_bulk_edit_result'); return add_query_arg('beyondwords_bulk_edit_result_nonce', $nonce, $redirect); } /** * Handle the "Delete audio" bulk action. * * @since 6.0.0 Make static. */ public static function handleBulkDeleteAction($redirect, $doaction, $objectIds) { if ($doaction !== 'beyondwords_delete_audio') { return $redirect; } // Remove query args $args = [ 'beyondwords_bulk_generated', 'beyondwords_bulk_deleted', 'beyondwords_bulk_failed', 'beyondwords_bulk_error', ]; $redirect = remove_query_arg($args, $redirect); // Order batch by Post ID asc sort($objectIds); $deleted = 0; // Handle "Delete audio" bulk action try { $result = self::deleteAudioForPosts($objectIds); $deleted = count($result); // Add $deleted query arg into redirect $redirect = add_query_arg('beyondwords_bulk_deleted', $deleted, $redirect); } catch (\Exception $e) { $redirect = add_query_arg('beyondwords_bulk_error', $e->getMessage(), $redirect); } // Add $nonce query arg into redirect $nonce = wp_create_nonce('beyondwords_bulk_edit_result'); return add_query_arg('beyondwords_bulk_edit_result_nonce', $nonce, $redirect); } }