modal_id = sanitize_key( $modal_id ); $this->admin_hooks = is_array( $admin_hooks ) ? $admin_hooks : array( $admin_hooks ); } public function init() { if ( $this->initialized ) { return; } add_action( 'admin_enqueue_scripts', array( $this, 'maybe_enqueue_assets' ) ); add_action( $this->get_render_hook(), array( $this, 'maybe_render_modal' ), $this->get_render_priority(), $this->get_render_args() ); $this->initialized = true; } protected function get_render_hook() { return 'admin_footer'; } protected function get_render_priority() { return 20; } protected function get_render_args() { return 0; } protected function is_valid_admin_page( $hook ) { if ( empty( $this->admin_hooks ) ) { return true; } return in_array( $hook, $this->admin_hooks, true ); } public function maybe_enqueue_assets( $hook ) { if ( ! $this->is_valid_admin_page( $hook ) ) { return; } $this->enqueue_assets( $hook ); } public function maybe_render_modal() { $screen = get_current_screen(); if ( ! $screen ) { return; } $current_hook = $screen->id; if ( ! empty( $this->admin_hooks ) && ! in_array( $current_hook, $this->admin_hooks, true ) ) { return; } $this->render_modal(); } protected function enqueue_assets( $hook ) { } protected function render_modal() { $title = $this->get_title(); $body = $this->get_body(); $footer = $this->get_footer(); $extra_class = $this->get_extra_class(); $description = $this->get_description(); ?> modal_id; } protected function get_strings() { return array( 'closeLabel' => __( 'Close dialog', 'chimpmatic-lite' ), ); } protected function get_js_data() { return array( 'modalId' => $this->modal_id, 'strings' => $this->get_strings(), ); } } }