'', 'desc' => '', 'group' => '' ), $atts, 'email-subscribers' ); $data['name_visible'] = $atts['namefield']; $data['list_visible'] = 'no'; $data['lists'] = array(); $data['form_id'] = 0; $data['list'] = $atts['group']; $data['desc'] = $atts['desc']; self::render_form( $data ); return ob_get_clean(); } /** * Render Subscription form using ES 4.0+ Shortcode * * @param $atts * * @return false|string */ public static function render_es_form( $atts ) { ob_start(); $atts = shortcode_atts( array( 'id' => '', 'show-in-popup' => '' ), $atts, 'email-subscribers-form' ); $id = $atts['id']; if ( ! empty( $id ) ) { $form = ES()->forms_db->get_form_by_id( $id ); if ( $form ) { $form_data = ES_Forms_Table::get_form_data_from_body( $form ); $form_data['show-in-popup-attr'] = isset( $atts['show-in-popup'] ) ? sanitize_text_field( $atts['show-in-popup'] ) : ''; $form_html = self::render_form( $form_data ); } } return ob_get_clean(); } // Handle Email Subscribers Group Selector Shortcode // Backward Compatibility public static function render_es_advanced_form( $atts ) { ob_start(); $atts = shortcode_atts( array( 'id' => '' ), $atts, 'email-subscribers-advanced-form' ); $af_id = $atts['id']; if ( ! empty( $af_id ) ) { $form = ES()->forms_db->get_form_by_af_id( $af_id ); if ( $form ) { $form_data = ES_Forms_Table::get_form_data_from_body( $form ); self::render_form( $form_data ); } } return ob_get_clean(); } /** * Get the name field to render inside the form * * @param $show_name * @param $name_label * @param $name_required * @param $name_placeholder * @param $submitted_name * * @return string */ public static function get_name_field_html( $show_name, $name_label, $name_required, $name_placeholder, $submitted_name = '' ) { $required = ''; if ( ! empty( $show_name ) && 'no' !== $show_name ) { if ( 'yes' === $name_required ) { $required = 'required'; if ( ! empty( $name_label ) ) { $name_label .= '*'; } } $name_html = '
'; return $email_html; } /** * * Get the List field to render inside the form * * @param $show_list * @param $list_label * @param $list_ids * @param $list * @param array $selected_list_ids * * @return string */ public static function get_list_field_html( $show_list, $list_label, $list_ids, $list, $selected_list_ids = array() ) { if ( ! empty( $list_ids ) && $show_list ) { $lists_id_name_map = ES()->lists_db->get_list_id_name_map(); $lists_id_hash_map = ES()->lists_db->get_list_id_hash_map( $list_ids ); $list_html = self::prepare_lists_checkboxes( $lists_id_name_map, $list_ids, 1, $selected_list_ids, $list_label, 0, 'esfpx_lists[]', $lists_id_hash_map ); } elseif ( ! empty( $list_ids ) && ! $show_list ) { $list_html = ''; $lists = ES()->lists_db->get_lists_by_id( $list_ids ); if ( ! empty( $lists ) ) { foreach ( $lists as $list ) { if ( ! empty( $list ) && ! empty( $list['hash'] ) ) { $list_html .= ''; } } } } elseif ( is_numeric( $list ) ) { $lists = ES()->lists_db->get_lists_by_id( $list ); $list_html = ''; if ( ! empty( $lists ) ) { $list_hash = ! empty( $lists[0]['hash'] ) ? $lists[0]['hash'] : ''; if ( ! empty( $list_hash ) ) { $list_html = ''; } } } else { $list_data = ES()->lists_db->get_list_by_name( $list ); if ( empty( $list_data ) ) { $list_id = ES()->lists_db->add_list( $list ); } else { $list_id = $list_data['id']; } $lists = ES()->lists_db->get_lists_by_id( $list_id ); $list_html = ''; if ( ! empty( $lists ) ) { $list_hash = ! empty( $lists[0]['hash'] ) ? $lists[0]['hash'] : ''; if ( ! empty( $list_hash ) ) { $list_html = ''; } } } return $list_html; } public static function render_form( $data ) { /** * - Show name? -> Prepare HTML for name * - Show email? -> Prepare HTML for email // Always true * - Show lists? -> Preapre HTML for Lists list_ids * - Hidden Field -> form_id, * list, * es_email_page, * es_email_page_url, * es-subscribe, * honeypot field */ // Compatibility for GDPR $active_plugins = get_option( 'active_plugins', array() ); if ( is_multisite() ) { $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); } $editor_type = ! empty( $data['settings']['editor_type'] ) ? $data['settings']['editor_type'] : ''; $is_dnd_editor = IG_ES_DRAG_AND_DROP_EDITOR === $editor_type; if ( ! $is_dnd_editor ) { $show_name = ! empty( $data['name_visible'] ) ? strtolower( $data['name_visible'] ) : false; $required_name = ! empty( $data['name_required'] ) ? $data['name_required'] : false; $name_label = ! empty( $data['name_label'] ) ? $data['name_label'] : ''; $name_placeholder = ! empty( $data['name_place_holder'] ) ? $data['name_place_holder'] : ''; $email_label = ! empty( $data['email_label'] ) ? $data['email_label'] : ''; $email_placeholder = ! empty( $data['email_place_holder'] ) ? $data['email_place_holder'] : ''; $button_label = ! empty( $data['button_label'] ) ? $data['button_label'] : __( 'Subscribe', 'email-subscribers' ); $list_label = ! empty( $data['list_label'] ) ? $data['list_label'] : __( 'Select list(s)', 'email-subscribers' ); $show_list = ! empty( $data['list_visible'] ) ? $data['list_visible'] : false; $list_ids = ! empty( $data['lists'] ) ? $data['lists'] : array(); $form_id = ! empty( $data['form_id'] ) ? $data['form_id'] : 0; $list = ! empty( $data['list'] ) ? $data['list'] : 0; $desc = ! empty( $data['desc'] ) ? $data['desc'] : ''; $form_version = ! empty( $data['form_version'] ) ? $data['form_version'] : '0.1'; $gdpr_consent = ! empty( $data['gdpr_consent'] ) ? $data['gdpr_consent'] : 'no'; $gdpr_consent_text = ! empty( $data['gdpr_consent_text'] ) ? $data['gdpr_consent_text'] : ''; $es_form_popup = isset( $data['show_in_popup'] ) ? $data['show_in_popup'] : 'no'; $es_popup_headline = isset( $data['popup_headline'] ) ? $data['popup_headline'] : ''; $show_in_popup_attr = isset( $data['show-in-popup-attr'] ) ? $data['show-in-popup-attr'] : ''; } else { $show_list = ! empty( $data['list_visible'] ) ? $data['list_visible'] : false; $list_ids = ! empty( $data['settings']['lists'] ) ? $data['settings']['lists'] : array(); $form_id = ! empty( $data['form_id'] ) ? $data['form_id'] : 0; $list = ! empty( $data['list'] ) ? $data['list'] : 0; $desc = ! empty( $data['desc'] ) ? $data['desc'] : ''; $form_version = ! empty( $data['form_version'] ) ? $data['form_version'] : '0.1'; $es_form_popup = isset( $data['settings']['show_in_popup'] ) ? $data['settings']['show_in_popup'] : 'no'; $es_popup_headline = isset( $data['settings']['popup_headline'] ) ? $data['settings']['popup_headline'] : ''; $show_in_popup_attr = isset( $data['show-in-popup-attr'] ) ? $data['show-in-popup-attr'] : ''; $button_label = ''; } $allowedtags = ig_es_allowed_html_tags_in_esc(); /** * We did not have $email_label, $name_label in * ES < 4.2.2 * * Since ES 4.2.2, we are adding form_version in form settings. * * If we don't find Form Version in settings, we are setting as 0.1 * * So, if form_version is 0.1 then set default label */ if ( '0.1' == $form_version ) { $email_label = __( 'Email', 'email-subscribers' ); $name_label = __( 'Name', 'email-subscribers' ); } self::$form_identifier = self::generate_form_identifier( $form_id ); $submitted_name = ''; $submitted_email = ''; $message_class = ''; $message_text = ''; $selected_list_ids = array(); if ( self::is_posted() ) { // self::$response is set by ES_Handle_Subscription::handle_subscription() when subscription form is posted $response = ! empty( self::$response ) ? self::$response: array(); if ( ! empty( $response ) ) { $message_class = ! empty( $response['status'] ) && 'SUCCESS' === $response['status'] ? 'success' : 'error'; $message_text = ! empty( $response['message_text'] ) ? $response['message_text'] : ''; } $submitted_name = ig_es_get_post_data( 'esfpx_name' ); $submitted_email = ig_es_get_post_data( 'esfpx_email' ); $selected_list_hashes = ig_es_get_post_data( 'esfpx_lists' ); if ( ! empty( $selected_list_hashes ) ) { $selected_lists = ES()->lists_db->get_lists_by_hash( $selected_list_hashes ); if ( $selected_lists ) { $selected_list_ids = array_column( $selected_lists, 'id' ); } } } else { if ( is_user_logged_in() ) { $prefill_form = apply_filters( 'ig_es_prefill_subscription_form', 'yes' ); if ( 'yes' === $prefill_form ) { $current_user = wp_get_current_user(); $submitted_email = $current_user->user_email; if ( ! empty( $current_user->user_firstname ) && ! empty( $current_user->user_lastname ) ) { $submitted_name = $current_user->user_firstname . ' ' . $current_user->user_lastname; } } } } //replace total contact $total_contacts = ES()->contacts_db->count_active_contacts_by_list_id(); $desc = str_replace( '{{TOTAL-CONTACTS}}', $total_contacts, $desc ); $current_page = get_the_ID(); $current_page_url = get_the_permalink( $current_page ); $unique_id = uniqid(); $hp_style = 'position:absolute;top:-99999px;' . ( is_rtl() ? 'right' : 'left' ) . ':-99999px;z-index:-99;'; $nonce = wp_create_nonce( 'es-subscribe' ); // Form html $form_html = ''; $form_header_html = ''; $form_data_html = ''; $form_orig_html = ''; $form_orig_html = $form_header_html; // Don't show form if submission was successful. if ( 'success' !== $message_class) { $form_action_url = ES_Common::get_current_request_url(); $enable_ajax_form_submission = get_option( 'ig_es_enable_ajax_form_submission', 'yes' ); $extra_form_class = ( 'yes' == $enable_ajax_form_submission ) ? ' es_ajax_subscription_form' : ''; $form_header_html .= ''; } $form_data_html .= ''; // Wrap form html inside a container. $form_data_html = '' . $list_label . '*
| ';
$lists_html .= $status_span . ' | ';
} else {
$lists_html .= '