Skip to content

Commit

Permalink
Merge pull request #7 from eduardovillao/feature/release-v2.2.1
Browse files Browse the repository at this point in the history
Feature/release v2.2.1
  • Loading branch information
eduardovillao authored Jan 6, 2025
2 parents ebb5f92 + 5f8ccf4 commit fdec5c5
Show file tree
Hide file tree
Showing 13 changed files with 388 additions and 322 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Extensiona for Elementor Form
# Extensions for Elementor Form

Extensions for Elementor Form adds powerful new actions and controls to the Elementor Pro Form widget, enhancing its default capabilities.

Expand Down Expand Up @@ -32,6 +32,10 @@ We’d love to hear from you! [[email protected]](mailto:plugins@eduardov

## Changelog
```
= 2.3 =
* Changed: refactor code to support Pro version.
* Changed: improve assets build process.
= 2.2 =
* Changed: code improvements.
Expand Down
65 changes: 12 additions & 53 deletions extensions-for-elementor-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
/**
* Plugin Name: Extensions for Elementor Form
* Plugin URI: https://eduardovillao.me/extensions-for-elementor-form
* Description: Extensions for Elementor Form create many actions and controls to Elementor Form. This plugin require the Elementor Pro (Form Widget).
* Description: This plugin empowers your Elementor Forms with advanced functionality that simplifies workflows, improves usability, and integrates seamlessly with tools like WhatsApp.
* Author: EduardoVillao.me
* Author URI: https://eduardovillao.me/
* Text Domain: extensions-for-elementor-form
* Version: 2.2
* Version: 2.3
* Requires at least: 5.5
* Requires PHP: 7.4
* License: GPL-2.0+
Expand All @@ -19,38 +19,23 @@

define( 'EEF_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'EEF_PLUGN_URL', plugin_dir_url( __FILE__ ) );
define( 'EEF_VERSION', '2.2' );
define( 'EEF_VERSION', '2.3' );
define( 'EEF_PHP_MINIMUM_VERSION', '7.4' );
define( 'EEF_WP_MINIMUM_VERSION', '5.5' );
define( 'EEF_PLUGIN_MAIN_FILE', __FILE__ );

/**
* Check PHP and WP version before include plugin class
*
* @since 2.0
*/
if ( ! version_compare( PHP_VERSION, EEF_PHP_MINIMUM_VERSION, '>=' ) ) {
add_action( 'admin_notices', 'eef_admin_notice_php_version_fail' );

\add_action( 'admin_notices', 'eef_admin_notice_php_version_fail' );
} elseif ( ! version_compare( get_bloginfo( 'version' ), EEF_WP_MINIMUM_VERSION, '>=' ) ) {
add_action( 'admin_notices', 'eef_admin_notice_wp_version_fail' );

\add_action( 'admin_notices', 'eef_admin_notice_wp_version_fail' );
} else {
add_action( 'plugins_loaded', 'eef_init_plugin', 10 );
}

/**
* Init plugin (temp. code)
*
* @since 2.0
*/
function eef_init_plugin() {
if ( ! eef_plugin_is_active( 'elementor-pro/elementor-pro.php' ) ) {
add_action( 'admin_notices', 'eef_notice_elementor_pro_inactive' );
return;
}

include_once EEF_PLUGIN_PATH . '/init-custom-actions.php';
include_once EEF_PLUGIN_PATH . '/includes/class-show-content-after-submit.php';
include_once EEF_PLUGIN_PATH . '/includes/class-plugin.php';
\add_action( 'plugins_loaded', array( 'EEF\Includes\Plugin', 'instance' ), 10 );
}

/**
Expand All @@ -61,13 +46,13 @@ function eef_init_plugin() {
*/
function eef_admin_notice_php_version_fail() {
$message = sprintf(
esc_html__( '%1$s requires PHP version %2$s or greater.', 'extensions-for-elementor-form' ),
\esc_html__( '%1$s requires PHP version %2$s or greater.', 'extensions-for-elementor-form' ),
'<strong>Extensions for Elementor Form</strong>',
EEF_PHP_MINIMUM_VERSION
);

$html_message = sprintf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
echo wp_kses_post( $html_message );
echo \wp_kses_post( $html_message );
}

/**
Expand All @@ -78,37 +63,11 @@ function eef_admin_notice_php_version_fail() {
*/
function eef_admin_notice_wp_version_fail() {
$message = sprintf(
esc_html__( '%1$s requires WordPress version %2$s or greater.', 'extensions-for-elementor-form' ),
\esc_html__( '%1$s requires WordPress version %2$s or greater.', 'extensions-for-elementor-form' ),
'<strong>Extensions for Elementor Form</strong>',
EEF_WP_MINIMUM_VERSION
);

$html_message = sprintf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
echo wp_kses_post( $html_message );
}

/**
* Admin notice Elementor Pro disabled
*
* @since 2.0
* @return string
*/
function eef_notice_elementor_pro_inactive() {
$message = sprintf(
esc_html__( '%1$s requires %2$s to be installed and activated.', 'extensions-for-elementor-form' ),
'<strong>Extensions for Elementor Form</strong>',
'<strong>Elementor Pro</strong>'
);

$html_message = sprintf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
echo wp_kses_post( $html_message );
}

/**
* Check if plugin is active
*
* @since 2.0
*/
function eef_plugin_is_active( $plugin_name ) {
return function_exists( 'is_plugin_active' ) ? is_plugin_active( $plugin_name ) : in_array( $plugin_name, (array) get_option( 'active_plugins', array() ), true );
echo \wp_kses_post( $html_message );
}
43 changes: 43 additions & 0 deletions includes/actions/class-register-actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace EEF\Includes\Actions;

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

class Register_Actions {
/**
* Actions
*/
private array $actions;

public function __construct( $actions ) {
$this->actions = $actions;
}

public function set_hooks() : void {
\add_action( 'elementor_pro/forms/actions/register', array( $this, 'register' ), -10 );
}

/**
* Register form acitons to be used after subumitting the form.
*
* @since 2.0
* @param ElementorPro\Modules\Forms\Registrars\Form_Actions_Registrar $form_actions_registrar
*/
public function register( $form_actions_registrar ) : void {
if ( empty( $this->actions ) ) {
return;
}

foreach ( $this->actions as $action ) {
include_once EEF_PLUGIN_PATH . $action['relative_path'] ?? '';

$class_name = 'EEF\Includes\Actions\\' . $action['class_name'];
if ( class_exists( $class_name ) ) {
$form_actions_registrar->register( new $class_name() );
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?php

namespace Eef\Includes;
namespace EEF\Includes\Actions;

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

use \Elementor\Plugin as ElementorPlugin;
use \Elementor\Controls_Manager as ElementorControls;
use \Elementor\Repeater as ElementorRepeater;

/**
* Register post after form submit.
*/
class Register_Post extends \ElementorPro\Modules\Forms\Classes\Action_Base {
public function __construct() {
\add_action( 'elementor/element/form/section_form_fields/before_section_end', array( $this, 'add_control_fields' ), 100, 2 );
}
/**
* Get Name
*
Expand Down Expand Up @@ -63,38 +70,38 @@ public function register_settings_section( $widget ) {
]
);

/**
* TODO:
* 1. Add or edit existent post.
* 2. Post terms (taxonomy).
* 3. Redirect to post after submit/created?.
* 4. Se post status === private add campo de senha.
*/
/**
* TODO:
* 1. Add or edit existent post.
* 2. Post terms (taxonomy).
* 3. Redirect to post after submit/created?.
* 4. Se post status === private add campo de senha.
*/
$widget->add_control(
'eef-register-post-post-type',
[
'label' => \esc_html__( 'Post Type', 'extensions-for-elementor-form' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'post',
'default' => 'post',
'options' => $this->get_registered_post_types(),
]
);

$widget->add_control(
$widget->add_control(
'eef-register-post-post-status',
[
'label' => \esc_html__( 'Post Status', 'extensions-for-elementor-form' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'draft',
'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' ),
'pending' => \esc_html__( 'Pending', 'extensions-for-elementor-form' ),
],
]
);

$widget->add_control(
$widget->add_control(
'eef-register-post-user-permission',
[
'label' => \esc_html__( 'Run only to logged in users?', 'extensions-for-elementor-form' ),
Expand Down Expand Up @@ -178,4 +185,86 @@ public function run( $record, $ajax_handler ) {
}
}
}

/**
* Add create post fields
*
* @param $element
* @param $args
*/
public function add_control_fields( $element, $args ) {
$elementor = ElementorPlugin::instance();
$control_data = $elementor->controls_manager->get_control_from_stack( $element->get_name(), 'form_fields' );

if ( is_wp_error( $control_data ) ) {
return;
}

$new_control = [
'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' => \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' => \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' => \esc_html__( 'Custom Field Name', 'extensions-for-elementor-form' ),
'type' => ElementorControls::TEXT,
'placeholder' => \esc_html__( 'custom_field_name', 'extensions-for-elementor-form' ),
'tab' => 'content',
'tabs_wrapper' => 'form_fields_tabs',
'inner_tab' => 'form_fields_advanced_tab',
'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.
*/
$this->register_control_in_form_advanced_tab( $element, $control_data, $pattern_field );
}

/**
* Register control in form advanced tab
*
* @param object $element
* @param array $control_data
* @param array $pattern_field
*/
public function register_control_in_form_advanced_tab( $element, $control_data, $pattern_field ) {
foreach( $pattern_field as $key => $control ) {
if( $key !== '_id' ) {
$new_order = [];
foreach ( $control_data['fields'] as $field_key => $field ) {
if ( 'field_value' === $field['name'] ) {
$new_order[$key] = $control;
}
$new_order[ $field_key ] = $field;
}

$control_data['fields'] = $new_order;
}
}

return $element->update_control( 'form_fields', $control_data );
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?php

namespace Eef\Includes;
namespace EEF\Includes\Actions;

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

/**
* Class Whatsapp_Action_After_Submit
* Custom elementor form action after submit to redirect to whatsapp
* Whatsapp_Action_After_Submit
* Class Whatsapp_Redirect
*/
class Whatsapp_Action_After_Submit extends \ElementorPro\Modules\Forms\Classes\Action_Base {
class Whatsapp_Redirect extends \ElementorPro\Modules\Forms\Classes\Action_Base {
/**
* Get Name
*
Expand Down
Loading

0 comments on commit fdec5c5

Please sign in to comment.