File manager - Edit - /home/premiey/www/wp-includes/images/media/actions.tar
Back
webhook.php 0000666 00000006171 15165307047 0006734 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Modules\Forms\Classes\Action_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Webhook extends Action_Base { public function get_name() { return 'webhook'; } public function get_label() { return esc_html__( 'Webhook', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_webhook', [ 'label' => esc_html__( 'Webhook', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); $widget->add_control( 'webhooks', [ 'label' => esc_html__( 'Webhook URL', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'placeholder' => esc_html__( 'https://your-webhook-url.com', 'elementor-pro' ), 'ai' => [ 'active' => false, ], 'label_block' => true, 'separator' => 'before', 'description' => esc_html__( 'Enter the integration URL (like Zapier) that will receive the form\'s submitted data.', 'elementor-pro' ), 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'webhooks_advanced_data', [ 'label' => esc_html__( 'Advanced Data', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'no', 'render_type' => 'none', ] ); $widget->end_controls_section(); } public function on_export( $element ) {} public function run( $record, $ajax_handler ) { $settings = $record->get( 'form_settings' ); if ( empty( $settings['webhooks'] ) ) { return; } if ( isset( $settings['webhooks_advanced_data'] ) && 'yes' === $settings['webhooks_advanced_data'] ) { $body['form'] = [ 'id' => $settings['id'], 'name' => $settings['form_name'], ]; $body['fields'] = $record->get( 'fields' ); $body['meta'] = $record->get( 'meta' ); } else { $body = $record->get_formatted_data( true ); $body['form_id'] = $settings['id']; $body['form_name'] = $settings['form_name']; } $args = [ 'body' => $body, ]; /** * Forms webhook request arguments. * * Filters the request arguments delivered by the form webhook when executing * an ajax request. * * @since 1.0.0 * * @param array $args Webhook request arguments. * @param Form_Record $record An instance of the form record. */ $args = apply_filters( 'elementor_pro/forms/webhooks/request_args', $args, $record ); $response = wp_remote_post( $settings['webhooks'], $args ); /** * Elementor form webhook response. * * Fires when the webhook response is retrieved by Elementor forms. This hook * allows developers to add functionality after recieving webhook responses. * * @since 1.0.0 * * @param \WP_Error|array $response The response or WP_Error on failure. * @param Form_Record $record An instance of the form record. */ do_action( 'elementor_pro/forms/webhooks/response', $response, $record ); if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { throw new \Exception( 'Webhook error.' ); } } } activecampaign.php 0000666 00000021742 15165307047 0010252 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use Elementor\Settings; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Integration_Base; use ElementorPro\Modules\Forms\Classes; use ElementorPro\Core\Utils; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Activecampaign extends Integration_Base { const OPTION_NAME_API_KEY = 'pro_activecampaign_api_key'; const OPTION_NAME_API_URL = 'pro_activecampaign_api_url'; private function get_global_api_key() { return get_option( 'elementor_' . self::OPTION_NAME_API_KEY, '' ); } private function get_global_api_url() { return get_option( 'elementor_' . self::OPTION_NAME_API_URL, '' ); } public function get_name() { return 'activecampaign'; } public function get_label() { return esc_html__( 'ActiveCampaign', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_activecampaign', [ 'label' => esc_html__( 'ActiveCampaign', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); self::global_api_control( $widget, $this->get_global_api_key(), 'ActiveCampaign API credentials', [ 'activecampaign_api_credentials_source' => 'default', ], $this->get_name() ); $widget->add_control( 'activecampaign_api_credentials_source', [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'label_block' => false, 'options' => [ 'default' => 'Default', 'custom' => 'Custom', ], 'default' => 'default', ] ); $widget->add_control( 'activecampaign_api_key', [ 'label' => esc_html__( 'Custom API Key', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'description' => esc_html__( 'Use this field to set a custom API Key for the current form', 'elementor-pro' ), 'condition' => [ 'activecampaign_api_credentials_source' => 'custom', ], ] ); $widget->add_control( 'activecampaign_api_url', [ 'label' => esc_html__( 'API URL', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'description' => esc_html__( 'Use this field to set a custom API URL for the current form', 'elementor-pro' ), 'condition' => [ 'activecampaign_api_credentials_source' => 'custom', ], ] ); $widget->add_control( 'activecampaign_list', [ 'label' => esc_html__( 'List', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'options' => [], 'render_type' => 'none', 'conditions' => [ 'relation' => 'or', 'terms' => [ [ 'name' => 'activecampaign_api_credentials_source', 'operator' => '=', 'value' => 'default', ], [ 'relation' => 'and', 'terms' => [ [ 'name' => 'activecampaign_api_url', 'operator' => '!==', 'value' => '', ], [ 'name' => 'activecampaign_api_key', 'operator' => '!==', 'value' => '', ], ], ], ], ], ] ); $this->register_fields_map_control( $widget ); $widget->add_control( 'activecampaign_tags', [ 'label' => esc_html__( 'Tags', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'description' => esc_html__( 'Add as many tags as you want, comma separated.', 'elementor-pro' ), 'condition' => [ 'activecampaign_list!' => '', ], ] ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['settings']['activecampaign_api_credentials_source'], $element['settings']['activecampaign_api_key'], $element['settings']['activecampaign_api_url'], $element['settings']['activecampaign_list'], $element['settings']['activecampaign_fields_map'], $element['settings']['activecampaign_tags'] ); return $element; } public function run( $record, $ajax_handler ) { $form_settings = $record->get( 'form_settings' ); $subscriber = $this->create_subscriber_object( $record ); if ( ! $subscriber ) { throw new \Exception( 'Integration requires an email field and a selected list.' ); } if ( 'default' === $form_settings['activecampaign_api_credentials_source'] ) { $api_key = $this->get_global_api_key(); $api_url = $this->get_global_api_url(); } else { $api_key = $form_settings['activecampaign_api_key']; $api_url = $form_settings['activecampaign_api_url']; } $handler = new Classes\Activecampaign_Handler( $api_key, $api_url ); $handler->create_subscriber( $subscriber ); } /** * Create subscriber array from submitted data and form settings * returns a subscriber array or false on error * * @param Form_Record $record * * @return array|bool */ private function create_subscriber_object( Form_Record $record ) { $form_settings = $record->get( 'form_settings' ); $subscriber = $this->map_fields( $record ); if ( ! isset( $subscriber['email'] ) ) { return false; } if ( ! isset( $form_settings['activecampaign_list'] ) ) { return false; } $subscriber['ip4'] = Utils::get_client_ip(); $list_id = $form_settings['activecampaign_list']; $subscriber[ 'p[' . $list_id . ']' ] = $list_id; if ( isset( $form_settings['activecampaign_tags'] ) && ! empty( $form_settings['activecampaign_tags'] ) ) { $subscriber['tags'] = $form_settings['activecampaign_tags']; } if ( isset( $form_settings['form_id'] ) && ! empty( $form_settings['form_id'] ) ) { $subscriber['form'] = $form_settings['form_id']; } return $subscriber; } /** * @param Form_Record $record * * @return array */ private function map_fields( Form_Record $record ) { $subscriber = []; $fields = $record->get( 'fields' ); // Other form has a field mapping foreach ( $record->get_form_settings( 'activecampaign_fields_map' ) as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } $value = $fields[ $map_item['local_id'] ]['value']; $subscriber[ $map_item['remote_id'] ] = $value; } return $subscriber; } /** * @param array $data * * @return array * @throws \Exception */ public function handle_panel_request( array $data ) { if ( ! empty( $data['api_cred'] ) && 'default' === $data['api_cred'] ) { $api_key = $this->get_global_api_key(); $api_url = $this->get_global_api_url(); } elseif ( ! empty( $data['api_key'] ) && ! empty( $data['api_url'] ) ) { $api_key = $data['api_key']; $api_url = $data['api_url']; } if ( empty( $api_key ) ) { throw new \Exception( '`api_key` is required.', 400 ); } if ( empty( $api_url ) ) { throw new \Exception( '`api_url` is required.', 400 ); } $handler = new Classes\Activecampaign_Handler( $api_key, $api_url ); return $handler->get_lists(); } public function ajax_validate_api_token() { check_ajax_referer( self::OPTION_NAME_API_KEY, '_nonce' ); if ( ! isset( $_POST['api_key'] ) || ! isset( $_POST['api_url'] ) ) { wp_send_json_error(); } try { new Classes\Activecampaign_Handler( Utils::_unstable_get_super_global_value( $_POST, 'api_key' ), Utils::_unstable_get_super_global_value( $_POST, 'api_url' ) ); } catch ( \Exception $exception ) { wp_send_json_error(); } wp_send_json_success(); } public function register_admin_fields( Settings $settings ) { $settings->add_section( Settings::TAB_INTEGRATIONS, 'activecampign', [ 'callback' => function() { echo '<hr><h2>' . esc_html__( 'ActiveCampaign', 'elementor-pro' ) . '</h2>'; }, 'fields' => [ self::OPTION_NAME_API_KEY => [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'field_args' => [ 'type' => 'text', ], ], self::OPTION_NAME_API_URL => [ 'label' => esc_html__( 'API URL', 'elementor-pro' ), 'field_args' => [ 'type' => 'url', 'desc' => sprintf( /* translators: 1: Link opening tag, 2: Link closing tag. */ esc_html__( 'To integrate with our forms you need an %1$sAPI Key%2$s.', 'elementor-pro' ), '<a href="https://help.activecampaign.com/hc/en-us/articles/207317590-Getting-started-with-the-API" target="_blank">', '</a>' ), ], ], 'validate_api_data' => [ 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '<button data-action="%s" data-nonce="%s" class="button elementor-button-spinner" id="elementor_pro_activecampaign_api_key_button">%s</button>', self::OPTION_NAME_API_KEY . '_validate', wp_create_nonce( self::OPTION_NAME_API_KEY ), esc_html__( 'Validate API Key', 'elementor-pro' ) ), ], ], ], ] ); } public function __construct() { if ( is_admin() ) { add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 15 ); } add_action( 'wp_ajax_' . self::OPTION_NAME_API_KEY . '_validate', [ $this, 'ajax_validate_api_token' ] ); } protected function get_fields_map_control_options() { return [ 'condition' => [ 'activecampaign_list!' => '', ], ]; } } discord.php 0000666 00000013521 15165307047 0006722 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Core\Utils; use ElementorPro\Modules\Forms\Classes\Action_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Discord extends Action_Base { public function get_name() { return 'discord'; } public function get_label() { return esc_html__( 'Discord', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_discord', [ 'label' => esc_html__( 'Discord', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); $widget->add_control( 'discord_webhook', [ 'label' => esc_html__( 'Webhook URL', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'placeholder' => 'https://discordapp.com/api/webhooks/', 'ai' => [ 'active' => false, ], 'label_block' => true, 'separator' => 'before', 'description' => esc_html__( 'Enter the webhook URL that will receive the form\'s submitted data.', 'elementor-pro' ) . ' ' . sprintf( '<a href="%s" target="_blank">%s</a>.', 'https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks', esc_html__( 'Click here for Instructions', 'elementor-pro' ) ), 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'discord_username', [ 'label' => esc_html__( 'Username', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'discord_avatar_url', [ 'label' => esc_html__( 'Avatar URL', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'discord_title', [ 'label' => esc_html__( 'Title', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'discord_content', [ 'label' => esc_html__( 'Description', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'discord_form_data', [ 'label' => esc_html__( 'Form Data', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', ] ); $widget->add_control( 'discord_ts', [ 'label' => esc_html__( 'Timestamp', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', ] ); $widget->add_control( 'discord_webhook_color', [ 'label' => esc_html__( 'Color', 'elementor-pro' ), 'type' => Controls_Manager::COLOR, 'alpha' => false, 'default' => '#D30C5C', ] ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['discord_avatar_url'], $element['discord_content'], $element['discord_webhook_color'], $element['discord_username'], $element['discord_form_data'], $element['discord_ts'], $element['discord_title'], $element['discord_webhook'] ); } public function run( $record, $ajax_handler ) { $settings = $record->get( 'form_settings' ); if ( empty( $settings['discord_webhook'] ) || false === strpos( $settings['discord_webhook'], 'https://discordapp.com/api/webhooks/' ) ) { return; } // PHPCS - The form is a visitor action and doesn't require a nonce. $referrer = Utils::_unstable_get_super_global_value( $_POST, 'referrer' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing $page_url = $referrer ? esc_url( $referrer ) : site_url(); $color = isset( $settings['discord_webhook_color'] ) ? hexdec( ltrim( $settings['discord_webhook_color'], '#' ) ) : hexdec( '9c0244' ); // Build discord webhook data $embeds = [ 'title' => isset( $settings['discord_title'] ) ? $settings['discord_title'] : esc_html__( 'A new Submission', 'elementor-pro' ), 'description' => isset( $settings['discord_content'] ) ? $settings['discord_content'] : esc_html__( 'A new Form Submission has been received', 'elementor-pro' ), 'author' => [ 'name' => isset( $settings['discord_username'] ) ? $settings['discord_username'] : esc_html__( 'Elementor Forms', 'elementor-pro' ), 'url' => $page_url, 'icon_url' => isset( $settings['discord_avatar_url'] ) ? $settings['discord_avatar_url'] : null, ], 'url' => $page_url, 'color' => $color, ]; if ( ! empty( $settings['discord_form_data'] ) && 'yes' === $settings['discord_form_data'] ) { // prepare Form Data $raw_fields = $record->get( 'fields' ); $fields = []; foreach ( $raw_fields as $id => $field ) { $fields[] = [ 'name' => $id, 'value' => $field['value'], 'inline' => false, ]; } $embeds['fields'] = array_values( $fields ); } if ( ! empty( $settings['discord_ts'] ) && 'yes' === $settings['discord_ts'] ) { $embeds['timestamp'] = gmdate( \DateTime::ISO8601 ); $embeds['footer'] = [ 'text' => sprintf( /* translators: %s: Elementor. */ esc_html__( 'Powered by %s', 'elementor-pro' ), 'Elementor' ), 'icon_url' => is_ssl() ? ELEMENTOR_ASSETS_URL . 'images/logo-icon.png' : null, ]; } $webhook_data = [ 'embeds' => array_values( [ $embeds ] ), ]; $webhook_data = apply_filters( 'elementor_pro/forms/discord/webhook_args', $webhook_data ); $response = wp_remote_post( $settings['discord_webhook'], [ 'body' => wp_json_encode( $webhook_data ), 'headers' => [ 'Content-Type' => 'application/json; charset=utf-8' ], ]); if ( 204 !== (int) wp_remote_retrieve_response_code( $response ) ) { throw new \Exception( 'Webhook error.' ); } } } cf7db.php 0000666 00000001311 15165307047 0006252 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use ElementorPro\Modules\Forms\Classes\Action_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class CF7DB extends Action_Base { public function get_name() { return 'cf7db'; } public function get_label() { return 'Contact Form to Database'; } public function register_settings_section( $widget ) {} public function on_export( $element ) {} public function run( $record, $ajax_handler ) { $data = (object) [ 'title' => $record->get_form_settings( 'form_name' ), 'posted_data' => $record->get_formatted_data( true ), ]; // Call hook to submit data do_action_ref_array( 'cfdb_submit', [ $data ] ); } } email.php 0000666 00000026315 15165307047 0006367 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Core\Utils; use ElementorPro\Modules\Forms\Classes\Ajax_Handler; use ElementorPro\Modules\Forms\Classes\Action_Base; use ElementorPro\Modules\Forms\Classes\Form_Record; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Email extends Action_Base { public function get_name() { return 'email'; } public function get_label() { return esc_html__( 'Email', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( $this->get_control_id( 'section_email' ), [ 'label' => $this->get_label(), 'tab' => Controls_Manager::TAB_CONTENT, 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); $widget->add_control( $this->get_control_id( 'email_to' ), [ 'label' => esc_html__( 'To', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'default' => get_option( 'admin_email' ), 'ai' => [ 'active' => false, ], 'placeholder' => get_option( 'admin_email' ), 'label_block' => true, 'title' => esc_html__( 'Separate emails with commas', 'elementor-pro' ), 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); /* translators: %s: Site title. */ $default_message = sprintf( esc_html__( 'New message from "%s"', 'elementor-pro' ), get_option( 'blogname' ) ); $widget->add_control( $this->get_control_id( 'email_subject' ), [ 'label' => esc_html__( 'Subject', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'default' => $default_message, 'ai' => [ 'active' => false, ], 'placeholder' => $default_message, 'label_block' => true, 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( $this->get_control_id( 'email_content' ), [ 'label' => esc_html__( 'Message', 'elementor-pro' ), 'type' => Controls_Manager::TEXTAREA, 'default' => '[all-fields]', 'ai' => [ 'active' => false, ], 'placeholder' => '[all-fields]', 'description' => sprintf( /* translators: %s: The [all-fields] shortcode. */ esc_html__( 'By default, all form fields are sent via %s shortcode. To customize sent fields, copy the shortcode that appears inside each field and paste it above.', 'elementor-pro' ), '<code>[all-fields]</code>' ), 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $site_domain = Utils::get_site_domain(); $widget->add_control( $this->get_control_id( 'email_from' ), [ 'label' => esc_html__( 'From Email', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'default' => 'email@' . $site_domain, 'ai' => [ 'active' => false, ], 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( $this->get_control_id( 'email_from_name' ), [ 'label' => esc_html__( 'From Name', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'default' => get_bloginfo( 'name' ), 'ai' => [ 'active' => false, ], 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( $this->get_control_id( 'email_reply_to' ), [ 'label' => esc_html__( 'Reply-To', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'options' => [ '' => '', ], 'render_type' => 'none', ] ); $widget->add_control( $this->get_control_id( 'email_to_cc' ), [ 'label' => esc_html__( 'Cc', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'default' => '', 'ai' => [ 'active' => false, ], 'title' => esc_html__( 'Separate emails with commas', 'elementor-pro' ), 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( $this->get_control_id( 'email_to_bcc' ), [ 'label' => esc_html__( 'Bcc', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'default' => '', 'ai' => [ 'active' => false, ], 'title' => esc_html__( 'Separate emails with commas', 'elementor-pro' ), 'render_type' => 'none', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( $this->get_control_id( 'form_metadata' ), [ 'label' => esc_html__( 'Meta Data', 'elementor-pro' ), 'type' => Controls_Manager::SELECT2, 'multiple' => true, 'label_block' => true, 'separator' => 'before', 'default' => [ 'date', 'time', 'page_url', 'user_agent', 'remote_ip', 'credit', ], 'options' => [ 'date' => esc_html__( 'Date', 'elementor-pro' ), 'time' => esc_html__( 'Time', 'elementor-pro' ), 'page_url' => esc_html__( 'Page URL', 'elementor-pro' ), 'user_agent' => esc_html__( 'User Agent', 'elementor-pro' ), 'remote_ip' => esc_html__( 'Remote IP', 'elementor-pro' ), 'credit' => esc_html__( 'Credit', 'elementor-pro' ), ], 'render_type' => 'none', ] ); $widget->add_control( $this->get_control_id( 'email_content_type' ), [ 'label' => esc_html__( 'Send As', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'default' => 'html', 'render_type' => 'none', 'options' => [ 'html' => esc_html__( 'HTML', 'elementor-pro' ), 'plain' => esc_html__( 'Plain', 'elementor-pro' ), ], ] ); $widget->end_controls_section(); } public function on_export( $element ) { $controls_to_unset = [ 'email_to', 'email_from', 'email_from_name', 'email_subject', 'email_reply_to', 'email_to_cc', 'email_to_bcc', ]; foreach ( $controls_to_unset as $base_id ) { $control_id = $this->get_control_id( $base_id ); unset( $element['settings'][ $control_id ] ); } return $element; } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler */ public function run( $record, $ajax_handler ) { $settings = $record->get( 'form_settings' ); $send_html = 'plain' !== $settings[ $this->get_control_id( 'email_content_type' ) ]; $line_break = $send_html ? '<br>' : "\n"; $fields = [ 'email_to' => get_option( 'admin_email' ), /* translators: %s: Site title. */ 'email_subject' => sprintf( esc_html__( 'New message from "%s"', 'elementor-pro' ), get_bloginfo( 'name' ) ), 'email_content' => '[all-fields]', 'email_from_name' => get_bloginfo( 'name' ), 'email_from' => get_bloginfo( 'admin_email' ), 'email_reply_to' => 'noreply@' . Utils::get_site_domain(), 'email_to_cc' => '', 'email_to_bcc' => '', ]; foreach ( $fields as $key => $default ) { $setting = trim( $settings[ $this->get_control_id( $key ) ] ); $setting = $record->replace_setting_shortcodes( $setting ); if ( ! empty( $setting ) ) { $fields[ $key ] = $setting; } } $email_reply_to = $this->get_reply_to( $record, $fields ); $fields['email_content'] = $this->replace_content_shortcodes( $fields['email_content'], $record, $line_break ); $email_meta = ''; $form_metadata_settings = $settings[ $this->get_control_id( 'form_metadata' ) ]; foreach ( $record->get( 'meta' ) as $id => $field ) { if ( in_array( $id, $form_metadata_settings ) ) { $email_meta .= $this->field_formatted( $field ) . $line_break; } } if ( ! empty( $email_meta ) ) { $fields['email_content'] .= $line_break . '---' . $line_break . $line_break . $email_meta; } $headers = sprintf( 'From: %s <%s>' . "\r\n", $fields['email_from_name'], $fields['email_from'] ); $headers .= sprintf( 'Reply-To: %s' . "\r\n", $email_reply_to ); if ( $send_html ) { $headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n"; } $cc_header = ''; if ( ! empty( $fields['email_to_cc'] ) ) { $cc_header = 'Cc: ' . $fields['email_to_cc'] . "\r\n"; } /** * Email headers. * * Filters the headers sent when an email is send from Elementor forms. This * hook allows developers to alter email headers triggered by Elementor forms. * * @since 1.0.0 * * @param string|array $headers Additional headers. */ $headers = apply_filters( 'elementor_pro/forms/wp_mail_headers', $headers ); /** * Email content. * * Filters the content of the email sent by Elementor forms. This hook allows * developers to alter the content of the email sent by Elementor forms. * * @since 1.0.0 * * @param string $email_content Email content. */ $fields['email_content'] = apply_filters( 'elementor_pro/forms/wp_mail_message', $fields['email_content'] ); $email_sent = wp_mail( $fields['email_to'], $fields['email_subject'], $fields['email_content'], $headers . $cc_header ); if ( ! empty( $fields['email_to_bcc'] ) ) { $bcc_emails = explode( ',', $fields['email_to_bcc'] ); foreach ( $bcc_emails as $bcc_email ) { wp_mail( trim( $bcc_email ), $fields['email_subject'], $fields['email_content'], $headers ); } } /** * Elementor form mail sent. * * Fires when an email was sent successfully by Elementor forms. This * hook allows developers to add functionality after mail sending. * * @since 1.0.0 * * @param array $settings Form settings. * @param Form_Record $record An instance of the form record. */ do_action( 'elementor_pro/forms/mail_sent', $settings, $record ); if ( ! $email_sent ) { $message = Ajax_Handler::get_default_message( Ajax_Handler::SERVER_ERROR, $settings ); $ajax_handler->add_error_message( $message ); throw new \Exception( $message ); } } private function field_formatted( $field ) { $formatted = ''; if ( ! empty( $field['title'] ) ) { $formatted = sprintf( '%s: %s', $field['title'], $field['value'] ); } elseif ( ! empty( $field['value'] ) ) { $formatted = sprintf( '%s', $field['value'] ); } return $formatted; } // Allow overwrite the control_id with a prefix, @see Email2 protected function get_control_id( $control_id ) { return $control_id; } protected function get_reply_to( $record, $fields ) { $email_reply_to = ''; if ( ! empty( $fields['email_reply_to'] ) ) { $sent_data = $record->get( 'sent_data' ); foreach ( $record->get( 'fields' ) as $field_index => $field ) { if ( $field_index === $fields['email_reply_to'] && ! empty( $sent_data[ $field_index ] ) && is_email( $sent_data[ $field_index ] ) ) { $email_reply_to = $sent_data[ $field_index ]; break; } } } return $email_reply_to; } /** * @param string $email_content * @param Form_Record $record * * @return string */ private function replace_content_shortcodes( $email_content, $record, $line_break ) { $email_content = do_shortcode( $email_content ); $all_fields_shortcode = '[all-fields]'; if ( false !== strpos( $email_content, $all_fields_shortcode ) ) { $text = ''; foreach ( $record->get( 'fields' ) as $field ) { $formatted = $this->field_formatted( $field ); if ( ( 'textarea' === $field['type'] ) && ( '<br>' === $line_break ) ) { $formatted = str_replace( [ "\r\n", "\n", "\r" ], '<br />', $formatted ); } $text .= $formatted . $line_break; } $email_content = str_replace( $all_fields_shortcode, $text, $email_content ); } return $email_content; } } mailchimp.php 0000666 00000031254 15165307047 0007241 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Modules\Forms\Classes\Ajax_Handler; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Integration_Base; use ElementorPro\Modules\Forms\Classes\Mailchimp_Handler; use Elementor\Settings; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Mailchimp extends Integration_Base { const OPTION_NAME_API_KEY = 'pro_mailchimp_api_key'; /** * @var string - Mailchimp API key. */ private $api_key; private function get_global_api_key() { return get_option( 'elementor_' . self::OPTION_NAME_API_KEY ); } public function get_name() { return 'mailchimp'; } public function get_label() { return esc_html__( 'MailChimp', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_mailchimp', [ 'label' => esc_html__( 'MailChimp', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); self::global_api_control( $widget, $this->get_global_api_key(), 'MailChimp API Key', [ 'mailchimp_api_key_source' => 'default', ], $this->get_name() ); $widget->add_control( 'mailchimp_api_key_source', [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'label_block' => false, 'options' => [ 'default' => 'Default', 'custom' => 'Custom', ], 'default' => 'default', ] ); $widget->add_control( 'mailchimp_api_key', [ 'label' => esc_html__( 'Custom API Key', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'condition' => [ 'mailchimp_api_key_source' => 'custom', ], 'description' => esc_html__( 'Use this field to set a custom API Key for the current form', 'elementor-pro' ), ] ); $widget->add_control( 'mailchimp_list', [ 'label' => esc_html__( 'Audience', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'options' => [], 'render_type' => 'none', 'conditions' => [ 'relation' => 'or', 'terms' => [ [ 'name' => 'mailchimp_api_key', 'operator' => '!==', 'value' => '', ], [ 'name' => 'mailchimp_api_key_source', 'operator' => '=', 'value' => 'default', ], ], ], ] ); $widget->add_control( 'mailchimp_groups', [ 'label' => esc_html__( 'Groups', 'elementor-pro' ), 'type' => Controls_Manager::SELECT2, 'options' => [], 'label_block' => true, 'multiple' => true, 'render_type' => 'none', 'condition' => [ 'mailchimp_list!' => '', ], ] ); $widget->add_control( 'mailchimp_tags', [ 'label' => esc_html__( 'Tags', 'elementor-pro' ), 'description' => esc_html__( 'Add comma separated tags', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'render_type' => 'none', 'condition' => [ 'mailchimp_list!' => '', ], ] ); $widget->add_control( 'mailchimp_double_opt_in', [ 'label' => esc_html__( 'Double Opt-In', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'default' => '', 'condition' => [ 'mailchimp_list!' => '', ], ] ); $this->register_fields_map_control( $widget ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['settings']['mailchimp_api_key_source'], $element['settings']['mailchimp_api_key'], $element['settings']['mailchimp_list'], $element['settings']['mailchimp_groups'], $element['settings']['mailchimp_fields_map'] ); return $element; } public function run( $record, $ajax_handler ) { $form_settings = $record->get( 'form_settings' ); if ( 'default' === $form_settings['mailchimp_api_key_source'] ) { $this->api_key = $this->get_global_api_key(); } else { $this->api_key = $form_settings['mailchimp_api_key']; } // Data from the form in the frontend. $subscriber_data = $this->map_fields( $record ); // Create or update a subscriber. $subscriber = $this->create_or_update_subscriber( $subscriber_data, $form_settings ); // Parse the Mailchimp tags. $tags = $this->parse_tags( $form_settings['mailchimp_tags'] ); // Set the subscriber tags only if he doesn't have them already. if ( ! $this->subscriber_has_tags( $subscriber, $tags ) ) { $this->set_subscriber_tags( $subscriber, $tags ); } } /** * @param string $tags - List of comma separated tags from the forms settings ( i.e. 'tag-1, tag-2' ). * * @return array|string[] - Array of tags that were extracted from the input ( i.e. [ 'tag-1', 'tag-2' ] ). */ private function parse_tags( $tags ) { $parsed_tags = []; if ( ! empty( $tags ) ) { $parsed_tags = explode( ',', trim( $tags ) ); // Remove empty tags. $parsed_tags = array_filter( $parsed_tags ); // Trim tags. $parsed_tags = array_map( 'trim', $parsed_tags ); } return $parsed_tags; } /** * Determine if a subscriber has specific tags, and ONLY those tags. * * @param array $subscriber - Subscriber data from an API response. * @param array $tags - List of tags to check ( i.e. [ 'tag-1', 'tag-2' ] ). * * @return bool */ private function subscriber_has_tags( array $subscriber, array $tags ) { // Extract current tags. $subscriber_tags = []; foreach ( $subscriber['tags'] as $tag ) { $subscriber_tags[] = $tag['name']; } return array_diff( $tags, $subscriber_tags ) === array_diff( $subscriber_tags, $tags ); } /** * Set Mailchimp subscriber tags. * * @param array $subscriber - Subscriber data from a create/update request. * @param array $tags - List of tags to set. * * @return void */ private function set_subscriber_tags( array $subscriber, array $tags ) { // Build the request tags. $request_tags = []; // Set current tags to active. foreach ( $subscriber['tags'] as $tag ) { $request_tags[] = [ 'name' => $tag['name'], 'status' => 'active', ]; } // Set new tags to active. foreach ( $tags as $tag ) { $request_tags[] = [ 'name' => $tag, 'status' => 'active', ]; } // Send the API request. $endpoint = sprintf( 'lists/%s/members/%s/tags', $subscriber['list_id'], md5( strtolower( $subscriber['email_address'] ) ) ); $args = [ 'tags' => $request_tags, ]; $handler = new Mailchimp_Handler( $this->api_key ); $response = $handler->post( $endpoint, $args ); if ( 204 !== $response['code'] ) { $error = ! empty( $response['body']['detail'] ) ? $response['body']['detail'] : ''; $code = $response['code']; throw new \Exception( "HTTP {$code} - {$error}" ); } } /** * Get Mailchimp subscriber data. * * @param string $list - Mailchimp List ID. * @param string $email_hash - Subscriber's email hash (lowercase + MD5). * * @return array|null */ private function get_subscriber_data( $list, $email_hash ) { $handler = new Mailchimp_Handler( $this->api_key ); $end_point = sprintf( 'lists/%s/members/%s', $list, $email_hash ); try { return $handler->query( $end_point ); } catch ( \Exception $e ) { return null; } } /** * Set Mailchimp subscriber data. * * @param string $list - Mailchimp List ID. * @param string $email_hash - Subscriber's email hash (lowercase + MD5). * @param array $data - New subscriber data to set. * * @return array */ private function set_subscriber_data( $list, $email_hash, $data ) { $handler = new Mailchimp_Handler( $this->api_key ); $end_point = sprintf( 'lists/%s/members/%s', $list, $email_hash ); $response = $handler->post( $end_point, $data, [ 'method' => 'PUT', // Add or Update ] ); if ( 200 !== $response['code'] ) { $error = ! empty( $response['body']['detail'] ) ? $response['body']['detail'] : ''; $code = $response['code']; throw new \Exception( "HTTP {$code} - {$error}" ); } return $response['body']; } /** * Create or update a Mailchimp subscriber. * * @param array $subscriber - Subscriber data from the form in the frontend. * @param array $form_settings - Settings from the editor. * * @return array - An array that contains the newly created subscriber's data. */ private function create_or_update_subscriber( array $subscriber, array $form_settings ) { if ( ! empty( $form_settings['mailchimp_groups'] ) ) { $subscriber['interests'] = []; } if ( is_array( $form_settings['mailchimp_groups'] ) ) { foreach ( $form_settings['mailchimp_groups'] as $mailchimp_group ) { $subscriber['interests'][ $mailchimp_group ] = true; } } if ( ! empty( $form_settings['mailchimp_tags'] ) ) { $subscriber['tags'] = explode( ',', trim( $form_settings['mailchimp_tags'] ) ); } $list = $form_settings['mailchimp_list']; $email_hash = md5( strtolower( $subscriber['email_address'] ) ); $double_opt_in = ( 'yes' === $form_settings['mailchimp_double_opt_in'] ); $subscriber['status_if_new'] = $double_opt_in ? 'pending' : 'subscribed'; if ( $double_opt_in ) { $subscriber_data = $this->get_subscriber_data( $list, $email_hash ); // Change the current status only if the user isn't subscribed already. if ( $subscriber_data && 'subscribed' !== $subscriber_data['status'] ) { $subscriber['status'] = 'pending'; } } else { $subscriber['status'] = 'subscribed'; } return $this->set_subscriber_data( $list, $email_hash, $subscriber ); } /** * @param Form_Record $record * * @return array */ private function map_fields( $record ) { $subscriber = []; $fields = $record->get( 'fields' ); // Other form has a field mapping foreach ( $record->get_form_settings( 'mailchimp_fields_map' ) as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } $value = $fields[ $map_item['local_id'] ]['value']; if ( 'email' === $map_item['remote_id'] ) { $subscriber['email_address'] = $value; } else { $subscriber['merge_fields'][ $map_item['remote_id'] ] = $value; } } return $subscriber; } public function ajax_validate_api_token() { check_ajax_referer( self::OPTION_NAME_API_KEY, '_nonce' ); if ( ! isset( $_POST['api_key'] ) ) { wp_send_json_error(); } try { new Mailchimp_Handler( $_POST['api_key'] ); // phpcs:ignore -- No need to sanitize to support special characters. } catch ( \Exception $exception ) { wp_send_json_error(); } wp_send_json_success(); } /** * @param array $data * * @return array * @throws \Exception */ public function handle_panel_request( array $data ) { if ( ! empty( $data['use_global_api_key'] ) && 'default' === $data['use_global_api_key'] ) { $api_key = $this->get_global_api_key(); } elseif ( ! empty( $data['api_key'] ) ) { $api_key = $data['api_key']; } if ( empty( $api_key ) ) { throw new \Exception( '`api_key` is required.', 400 ); } $handler = new Mailchimp_Handler( $api_key ); switch ( $data['mailchimp_action'] ) { case 'lists': return $handler->get_lists(); case 'fields': return $handler->get_fields( $data['mailchimp_list'] ); case 'groups': return $handler->get_groups( $data['mailchimp_list'] ); default: return $handler->get_list_details( $data['mailchimp_list'] ); } } public function register_admin_fields( Settings $settings ) { $settings->add_section( Settings::TAB_INTEGRATIONS, 'mailchimp', [ 'callback' => function() { echo '<hr><h2>' . esc_html__( 'MailChimp', 'elementor-pro' ) . '</h2>'; }, 'fields' => [ self::OPTION_NAME_API_KEY => [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'field_args' => [ 'type' => 'text', 'desc' => sprintf( /* translators: 1: Link opening tag, 2: Link closing tag. */ esc_html__( 'To integrate with our forms you need an %1$sAPI Key%2$s.', 'elementor-pro' ), '<a href="https://kb.mailchimp.com/integrations/api-integrations/about-api-keys" target="_blank">', '</a>' ), ], ], 'validate_api_data' => [ 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '<button data-action="%s" data-nonce="%s" class="button elementor-button-spinner" id="elementor_pro_mailchimp_api_key_button">%s</button>', self::OPTION_NAME_API_KEY . '_validate', wp_create_nonce( self::OPTION_NAME_API_KEY ), esc_html__( 'Validate API Key', 'elementor-pro' ) ), ], ], ], ] ); } public function __construct() { if ( is_admin() ) { add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 14 ); } add_action( 'wp_ajax_' . self::OPTION_NAME_API_KEY . '_validate', [ $this, 'ajax_validate_api_token' ] ); } protected function get_fields_map_control_options() { return [ 'condition' => [ 'mailchimp_list!' => '', ], ]; } } mailpoet.php 0000666 00000005646 15165307047 0007116 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Integration_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Mailpoet extends Integration_Base { public function get_name() { return 'mailpoet'; } public function get_label() { return 'MailPoet'; } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_mailpoet', [ 'label' => esc_html__( 'MailPoet', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); /** @var \WYSIJA_model_list $model_list */ $model_list = \WYSIJA::get( 'list', 'model' ); $mailpoet_lists = $model_list->get( [ 'name', 'list_id' ], [ 'is_enabled' => 1 ] ); $options = []; foreach ( $mailpoet_lists as $list ) { $options[ $list['list_id'] ] = $list['name']; } $widget->add_control( 'mailpoet_lists', [ 'label' => esc_html__( 'List', 'elementor-pro' ), 'type' => Controls_Manager::SELECT2, 'label_block' => true, 'options' => $options, 'render_type' => 'none', ] ); $this->register_fields_map_control( $widget ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['mailpoet_lists'] ); return $element; } public function run( $record, $ajax_handler ) { $subscriber = $this->map_fields( $record ); /** @var \WYSIJA_help_user $helper_user */ $helper_user = \WYSIJA::get( 'user', 'helper' ); $helper_user->addSubscriber( $subscriber ); } /** * @param Form_Record $record * * @return array */ private function map_fields( $record ) { $settings = $record->get( 'form_settings' ); $fields = $record->get( 'fields' ); $subscriber = [ 'user' => [ 'email' => '', ], 'user_list' => [ 'list_ids' => (array) $settings['mailpoet_lists'] ], ]; foreach ( $settings['mailpoet_fields_map'] as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } $value = $fields[ $map_item['local_id'] ]['value']; if ( 'email' === $map_item['remote_id'] ) { $subscriber['user']['email'] = $value; } else { $subscriber['user'][ $map_item['remote_id'] ] = $value; } } return $subscriber; } protected function get_fields_map_control_options() { return [ 'default' => [ [ 'remote_id' => 'firstname', 'remote_label' => esc_html__( 'First Name', 'elementor-pro' ), 'remote_type' => 'text', ], [ 'remote_id' => 'lastname', 'remote_label' => esc_html__( 'Last Name', 'elementor-pro' ), 'remote_type' => 'text', ], [ 'remote_id' => 'email', 'remote_label' => esc_html__( 'Email', 'elementor-pro' ), 'remote_type' => 'email', 'remote_required' => true, ], ], 'condition' => [ 'mailpoet_lists!' => '', ], ]; } } convertkit.php 0000666 00000016166 15165307047 0007473 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Integration_Base; use ElementorPro\Modules\Forms\Classes\Convertkit_Handler; use ElementorPro\Core\Utils; use Elementor\Settings; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Convertkit extends Integration_Base { const OPTION_NAME_API_KEY = 'pro_convertkit_api_key'; private function get_global_api_key() { return get_option( 'elementor_' . self::OPTION_NAME_API_KEY ); } public function get_name() { return 'convertkit'; } public function get_label() { return esc_html__( 'ConvertKit', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_convertkit', [ 'label' => esc_html__( 'ConvertKit', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); self::global_api_control( $widget, $this->get_global_api_key(), 'ConvertKit API key', [ 'convertkit_api_key_source' => 'default', ], $this->get_name() ); $widget->add_control( 'convertkit_api_key_source', [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'label_block' => false, 'options' => [ 'default' => 'Default', 'custom' => 'Custom', ], 'default' => 'default', ] ); $widget->add_control( 'convertkit_custom_api_key', [ 'label' => esc_html__( 'Custom API Key', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'description' => esc_html__( 'Use this field to set a custom API Key for the current form', 'elementor-pro' ), 'condition' => [ 'convertkit_api_key_source' => 'custom', ], ] ); $widget->add_control( 'convertkit_form', [ 'label' => esc_html__( 'Form', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'options' => [], 'render_type' => 'none', 'conditions' => [ 'relation' => 'or', 'terms' => [ [ 'name' => 'convertkit_custom_api_key', 'operator' => '!==', 'value' => '', ], [ 'name' => 'convertkit_api_key_source', 'operator' => '=', 'value' => 'default', ], ], ], ] ); $this->register_fields_map_control( $widget ); $widget->add_control( 'convertkit_tags', [ 'label' => esc_html__( 'Tags', 'elementor-pro' ), 'type' => Controls_Manager::SELECT2, 'options' => [], 'multiple' => true, 'render_type' => 'none', 'label_block' => true, 'condition' => [ 'convertkit_form!' => '', ], ] ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['settings']['convertkit_api_key_source'], $element['settings']['convertkit_custom_api_key'], $element['settings']['convertkit_form'], $element['settings']['convertkit_fields_map'] ); return $element; } public function run( $record, $ajax_handler ) { $form_settings = $record->get( 'form_settings' ); $subscriber = $this->create_subscriber_object( $record ); if ( ! $subscriber ) { throw new \Exception( 'Integration requires an email field.' ); } if ( 'default' === $form_settings['convertkit_api_key_source'] ) { $api_key = $this->get_global_api_key(); } else { $api_key = $form_settings['convertkit_custom_api_key']; } if ( '' !== $form_settings['convertkit_tags'] ) { $subscriber['tags'] = $form_settings['convertkit_tags']; } $handler = new ConvertKit_Handler( $api_key ); $handler->create_subscriber( $form_settings['convertkit_form'], $subscriber ); } /** * Create subscriber array from submitted data and form settings * returns a subscriber array or false on error * * @param Form_Record $record * * @return array|bool */ private function create_subscriber_object( Form_Record $record ) { $subscriber = $this->map_fields( $record ); if ( ! isset( $subscriber['email'] ) ) { return false; } $subscriber['ipAddress'] = Utils::get_client_ip(); return $subscriber; } /** * @param Form_Record $record * * @return array */ private function map_fields( Form_Record $record ) { $subscriber = []; $fields = $record->get( 'fields' ); // Other form has a field mapping foreach ( $record->get_form_settings( 'convertkit_fields_map' ) as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } $value = $fields[ $map_item['local_id'] ]['value']; if ( in_array( $map_item['remote_id'], [ 'first_name', 'email' ] ) ) { $subscriber[ $map_item['remote_id'] ] = $value; continue; } } return $subscriber; } /** * @param array $data * * @return array * @throws \Exception */ public function handle_panel_request( array $data ) { if ( ! empty( $data['api_key'] ) && 'default' === $data['api_key'] ) { $api_key = $this->get_global_api_key(); } elseif ( ! empty( $data['custom_api_key'] ) ) { $api_key = $data['custom_api_key']; } if ( empty( $api_key ) ) { throw new \Exception( '`api_key` is required.', 400 ); } $handler = new Convertkit_Handler( $api_key ); return $handler->get_forms_and_tags(); } public function ajax_validate_api_token() { check_ajax_referer( self::OPTION_NAME_API_KEY, '_nonce' ); if ( ! isset( $_POST['api_key'] ) ) { wp_send_json_error(); } try { new Convertkit_Handler( $_POST['api_key'] ); // phpcs:ignore -- No need to sanitize to support special characters. } catch ( \Exception $exception ) { wp_send_json_error(); } wp_send_json_success(); } public function register_admin_fields( Settings $settings ) { $settings->add_section( Settings::TAB_INTEGRATIONS, 'convertkit', [ 'callback' => function() { echo '<hr><h2>' . esc_html__( 'ConvertKit', 'elementor-pro' ) . '</h2>'; }, 'fields' => [ self::OPTION_NAME_API_KEY => [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'field_args' => [ 'type' => 'text', 'desc' => sprintf( /* translators: 1: Link opening tag, 2: Link closing tag. */ esc_html__( 'To integrate with our forms you need an %1$sAPI Key%2$s.', 'elementor-pro' ), '<a href="https://app.convertkit.com/account/edit" target="_blank">', '</a>' ), ], ], 'validate_api_data' => [ 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '<button data-action="%s" data-nonce="%s" class="button elementor-button-spinner" id="elementor_pro_convertkit_api_key_button">%s</button>', self::OPTION_NAME_API_KEY . '_validate', wp_create_nonce( self::OPTION_NAME_API_KEY ), esc_html__( 'Validate API Key', 'elementor-pro' ) ), ], ], ], ] ); } public function __construct() { if ( is_admin() ) { add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 15 ); } add_action( 'wp_ajax_' . self::OPTION_NAME_API_KEY . '_validate', [ $this, 'ajax_validate_api_token' ] ); } protected function get_fields_map_control_options() { return [ 'condition' => [ 'convertkit_form!' => '', ], ]; } } activity-log.php 0000666 00000001714 15165307047 0007707 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use ElementorPro\Modules\Forms\Classes\Action_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Integration with Activity Log */ class Activity_Log extends Action_Base { public function get_name() { return 'activity-log'; } public function get_label() { return 'Activity Log'; } public function register_settings_section( $widget ) {} public function on_export( $element ) {} public function aal_init_roles( $roles ) { $roles['manage_options'][] = 'Elementor Forms'; return $roles; } public function run( $record, $ajax_handler ) { aal_insert_log( [ 'action' => 'New Record', 'object_type' => 'Elementor Forms', 'object_id' => $record->get_form_settings( 'id' ), 'object_name' => $record->get_form_settings( 'form_name' ), ] ); } public function __construct() { add_filter( 'aal_init_roles', [ $this, 'aal_init_roles' ] ); } } mailerlite.php 0000666 00000017360 15165307047 0007427 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use Elementor\Settings; use ElementorPro\Core\Utils; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Mailerlite_Handler; use ElementorPro\Modules\Forms\Classes\Integration_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Mailerlite extends Integration_Base { const OPTION_NAME_API_KEY = 'pro_mailerlite_api_key'; private function get_global_api_key() { return get_option( 'elementor_' . self::OPTION_NAME_API_KEY ); } public function get_name() { return 'mailerlite'; } public function get_label() { return esc_html__( 'MailerLite', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_mailerlite', [ 'label' => esc_html__( 'MailerLite', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); self::global_api_control( $widget, $this->get_global_api_key(), 'MailerLite API Key', [ 'mailerlite_api_key_source' => 'default', ], $this->get_name() ); $widget->add_control( 'mailerlite_api_key_source', [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'label_block' => false, 'options' => [ 'default' => 'Default', 'custom' => 'Custom', ], 'default' => 'default', ] ); $widget->add_control( 'mailerlite_custom_api_key', [ 'label' => esc_html__( 'Custom API Key', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'condition' => [ 'mailerlite_api_key_source' => 'custom', ], 'description' => esc_html__( 'Use this field to set a custom API Key for the current form', 'elementor-pro' ), ] ); $widget->add_control( 'mailerlite_group', [ 'label' => esc_html__( 'Group', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'options' => [], 'render_type' => 'none', 'conditions' => [ 'relation' => 'or', 'terms' => [ [ 'name' => 'mailerlite_custom_api_key', 'operator' => '!==', 'value' => '', ], [ 'name' => 'mailerlite_api_key_source', 'operator' => '=', 'value' => 'default', ], ], ], ] ); $this->register_fields_map_control( $widget ); $widget->add_control( 'allow_resubscribe', [ 'label' => esc_html__( 'Allow Resubscribe', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'condition' => [ 'mailerlite_group!' => '', ], ] ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['settings']['mailerlite_api_key_source'], $element['settings']['mailerlite_custom_api_key'], $element['settings']['mailerlite_group'], $element['settings']['mailerlite_fields_map'] ); return $element; } public function run( $record, $ajax_handler ) { $form_settings = $record->get( 'form_settings' ); $subscriber = $this->create_subscriber_object( $record ); if ( ! $subscriber ) { new \Exception( esc_html__( 'Integration requires an email field', 'elementor-pro' ) ); } if ( 'default' === $form_settings['mailerlite_api_key_source'] ) { $api_key = $this->get_global_api_key(); } else { $api_key = $form_settings['mailerlite_custom_api_key']; } $handler = new Mailerlite_Handler( $api_key ); $handler->create_subscriber( $form_settings['mailerlite_group'], $subscriber ); } /** * Create subscriber array from submitted data and form settings * returns a subscriber array or false on error * * @param Form_Record $record * * @return array|bool */ private function create_subscriber_object( Form_Record $record ) { $email = $this->get_mapped_field( $record, 'email' ); if ( ! $email ) { return false; } $subscriber = [ 'email' => $email, 'name' => $this->get_mapped_field( $record, 'name' ), ]; $subscriber['fields'] = $this->get_mailerlite_custom_fields( $record ); // Allow re-subscribe $allow_resubscribe = $record->get_form_settings( 'allow_resubscribe' ); if ( ! empty( $allow_resubscribe ) && 'yes' === $allow_resubscribe ) { $subscriber['resubscribe'] = true; } return $subscriber; } /** * @param Form_Record $record * * @return array */ private function get_mailerlite_custom_fields( Form_Record $record ) { $custom_fields = []; $form_fields = $record->get( 'fields' ); $field_mapping = $record->get_form_settings( 'mailerlite_fields_map' ); foreach ( $field_mapping as $map_item ) { if ( in_array( $map_item['remote_id'], [ 'email', 'name' ] ) ) { continue; } if ( empty( $map_item['local_id'] ) ) { continue; } foreach ( $form_fields as $id => $field ) { if ( $id !== $map_item['local_id'] ) { continue; } $custom_fields[ $map_item['remote_id'] ] = $field['value']; } } return $custom_fields; } private function get_mapped_field( Form_Record $record, $field_id ) { $fields = $record->get( 'fields' ); foreach ( $record->get_form_settings( 'mailerlite_fields_map' ) as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } if ( $field_id === $map_item['remote_id'] ) { return $fields[ $map_item['local_id'] ]['value']; } } return ''; } public function handle_panel_request( array $data ) { if ( ! empty( $data['api_key'] ) && 'default' === $data['api_key'] ) { $api_key = $this->get_global_api_key(); } elseif ( ! empty( $data['custom_api_key'] ) ) { $api_key = $data['custom_api_key']; } if ( empty( $api_key ) ) { throw new \Exception( '`api_key` is required.', 400 ); } $handler = new Mailerlite_Handler( $api_key ); if ( 'groups' === $data['mailerlite_action'] ) { return $handler->get_groups(); } } public function register_admin_fields( Settings $settings ) { $settings->add_section( Settings::TAB_INTEGRATIONS, 'mailerlite', [ 'callback' => function() { echo '<hr><h2>' . esc_html__( 'MailerLite', 'elementor-pro' ) . '</h2>'; }, 'fields' => [ self::OPTION_NAME_API_KEY => [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'field_args' => [ 'type' => 'text', 'desc' => sprintf( /* translators: 1: Link opening tag, 2: Link closing tag. */ esc_html__( 'To integrate with our forms you need an %1$sAPI Key%2$s.', 'elementor-pro' ), '<a href="https://help.mailerlite.com/article/show/35040-where-can-i-find-the-api-key" target="_blank">', '</a>' ), ], ], 'validate_api_data' => [ 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '<button data-action="%s" data-nonce="%s" class="button elementor-button-spinner" id="elementor_pro_mailerlite_api_key_button">%s</button>', self::OPTION_NAME_API_KEY . '_validate', wp_create_nonce( self::OPTION_NAME_API_KEY ), esc_html__( 'Validate API Key', 'elementor-pro' ) ), ], ], ], ] ); } public function ajax_validate_api_key() { check_ajax_referer( self::OPTION_NAME_API_KEY, '_nonce' ); if ( ! isset( $_POST['api_key'] ) ) { wp_send_json_error(); } try { new Mailerlite_Handler( $_POST['api_key'] ); // phpcs:ignore -- No need to sanitize to support special characters. } catch ( \Exception $exception ) { wp_send_json_error(); } wp_send_json_success(); } public function __construct() { if ( is_admin() ) { add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 15 ); } add_action( 'wp_ajax_' . self::OPTION_NAME_API_KEY . '_validate', [ $this, 'ajax_validate_api_key' ] ); } protected function get_fields_map_control_options() { return [ 'condition' => [ 'mailerlite_group!' => '', ], ]; } } getresponse.php 0000666 00000021133 15165307047 0007627 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Integration_Base; use ElementorPro\Modules\Forms\Classes\Getresponse_Handler; use ElementorPro\Core\Utils; use Elementor\Settings; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Getresponse extends Integration_Base { const OPTION_NAME_API_KEY = 'pro_getresponse_api_key'; private function get_global_api_key() { return get_option( 'elementor_' . self::OPTION_NAME_API_KEY, '' ); } public function get_name() { return 'getresponse'; } public function get_label() { return esc_html__( 'GetResponse', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_getresponse', [ 'label' => esc_html__( 'GetResponse', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); self::global_api_control( $widget, $this->get_global_api_key(), 'GetResponse API key', [ 'getresponse_api_key_source' => 'default', ], $this->get_name() ); $widget->add_control( 'getresponse_api_key_source', [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'label_block' => false, 'options' => [ 'default' => 'Default', 'custom' => 'Custom', ], 'default' => 'default', ] ); $widget->add_control( 'getresponse_custom_api_key', [ 'label' => esc_html__( 'Custom API Key', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'description' => esc_html__( 'Use this field to set a custom API Key for the current form', 'elementor-pro' ), 'condition' => [ 'getresponse_api_key_source' => 'custom', ], ] ); $widget->add_control( 'getresponse_list', [ 'label' => esc_html__( 'List', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'options' => [], 'render_type' => 'none', 'conditions' => [ 'relation' => 'or', 'terms' => [ [ 'name' => 'getresponse_custom_api_key', 'operator' => '!==', 'value' => '', ], [ 'name' => 'getresponse_api_key_source', 'operator' => '=', 'value' => 'default', ], ], ], ] ); $widget->add_control( 'getresponse_dayofcycle', [ 'label' => esc_html__( 'Day Of Cycle', 'elementor-pro' ), 'type' => Controls_Manager::NUMBER, 'min' => 0, 'condition' => [ 'getresponse_list!' => '', ], ] ); $this->register_fields_map_control( $widget ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['settings']['getresponse_api_key_source'], $element['settings']['getresponse_custom_api_key'], $element['settings']['getresponse_list'], $element['settings']['getresponse_fields_map'] ); return $element; } public function run( $record, $ajax_handler ) { $form_settings = $record->get( 'form_settings' ); $subscriber = $this->create_subscriber_object( $record ); if ( ! $subscriber ) { throw new \Exception( 'Integration requires an email field.' ); } if ( 'default' === $form_settings['getresponse_api_key_source'] ) { $api_key = $this->get_global_api_key(); } else { $api_key = $form_settings['getresponse_custom_api_key']; } try { $handler = new Getresponse_Handler( $api_key ); $handler->create_subscriber( $subscriber ); } catch ( \Exception $exception ) { foreach ( (array) $handler->rest_client->request_cache as $response ) { if ( isset( $response['parsed'] ) || ! isset( $response['raw'] ) || ! isset( $response['raw']['response'] ) || ! isset( $response['raw']['response']['code'] ) ) { continue; } if ( ! in_array( $response['raw']['response']['code'], [ 200, 202, 409 ] ) ) { throw new \Exception( $exception->getMessage() ); } } } } /** * Create subscriber array from submitted data and form settings * returns a subscriber array or false on error * * @param Form_Record $record * * @return array|bool */ private function create_subscriber_object( Form_Record $record ) { $form_settings = $record->get( 'form_settings' ); $subscriber = $this->map_fields( $record ); if ( ! isset( $subscriber['email'] ) ) { return false; } if ( isset( $form_settings['getresponse_dayofcycle'] ) ) { $subscriber['dayOfCycle'] = intval( $form_settings['getresponse_dayofcycle'] ); } $subscriber['ipAddress'] = Utils::get_client_ip(); $subscriber['campaign'] = [ 'campaignId' => $form_settings['getresponse_list'] ]; return $subscriber; } /** * @param Form_Record $record * * @return array */ private function get_getresponse_custom_fields( Form_Record $record ) { $local_email_id = ''; $local_name_id = ''; foreach ( $record->get_form_settings( 'getresponse_fields_map' ) as $map_item ) { if ( 'email' === $map_item['remote_id'] ) { $local_email_id = $map_item['local_id']; } if ( 'name' === $map_item['remote_id'] ) { $local_name_id = $map_item['local_id']; } } $custom_fields = []; foreach ( $record->get( 'fields' ) as $id => $field ) { if ( in_array( $id, [ $local_email_id, $local_name_id ] ) ) { continue; } $custom_fields[ $id ] = $field['value']; } return $custom_fields; } /** * @param Form_Record $record * * @return array */ private function map_fields( Form_Record $record ) { $subscriber = []; $custom_fields = []; $fields = $record->get( 'fields' ); // Other form has a field mapping foreach ( $record->get_form_settings( 'getresponse_fields_map' ) as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } $value = $fields[ $map_item['local_id'] ]['value']; if ( in_array( $map_item['remote_id'], [ 'name', 'email' ] ) ) { $subscriber[ $map_item['remote_id'] ] = $value; continue; } $custom_fields[] = [ 'customFieldId' => $map_item['remote_id'], 'value' => [ $value ], ]; } $subscriber['customFieldValues'] = $custom_fields; return $subscriber; } /** * @param array $data * * @return array * @throws \Exception */ public function handle_panel_request( array $data ) { if ( ! empty( $data['api_key'] ) && 'default' === $data['api_key'] ) { $api_key = $this->get_global_api_key(); } elseif ( ! empty( $data['custom_api_key'] ) ) { $api_key = $data['custom_api_key']; } if ( empty( $api_key ) ) { throw new \Exception( '`api_key` is required.', 400 ); } $handler = new Getresponse_Handler( $api_key ); if ( 'lists' === $data['getresponse_action'] ) { return $handler->get_lists(); } return $handler->get_fields(); } public function ajax_validate_api_token() { check_ajax_referer( self::OPTION_NAME_API_KEY, '_nonce' ); if ( ! isset( $_POST['api_key'] ) ) { wp_send_json_error(); } try { new Getresponse_Handler( $_POST['api_key'] ); // phpcs:ignore -- No need to sanitize to support special characters. } catch ( \Exception $exception ) { wp_send_json_error(); } wp_send_json_success(); } public function register_admin_fields( Settings $settings ) { $settings->add_section( Settings::TAB_INTEGRATIONS, 'getresponse', [ 'callback' => function() { echo '<hr><h2>' . esc_html__( 'GetResponse', 'elementor-pro' ) . '</h2>'; }, 'fields' => [ self::OPTION_NAME_API_KEY => [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'field_args' => [ 'type' => 'text', 'desc' => sprintf( /* translators: 1: Link opening tag, 2: Link closing tag. */ esc_html__( 'To integrate with our forms you need an %1$sAPI Key%2$s.', 'elementor-pro' ), '<a href="https://www.getresponse.com" target="_blank">', '</a>' ), ], ], 'validate_api_data' => [ 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '<button data-action="%s" data-nonce="%s" class="button elementor-button-spinner" id="elementor_pro_getresponse_api_key_button">%s</button>', self::OPTION_NAME_API_KEY . '_validate', wp_create_nonce( self::OPTION_NAME_API_KEY ), esc_html__( 'Validate API Key', 'elementor-pro' ) ), ], ], ], ] ); } public function __construct() { if ( is_admin() ) { add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 15 ); } add_action( 'wp_ajax_' . self::OPTION_NAME_API_KEY . '_validate', [ $this, 'ajax_validate_api_token' ] ); } protected function get_fields_map_control_options() { return [ 'condition' => [ 'getresponse_list!' => '', ], ]; } } email2.php 0000666 00000001756 15165307047 0006453 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Email2 extends Email { public function get_name() { return 'email2'; } public function get_label() { return esc_html__( 'Email 2', 'elementor-pro' ); } protected function get_control_id( $control_id ) { return $control_id . '_2'; } protected function get_reply_to( $record, $fields ) { return isset( $fields['email_reply_to'] ) ? $fields['email_reply_to'] : ''; } public function register_settings_section( $widget ) { parent::register_settings_section( $widget ); $admin_email = get_option( 'admin_email' ); $widget->update_control( $this->get_control_id( 'email_reply_to' ), [ 'type' => Controls_Manager::TEXT, 'default' => $admin_email, 'placeholder' => $admin_email, ] ); $widget->update_control( $this->get_control_id( 'form_metadata' ), [ 'default' => [], ] ); } } slack.php 0000666 00000014054 15165307047 0006372 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Core\Utils; use ElementorPro\Modules\Forms\Classes\Action_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Slack extends Action_Base { public function get_name() { return 'slack'; } public function get_label() { return esc_html__( 'Slack', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_slack', [ 'label' => esc_html__( 'Slack', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); $widget->add_control( 'slack_webhook', [ 'label' => esc_html__( 'Webhook URL', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'placeholder' => 'https://hooks.slack.com/services/', 'ai' => [ 'active' => false, ], 'label_block' => true, 'separator' => 'before', 'description' => esc_html__( 'Enter the webhook URL that will receive the form\'s submitted data.', 'elementor-pro' ) . ' ' . sprintf( '<a href="%s" target="_blank">%s</a>.', 'https://slack.com/apps/A0F7XDUAZ-incoming-webhooks/', esc_html__( 'Click here for Instructions', 'elementor-pro' ) ), 'render_type' => 'none', 'classes' => 'elementor-control-direction-ltr', 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'slack_channel', [ 'label' => esc_html__( 'Channel', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'slack_username', [ 'label' => esc_html__( 'Username', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'slack_pretext', [ 'label' => esc_html__( 'Pre Text', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'slack_title', [ 'label' => esc_html__( 'Title', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'slack_text', [ 'label' => esc_html__( 'Description', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, ], ] ); $widget->add_control( 'slack_add_fields', [ 'label' => esc_html__( 'Form Data', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', ] ); $widget->add_control( 'slack_add_ts', [ 'label' => esc_html__( 'Timestamp', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', ] ); $widget->add_control( 'slack_webhook_color', [ 'label' => esc_html__( 'Color', 'elementor-pro' ), 'type' => Controls_Manager::COLOR, 'alpha' => false, 'default' => '#D30C5C', ] ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['slack_add_ts'], $element['slack_add_fields'], $element['slack_webhook_color'], $element['slack_text'], $element['slack_pretext'], $element['slack_title'], $element['slack_username'], $element['slack_webhook'], $element['slack_channel'] ); } public function run( $record, $ajax_handler ) { $settings = $record->get( 'form_settings' ); if ( empty( $settings['slack_webhook'] ) || false === strpos( $settings['slack_webhook'], 'https://hooks.slack.com/services/' ) ) { return; } // Build slack webhook data $webhook_data = [ 'username' => isset( $settings['slack_username'] ) ? $settings['slack_username'] : '', ]; if ( ! empty( $settings['slack_channel'] ) ) { $webhook_data['channel'] = $settings['slack_channel']; } // The nonce already validated // phpcs:ignore WordPress.Security.NonceVerification.Missing $referrer = Utils::_unstable_get_super_global_value( $_POST, 'referrer' ); $attachment = [ 'text' => esc_html__( 'A new Form Submission has been received', 'elementor-pro' ), 'title' => esc_html__( 'A new Submission', 'elementor-pro' ), 'color' => isset( $settings['slack_webhook_color'] ) ? $settings['slack_webhook_color'] : '#D30C5C', 'title_link' => esc_url( $referrer ?? site_url() ), ]; if ( ! empty( $settings['slack_title'] ) ) { $attachment['title'] = $settings['slack_title']; } if ( ! empty( $settings['slack_text'] ) ) { $attachment['text'] = $settings['slack_text']; } if ( ! empty( $settings['slack_pretext'] ) ) { $attachment['pretext'] = $settings['slack_pretext']; } if ( ! empty( $settings['slack_add_fields'] ) && 'yes' === $settings['slack_add_fields'] ) { // prepare Form Data $raw_fields = $record->get( 'fields' ); $fields = []; foreach ( $raw_fields as $id => $field ) { $fields[] = [ 'title' => $field['title'] ? $field['title'] : $id, 'value' => $field['value'], 'short' => false, ]; } $attachment['fields'] = $fields; } if ( ! empty( $settings['slack_add_ts'] ) && 'yes' === $settings['slack_add_ts'] ) { $attachment = array_merge( $attachment, [ 'footer' => sprintf( /* translators: %s: Elementor. */ esc_html__( 'Powered by %s', 'elementor-pro' ), 'Elementor' ), 'footer_icon' => is_ssl() ? ELEMENTOR_ASSETS_URL . 'images/logo-icon.png' : null, 'ts' => time(), ] ); } $webhook_data['attachments'] = [ $attachment ]; $webhook_data = apply_filters( 'elementor_pro/forms/slack/webhook_args', $webhook_data ); $response = wp_remote_post( $settings['slack_webhook'], [ 'headers' => [ 'Content-Type' => 'application/json', ], 'body' => wp_json_encode( $webhook_data ), ] ); if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { throw new \Exception( 'Webhook error.' ); } } } mailpoet3.php 0000666 00000006770 15165307047 0007200 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Integration_Base; use MailPoet\API\API; use MailPoet\Models\Subscriber; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly }; class Mailpoet3 extends Integration_Base { public function get_name() { return 'mailpoet3'; } public function get_label() { return 'MailPoet 3'; } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_mailpoet3', [ 'label' => esc_html__( 'MailPoet 3', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); $mailpoet3_lists = API::MP( 'v1' )->getLists(); $options = []; foreach ( $mailpoet3_lists as $list ) { $options[ $list['id'] ] = $list['name']; } $widget->add_control( 'mailpoet3_lists', [ 'label' => esc_html__( 'List', 'elementor-pro' ), 'type' => Controls_Manager::SELECT2, 'label_block' => true, 'options' => $options, 'render_type' => 'none', ] ); $this->register_fields_map_control( $widget ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['mailpoet3_lists'] ); return $element; } public function run( $record, $ajax_handler ) { $settings = $record->get( 'form_settings' ); $subscriber = $this->map_fields( $record ); $existing_subscriber = false; try { API::MP( 'v1' )->addSubscriber( $subscriber, (array) $settings['mailpoet3_lists'] ); $existing_subscriber = false; } catch ( \Exception $exception ) { $error_string = esc_html__( 'This subscriber already exists.', 'mailpoet' ); // phpcs:ignore WordPress.WP.I18n if ( $error_string === $exception->getMessage() ) { $existing_subscriber = true; } else { throw $exception; } } if ( $existing_subscriber ) { API::MP( 'v1' )->subscribeToLists( $subscriber['email'], (array) $settings['mailpoet3_lists'] ); } } /** * @param Form_Record $record * * @return array */ private function map_fields( $record ) { $settings = $record->get( 'form_settings' ); $fields = $record->get( 'fields' ); $subscriber = []; foreach ( $settings['mailpoet3_fields_map'] as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } $subscriber[ $map_item['remote_id'] ] = $fields[ $map_item['local_id'] ]['value']; } return $subscriber; } protected function get_fields_map_control_options() { $mailpoet_fields = [ [ 'remote_id' => 'first_name', 'remote_label' => esc_html__( 'First Name', 'elementor-pro' ), 'remote_type' => 'text', ], [ 'remote_id' => 'last_name', 'remote_label' => esc_html__( 'Last Name', 'elementor-pro' ), 'remote_type' => 'text', ], [ 'remote_id' => 'email', 'remote_label' => esc_html__( 'Email', 'elementor-pro' ), 'remote_type' => 'email', 'remote_required' => true, ], ]; $fields = API::MP( 'v1' )->getSubscriberFields(); if ( ! empty( $fields ) && is_array( $fields ) ) { foreach ( $fields as $index => $remote ) { if ( in_array( $remote['id'], [ 'first_name', 'last_name', 'email' ] ) ) { continue; } $mailpoet_fields[] = [ 'remote_id' => $remote['id'], 'remote_label' => $remote['name'], 'remote_type' => 'text', ]; } } return [ 'default' => $mailpoet_fields, 'condition' => [ 'mailpoet3_lists!' => '', ], ]; } } drip.php 0000666 00000021070 15165307047 0006227 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use Elementor\Settings; use ElementorPro\Modules\Forms\Classes\Form_Record; use ElementorPro\Modules\Forms\Classes\Integration_Base; use ElementorPro\Modules\Forms\Classes\Drip_Handler; use ElementorPro\Core\Utils; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Drip extends Integration_Base { const OPTION_NAME_API_KEY = 'pro_drip_api_token'; private function get_global_api_key() { return get_option( 'elementor_' . self::OPTION_NAME_API_KEY ); } public function get_name() { return 'drip'; } public function get_label() { return esc_html__( 'Drip', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_drip', [ 'label' => esc_html__( 'Drip', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); self::global_api_control( $widget, $this->get_global_api_key(), 'Drip API Token', [ 'drip_api_token_source' => 'default', ], $this->get_name() ); $widget->add_control( 'drip_api_token_source', [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'label_block' => false, 'options' => [ 'default' => 'Default', 'custom' => 'Custom', ], 'default' => 'default', ] ); $widget->add_control( 'drip_custom_api_token', [ 'label' => esc_html__( 'Custom API Key', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'condition' => [ 'drip_api_token_source' => 'custom', ], 'description' => esc_html__( 'Use this field to set a custom API Key for the current form', 'elementor-pro' ), ] ); $widget->add_control( 'drip_account', [ 'label' => esc_html__( 'Account', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'options' => [], 'render_type' => 'none', 'conditions' => [ 'relation' => 'or', 'terms' => [ [ 'name' => 'drip_custom_api_token', 'operator' => '!==', 'value' => '', ], [ 'name' => 'drip_api_token_source', 'operator' => '=', 'value' => 'default', ], ], ], ] ); $this->register_fields_map_control( $widget ); $widget->add_control( 'drip_custom_field_heading', [ 'label' => esc_html__( 'Send Additional Data to Drip', 'elementor-pro' ), 'type' => Controls_Manager::HEADING, 'condition' => [ 'drip_account!' => '', ], ] ); $widget->add_control( 'drip_custom_fields', [ 'label' => esc_html__( 'Form Fields', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'no', 'description' => esc_html__( 'Send all form fields to drip as custom fields', 'elementor-pro' ), 'condition' => [ 'drip_account!' => '', ], ] ); $widget->add_control( 'tags', [ 'label' => esc_html__( 'Tags', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'description' => esc_html__( 'Add as many tags as you want, comma separated.', 'elementor-pro' ), 'condition' => [ 'drip_account!' => '', ], ] ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['settings']['drip_api_token_source'], $element['settings']['drip_custom_api_token'], $element['settings']['drip_account'], $element['settings']['drip_fields_map'], $element['settings']['tags'], $element['settings']['drip_custom_fields'] ); return $element; } public function run( $record, $ajax_handler ) { $form_settings = $record->get( 'form_settings' ); $subscriber = $this->create_subscriber_object( $record ); if ( ! $subscriber ) { throw new \Exception( 'Integration requires an email field.' ); } if ( 'default' === $form_settings['drip_api_token_source'] ) { $api_key = $this->get_global_api_key(); } else { $api_key = $form_settings['drip_custom_api_token']; } $handler = new Drip_Handler( $api_key ); $handler->create_subscriber( $form_settings['drip_account'], $subscriber ); } /** * Create subscriber array from submitted data and form settings * returns a subscriber array or false on error * * @param Form_Record $record * * @return array|bool */ private function create_subscriber_object( Form_Record $record ) { $form_settings = $record->get( 'form_settings' ); $email = $this->map_email_field( $record ); if ( ! $email ) { return false; } $subscriber = [ 'ip_address' => Utils::get_client_ip(), 'email' => $email, ]; if ( isset( $form_settings['tags'] ) && ! empty( $form_settings['tags'] ) ) { $tags = $record->replace_setting_shortcodes( $form_settings['tags'] ); $subscriber['tags'] = explode( ',', $tags ); } $custom_fields = []; if ( isset( $form_settings['drip_custom_fields'] ) && 'yes' === $form_settings['drip_custom_fields'] ) { $custom_fields = $this->get_drip_custom_fields( $record ); } $subscriber['custom_fields'] = $custom_fields; return $subscriber; } /** * @param Form_Record $record * * @return array */ private function get_drip_custom_fields( Form_Record $record ) { $local_email_id = ''; foreach ( $record->get_form_settings( 'drip_fields_map' ) as $map_item ) { if ( 'email' === $map_item['remote_id'] ) { $local_email_id = $map_item['local_id']; } } $custom_fields = []; foreach ( $record->get( 'fields' ) as $id => $field ) { if ( $local_email_id === $id ) { continue; } $custom_fields[ $id ] = $field['value']; } return $custom_fields; } /** * extracts Email field from form based on mapping * returns email address or false if missing * * @param Form_Record $record * * @return bool */ private function map_email_field( Form_Record $record ) { $fields = $record->get( 'fields' ); foreach ( $record->get_form_settings( 'drip_fields_map' ) as $map_item ) { if ( empty( $fields[ $map_item['local_id'] ]['value'] ) ) { continue; } $value = $fields[ $map_item['local_id'] ]['value']; if ( 'email' === $map_item['remote_id'] ) { return $value; } } return false; } /** * @param array $data * * @return array * @throws \Exception */ public function handle_panel_request( array $data ) { if ( ! empty( $data['api_token'] ) && 'default' === $data['api_token'] ) { $api_key = $this->get_global_api_key(); } elseif ( ! empty( $data['custom_api_token'] ) ) { $api_key = $data['custom_api_token']; } if ( empty( $api_key ) ) { throw new \Exception( '`api_token` is required.', 400 ); } $handler = new Drip_Handler( $api_key ); return $handler->get_accounts(); } public function register_admin_fields( Settings $settings ) { $settings->add_section( Settings::TAB_INTEGRATIONS, 'drip', [ 'callback' => function() { echo '<hr><h2>' . esc_html__( 'Drip', 'elementor-pro' ) . '</h2>'; }, 'fields' => [ self::OPTION_NAME_API_KEY => [ 'label' => esc_html__( 'API Key', 'elementor-pro' ), 'field_args' => [ 'type' => 'text', 'desc' => sprintf( /* translators: 1: Link opening tag, 2: Link closing tag. */ esc_html__( 'To integrate with our forms you need an %1$sAPI Key%2$s.', 'elementor-pro' ), '<a href="http://kb.getdrip.com/general/where-can-i-find-my-api-token/" target="_blank">', '</a>' ), ], ], 'validate_api_data' => [ 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '<button data-action="%s" data-nonce="%s" class="button elementor-button-spinner" id="elementor_pro_drip_api_token_button">%s</button>', self::OPTION_NAME_API_KEY . '_validate', wp_create_nonce( self::OPTION_NAME_API_KEY ), esc_html__( 'Validate API Key', 'elementor-pro' ) ), ], ], ], ] ); } /** * */ public function ajax_validate_api_token() { check_ajax_referer( self::OPTION_NAME_API_KEY, '_nonce' ); if ( ! isset( $_POST['api_key'] ) ) { wp_send_json_error(); } try { new Drip_Handler( $_POST['api_key'] ); // phpcs:ignore -- No need to sanitize to support special characters. } catch ( \Exception $exception ) { wp_send_json_error(); } wp_send_json_success(); } public function __construct() { if ( is_admin() ) { add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_fields' ], 15 ); } add_action( 'wp_ajax_' . self::OPTION_NAME_API_KEY . '_validate', [ $this, 'ajax_validate_api_token' ] ); } protected function get_fields_map_control_options() { return [ 'condition' => [ 'drip_account!' => '', ], ]; } } redirect.php 0000666 00000003372 15165307047 0007077 0 ustar 00 <?php namespace ElementorPro\Modules\Forms\Actions; use Elementor\Controls_Manager; use Elementor\Modules\DynamicTags\Module as TagsModule; use ElementorPro\Modules\Forms\Classes\Action_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Redirect extends Action_Base { public function get_name() { return 'redirect'; } public function get_label() { return esc_html__( 'Redirect', 'elementor-pro' ); } public function register_settings_section( $widget ) { $widget->start_controls_section( 'section_redirect', [ 'label' => esc_html__( 'Redirect', 'elementor-pro' ), 'condition' => [ 'submit_actions' => $this->get_name(), ], ] ); $widget->add_control( 'redirect_to', [ 'label' => esc_html__( 'Redirect To', 'elementor-pro' ), 'type' => Controls_Manager::TEXT, 'placeholder' => esc_html__( 'https://your-link.com', 'elementor-pro' ), 'ai' => [ 'active' => false, ], 'dynamic' => [ 'active' => true, 'categories' => [ TagsModule::POST_META_CATEGORY, TagsModule::TEXT_CATEGORY, TagsModule::URL_CATEGORY, ], ], 'label_block' => true, 'render_type' => 'none', 'classes' => 'elementor-control-direction-ltr', ] ); $widget->end_controls_section(); } public function on_export( $element ) { unset( $element['settings']['redirect_to'] ); return $element; } public function run( $record, $ajax_handler ) { $redirect_to = $record->get_form_settings( 'redirect_to' ); $redirect_to = $record->replace_setting_shortcodes( $redirect_to, true ); if ( ! empty( $redirect_to ) && filter_var( $redirect_to, FILTER_VALIDATE_URL ) ) { $ajax_handler->add_response_data( 'redirect_url', $redirect_to ); } } }
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0 |
proxy
|
phpinfo
|
Settings