Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with Form Submissions [TMZ-121] #222

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ public static function plugin_title(): string {
return __( 'Hello+', 'hello-plus' );
}

public static function are_submissions_enabled(): bool {
return static::has_pro() &&
class_exists( '\ElementorPro\Modules\Forms\Submissions\Actions\Save_To_Database' ) &&
class_exists( '\ElementorPro\License\API' ) &&
class_exists( '\ElementorPro\Modules\Forms\Submissions\Component' ) &&
\ElementorPro\License\API::is_licence_has_feature(
\ElementorPro\Modules\Forms\Submissions\Component::NAME,
\ElementorPro\License\APi::BC_VALIDATION_CALLBACK
);
}

public static function get_widgets_depends(): array {
return [ 'helloplus-button', 'helloplus-image', 'helloplus-shapes' ];
}
Expand Down
196 changes: 0 additions & 196 deletions modules/forms/actions/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,202 +22,6 @@ public function get_label(): string {
}

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', 'hello-plus' ),
'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', 'hello-plus' ),
'render_type' => 'none',
'dynamic' => [
'active' => true,
],
]
);

/* translators: %s: Site title. */
$default_message = sprintf( esc_html__( 'New message from [%s]', 'hello-plus' ), get_bloginfo( 'name' ) );

$widget->add_control(
$this->get_control_id( 'email_subject' ),
[
'label' => esc_html__( 'Subject', 'hello-plus' ),
'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', 'hello-plus' ),
'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.', 'hello-plus' ),
'<code>[all-fields]</code>'
),
'render_type' => 'none',
'dynamic' => [
'active' => true,
],
]
);

$site_domain = Module::get_site_domain();

$widget->add_control(
$this->get_control_id( 'email_from' ),
[
'label' => esc_html__( 'From Email', 'hello-plus' ),
'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', 'hello-plus' ),
'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', 'hello-plus' ),
'type' => Controls_Manager::SELECT,
'options' => [
'' => '',
],
'render_type' => 'none',
]
);

$widget->add_control(
$this->get_control_id( 'email_to_cc' ),
[
'label' => esc_html__( 'Cc', 'hello-plus' ),
'type' => Controls_Manager::TEXT,
'default' => '',
'ai' => [
'active' => false,
],
'title' => esc_html__( 'Separate emails with commas', 'hello-plus' ),
'render_type' => 'none',
'dynamic' => [
'active' => true,
],
]
);

$widget->add_control(
$this->get_control_id( 'email_to_bcc' ),
[
'label' => esc_html__( 'Bcc', 'hello-plus' ),
'type' => Controls_Manager::TEXT,
'default' => '',
'ai' => [
'active' => false,
],
'title' => esc_html__( 'Separate emails with commas', 'hello-plus' ),
'render_type' => 'none',
'dynamic' => [
'active' => true,
],
]
);

$widget->add_control(
$this->get_control_id( 'form_metadata' ),
[
'label' => esc_html__( 'Meta Data', 'hello-plus' ),
'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', 'hello-plus' ),
'time' => esc_html__( 'Time', 'hello-plus' ),
'page_url' => esc_html__( 'Page URL', 'hello-plus' ),
'user_agent' => esc_html__( 'User Agent', 'hello-plus' ),
'remote_ip' => esc_html__( 'Remote IP', 'hello-plus' ),
'credit' => esc_html__( 'Credit', 'hello-plus' ),
],
'render_type' => 'none',
]
);

$widget->add_control(
$this->get_control_id( 'email_content_type' ),
[
'label' => esc_html__( 'Send As', 'hello-plus' ),
'type' => Controls_Manager::SELECT,
'default' => 'html',
'render_type' => 'none',
'options' => [
'html' => esc_html__( 'HTML', 'hello-plus' ),
'plain' => esc_html__( 'Plain', 'hello-plus' ),
],
]
);

$widget->end_controls_section();
}

public function on_export( $element ) {
Expand Down
34 changes: 0 additions & 34 deletions modules/forms/actions/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,6 @@ public function get_label(): string {
}

public function register_settings_section( $widget ) {
$widget->start_controls_section(
'section_redirect',
[
'label' => esc_html__( 'Redirect', 'hello-plus' ),
'condition' => [
'submit_actions' => $this->get_name(),
],
]
);

$widget->add_control(
'redirect_to',
[
'label' => esc_html__( 'Redirect To', 'hello-plus' ),
'type' => Controls_Manager::TEXT,
'placeholder' => esc_html__( 'https://your-link.com', 'hello-plus' ),
'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 ) {
Expand Down
35 changes: 35 additions & 0 deletions modules/forms/assets/js/editor/module.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { __ } from '@wordpress/i18n';
import Component from './component';
import FieldsMapControl from './fields-map-control';
import FieldsRepeaterControl from './fields-repeater-control';
Expand All @@ -19,6 +20,40 @@ export default class FormsModule extends elementorModules.editor.utils.Module {

elementor.addControlView( 'Fields_map', FieldsMapControl );
elementor.addControlView( 'form-fields-repeater', FieldsRepeaterControl );

elementorPromotionsData.collect_submit = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nuritsha this is not the best implementation ever, but I have not found a way to filter the data in the promotions. module.
In my opinion we would need to add a filter here ( https://github.com/elementor/elementor/blob/main/modules/promotions/promotion-data.php#L18 ) and do this in PHP, but didn't want to create a dependency.
Of course image and url need to be confirmed.

title: __( 'Collect Submissions', 'hello-plus' ),
description: [ __( 'Upgrade to Pro "Advanced Solo" to access and manage all your form submissions in one place..', 'hello-plus' ) ],
upgrade_text: __( 'Upgrade', 'hello-plus' ),
upgrade_url: 'https://go.elementor.com/go-pro-button-widget-control/',
image: 'https://assets.elementor.com/free-to-pro-upsell/v1/images/cta.jpg',
image_alt: __( 'Upgrade', 'hello-plus' ),
};
}

showPromotion( targetElement ) {
const hasProAndNotConnected = elementor.helpers.hasProAndNotConnected(),
dialogOptions = {
title: __( 'Dynamic Content', 'elementor' ),
content: __(
'Create more personalized and dynamic sites by populating data from various sources with dozens of dynamic tags to choose from.',
'elementor',
),
targetElement,
position: {
blockStart: '-10',
},
actionButton: {
url: hasProAndNotConnected
? elementorProEditorConfig.urls.connect
: elementor.config.dynamicPromotionURL.replace( '%s', this.view.model.get( 'name' ) ),
text: hasProAndNotConnected
? __( 'Connect & Activate', 'elementor' )
: __( 'Upgrade', 'elementor' ),
},
};

elementor.promotion.showDialog( dialogOptions );
}

onElementorInitComponents() {
Expand Down
2 changes: 1 addition & 1 deletion modules/forms/classes/action-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract public function run( Form_Record $record, Ajax_Handler $ajax_handler );
/**
* @param Ehp_Form $form
*/
abstract public function register_settings_section( $form );
abstract public function register_settings_section( $widget );

/**
* @param array $element
Expand Down
9 changes: 7 additions & 2 deletions modules/forms/classes/form-record.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@ public function set( $property, $value ) {

public function get_form_settings( $setting ) {
if ( isset( $this->form_settings[ $setting ] ) ) {
return $this->form_settings[ $setting ];
$setting_value = $this->form_settings[ $setting ];
if ( 'submit_actions' === $setting ) {
$setting_value = [ $setting_value ];
}

return $setting_value;
}

return null;
return [];
}

public function get_field( $args ) {
Expand Down
18 changes: 14 additions & 4 deletions modules/forms/registrars/form-actions-registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace HelloPlus\Modules\Forms\Registrars;

use HelloPlus\Includes\Utils;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand Down Expand Up @@ -33,9 +35,17 @@ public function __construct() {
* @return void
*/
public function init() {
foreach ( static::FEATURE_NAME_CLASS_NAME_MAP as $action ) {
$class_name = 'HelloPlus\Modules\Forms\Actions\\' . $action;
$this->register( new $class_name() );
}
add_action( 'elementor/init', function () {
if (
Utils::are_submissions_enabled()
) {
$this->register( new \ElementorPro\Modules\Forms\Submissions\Actions\Save_To_Database() );
}

foreach ( static::FEATURE_NAME_CLASS_NAME_MAP as $action ) {
$class_name = 'HelloPlus\Modules\Forms\Actions\\' . $action;
$this->register( new $class_name() );
}
} );
}
}
1 change: 0 additions & 1 deletion modules/forms/registrars/registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function register( $instance, $id = null ) {
}

$this->items[ $id ] = $instance;

return true;
}

Expand Down
Loading
Loading