PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
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 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / actions-v2 / insert-post / insert-post-action.php
jetformbuilder / modules / actions-v2 / insert-post Last commit date
assets 1 year ago properties 1 year ago insert-post-action.php 1 year ago insert-post.php 1 year ago
insert-post-action.php
180 lines
1 <?php
2
3 namespace JFB_Modules\Actions_V2\Insert_Post;
4
5 use Jet_Form_Builder\Actions\Action_Handler;
6 use JFB_Modules\Actions_V2\Insert_Post\Properties\Abstract_Post_Modifier;
7 use JFB_Modules\Actions_V2\Insert_Post\Properties\Post_Modifier;
8 use Jet_Form_Builder\Actions\Types\Base;
9 use Jet_Form_Builder\Classes\Arrayable\Array_Tools;
10 use Jet_Form_Builder\Classes\Tools;
11
12 // If this file is called directly, abort.
13 if ( ! defined( 'WPINC' ) ) {
14 die;
15 }
16
17 /**
18 * Define Base_Type class
19 */
20 class Insert_Post_Action extends Base {
21
22 public function get_name() {
23 return __( 'Insert/Update Post', 'jet-form-builder' );
24 }
25
26 public function get_id() {
27 return 'insert_post';
28 }
29
30 public function action_attributes() {
31 return array(
32 'post_type' => array(
33 'default' => '',
34 ),
35 'post_status' => array(
36 'default' => '',
37 ),
38 'fields_map' => array(
39 'default' => array(),
40 ),
41 'default_meta' => array(
42 'default' => array(),
43 ),
44 );
45 }
46
47 /**
48 * @param array $request
49 * @param Action_Handler $handler
50 *
51 * @return void
52 */
53 public function do_action( array $request, Action_Handler $handler ) {
54 $modifiers = array_reverse( $this->get_modifiers() );
55
56 /** @var Abstract_Post_Modifier $modifier */
57 foreach ( $modifiers as $modifier ) {
58 if ( ! $modifier->is_supported( $this ) ) {
59 continue;
60 }
61
62 $modifier->before_run( $this );
63 $modifier->run();
64 break;
65 }
66 }
67
68 public function get_post_type(): string {
69 return $this->settings['post_type'] ?? '';
70 }
71
72 public function get_inserted_post_context( $post_id = false ) {
73 $post_id = $post_id ?: jet_fb_action_handler()->get_inserted_post_id();
74
75 return jet_fb_action_handler()->get_context(
76 'insert_post',
77 self::get_context_post_key( $post_id )
78 );
79 }
80
81 public static function get_context_post_key( $post_id ) {
82 return "post-id-{$post_id}";
83 }
84
85 public function editor_labels() {
86 return array(
87 'post_type' => __( 'Post Type:', 'jet-form-builder' ),
88 'post_status' => __( 'Post Status:', 'jet-form-builder' ),
89 'fields_map' => __( 'Fields Map:', 'jet-form-builder' ),
90 'default_meta' => __( 'Default Fields:', 'jet-form-builder' ),
91 );
92 }
93
94 public function editor_labels_help() {
95 return array(
96 'fields_map' => __( 'Set meta fields names or post properties to save appropriate form fields into', 'jet-form-builder' ),
97 'default_meta' => __( 'Set default meta values which should be set on post insert/update', 'jet-form-builder' ),
98 );
99 }
100
101 /**
102 * Regsiter custom action data for the editor
103 *
104 * @return [type] [description]
105 */
106 public function action_data() {
107 $properties = array();
108 $modifiers = $this->get_modifiers();
109
110 foreach ( $modifiers as $modifier ) {
111 $properties[ $modifier->get_id() ] = Tools::with_placeholder(
112 Array_Tools::to_array( $modifier->properties->all() )
113 );
114 }
115
116 return array(
117 'postTypes' => Tools::get_post_types_for_js(),
118 'taxonomies' => Tools::get_taxonomies_for_modify(),
119 'postStatuses' => $this->get_post_statuses_for_options(),
120 'properties' => $properties,
121 );
122 }
123
124 /**
125 * Just add a new element to the end.
126 * When the action is executed, this array is flipped,
127 * which puts the \Jet_Form_Builder\Actions\Methods\Post_Modifier at the end.
128 *
129 * @return Abstract_Post_Modifier[]
130 * @since 2.1.4
131 */
132 public function get_modifiers(): array {
133 return apply_filters(
134 'jet-form-builder/action/insert-post/modifiers',
135 array(
136 new Post_Modifier(),
137 )
138 );
139 }
140
141 /**
142 * Returns post statuses list for the options
143 *
144 * @return array
145 */
146 public function get_post_statuses_for_options() {
147
148 $statuses = get_post_statuses();
149 $result = array();
150
151 foreach ( $statuses as $name => $label ) {
152 $result[] = array(
153 'value' => $name,
154 'label' => $label,
155 );
156 }
157
158 $result = array_merge(
159 $result,
160 array(
161 array(
162 'value' => 'trash',
163 'label' => __( 'Move to Trash', 'jet-form-builder' ),
164 ),
165 array(
166 'value' => 'from-field',
167 'label' => __( 'Get from the form field', 'jet-form-builder' ),
168 ),
169 array(
170 'value' => 'keep-current',
171 'label' => __( 'Keep current status (when updating post)', 'jet-form-builder' ),
172 ),
173 )
174 );
175
176 return Tools::with_placeholder( apply_filters( 'jet-form-builder/actions/insert-post/allowed-post-statuses', $result ) );
177 }
178
179 }
180