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( 'ig_es_' . IG_CAMPAIGN_TYPE_POST_NOTIFICATION . '_content_settings', array( $this, 'show_post_notification_content_settings' ) ); add_action( 'ig_es_' . IG_CAMPAIGN_TYPE_POST_DIGEST . '_content_settings', array( $this, 'show_post_notification_content_settings' ) ); add_action( 'ig_es_show_' . IG_CAMPAIGN_TYPE_POST_NOTIFICATION . '_campaign_summary_action_buttons', array( $this, 'show_summary_actions_buttons' ) ); add_action( 'ig_es_show_' . IG_CAMPAIGN_TYPE_POST_DIGEST . '_campaign_summary_action_buttons', array( $this, 'show_summary_actions_buttons' ) ); add_action( 'ig_es_' . IG_CAMPAIGN_TYPE_POST_NOTIFICATION . '_default_subject', array( $this, 'get_post_notification_default_subject' ) ); add_action( 'ig_es_' . IG_CAMPAIGN_TYPE_POST_NOTIFICATION . '_default_content', array( $this, 'get_post_notification_default_content' ) ); } public function es_notifications_callback() { $action = ig_es_get_request_data( 'action' ); ?>
edit_list( absint( $list ) ); } else { $this->es_newnotification_callback(); } ?>
prepare_post_notification_form(); return; } if ( empty( $cat ) ) { $message = __( 'Please select categories.', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); $this->prepare_post_notification_form(); return; } $type = 'post_notification'; $title = get_the_title( $template_id ); $data = array( 'categories' => ES_Common::convert_categories_array_to_string( $cat ), 'list_ids' => $list_id, 'base_template_id' => $template_id, 'status' => 1, 'type' => $type, 'name' => $title, 'slug' => sanitize_title( $title ), ); $data = apply_filters( 'ig_es_post_notification_data', $data ); if ( empty( $data['base_template_id'] ) ) { $message = __( 'Please select template.', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); $this->prepare_post_notification_form(); return; } $this->save_list( $data ); $type = ucwords( str_replace( '_', ' ', $data['type'] ) ); /* translators: %s: Campaign Type */ $message = sprintf( __( '%s added successfully!', 'email-subscribers' ), $type ); ES_Common::show_message( $message, 'success' ); } else { $message = __( 'Sorry, you are not allowed to add post notification.', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); } } $this->prepare_post_notification_form(); } public function custom_admin_notice() { $es_note_cate = ig_es_get_request_data( 'es_note_cate' ); if ( $es_note_cate ) { echo '

Notification Added Successfully!

'; } } public function update_list( $id ) { global $wpdb; $cat = ig_es_get_request_data( 'es_note_cat' ); $data = array( 'categories' => ES_Common::convert_categories_array_to_string( $cat ), 'list_ids' => ig_es_get_request_data( 'list_id' ), 'base_template_id' => ig_es_get_request_data( 'template_id' ), 'status' => 'active', ); $wpdb->update( IG_CAMPAIGNS_TABLE, $data, array( 'id' => $id ) ); } public function save_list( $data, $id = null ) { return ES()->campaigns_db->save_campaign( $data, $id ); } /** * Retrieve lists data from the database * * @param int $per_page * @param int $page_number * * @return mixed */ public static function get_lists( $per_page = 5, $page_number = 1 ) { global $wpdb, $wpbd; $order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) ); $order = ig_es_get_request_data( 'order' ); $search = ig_es_get_request_data( 's' ); $add_where_clause = false; $sql = 'SELECT * FROM ' . IG_CAMPAIGNS_TABLE; $args = array(); $query = array(); if ( ! empty( $search ) ) { $add_where_clause = true; $query[] = ' name LIKE %s '; $args[] = '%' . $wpdb->esc_like( $search ) . '%'; } if ( $add_where_clause ) { $sql .= ' WHERE '; if ( count( $query ) > 0 ) { $sql .= implode( ' AND ', $query ); $sql = $wpbd->prepare( $sql, $args ); } } // Prepare Order by clause $order_by_clause = ''; if ( ! empty( $order_by ) ) { $order_by_clause = ' ORDER BY ' . esc_sql( $order_by ); $order_by_clause .= ! empty( $order ) ? ' ' . esc_sql( $order ) : ' ASC'; } $sql .= $order_by_clause; $sql .= " LIMIT $per_page"; $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page; $result = $wpbd->get_results( $sql, 'ARRAY_A' ); return $result; } public function edit_list( $id ) { global $wpdb; $notification_query = $wpdb->prepare( ' id = %d LIMIT 0, 1', $id ); $notifications = ES()->campaigns_db->get_by_conditions( $notification_query ); $data = array(); $submitted = ig_es_get_request_data( 'submitted' ); if ( 'submitted' === $submitted ) { // Get nonce field value. $nonce = ig_es_get_request_data( '_wpnonce' ); // Verify nonce. if ( wp_verify_nonce( $nonce, 'es_post_notification' ) ) { $categories = ig_es_get_request_data( 'es_note_cat', array() ); // all categories selected $parent_category_option = ig_es_get_request_data( 'es_note_cat_parent' ); if ( in_array( $parent_category_option, array( '{a}All{a}', '{a}None{a}' ), true ) ) { array_unshift( $categories, $parent_category_option ); } $data = array( 'categories' => ES_Common::convert_categories_array_to_string( $categories ), 'list_ids' => ig_es_get_request_data( 'list_id' ), 'base_template_id' => ig_es_get_request_data( 'template_id' ), 'status' => ig_es_get_request_data( 'status' ), ); $title = ''; if ( ! empty( $data['base_template_id'] ) ) { $title = get_the_title( $data['base_template_id'] ); } $data['name'] = $title; $data = apply_filters( 'ig_es_post_notification_data', $data ); $data['type'] = ! empty( $data['type'] ) ? $data['type'] : 'post_notification'; // check tempalte id if ( empty( $data['base_template_id'] ) ) { $message = __( 'Please select template.', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); $this->prepare_post_notification_form( $id, $data ); return; } // check categories if ( empty( $categories ) ) { $message = __( 'Please select Categories.', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); $this->prepare_post_notification_form( $id, $data ); return; } $this->save_list( $data, $id ); $data['categories'] = ES_Common::convert_categories_string_to_array( $data['categories'], true ); $type = ucwords( str_replace( '_', ' ', $data['type'] ) ); /* translators: %s: Campaign type */ $message = sprintf( __( '%s updated successfully!', 'email-subscribers' ), $type ); ES_Common::show_message( $message, 'success' ); } else { $message = __( 'Sorry, you are not allowed to update post notification.', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); } } else { $notification = array_shift( $notifications ); $id = $notification['id']; $categories_str = ! empty( $notification['categories'] ) ? $notification['categories'] : ''; $categories = ES_Common::convert_categories_string_to_array( $categories_str, true ); $data = array( 'categories' => $categories, 'list_ids' => $notification['list_ids'], 'base_template_id' => $notification['base_template_id'], 'status' => $notification['status'], ); } $this->prepare_post_notification_form( $id, $data ); } public static function prepare_post_notification_form( $id = '', $data = array() ) { $is_new = empty( $id ) ? 1 : 0; $action = 'new'; $heading = __( ' New Post Notification', 'email-subscribers' ); if ( ! $is_new ) { $action = 'edit'; $heading = __( ' Edit Post Notification', 'email-subscribers' ); } $cat = isset( $data['categories'] ) ? $data['categories'] : ''; $list_id = isset( $data['list_ids'] ) ? $data['list_ids'] : ''; $template_id = isset( $data['base_template_id'] ) ? $data['base_template_id'] : ''; $status = isset( $data['status'] ) ? $data['status'] : 0; $nonce = wp_create_nonce( 'es_post_notification' ); $select_list_attr = ES()->is_pro() ? 'multiple="multiple"' : ''; $select_list_name = ES()->is_pro() ? 'list_id[]' : 'list_id'; $select_list_class = ES()->is_pro() ? 'ig-es-form-multiselect' : 'form-select'; $allowedtags = ig_es_allowed_html_tags_in_esc(); ?>


'Delete', ); return $actions; } public function search_box( $text, $input_id ) { ?>

show_post_notification_fields( $campaign_data ); } } /** * Show post notification related fields * * Post categories etc. * * @since 5.1.0 * * @param array $campaign_data */ public function show_post_notification_fields( $campaign_data ) { // We are storing both post categories and CPTs in one column 'categories'. $categories = isset( $campaign_data['categories'] ) ? $campaign_data['categories'] : ''; $campaign_id = ! empty( $campaign_data['id'] ) ? $campaign_data['id'] : 0; $selected_post_types = array(); $using_new_category_format = ES_Campaign_Controller::is_using_new_category_format( $campaign_id ); if ( $using_new_category_format ) { $cat_cpts = array(); $categories_str = trim( trim( $categories ), '##' ); $categories_array = explode( '##', $categories_str ); if ( ! empty( $categories_array ) ) { foreach ( $categories_array as $category ) { $cpt_categories = explode( '|', $category ); foreach ( $cpt_categories as $cpt_category ) { if ( false !== strpos( $cpt_category, ':' ) ) { list( $post_type, $post_type_categories ) = explode( ':', $cpt_category ); if ( 'post' === $post_type ) { $cat_cpts = explode( ',', $post_type_categories ); } $selected_post_types[] = $post_type; } } } } } else { $cat_cpts = ES_Common::convert_categories_string_to_array( $categories, true ); } $allowedtags = ig_es_allowed_html_tags_in_esc(); $campaign_type = ! empty( $campaign_data['type'] ) ? $campaign_data['type'] : ''; $editor_type = ! empty( $campaign_data['meta']['editor_type'] ) ? $campaign_data['meta']['editor_type'] : IG_ES_DRAG_AND_DROP_EDITOR; ?>
labels->singular_name; ?>
class="es_custom_post_type form-checkbox" >
get_dnd_editor_default_content(); $classic_editor_content = wpautop( $this->get_classic_editor_default_content() ); $content_data = array( IG_ES_CLASSIC_EDITOR => $classic_editor_content, IG_ES_DRAG_AND_DROP_EDITOR => $dnd_editor_content ); } return $content_data; } public function get_classic_editor_default_content() { $default_content = __( "Hello {{subscriber.name | fallback='there'}},", 'email-subscribers' ) . "\r\n\r\n"; $default_content .= __( 'We have published a new blog article on our website.', 'email-subscribers' ) . "\r\n"; $default_content .= "{{campaign.posts}}\r\n{{post.title}}\r\n {{post.image}}\r\n\r\n"; $default_content .= "{{post.link}}\r\n{{/campaign.posts}}\r\n\r\n"; $default_content .= __( 'Thanks & Regards', 'email-subscribers' ) . ",\r\n"; $default_content .= __( 'Admin', 'email-subscribers' ) . "\r\n\r\n"; $default_content .= __( 'You received this email because in the past you have provided us your email address : {{subscriber.email}} to receive notifications when new updates are posted.', 'email-subscribers' ); return $default_content; } public function get_dnd_editor_default_content() { $default_content = ' ' . __( "Hello {{subscriber.name | fallback='there'}},", 'email-subscribers' ) . ' ' . __( 'We have published a new post on our site.', 'email-subscribers' ) . '
{{campaign.posts}} {{post.title}} {{post.excerpt}} Read More {{/campaign.posts}}
@2022,' . __( 'Your Brand Name', 'email-subscribers' ) . '. ' . __( 'You received this email because in the past you have provided us your email address : {{subscriber.email}} to receive notifications when new updates are posted.', 'email-subscribers' ) . __( 'If you wish to unsubscribe from our newsletter, click', 'email-subscribers' ) . ' ' . __( 'here', 'email-subscribers' ) . '
'; return $default_content; } } ES_Post_Notifications_Table::get_instance();