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( 'wp_ajax_ig_es_get_form_preview', array( $this, 'get_form_preview' ) ); add_action( 'ig_es_render_dnd_form', array( $this, 'render_dnd_form' ), 10, 2 ); add_action( 'ig_es_render_classic_form', array( $this, 'render_classic_form' ), 10, 2 ); } public function render_classic_form( $id, $data ) { $is_new = empty( $id ) ? 1 : 0; $action = 'new'; if ( ! $is_new ) { $action = 'edit'; } $form_data['name'] = ! empty( $data['name'] ) ? sanitize_text_field( $data['name'] ) : ''; $form_data['name_visible'] = ! empty( $data['name_visible'] ) ? sanitize_text_field( $data['name_visible'] ) : 'no'; $form_data['name_required'] = ! empty( $data['name_required'] ) ? sanitize_text_field( $data['name_required'] ) : 'no'; $form_data['name_label'] = ! empty( $data['name_label'] ) ? sanitize_text_field( $data['name_label'] ) : ''; $form_data['name_place_holder'] = ! empty( $data['name_place_holder'] ) ? sanitize_text_field( $data['name_place_holder'] ) : ''; $form_data['email_label'] = ! empty( $data['email_label'] ) ? sanitize_text_field( $data['email_label'] ) : ''; $form_data['email_place_holder'] = ! empty( $data['email_place_holder'] ) ? sanitize_text_field( $data['email_place_holder'] ) : ''; $form_data['button_label'] = ! empty( $data['button_label'] ) ? sanitize_text_field( $data['button_label'] ) : __( 'Subscribe', 'email-subscribers' ); $form_data['list_visible'] = ! empty( $data['list_visible'] ) ? $data['list_visible'] : 'no'; $form_data['gdpr_consent'] = ! empty( $data['gdpr_consent'] ) ? $data['gdpr_consent'] : 'no'; $form_data['gdpr_consent_text'] = ! empty( $data['gdpr_consent_text'] ) ? $data['gdpr_consent_text'] : __( 'Please read our terms and conditions', 'email-subscribers' ); $form_data['list_label'] = ! empty( $data['list_label'] ) ? $data['list_label'] : ''; $form_data['lists'] = ! empty( $data['lists'] ) ? $data['lists'] : array(); $form_data['af_id'] = ! empty( $data['af_id'] ) ? $data['af_id'] : 0; $form_data['desc'] = ! empty( $data['desc'] ) ? wp_kses_post( trim( wp_unslash( $data['desc'] ) ) ) : ''; $form_data['captcha'] = ES_Common::get_captcha_setting( 0, $data ); $form_data['show_in_popup'] = ! empty( $data['show_in_popup'] ) ? $data['show_in_popup'] : 'no'; $form_data['popup_headline'] = ! empty( $data['popup_headline'] ) ? $data['popup_headline'] : ''; $lists = ES()->lists_db->get_list_id_name_map(); $nonce = wp_create_nonce( 'es_form' ); ?>

/> /> > >

0 ) { $lists_checkboxes = ES_Shortcode::prepare_lists_checkboxes( $lists, array_keys( $lists ), 3, (array) $form_data['lists'] ); echo wp_kses( $lists_checkboxes, $allowedtags ); } else { $create_list_link = admin_url( 'admin.php?page=es_lists&action=new' ); ?> ' . esc_html__( 'create your first list', 'email-subscribers' ) . '' ); ?>

0 ) { ?>

here', $lists_page_url ), 'email-subscribers' ); $status = 'error'; ES_Common::show_message( $message, $status ); } ?>

array( 'data-html-textarea-name' => 'form_data[body]', 'data-page' => 'form', ), ); ( new ES_Drag_And_Drop_Editor() )->show_editor( $form_editor_settings ); ?>
' . $editor_css . '' . $form_body; $response['preview_html'] = $preview_html; $response = self::process_form_body( $response); if ( ! empty( $response ) ) { wp_send_json_success( $response ); } else { wp_send_json_error(); } } //The code to replace the keywords in DND editor public static function process_form_body( $content) { if (!empty($content)) { // Define the replacements as an associative array $replacements = array( '{{TOTAL-CONTACTS}}' => ES()->contacts_db->count_active_contacts_by_list_id(), '{{site.total_contacts}}' => ES()->contacts_db->count_active_contacts_by_list_id(), '{{SITENAME}}' => get_option('blogname'), '{{site.name}}' => get_option('blogname'), '{{SITEURL}}' => home_url('/'), '{{site.url}}' => home_url('/'), ); // Perform the replacements $content = str_replace(array_keys($replacements), array_values($replacements), $content); } return $content; } public static function get_styles_path() { $form_styles_path = ES_PLUGIN_DIR . 'lite/admin/css/form-styles/'; return $form_styles_path; } public static function get_form_styles() { $form_styles_path = self::get_styles_path(); $form_styles = array( array( 'id' => 'theme-styling', 'name' => __( 'Theme styling', 'email-subscribers' ), 'css' => file_get_contents( $form_styles_path . 'theme-styling.css' ), ), ); $form_styles = apply_filters( 'ig_es_form_styles', $form_styles ); return $form_styles; } public static function get_frontend_css() { $css_html = ''; $response = wp_remote_get(get_home_url()); if ( is_wp_error( $response )) { return $css_html; } $content = $response['body']; preg_match_all( '//', $content, $matches ); $mateched_link_tags = $matches[0]; if ( ! empty( $mateched_link_tags ) ) { $css_html .= implode( '', $mateched_link_tags ); } preg_match_all('/]*>[\s\S]*?<\/style>/', $content, $matches ); $matched_style_tags = $matches[0]; if ( ! empty( $matched_style_tags ) ) { $css_html .= implode( '', $matched_style_tags ); } return $css_html; } public static function get_common_css() { $form_styles_path = self::get_styles_path(); $common_css = file_get_contents( $form_styles_path . 'common.css' ); return $common_css; } } } ES_Form_Admin::get_instance();