'', '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 .= '
'; if ( '' != $desc ) { $form_header_html .= '
' . $desc . '
'; } $form_data_html = ' '; $spinner_image_path = ES_PLUGIN_URL . 'lite/public/images/spinner.gif'; $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 ) { // Name $name_html = self::get_name_field_html($show_name, $name_label, $required_name, $name_placeholder, $submitted_name); // Lists $list_html = self::get_list_field_html($show_list, $list_label, $list_ids, $list, $selected_list_ids); $email_html = self::get_email_field_html($email_label, $email_placeholder, $submitted_email); $form = array( $form_header_html, $name_html, $email_html, $list_html, $form_html, $form_data_html ); $form_orig_html = implode( '', $form ); $form_data_html = apply_filters( 'ig_es_after_form_fields', $form_orig_html, $data ); if ( 'yes' === $gdpr_consent ) { $form_data_html .= '
'; } elseif ( ( in_array( 'gdpr/gdpr.php', $active_plugins ) || array_key_exists( 'gdpr/gdpr.php', $active_plugins ) ) ) { GDPR::consent_checkboxes(); } $form_data_html .= ''; } else { if ( ! empty( $list_ids ) ) { $list_html = self::get_list_field_html(false, '', $list_ids, '', $selected_list_ids); $form_html .= $list_html; } $form_body = ''; if ( ! empty( $data['settings']['dnd_editor_css'] ) ) { $editor_css = $data['settings']['dnd_editor_css']; // We are using attribute selector data-form-id to apply Form style and not form unique id since when using it, it overrides GrapeJs custom style changes done through GrapeJS style editor. $editor_css = str_replace( '.es-form-field-container', 'form[data-form-id="' . $form_id . '"] .es-form-field-container', $editor_css ); $editor_css = str_replace( '* {', 'form.es_subscription_form[data-form-id="' . $form_id . '"] * {', $editor_css ); $form_body = ''; } $form_body .= ! empty( $data['body'] ) ? do_shortcode( $data['body'] ) : ''; $form = array( $form_header_html, $form_html, $form_data_html, $form_body ); $form_orig_html = implode( '', $form ); $form_data_html = $form_orig_html; } $form_data_html .= 'Loading
'; } $form_data_html .= '' . $message_text . ''; // Wrap form html inside a container. $form_data_html = '
' . $form_data_html . '
'; $form = $form_data_html; $show_in_popup = false; if ( ! empty( $es_form_popup ) && 'yes' === $es_form_popup ) { if ( empty( $show_in_popup_attr ) || 'yes' === $show_in_popup_attr ) { $show_in_popup = true; } } if ( $show_in_popup ) { if ( ! wp_style_is( 'ig-es-popup-frontend' ) ) { wp_enqueue_style( 'ig-es-popup-frontend' ); } if ( ! wp_style_is( 'ig-es-popup-css' ) ) { wp_enqueue_style( 'ig-es-popup-css' ); } ?>

' . $list_label . '*

'; $i = 0; if ( ! empty( $contact_id ) ) { $list_contact_status_map = ES()->lists_contacts_db->get_list_contact_status_map( $contact_id ); } $lists = apply_filters( 'ig_es_lists', $lists ); foreach ( $lists as $list_id => $list_name ) { if ( 0 != $i && 0 === ( $i % $columns ) ) { $lists_html .= ''; } $status_span = ''; if ( in_array( $list_id, $list_ids ) ) { // Check if list hash has been passed for given list id, if yes then use list hash, else use list id if ( ! empty( $lists_id_hash_map[ $list_id ] ) ) { $list_value = $lists_id_hash_map[ $list_id ]; } else { $list_value = $list_id; } if ( in_array( $list_id, $selected_lists ) ) { if ( ! empty( $contact_id ) ) { $status_span = ''; } $lists_html .= ''; } else { $lists_html .= ''; } $i ++; } } $lists_html .= '
'; $lists_html .= $status_span . '
'; return $lists_html; } /** * Generate a unique form identifier based on number of forms already rendered on the page. * * @return string $form_identifier * * @since 4.7.5 */ public static function generate_form_identifier( $form_id = 0 ) { static $form_count = 1; $form_identifier = ''; if ( in_the_loop() ) { $page_id = get_the_ID(); $form_identifier = sprintf( 'f%1$d-p%2$d-n%3$d', $form_id, $page_id, $form_count ); } else { $form_identifier = sprintf( 'f%1$d-n%2$d', $form_id, $form_count ); } $form_count++; return $form_identifier; } /** * Get form's identifier * * @return string * * @since 4.7.5 */ public static function get_form_identifier() { return self::$form_identifier; } /** * Return true if this form is the same one as currently posted. * * @return boolean * * @since 4.7.5 */ public static function is_posted() { $form_identifier = ig_es_get_request_data( 'esfpx_es_form_identifier' ); if ( empty( $form_identifier ) ) { return false; } return self::get_form_identifier() === $form_identifier; } }