Skip to content
Permalink
Browse files

Added plugin files via upload

First upload of the plugin files to create the repo
  • Loading branch information
JoseSoteloCohen committed May 19, 2019
1 parent 07fb245 commit a0a315b1604978b1dc2a3a04ab8ff62910e7a5ef
Showing with 528 additions and 0 deletions.
  1. +2 −0 index.php
  2. +183 −0 plugin.php
  3. +76 −0 readme.txt
  4. +267 −0 sendy-elements.php
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
@@ -0,0 +1,183 @@
<?php
/**
* Class Sendy_Action_After_Submit
* @see https://developers.elementor.com/custom-form-action/
* Custom elementor form action after submit to add a subsciber to
* Sendy list via API
*/
class Sendy_Action_After_Submit extends \ElementorPro\Modules\Forms\Classes\Action_Base {
/**
* Get Name
*
* Return the action name
*
* @access public
* @return string
*/
public function get_name() {
return 'sendy';
}

/**
* Get Label
*
* Returns the action label
*
* @access public
* @return string
*/
public function get_label() {
return __( 'Sendy', 'text-domain' );
}

/**
* Run
*
* Runs the action after submit
*
* @access public
* @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' );

// Make sure that there is a Sendy installation url
if ( empty( $settings['sendy_url'] ) ) {
return;
}

// Make sure that there is a Sendy list ID
if ( empty( $settings['sendy_list'] ) ) {
return;
}

// Make sure that there is a Sendy Email field ID
// which is required by Sendy's API to subsribe a user
if ( empty( $settings['sendy_email_field'] ) ) {
return;
}

// Get sumitetd Form data
$raw_fields = $record->get( 'fields' );

// Normalize the Form Data
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}

// Make sure that the user emtered an email
// which is required by Sendy's API to subsribe a user
if ( empty( $fields[ $settings['sendy_email_field'] ] ) ) {
return;
}

// If we got this far we can start building our request data
// Based on the param list at https://sendy.co/api
$sendy_data = [
'name' => $fields[ $settings['sendy_name_field'] ],
'email' => $fields[ $settings['sendy_email_field'] ],
'list' => $settings['sendy_list'],
'ipaddress' => \ElementorPro\Classes\Utils::get_client_ip(),
'referrer' => isset( $_POST['referrer'] ) ? $_POST['referrer'] : '',
];

// add name if field is mapped
if ( empty( $fields[ $settings['sendy_name_field'] ] ) ) {
$sendy_data['name'] = $fields[ $settings['sendy_name_field'] ];
}

// Send the request
wp_remote_post( $settings['sendy_url'] . 'subscribe', [
'body' => $sendy_data,
] );
}

/**
* Register Settings Section
*
* Registers the Action controls
*
* @access public
* @param \Elementor\Widget_Base $widget
*/
public function register_settings_section( $widget ) {
$widget->start_controls_section(
'section_sendy',
[
'label' => __( 'Sendy', 'text-domain' ),
'condition' => [
'submit_actions' => $this->get_name(),
],
]
);

$widget->add_control(
'sendy_url',
[
'label' => __( 'Sendy URL', 'text-domain' ),
'type' => \Elementor\Controls_Manager::TEXT,
'placeholder' => 'http://your_sendy_installation/',
'label_block' => true,
'separator' => 'before',
'description' => __( 'Enter the URL where you have Sendy installed', 'text-domain' ),
]
);

$widget->add_control(
'sendy_list',
[
'label' => __( 'Sendy List ID', 'text-domain' ),
'type' => \Elementor\Controls_Manager::TEXT,
'separator' => 'before',
'description' => __( 'the list id you want to subscribe a user to. This encrypted & hashed id can be found under View all lists section named ID.', 'text-domain' ),
]
);

$widget->add_control(
'sendy_email_field',
[
'label' => __( 'Email Field ID', 'text-domain' ),
'type' => \Elementor\Controls_Manager::TEXT,
]
);

$widget->add_control(
'sendy_name_field',
[
'label' => __( 'Name Field ID', 'text-domain' ),
'type' => \Elementor\Controls_Manager::TEXT,
]
);

$widget->end_controls_section();

}

/**
* On Export
*
* Clears form settings on export
* @access Public
* @param array $element
*/
public function on_export( $element ) {
unset(
$element['sendy_url'],
$element['sendy_list'],
$element['sendy_name_field'],
$element['sendy_email_field']
);
}
}
add_action( 'elementor_pro/init', function() {
// Here its safe to include our action class file
include_once( 'sendy-elements.php' );

// Instantiate the action class
$sendy_action = new Sendy_Action_After_Submit();

// Register the action with form widget
\ElementorPro\Plugin::instance()->modules_manager->get_modules( 'forms' )->add_form_action( $sendy_action->get_name(), $sendy_action );
});
@@ -0,0 +1,76 @@
=== Sendy Elements ===
Contributors: josesotelocohen
Donate link: https://inboundlatino.com/donate
Tags: sendy, elementor, forms, newsletters, email marketing
Requires at least: 4.7
Tested up to: 5.2
Requires PHP: 5.4
Stable tag: 1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Simple plugin that integrates Elementor Pro form widget with Sendy via API.


== Description ==


Simple solution for users of Sendy and Elementor that do not wish to modify the functions.php file of their theme. This plugin will allow you to send subscriptions made via Elementor's Pro form widget to your Sendy list.


== Installation ==

= Minimum Requirements =

* WordPress 4.7 or greater
* PHP version 5.4 or greater
* MySQL version 5.0 or greater
* Elementor Pro 5.2 or greater

= We recommend your host supports: =

* PHP version 7.0 or greater
* MySQL version 5.6 or greater
* WordPress Memory limit of 64 MB or greater (128 MB or higher is preferred)


= Installation =

1. Install using the WordPress built-in Plugin installer, or Extract the zip file and drop the contents in the `wp-content/plugins/` directory of your WordPress installation.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Go to Pages > Add New
4. Press the 'Edit with Elementor' button.
5. Now you can drag and drop the form widget of Elementor Pro from the left panel onto the content area, and find the Sendy action in the "Actions after submit" dropdown.
6. Fill your Sendy List details and all your subscribers will be sent to that list.


== Frequently Asked Questions ==

**Why do I need this plugin?**

Because there's no native way to send subscribers from Elementor Pro form widget to Sendy, so if you want to avoid modifying your Functions.php to achieve this, you can just install Sendy Elements with a couple of clicks.

**Why is Elementor Pro required?**

Because this integration works with the Form Widget, which is a Elementor Pro unique feature not available in the free plugin.

**Can I still use other integrations if I install Sendy Elements?**

Yes, all the other form widget integrations will be available. You can even use more than one at the same time per form.

**Do I need to know how to code to use Sendy Elements?**

No, you don't and that's the main reason that I created this plugin, so you can integrate both Sendy and Elementor without knowing how to code.


== Screenshots ==

1. **Select from the Dropdown.** Just select Sendy from the "Actions After Submit" dropdown in the form widget.
2. **Sendy List ID.** You can find the list ID in your Sendy Lists dashboard.
3. **Sendy URL.** This is the domain where you installed Sendy.


== Changelog ==

= 1.0.0 - 2019-05-19 =
* Initial Release

0 comments on commit a0a315b

Please sign in to comment.
You can’t perform that action at this time.