plugin_directory = DrawAttention::get_plugin_url() . '/public/'; $this->parent = $parent; add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_meta_box_assets' ) ); add_action( 'admin_footer', array( $this, 'newsletter_modal_dialog' ) ); // add_action( 'admin_footer', array( $this, 'newsletter_modal_dialog' ), 10, 1 ); // disable until we fix DA email issues add_action( 'add_meta_boxes', array( $this, 'add_newsletter_widget' ) ); // Order the meta boxes add_action( 'do_meta_boxes', array( $this, 'set_meta_boxes_position' ) ); } public function enqueue_meta_box_assets() { if ( ! $this->is_da_image_edit_screen() ) { return; } wp_enqueue_style( 'da-custom-meta-box-styles', $this->plugin_directory . 'assets/css/custom-meta-box-styles.css', array(), DrawAttention::VERSION ); wp_enqueue_script( 'da-news-letter-js', $this->plugin_directory . 'assets/js/news-letter.js', array(), DrawAttention::VERSION ); } private function is_da_image_edit_screen() { $current_screen = get_current_screen(); return $current_screen && 'post' === $current_screen->base && 'da_image' === $current_screen->post_type; } public function metabox_newsletter_component() { echo "
Newsletter Image

" . __( 'Stay up to date with the latest from Draw Attention', 'draw-attention' ) . "

" . __( 'Subscribe now! Get 20% Coupon', 'draw-attention' ) . "

" . __( "We'll only send you awesome content. Never spam.", 'draw-attention' ) . '
'; } public function newsletter_modal_dialog() { if ( ! $this->is_da_image_edit_screen() ) { return; } $user_email = wp_get_current_user()->user_email ?? ''; echo " '; } public function add_newsletter_widget() { add_meta_box( 'DrawAttention_Newsletter', __( 'Newsletter', 'draw-attention' ), array( $this, 'metabox_newsletter_component' ), $this->parent->cpt->post_type, 'side', 'low' ); } /** * Modify the order of meta boxes for a specific post type. * * @param string $post_type The post type to modify meta box order for. */ function set_meta_boxes_position( $post_type ) { global $wp_meta_boxes; if ( 'da_image' !== $post_type ) { return; } if ( empty( $wp_meta_boxes['da_image']['side']['low'] ) ) { return; } $custom_meta_boxes = $wp_meta_boxes[ $post_type ]['side']['low']; $order = array( 'da_shortcode', 'DrawAttention_Newsletter', 'da_theme_pack', ); $ordered_meta_boxes = array(); foreach ( $order as $box_id ) { if ( isset( $custom_meta_boxes[ $box_id ] ) ) { $ordered_meta_boxes[ $box_id ] = $custom_meta_boxes[ $box_id ]; unset( $custom_meta_boxes[ $box_id ] ); } } $wp_meta_boxes[ $post_type ]['side']['low'] = array_merge( $ordered_meta_boxes, $custom_meta_boxes ); } }