Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
class-wp-revisions-control-bulk-actions.php 5.69 KiB
<?php
/**
 * Bulk actions.
 *
 * @package WP_Revisions_Control
 */

use WP_Revisions_Control\Singleton;

/**
 * Class WP_Revisions_Control_Bulk_Actions.
 */
class WP_Revisions_Control_Bulk_Actions {
	use Singleton;

	/**
	 * Supported post types.
	 *
	 * @var array
	 */
	protected $post_types;

	/**
	 * Base for bulk action names.
	 *
	 * @var string
	 */
	protected $action_base = 'wp_rev_ctl_bulk_';

	/**
	 * Custom bulk actions.
	 *
	 * @var array
	 */
	protected $actions;

	/**
	 * One-time actions.
	 */
	public function setup() {
		$this->post_types = WP_Revisions_Control::get_instance()->get_post_types();

		if ( empty( $this->post_types ) || ! is_array( $this->post_types ) ) {
			return;
		}

		$this->register_actions();

		add_action( 'load-edit.php', array( $this, 'register_admin_hooks' ) );
		add_filter( 'removable_query_args', array( $this, 'remove_message_query_args' ) );
	}

	/**
	 * Register custom actions.
	 */
	protected function register_actions() {
		$actions = array();

		$actions[ $this->action_base . 'purge_excess' ] = __(
			'Purge excess revisions',
			'wp_revisions_control'
		);

		$actions[ $this->action_base . 'purge_all' ] = __(
			'Purge ALL revisions',
			'wp_revisions_control'
		);

		$this->actions = $actions;
	}