PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
← All changes | includes/actions/manager.php +164 -98 1.0.2 → 3.6.6 View file →
@@ -1,98 +1,164 @@
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 -}
1 +<?php
2 +
3 +namespace Jet_Form_Builder\Actions;
4 +
5 +// If this file is called directly, abort.
6 +
7 +use Jet_Form_Builder\Exceptions\Repository_Exception;
8 +use Jet_Form_Builder\Form_Messages\Action_Messages_Manager;
9 +use JFB_Components\Repository\Repository_Pattern_Trait;
10 +
11 +if ( ! defined( 'WPINC' ) ) {
12 + die;
13 +}
14 +
15 +/**
16 + * Define Manager class
17 + */
18 +class Manager {
19 +
20 + use Repository_Pattern_Trait;
21 +
22 + private $localized_actions = array();
23 +
24 + public function __construct() {
25 + add_action( 'init', array( $this, 'register_action_types' ), 99 );
26 + add_action( 'jet-form-builder/editor-assets/before', array( $this, 'register_assets' ) );
27 + }
28 +
29 + public function rep_instances(): array {
30 + return array();
31 + }
32 +
33 + /**
34 + * Register allowed action types
35 + *
36 + * @return void
37 + */
38 + public function register_action_types() {
39 + $this->rep_install();
40 +
41 + do_action( 'jet-form-builder/actions/register', $this );
42 + }
43 +
44 + /**
45 + * @param $type
46 + *
47 + * @return $this
48 + */
49 + public function register_action_type( $type ) {
50 + $this->rep_install_item_soft( $type );
51 +
52 + return $this;
53 + }
54 +
55 + /**
56 + * @param $type
57 + *
58 + * @throws Repository_Exception
59 + */
60 + public function rep_before_install_item( $type ) {
61 + if ( ! $type->dependence() ) {
62 + $this->_rep_abort_this();
63 + }
64 + }
65 +
66 +
67 + /**
68 + * @param string $type
69 + *
70 + * @return Types\Base|array
71 + */
72 + public function get_actions( $type = '' ) {
73 + if ( ! $type ) {
74 + return $this->rep_get_items();
75 + }
76 +
77 + try {
78 + return $this->get_action( $type );
79 + } catch ( Repository_Exception $exception ) {
80 + return array();
81 + }
82 + }
83 +
84 + /**
85 + * @param $type
86 + *
87 + * @return Types\Base
88 + * @throws Repository_Exception
89 + */
90 + public function get_action( $type ): Types\Base {
91 + return $this->rep_get_item( $type );
92 + }
93 +
94 + /**
95 + * @param $type
96 + *
97 + * @return Types\Base
98 + * @throws Repository_Exception
99 + */
100 + public function get_action_clone( $type ): Types\Base {
101 + return $this->rep_clone_item( $type );
102 + }
103 +
104 + public function has_action_type( $type ): bool {
105 + return $this->rep_isset_item( $type );
106 + }
107 +
108 + /**
109 + * @param Types\Base[] $source
110 + *
111 + * @return array
112 + */
113 + public function prepare_actions_data( $source ) {
114 + $prepared_types = array();
115 +
116 + foreach ( $source as $type ) {
117 + $type_script_name = $type->self_script_name();
118 +
119 + $prepared_types[] = array(
120 + 'id' => $type->get_id(),
121 + 'name' => $type->get_name(),
122 + 'disabled' => $type->is_disabled(),
123 + 'self' => $type_script_name,
124 + 'callback' => false, // should be rewritten from JS
125 + );
126 + $action_localize = $type->action_data();
127 +
128 + $action_localize['__messages'] = Action_Messages_Manager::instance()->get_messages( $type );
129 + $action_localize['__labels'] = $type->editor_labels();
130 + $action_localize['__help_messages'] = $type->editor_labels_help();
131 + $action_localize['__unsupported_events'] = $type->unsupported_events();
132 + $action_localize['__supported_events'] = $type->supported_events();
133 + $action_localize['__global_tab'] = $type->option_name;
134 +
135 + if ( ! empty( $action_localize ) && $type_script_name ) {
136 + $this->localized_actions[ $type->self_script_name() ] = $action_localize;
137 + }
138 + }
139 +
140 + return $prepared_types;
141 + }
142 +
143 + public function register_action_types_assets( $handle ) {
144 + foreach ( $this->localized_actions as $name => $localized_action ) {
145 + wp_localize_script(
146 + $handle,
147 + $name,
148 + $localized_action
149 + );
150 + }
151 + }
152 +
153 + public function register_assets() {
154 + $data = self::prepare_actions_data( $this->rep_get_items() );
155 +
156 + wp_localize_script(
157 + 'jet-fb-components',
158 + 'jetFormActionTypes',
159 + $data
160 + );
161 +
162 + $this->register_action_types_assets( 'jet-fb-components' );
163 + }
164 +}