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