sudar /
bulk-delete
| 1 | <?php |
||
| 2 | |||
| 3 | namespace BulkWP\BulkDelete\Core\Base; |
||
| 4 | |||
| 5 | 1 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
| 6 | |||
| 7 | /** |
||
| 8 | * Base class for all Bulk Delete pages that will have metaboxes. |
||
| 9 | * |
||
| 10 | * @since 6.0.0 |
||
| 11 | */ |
||
| 12 | abstract class MetaboxPage extends BasePage { |
||
| 13 | /** |
||
| 14 | * Item Type. Possible values 'posts', 'pages', 'users' etc. |
||
| 15 | * |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $item_type; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Metaboxes registered to this page. |
||
| 22 | * |
||
| 23 | * @var \BulkWP\BulkDelete\Core\Base\BaseMetabox[] |
||
| 24 | */ |
||
| 25 | protected $metaboxes = array(); |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Register the metaboxes after the page is registered. |
||
| 29 | */ |
||
| 30 | public function register() { |
||
| 31 | parent::register(); |
||
| 32 | |||
| 33 | if ( $this->has_metaboxes() ) { |
||
| 34 | $this->register_metaboxes(); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Add a metabox to page. |
||
| 40 | * |
||
| 41 | * @param \BulkWP\BulkDelete\Core\Base\BaseMetabox $metabox Metabox to add. |
||
| 42 | */ |
||
| 43 | public function add_metabox( $metabox ) { |
||
| 44 | if ( in_array( $metabox, $this->metaboxes, true ) ) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | $this->metaboxes[] = $metabox; |
||
| 49 | } |
||
| 50 | |||
| 51 | protected function register_hooks() { |
||
| 52 | parent::register_hooks(); |
||
| 53 | |||
| 54 | add_action( 'admin_print_scripts-' . $this->hook_suffix, array( $this, 'enqueue_assets' ) ); |
||
| 55 | add_action( "load-{$this->hook_suffix}", array( $this, 'on_load_page' ) ); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Enqueue Scripts and Styles. |
||
| 60 | */ |
||
| 61 | public function enqueue_assets() { |
||
| 62 | global $wp_scripts; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Runs just before enqueuing scripts and styles in all Bulk WP admin pages. |
||
| 66 | * |
||
| 67 | * This action is primarily for registering or deregistering additional scripts or styles. |
||
| 68 | * |
||
| 69 | * @since 5.5.1 |
||
| 70 | */ |
||
| 71 | do_action( 'bd_before_admin_enqueue_scripts' ); |
||
| 72 | |||
| 73 | wp_enqueue_script( 'jquery-ui-timepicker', $this->get_plugin_dir_url() . 'assets/js/jquery-ui-timepicker-addon.min.js', array( |
||
| 74 | 'jquery-ui-slider', |
||
| 75 | 'jquery-ui-datepicker', |
||
| 76 | ), '1.5.4', true ); |
||
| 77 | wp_enqueue_style( 'jquery-ui-timepicker', $this->get_plugin_dir_url() . 'assets/css/jquery-ui-timepicker-addon.min.css', array(), '1.5.4' ); |
||
| 78 | |||
| 79 | wp_enqueue_script( 'select2', $this->get_plugin_dir_url() . 'assets/js/select2.min.js', array( 'jquery' ), '4.0.0', true ); |
||
| 80 | wp_enqueue_style( 'select2', $this->get_plugin_dir_url() . 'assets/css/select2.min.css', array(), '4.0.0' ); |
||
| 81 | |||
| 82 | $postfix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min'; |
||
| 83 | wp_enqueue_script( 'bulk-delete', $this->get_plugin_dir_url() . 'assets/js/bulk-delete' . $postfix . '.js', array( |
||
| 84 | 'jquery-ui-timepicker', |
||
| 85 | 'jquery-ui-tooltip', |
||
| 86 | 'postbox', |
||
| 87 | ), \Bulk_Delete::VERSION, true ); |
||
| 88 | wp_enqueue_style( 'bulk-delete', $this->get_plugin_dir_url() . 'assets/css/bulk-delete' . $postfix . '.css', array( 'select2' ), \Bulk_Delete::VERSION ); |
||
| 89 | |||
| 90 | $ui = $wp_scripts->query( 'jquery-ui-core' ); |
||
| 91 | $url = "//ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.css"; |
||
| 92 | wp_enqueue_style( 'jquery-ui-smoothness', $url, false, $ui->ver ); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 93 | |||
| 94 | /** |
||
| 95 | * Filter JavaScript array. |
||
| 96 | * |
||
| 97 | * This filter can be used to extend the array that is passed to JavaScript |
||
| 98 | * |
||
| 99 | * @since 5.4 |
||
| 100 | */ |
||
| 101 | $translation_array = apply_filters( 'bd_javascript_array', array( |
||
| 102 | 'msg' => array(), |
||
| 103 | 'validators' => array(), |
||
| 104 | 'dt_iterators' => array(), |
||
| 105 | 'pre_action_msg' => array(), |
||
| 106 | 'error_msg' => array(), |
||
| 107 | 'pro_iterators' => array(), |
||
| 108 | ) ); |
||
| 109 | wp_localize_script( 'bulk-delete', 'BulkWP', $translation_array ); // TODO: Change JavaScript variable to BulkWP.BulkDelete. |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Runs just after enqueuing scripts and styles in all Bulk WP admin pages. |
||
| 113 | * |
||
| 114 | * This action is primarily for registering additional scripts or styles. |
||
| 115 | * |
||
| 116 | * @since 5.5.1 |
||
| 117 | */ |
||
| 118 | do_action( 'bd_after_admin_enqueue_scripts' ); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Trigger the add_meta_boxes hooks to allow meta boxes to be added when the page is loaded. |
||
| 123 | */ |
||
| 124 | public function on_load_page() { |
||
| 125 | do_action( 'add_meta_boxes_' . $this->hook_suffix, null ); |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Add additional nonce fields that are related to metaboxes. |
||
| 130 | */ |
||
| 131 | protected function render_nonce_fields() { |
||
| 132 | parent::render_nonce_fields(); |
||
| 133 | |||
| 134 | // Used to save closed meta boxes and their order. |
||
| 135 | wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
||
| 136 | wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Render meta boxes in body. |
||
| 141 | */ |
||
| 142 | protected function render_body() { |
||
| 143 | do_meta_boxes( '', 'advanced', null ); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Render footer. |
||
| 148 | */ |
||
| 149 | protected function render_footer() { |
||
| 150 | parent::render_footer(); |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Runs just before displaying the footer text in the admin page. |
||
| 154 | * |
||
| 155 | * This action is primarily for adding extra content in the footer of admin page. |
||
| 156 | * |
||
| 157 | * @since 5.5.4 |
||
| 158 | */ |
||
| 159 | do_action( "bd_admin_footer_for_{$this->item_type}" ); |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Does this page has metaboxes? |
||
| 164 | * |
||
| 165 | * @return bool True if page has metaboxes, False otherwise. |
||
| 166 | */ |
||
| 167 | protected function has_metaboxes() { |
||
| 168 | return ! empty( $this->metaboxes ); |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Load all the registered metaboxes. |
||
| 173 | */ |
||
| 174 | protected function register_metaboxes() { |
||
| 175 | foreach ( $this->metaboxes as $metabox ) { |
||
| 176 | $metabox->register( $this->hook_suffix, $this->page_slug ); |
||
| 177 | $this->actions[] = $metabox->get_action(); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 |