PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.1
JetFormBuilder — Dynamic Blocks Form Builder v3.1.1
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 / includes / post-type.php
jetformbuilder / includes Last commit date
actions 2 years ago addons 2 years ago admin 2 years ago blocks 2 years ago classes 2 years ago db-queries 2 years ago exceptions 2 years ago form-actions 2 years ago form-messages 2 years ago form-patterns 2 years ago form-response 2 years ago generators 2 years ago integrations 2 years ago migrations 2 years ago post-meta 2 years ago presets 2 years ago request 2 years ago shortcodes 2 years ago autoloader.php 2 years ago file-upload.php 2 years ago form-break.php 2 years ago form-handler.php 2 years ago form-manager.php 2 years ago functions.php 2 years ago live-form.php 2 years ago plugin.php 2 years ago post-type.php 2 years ago
post-type.php
395 lines
1 <?php
2
3 namespace Jet_Form_Builder;
4
5 use Jet_Form_Builder\Classes\Arguments\Default_Form_Arguments;
6 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
7 use Jet_Form_Builder\Classes\Compatibility;
8 use Jet_Form_Builder\Classes\Get_Icon_Trait;
9 use JFB_Components\Repository\Repository_Pattern_Trait;
10 use Jet_Form_Builder\Classes\Tools;
11 use Jet_Form_Builder\Exceptions\Repository_Exception;
12 use Jet_Form_Builder\Post_Meta\Actions_Meta;
13 use Jet_Form_Builder\Post_Meta\Base_Meta_Type;
14 use Jet_Form_Builder\Post_Meta\Args_Meta;
15 use Jet_Form_Builder\Post_Meta\Preset_Meta;
16 use Jet_Form_Builder\Post_Meta\Gateways_Meta;
17 use Jet_Form_Builder\Post_Meta\Messages_Meta;
18 use Jet_Form_Builder\Post_Meta\Recaptcha_Meta;
19 use Jet_Form_Builder\Post_Meta\Validation_Meta;
20 use Jet_Form_Builder\Shortcodes\Manager;
21
22 // If this file is called directly, abort.
23
24 if ( ! defined( 'WPINC' ) ) {
25 die;
26 }
27
28 /**
29 * @method Base_Meta_Type rep_get_item( $class_or_slug )
30 *
31 * Class Post_Type
32 *
33 * @package Jet_Form_Builder
34 */
35 class Post_Type {
36
37 use Get_Icon_Trait;
38 use Repository_Pattern_Trait;
39
40 /**
41 * Used to define the editor
42 *
43 * @var boolean
44 */
45 public $is_form_editor = false;
46
47 const CAPABILITIES = array(
48 'edit_jet_fb_form',
49 'read_jet_fb_form',
50 'delete_jet_fb_form',
51 'edit_jet_fb_forms',
52 'edit_others_jet_fb_forms',
53 'delete_jet_fb_forms',
54 'publish_jet_fb_forms',
55 'read_private_jet_fb_forms',
56 );
57
58 /**
59 * Constructor for the class
60 */
61 public function __construct() {
62 add_action( 'init', array( $this, 'register_post_type' ) );
63 add_action( 'current_screen', array( $this, 'set_current_screen' ) );
64
65 add_filter( "manage_{$this->slug()}_posts_columns", array( $this, 'filter_columns' ) );
66 add_action( "manage_{$this->slug()}_posts_custom_column", array( $this, 'add_admin_column_content' ), 10, 2 );
67
68 /**
69 * @since 3.0.1
70 */
71 add_filter( 'gutenberg_can_edit_post_type', array( $this, 'can_edit_post_type' ), 150, 2 );
72 add_filter( 'use_block_editor_for_post_type', array( $this, 'can_edit_post_type' ), 150, 2 );
73
74 /** @since 3.0.9 */
75 add_action( 'admin_init', array( $this, 'remove_admin_capabilities' ) );
76 register_deactivation_hook( JET_FORM_BUILDER__FILE__, array( $this, 'remove_admin_capabilities' ) );
77
78 /** @since 3.1.1 */
79 // watch on this methods performance because it executed multiple times on each page load
80 add_filter( 'user_has_cap', array( $this, 'add_admin_capabilities' ) );
81 }
82
83 public function rep_instances(): array {
84 return array(
85 new Args_Meta(),
86 new Messages_Meta(),
87 new Preset_Meta(),
88 new Recaptcha_Meta(),
89 new Actions_Meta(),
90 new Gateways_Meta(),
91 new Validation_Meta(),
92 );
93 }
94
95 public function filter_columns( $columns ) {
96 $after = array( 'date' => $columns['date'] );
97 unset( $columns['date'] );
98
99 $columns['jfb_shortcode'] = __( 'Shortcode', 'jet-form-builder' );
100
101 return array_merge( $columns, $after );
102 }
103
104 public function add_admin_column_content( $column, $form_id ) {
105 if ( 'jfb_shortcode' !== $column ) {
106 return;
107 }
108 $arguments = array_diff( $this->get_args( $form_id ), Form_Arguments::arguments() );
109
110 $arguments = array_merge(
111 array( 'form_id' => $form_id ),
112 Default_Form_Arguments::arguments(),
113 $arguments
114 );
115
116 printf(
117 '<input readonly type="text" onclick="this.select()" value="%s" style="%s"/>',
118 esc_attr( Manager::get_shortcode( 'jet_fb_form', $arguments ) ),
119 'width: 100%'
120 );
121 }
122
123 /**
124 * Returns current post type slug
125 *
126 * @return string [type] [description]
127 */
128 public function slug() {
129 return 'jet-form-builder';
130 }
131
132 public function set_current_screen() {
133 $screen = get_current_screen();
134
135 if ( ! $screen || ! $screen->is_block_editor ) {
136 return;
137 }
138
139 if ( $this->slug() === $screen->id ) {
140 $this->is_form_editor = true;
141
142 } elseif ( $this->slug() !== $screen->id ) {
143 $this->is_form_editor = false;
144 }
145 }
146
147 public function is_form_list_page() {
148 if ( ! did_action( 'current_screen' ) ) {
149 return false;
150 }
151
152 $screen = get_current_screen();
153
154 return ( "edit-{$this->slug()}" === $screen->id );
155 }
156
157 /**
158 * @param $can
159 * @param $post_type
160 *
161 * @return bool
162 * @since 3.0.1
163 */
164 public function can_edit_post_type( $can, $post_type ): bool {
165 return $this->slug() === $post_type ? true : $can;
166 }
167
168 /**
169 * Register templates post type
170 *
171 * @return void
172 */
173 public function register_post_type() {
174
175 $args = array(
176 'labels' => array(
177 'name' => __( 'Forms', 'jet-form-builder' ),
178 'all_items' => __( 'Forms', 'jet-form-builder' ),
179 'add_new' => __( 'Add New', 'jet-form-builder' ),
180 'add_new_item' => __( 'Add New Form', 'jet-form-builder' ),
181 'edit_item' => __( 'Edit Form', 'jet-form-builder' ),
182 'new_item' => __( 'New Form', 'jet-form-builder' ),
183 'view_item' => __( 'View Form', 'jet-form-builder' ),
184 'search_items' => __( 'Search Form', 'jet-form-builder' ),
185 'not_found' => __( 'No Forms Found', 'jet-form-builder' ),
186 'not_found_in_trash' => __( 'No Forms Found In Trash', 'jet-form-builder' ),
187 'singular_name' => __( 'JetForm', 'jet-form-builder' ),
188 'menu_name' => __( 'JetFormBuilder', 'jet-form-builder' ),
189 ),
190 'public' => true,
191 'show_ui' => true,
192 'show_in_admin_bar' => true,
193 'show_in_menu' => true,
194 'show_in_nav_menus' => false,
195 'show_in_rest' => true,
196 'publicly_queryable' => false,
197 'exclude_from_search' => true,
198 'has_archive' => false,
199 'query_var' => false,
200 'can_export' => true,
201 'rewrite' => false,
202 'capability_type' => 'jet_fb_form',
203 'menu_icon' => $this->get_post_type_icon(),
204 'menu_position' => 120,
205 'supports' => array( 'title', 'editor', 'custom-fields' ),
206 );
207
208 $post_type = register_post_type(
209 $this->slug(),
210 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
211 apply_filters( 'jet-form-builder/post-type/args', $args )
212 );
213
214 $this->rep_install();
215
216 /** @var Base_Meta_Type $item */
217 foreach ( $this->rep_get_items() as $item ) {
218 register_post_meta( $this->slug(), $item->get_id(), $item->to_array() );
219 }
220 }
221
222 public function add_admin_capabilities( $allcaps ) {
223 $capability = apply_filters( 'jet-form-builder/capability/form', 'manage_options' );
224
225 if ( empty( $allcaps[ $capability ] ) ) {
226 return $allcaps;
227 }
228
229 foreach ( self::CAPABILITIES as $capability ) {
230 $allcaps[ $capability ] = true;
231 }
232
233 return $allcaps;
234 }
235
236 public function remove_admin_capabilities() {
237 $role = get_role( 'administrator' );
238
239 foreach ( self::CAPABILITIES as $capability ) {
240 if ( ! $role->has_cap( $capability ) ) {
241 continue;
242 }
243 $role->remove_cap( $capability );
244 }
245 }
246
247 /**
248 * @param string $name
249 *
250 * @return false|Base_Meta_Type
251 */
252 public function get_meta( string $name ) {
253 try {
254 return $this->rep_get_item( $name );
255 } catch ( Repository_Exception $exception ) {
256 return false;
257 }
258 }
259
260 /**
261 * @param $item
262 *
263 * @throws Exceptions\Repository_Exception
264 */
265 public function rep_before_install_item( $item ) {
266 if ( $item->is_supported() ) {
267 return;
268 }
269 $this->_rep_abort_this();
270 }
271
272 private function get_post_type_icon() {
273 $path = $this->get_icon_path( 'post-type.php' );
274
275 return include_once $path;
276 }
277
278 /**
279 * Returns form meta arguments:
280 * fields_layout, submit_type, captcha and required_mark
281 * in assoc array
282 *
283 * @param int|false $form_id
284 *
285 * @return array
286 */
287 public function get_args( $form_id = false ): array {
288 return $this->get_meta( Args_Meta::class )->query( $form_id );
289 }
290
291 /**
292 * Returns form messages
293 *
294 * @param int|false $form_id
295 *
296 * @return array
297 */
298 public function get_messages( $form_id = false ) {
299 return $this->get_meta( Messages_Meta::class )->query( $form_id );
300 }
301
302 /**
303 * Returns form actions
304 *
305 * @param int|false $form_id
306 *
307 * @return array
308 */
309 public function get_actions( $form_id = false ) {
310 return $this->get_meta( Actions_Meta::class )->query( $form_id );
311 }
312
313 /**
314 * Returns form actions
315 *
316 * @param int|false $form_id
317 *
318 * @return array
319 */
320 public function get_preset( $form_id = false ) {
321 return $this->get_meta( Preset_Meta::class )->query( $form_id );
322 }
323
324 /**
325 * Returns captcha settings
326 *
327 * @param int|false $form_id
328 *
329 * @return array
330 */
331 public function get_captcha( $form_id = false ) {
332 return $this->get_meta( Recaptcha_Meta::class )->query( $form_id );
333 }
334
335 /**
336 * Returns form gateways
337 *
338 * @param int|false $form_id
339 *
340 * @return array
341 */
342 public function get_gateways( $form_id = false ): array {
343 try {
344 return $this->rep_get_item( Gateways_Meta::class )->query( $form_id );
345 } catch ( Repository_Exception $exception ) {
346 return array();
347 }
348 }
349
350 public function get_validation( $form_id = false ) {
351 return $this->get_meta( Validation_Meta::class )->query( $form_id );
352 }
353
354 /**
355 * @param $meta_key
356 * @param int|false $form_id
357 *
358 * @return array|mixed
359 * @deprecated since 3.0.0
360 */
361 public function get_form_meta( $meta_key, $form_id = false ) {
362 if ( false === $form_id ) {
363 $form_id = jet_fb_live()->form_id;
364 }
365
366 return Tools::decode_json(
367 get_post_meta(
368 $form_id,
369 $meta_key,
370 true
371 )
372 );
373 }
374
375 public function maybe_get_jet_sm_ready_styles( $form_id ) {
376 return Compatibility::has_jet_sm() ? get_post_meta( $form_id, '_jet_sm_ready_style', true ) : '';
377 }
378
379 /**
380 * Returns captcha settings
381 *
382 * @param int|false $form_id
383 *
384 * @return array
385 * @deprecated 3.1.0 Use ::get_captcha() instead
386 */
387 public function get_recaptcha( $form_id = false ) {
388 _deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::get_captcha()' );
389
390 return $this->get_captcha( $form_id );
391 }
392
393
394 }
395