| 1 |
<?php |
| 2 |
|
| 3 |
namespace Jet_Form_Builder\Actions; |
| 4 |
|
| 5 |
// If this file is called directly, abort. |
| 6 |
|
| 7 |
use Jet_Form_Builder\Actions\Types; |
| 8 |
|
| 9 |
if ( ! defined( 'WPINC' ) ) { |
| 10 |
die; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Define Manager class |
| 15 |
*/ |
| 16 |
class Manager { |
| 17 |
|
| 18 |
private $_types = array(); |
| 19 |
|
| 20 |
public function __construct() { |
| 21 |
add_action( 'init', array( $this, 'register_action_types' ), 99 ); |
| 22 |
add_action( 'jet-form-builder/editor-assets/after', array( $this, 'register_types_for_editor' ), 10, 2 ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Register allowed action types |
| 27 |
* |
| 28 |
* @return [type] [description] |
| 29 |
*/ |
| 30 |
public function register_action_types() { |
| 31 |
|
| 32 |
$actions = array( |
| 33 |
new Types\Send_Email(), |
| 34 |
new Types\Insert_Post(), |
| 35 |
new Types\Register_User(), |
| 36 |
new Types\Update_User(), |
| 37 |
new Types\Update_Options(), |
| 38 |
new Types\Call_Hook(), |
| 39 |
new Types\Call_Webhook(), |
| 40 |
new Types\Redirect_To_Page(), |
| 41 |
new Types\Mailchimp(), |
| 42 |
new Types\Getresponse(), |
| 43 |
new Types\Active_Campaign() |
| 44 |
); |
| 45 |
|
| 46 |
foreach ( $actions as $action ) { |
| 47 |
$this->register_action_type( $action ); |
| 48 |
} |
| 49 |
|
| 50 |
do_action( 'jet-form-builder/actions/register', $this ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Register new action type |
| 55 |
* |
| 56 |
* @param [type] $type [description] |
| 57 |
* |
| 58 |
* @return [type] [description] |
| 59 |
*/ |
| 60 |
public function register_action_type( $type ) { |
| 61 |
if ( $type->dependence() ) { |
| 62 |
$this->_types[ $type->get_id() ] = $type; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* @return array |
| 68 |
*/ |
| 69 |
public function get_actions() { |
| 70 |
return $this->_types; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Regsiter action types data for the editor |
| 75 |
* |
| 76 |
* @return [type] [description] |
| 77 |
*/ |
| 78 |
public function register_types_for_editor( $editor, $handle ) { |
| 79 |
|
| 80 |
$prepared_types = array(); |
| 81 |
|
| 82 |
foreach ( $this->_types as $type ) { |
| 83 |
|
| 84 |
$prepared_types[] = array( |
| 85 |
'id' => $type->get_id(), |
| 86 |
'name' => $type->get_name(), |
| 87 |
'callback' => false, // should be rewritten from JS |
| 88 |
); |
| 89 |
|
| 90 |
$type->action_data( $editor, $handle ); |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
wp_localize_script( $handle, 'jetFormActionTypes', $prepared_types ); |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|