init(); } public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } public function init() { $this->register_hooks(); } public function register_hooks() { add_action( 'admin_init', array( $this, 'process_submission' ) ); add_action( 'ig_es_before_template_settings', array( $this, 'show_template_setting_fields' ) ); // preview popup //add_action( 'ig_es_template_preview_options_content', array( $this, 'show_campaign_preview_options_content' ) ); add_action( 'wp_ajax_ig_es_draft_campaign', array( $this, 'draft_campaign' ) ); add_action( 'wp_ajax_ig_es_get_template_preview', array( $this, 'get_template_preview' ) ); //add_action( 'media_buttons', array( $this, 'add_tag_button' ) ); } public function setup() { $template_id = $this->get_template_id_from_url(); if ( ! empty( $template_id ) ) { $template = get_post( $template_id, ARRAY_A ); if ( $template ) { $template_meta = get_post_custom( $template_id ); if ( ! empty( $template_meta ) ) { foreach ( $template_meta as $meta_key => $meta_value ) { $template_meta[ $meta_key ] = $meta_value[0]; } } if ( empty( $template_meta['es_editor_type'] ) ) { $template_meta['es_editor_type'] = IG_ES_CLASSIC_EDITOR; } $template['meta'] = $template_meta; $this->template_data = $template; } } else { $this->template_data['meta']['es_editor_type'] = $this->get_editor_type_from_url(); } } public function get_template_id_from_url() { $template_id = ig_es_get_request_data( 'id' ); return $template_id; } public function get_editor_type_from_url() { $editor_type = ig_es_get_request_data( 'editor-type' ); if ( empty( $editor_type ) ) { $editor_type = IG_ES_DRAG_AND_DROP_EDITOR; } return $editor_type; } public static function set_screen( $status, $option, $value ) { return $value; } public function render() { $data = ig_es_get_request_data( 'data', array(), false ); $message_data = array(); $template_action = ig_es_get_request_data( 'ig_es_template_action' ); if ( ! empty( $template_action ) ) { if ( empty( $data['subject'] ) ) { $message = __( 'Please add a subject.', 'email-subscribers' ); $message_data = array( 'message' => $message, 'type' => 'error', ); } } $action = ig_es_get_request_data( 'action' ); if ( 'added' === $action ) { $message = __( 'Template added successfully.', 'email-subscribers' ); $message_data = array( 'message' => $message, 'type' => 'success', ); } elseif ( 'updated' === $action ) { $message = __( 'Template updated successfully.', 'email-subscribers' ); $message_data = array( 'message' => $message, 'type' => 'success', ); } $this->show_form( $message_data ); } /** * Add an Tag button to WP Editor * * @param string $editor_id Editor id * * @since 5.4.10 */ public function add_tag_button( $editor_id ) { if ( ! ES()->is_es_admin_screen() ) { return; } $template_type = isset( $this->campaign_data['type'] ) ? $this->campaign_data['type'] : ''; ?>
get_post_notification_tags(); $template_tags = array( 'post_notification' => $post_notification_tags, ); return apply_filters( 'ig_es_campaign_tags', $template_tags ); } public function get_post_notification_tags() { $post_notification_tags = array( '{{post.date}}', '{{post.title}}', '{{post.image}}', '{{post.excerpt}}', '{{post.description}}', '{{post.author}}', '{{post.link}}', '{{post.link_with_title}}', '{{post.link_only}}', '{{post.full}}', '{{post.cats}}', '{{post.more_tag}}', '{{post.image_url}}' ); return apply_filters( 'ig_es_post_notification_tags', $post_notification_tags ); } public function get_subscriber_tags() { $subscriber_tags = array( '{{subscriber.name}}', '{{subscriber.first_name}}', '{{subscriber.last_name}}', '{{subscriber.email}}', ); return apply_filters( 'ig_es_subscriber_tags', $subscriber_tags ); } public function get_site_tags() { $site_tags = array( '{{site.total_contacts}}', '{{site.url}}', '{{site.name}}', ); return apply_filters( 'ig_es_site_tags', $site_tags ); } public function render_merge_tags( $merge_tags = array() ) { if ( empty( $merge_tags ) ) { return; } foreach ( $merge_tags as $tag_key => $tag ) { ?>