Skip to content

Commit

Permalink
Merge pull request #3 from eduardovillao/feature/enable-dynamic-to-wh…
Browse files Browse the repository at this point in the history
…atsapp-action

feature: add dynamic to whatsapp action controls + improve escape code
  • Loading branch information
eduardovillao authored Nov 22, 2024
2 parents 5bace59 + cb2fa13 commit 208ff72
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 58 deletions.
14 changes: 6 additions & 8 deletions extensions-for-elementor-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@
* Author: EduardoVillao.me
* Author URI: https://eduardovillao.me/
* Text Domain: extensions-for-elementor-form
* Version: 2.0.3
* Version: 2.1
* Requires at least: 5.5
* Requires PHP: 7.0
* License: GPL-2.0+
* Requires PHP: 7.4
* License: GPL v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Requires Plugins: elementor-pro
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

use ElementorPro\Plugin;
use ElementorPro\Modules\ThemeBuilder\Module;

define( 'EEF_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'EEF_PLUGN_URL', plugin_dir_url( __FILE__ ) );
define( 'EEF_VERSION', '2.0.3' );
define( 'EEF_PHP_MINIMUM_VERSION', '7.0' );
define( 'EEF_VERSION', '2.1' );
define( 'EEF_PHP_MINIMUM_VERSION', '7.4' );
define( 'EEF_WP_MINIMUM_VERSION', '5.5' );

/**
Expand Down
34 changes: 17 additions & 17 deletions includes/class-register-create-post-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* Register custom field inside a form repeater (advanced tab) if action is enabled.
*
*
* @since 2.0
*/
class Register_Create_Post_Fields {
Expand All @@ -25,7 +25,7 @@ public function __construct() {

/**
* Add create post fields
*
*
* @since 2.0
* @param $element
* @param $args
Expand All @@ -39,45 +39,45 @@ public function add_control_fields( $element, $args ) {
}

$new_control = [
'label' => __( 'Field to Register', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'Field to Register', 'extensions-for-elementor-form' ),
'type' => ElementorControls::SELECT,
'tab' => 'content',
'tabs_wrapper' => 'form_fields_tabs',
'inner_tab' => 'form_fields_advanced_tab',
'classes' => 'elementor-hidden-control',
'description' => __( 'Use this input to define what post field will receive this data when post is registered', 'extensions-for-elementor-form' ),
'description' => \esc_html__( 'Use this input to define what post field will receive this data when post is registered', 'extensions-for-elementor-form' ),
'default' => 'select',
'options' => [
'select' => __( 'Select', 'extensions-for-elementor-form' ),
'post_title' => __( 'Post Title', 'extensions-for-elementor-form' ),
'post_content' => __( 'Post Content', 'extensions-for-elementor-form' ),
'post_excerpt' => __( 'Post Excerpt', 'extensions-for-elementor-form' ),
'post_author' => __( 'Post Author', 'extensions-for-elementor-form' ),
'custom_field' => __( 'Custom Field', 'extensions-for-elementor-form' ),
'select' => \esc_html__( 'Select', 'extensions-for-elementor-form' ),
'post_title' => \esc_html__( 'Post Title', 'extensions-for-elementor-form' ),
'post_content' => \esc_html__( 'Post Content', 'extensions-for-elementor-form' ),
'post_excerpt' => \esc_html__( 'Post Excerpt', 'extensions-for-elementor-form' ),
'post_author' => \esc_html__( 'Post Author', 'extensions-for-elementor-form' ),
'custom_field' => \esc_html__( 'Custom Field', 'extensions-for-elementor-form' ),
],
];

$new_control_2 = [
'label' => __( 'Custom Field Name', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'Custom Field Name', 'extensions-for-elementor-form' ),
'type' => ElementorControls::TEXT,
'placeholder' => __( 'custom_field_name', 'extensions-for-elementor-form' ),
'placeholder' => \esc_html__( 'custom_field_name', 'extensions-for-elementor-form' ),
'tab' => 'content',
'tabs_wrapper' => 'form_fields_tabs',
'inner_tab' => 'form_fields_advanced_tab',
'description' => __( 'Add the Custom Field name here. You can use default fields or custom created with ACF or similars', 'extensions-for-elementor-form' ),
'description' => \esc_html__( 'Add the Custom Field name here. You can use default fields or custom created with ACF or similars', 'extensions-for-elementor-form' ),
'condition' => [
'eef-register-post-field' => 'custom_field',
],
];

$mask_control = new ElementorRepeater();
$mask_control->add_control( 'eef-register-post-field', $new_control );
$mask_control->add_control( 'eef-register-post-custom-field', $new_control_2 );
$pattern_field = $mask_control->get_controls();

/**
* Register control in form advanced tab.
*
*
* @since 2.0
*/
$this->register_control_in_form_advanced_tab( $element, $control_data, $pattern_field );
Expand All @@ -90,7 +90,7 @@ public function add_control_fields( $element, $args ) {
* @param array $control_data
* @param array $pattern_field
* @return void
*
*
* @since 2.0
*/
public function register_control_in_form_advanced_tab( $element, $control_data, $pattern_field ) {
Expand All @@ -110,4 +110,4 @@ public function register_control_in_form_advanced_tab( $element, $control_data,

return $element->update_control( 'form_fields', $control_data );
}
}
}
28 changes: 14 additions & 14 deletions includes/class-register-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private function get_registered_post_types() {
$registered_post_types = get_post_types( array( 'public' => true ), 'objects' );
$post_type_options = array();
foreach ( $registered_post_types as $post_type ) {
$post_type_options[ $post_type->name ] = $post_type->label;
$post_type_options[ $post_type->name ] = $post_type->label;
}

return $post_type_options;
Expand All @@ -56,7 +56,7 @@ public function register_settings_section( $widget ) {
$widget->start_controls_section(
'eef-register-post-section',
[
'label' => __( 'Register Post/Custom Post', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'Register Post/Custom Post', 'extensions-for-elementor-form' ),
'condition' => [
'submit_actions' => $this->get_name(),
],
Expand All @@ -73,7 +73,7 @@ public function register_settings_section( $widget ) {
$widget->add_control(
'eef-register-post-post-type',
[
'label' => __( 'Post Type', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'Post Type', 'extensions-for-elementor-form' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'post',
'options' => $this->get_registered_post_types(),
Expand All @@ -83,27 +83,27 @@ public function register_settings_section( $widget ) {
$widget->add_control(
'eef-register-post-post-status',
[
'label' => __( 'Post Status', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'Post Status', 'extensions-for-elementor-form' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'draft',
'options' => [
'draft' => esc_html__( 'Draft', 'extensions-for-elementor-form' ),
'publish' => esc_html__( 'Publish', 'extensions-for-elementor-form' ),
'pending' => esc_html__( 'Pending', 'extensions-for-elementor-form' ),
'draft' => \esc_html__( 'Draft', 'extensions-for-elementor-form' ),
'publish' => \esc_html__( 'Publish', 'extensions-for-elementor-form' ),
'pending' => \esc_html__( 'Pending', 'extensions-for-elementor-form' ),
],
]
);

$widget->add_control(
'eef-register-post-user-permission',
[
'label' => esc_html__( 'Run only to logged in users?', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'Run only to logged in users?', 'extensions-for-elementor-form' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Yes', 'extensions-for-elementor-form' ),
'label_off' => esc_html__( 'No', 'extensions-for-elementor-form' ),
'label_on' => \esc_html__( 'Yes', 'extensions-for-elementor-form' ),
'label_off' => \esc_html__( 'No', 'extensions-for-elementor-form' ),
'return_value' => 'yes',
'default' => 'yes',
'description' => __( 'Warning: Save data from not logged in users can be a security risk', 'extensions-for-elementor-form' ),
'description' => \esc_html__( 'Warning: Save data from not logged in users can be a security risk', 'extensions-for-elementor-form' ),
]
);

Expand Down Expand Up @@ -157,14 +157,14 @@ public function run( $record, $ajax_handler ) {
$custom_fields_to_register[ $field['custom-field-to-register'] ] = $field['value'];
}
}

$is_restrict_to_loggedin_users = $record->get_form_settings( 'eef-register-post-user-permission' );
if ( $is_restrict_to_loggedin_users !== 'yes' ) {
$post_id = wp_insert_post( $new_post_data, true );
if ( ! is_wp_error( $post_id ) ) {
foreach ( $custom_fields_to_register as $meta_key => $meta_value ) {
add_post_meta( $post_id, $meta_key, $meta_value );
}
}
}
return;
}
Expand All @@ -174,7 +174,7 @@ public function run( $record, $ajax_handler ) {
if ( ! is_wp_error( $post_id ) ) {
foreach ( $custom_fields_to_register as $meta_key => $meta_value ) {
add_post_meta( $post_id, $meta_key, $meta_value );
}
}
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions includes/class-show-content-after-submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ public function evcode_add_message_control ( $element, $args ) {
$element->start_controls_section(
'evcode_message_template',
[
'label' => __( 'Custom Sucess Message', 'extensions_elementor_form' ),
'label' => \esc_html__( 'Custom Sucess Message', 'extensions_elementor_form' ),
]
);

$element->add_control(
'hide_form_after_submit',
[
'label' => __( 'Hide form after submit?', 'extensions_elementor_form' ),
'label' => \esc_html__( 'Hide form after submit?', 'extensions_elementor_form' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __( 'Hide', 'extensions_elementor_form' ),
'label_off' => __( 'Show', 'extensions_elementor_form' ),
'label_on' => \esc_html__( 'Hide', 'extensions_elementor_form' ),
'label_off' => \esc_html__( 'Show', 'extensions_elementor_form' ),
'return_value' => 'yes',
'default' => 'yes',
'description' => __( 'This option hide the form after sucess submit.', 'extensions_elementor_form' ),
'description' => \esc_html__( 'This option hide the form after sucess submit.', 'extensions_elementor_form' ),
]
);

$element->add_control(
'template-custom-sucess-message',
[
'label' => __( 'Message Template', 'extensions_elementor_form' ),
'label' => \esc_html__( 'Message Template', 'extensions_elementor_form' ),
'type' => Elementor\Controls_Manager::TEXT,
'placeholder' => __( '[your-shortcode-here]', 'extensions_elementor_form' ),
'placeholder' => \esc_html__( '[your-shortcode-here]', 'extensions_elementor_form' ),
'label_block' => true,
'render_type' => 'none',
'classes' => 'elementor_control_message_control-ltr',
'description' => __( 'Paste shortcode for your sucess message template.', 'extensions_elementor_form' ),
'description' => \esc_html__( 'Paste shortcode for your sucess message template.', 'extensions_elementor_form' ),
]
);

Expand All @@ -66,7 +66,7 @@ public function evcode_add_message_class ( $form ) {
$settings = $form->get_settings();

add_action( 'elementor-pro/forms/pre_render', [ $this, 'template_message' ] );

if( 'yes' == $settings['hide_form_after_submit'] ) {
$form->add_render_attribute( 'wrapper', 'class', 'ele-extensions-hide-form', true );
}
Expand Down
20 changes: 13 additions & 7 deletions includes/class-whatsapp-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function register_settings_section( $widget ) {
$widget->start_controls_section(
'section_whatsapp-redirect',
[
'label' => __( 'WhatsApp Redirect', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'WhatsApp Redirect', 'extensions-for-elementor-form' ),
'condition' => [
'submit_actions' => $this->get_name(),
],
Expand All @@ -55,26 +55,32 @@ public function register_settings_section( $widget ) {
$widget->add_control(
'whatsapp_to',
[
'label' => __( 'WhatsApp Phone', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'WhatsApp Phone', 'extensions-for-elementor-form' ),
'type' => \Elementor\Controls_Manager::TEXT,
'placeholder' => __( '13459999999', 'extensions-for-elementor-form' ),
'placeholder' => \esc_html__( '13459999999', 'extensions-for-elementor-form' ),
'label_block' => true,
'render_type' => 'none',
'classes' => 'elementor-control-whats-phone-direction-ltr',
'description' => __( 'Phone with country code, like: 5551999999999', 'extensions-for-elementor-form' ),
'description' => \esc_html__( 'Phone with country code, like: 5551999999999', 'extensions-for-elementor-form' ),
'dynamic' => [
'active' => true,
],
]
);

$widget->add_control(
'whatsapp_message',
[
'label' => __( 'WhatsApp Message', 'extensions-for-elementor-form' ),
'label' => \esc_html__( 'WhatsApp Message', 'extensions-for-elementor-form' ),
'type' => \Elementor\Controls_Manager::TEXTAREA,
'placeholder' => __( 'Write yout text or use fields shortcode', 'extensions-for-elementor-form' ),
'placeholder' => \esc_html__( 'Write yout text or use fields shortcode', 'extensions-for-elementor-form' ),
'label_block' => true,
'render_type' => 'none',
'classes' => 'elementor-control-whats-direction-ltr',
'description' => __( 'Use fields shortcodes for send form data os write your custom text.<br>=> To add break line use token: %break%', 'extensions-for-elementor-form' ),
'description' => \esc_html__( 'Use fields shortcodes for send form data os write your custom text.<br>=> To add break line use token: %break%', 'extensions-for-elementor-form' ),
'dynamic' => [
'active' => true,
],
]
);

Expand Down
11 changes: 8 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Donate link: https://eduardovillao.me/
Tags: elementor, elementor form, elementor plugins, form, register post, register custom post type
Requires at least: 5.5
Tested up to: 6.7
Stable tag: 2.0.3
Requires PHP: 7.0
License: GPLv2License
Stable tag: 2.1
Requires PHP: 7.4
License: GPL v2 or later
URI:https://www.gnu.org/licenses/gpl-2.0.html

== Description ==
Expand Down Expand Up @@ -61,6 +61,11 @@ No! This extensions will be work only with Elementor plugin.

== Changelog ==

= 2.1 =
* Added: dynamic controls to phone and message on WhatsApp redirection action.
* Changed: PHP minimum version set to 7.4.
* Changes: code improvements.

= 2.0.3 =
* Changed: compatibility with WordPress 6.7
* Changed: code improvements
Expand Down

0 comments on commit 208ff72

Please sign in to comment.