PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.7
JetFormBuilder — Dynamic Blocks Form Builder v3.0.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 / includes / post-type.php
jetformbuilder / includes Last commit date
actions 3 years ago addons 3 years ago admin 3 years ago blocks 3 years ago classes 3 years ago compatibility 3 years ago db-queries 3 years ago dev-mode 3 years ago exceptions 3 years ago form-actions 3 years ago form-messages 3 years ago form-patterns 3 years ago form-response 3 years ago gateways 3 years ago generators 3 years ago integrations 3 years ago migrations 3 years ago post-meta 3 years ago presets 3 years ago request 3 years ago rest-api 3 years ago shortcodes 3 years ago wp-cli 3 years ago autoloader.php 3 years ago file-upload.php 3 years ago form-break.php 3 years ago form-handler.php 3 years ago form-manager.php 3 years ago live-form.php 3 years ago plugin.php 3 years ago post-type.php 3 years ago
post-type.php
327 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 Jet_Form_Builder\Classes\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 * Post_Type class
30 */
31 class Post_Type {
32
33 use Get_Icon_Trait;
34 use Repository_Pattern_Trait;
35
36 /**
37 * Used to define the editor
38 *
39 * @var boolean
40 */
41 public $is_form_editor = false;
42
43 /**
44 * Constructor for the class
45 */
46 public function __construct() {
47 add_action( 'init', array( $this, 'register_post_type' ) );
48 add_action( 'current_screen', array( $this, 'set_current_screen' ) );
49
50 add_filter( "manage_{$this->slug()}_posts_columns", array( $this, 'filter_columns' ) );
51 add_action( "manage_{$this->slug()}_posts_custom_column", array( $this, 'add_admin_column_content' ), 10, 2 );
52
53 /**
54 * @since 3.0.1
55 */
56 add_filter( 'gutenberg_can_edit_post_type', array( $this, 'can_edit_post_type' ), 150, 2 );
57 add_filter( 'use_block_editor_for_post_type', array( $this, 'can_edit_post_type' ), 150, 2 );
58 }
59
60 public function rep_instances(): array {
61 return array(
62 new Args_Meta(),
63 new Messages_Meta(),
64 new Preset_Meta(),
65 new Recaptcha_Meta(),
66 new Actions_Meta(),
67 new Gateways_Meta(),
68 new Validation_Meta(),
69 );
70 }
71
72 public function filter_columns( $columns ) {
73 $after = array( 'date' => $columns['date'] );
74 unset( $columns['date'] );
75
76 $columns['jfb_shortcode'] = __( 'Shortcode', 'jet-form-builder' );
77
78 return array_merge( $columns, $after );
79 }
80
81 public function add_admin_column_content( $column, $form_id ) {
82 if ( 'jfb_shortcode' !== $column ) {
83 return;
84 }
85 $arguments = array_diff( $this->get_args( $form_id ), Form_Arguments::arguments() );
86
87 $arguments = array_merge(
88 array( 'form_id' => $form_id ),
89 Default_Form_Arguments::arguments(),
90 $arguments
91 );
92
93 printf(
94 '<input readonly type="text" onclick="this.select()" value="%s" style="%s"/>',
95 esc_attr( Manager::get_shortcode( 'jet_fb_form', $arguments ) ),
96 'width: 100%'
97 );
98 }
99
100
101 /**
102 * Returns current post type slug
103 *
104 * @return string [type] [description]
105 */
106 public function slug() {
107 return 'jet-form-builder';
108 }
109
110
111 public function set_current_screen() {
112 $screen = get_current_screen();
113
114 if ( ! $screen || ! $screen->is_block_editor ) {
115 return;
116 }
117
118 if ( $this->slug() === $screen->id ) {
119 $this->is_form_editor = true;
120
121 } elseif ( $this->slug() !== $screen->id ) {
122 $this->is_form_editor = false;
123 }
124 }
125
126 public function is_form_list_page() {
127 if ( ! did_action( 'current_screen' ) ) {
128 return false;
129 }
130
131 $screen = get_current_screen();
132
133 return ( "edit-{$this->slug()}" === $screen->id );
134 }
135
136 /**
137 * @param $can
138 * @param $post_type
139 *
140 * @return bool
141 * @since 3.0.1
142 */
143 public function can_edit_post_type( $can, $post_type ): bool {
144 return $this->slug() === $post_type ? true : $can;
145 }
146
147 /**
148 * Register templates post type
149 *
150 * @return void
151 */
152 public function register_post_type() {
153
154 $args = array(
155 'labels' => array(
156 'name' => __( 'Forms', 'jet-form-builder' ),
157 'all_items' => __( 'Forms', 'jet-form-builder' ),
158 'add_new' => __( 'Add New', 'jet-form-builder' ),
159 'add_new_item' => __( 'Add New Form', 'jet-form-builder' ),
160 'edit_item' => __( 'Edit Form', 'jet-form-builder' ),
161 'new_item' => __( 'New Form', 'jet-form-builder' ),
162 'view_item' => __( 'View Form', 'jet-form-builder' ),
163 'search_items' => __( 'Search Form', 'jet-form-builder' ),
164 'not_found' => __( 'No Forms Found', 'jet-form-builder' ),
165 'not_found_in_trash' => __( 'No Forms Found In Trash', 'jet-form-builder' ),
166 'singular_name' => __( 'JetForm', 'jet-form-builder' ),
167 'menu_name' => __( 'JetFormBuilder', 'jet-form-builder' ),
168 ),
169 'public' => true,
170 'show_ui' => true,
171 'show_in_admin_bar' => true,
172 'show_in_menu' => true,
173 'show_in_nav_menus' => false,
174 'show_in_rest' => true,
175 'publicly_queryable' => false,
176 'exclude_from_search' => true,
177 'has_archive' => false,
178 'query_var' => false,
179 'can_export' => true,
180 'rewrite' => false,
181 'capability_type' => 'post',
182 'menu_icon' => $this->get_post_type_icon(),
183 'menu_position' => 120,
184 'supports' => array( 'title', 'editor', 'custom-fields' ),
185 );
186
187 $post_type = register_post_type(
188 $this->slug(),
189 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
190 apply_filters( 'jet-form-builder/post-type/args', $args )
191 );
192
193 $this->rep_install();
194
195 /** @var Base_Meta_Type $item */
196 foreach ( $this->rep_get_items() as $item ) {
197 register_post_meta( $this->slug(), $item->get_id(), $item->to_array() );
198 }
199 }
200
201 /**
202 * @param string $name
203 *
204 * @return false|Base_Meta_Type
205 */
206 public function get_meta( string $name ) {
207 try {
208 return $this->rep_get_item( $name );
209 } catch ( Repository_Exception $exception ) {
210 return false;
211 }
212 }
213
214 /**
215 * @param $item
216 *
217 * @throws Exceptions\Repository_Exception
218 */
219 public function rep_before_install_item( $item ) {
220 if ( $item->is_supported() ) {
221 return;
222 }
223 $this->_rep_abort_this();
224 }
225
226 private function get_post_type_icon() {
227 $path = $this->get_icon_path( 'post-type.php' );
228
229 return include_once $path;
230 }
231
232 /**
233 * Returns form meta arguments:
234 * fields_layout, submit_type, captcha and required_mark
235 * in assoc array
236 *
237 * @param $form_id
238 *
239 * @return array
240 */
241 public function get_args( $form_id ): array {
242 return $this->get_meta( Args_Meta::class )->query( $form_id );
243 }
244
245 /**
246 * Returns form messages
247 *
248 * @param $form_id
249 *
250 * @return array
251 */
252 public function get_messages( $form_id ) {
253 return $this->get_meta( Messages_Meta::class )->query( $form_id );
254 }
255
256 /**
257 * Returns form actions
258 *
259 * @param $form_id
260 *
261 * @return array
262 */
263 public function get_actions( $form_id ) {
264 return $this->get_meta( Actions_Meta::class )->query( $form_id );
265 }
266
267 /**
268 * Returns form actions
269 *
270 * @param $form_id
271 *
272 * @return array
273 */
274 public function get_preset( $form_id ) {
275 return $this->get_meta( Preset_Meta::class )->query( $form_id );
276 }
277
278 /**
279 * Returns captcha settings
280 *
281 * @param $form_id
282 *
283 * @return array
284 */
285 public function get_recaptcha( $form_id ) {
286 return $this->get_meta( Recaptcha_Meta::class )->query( $form_id );
287 }
288
289 /**
290 * Returns form gateways
291 *
292 * @param $form_id
293 *
294 * @return array
295 */
296 public function get_gateways( $form_id ) {
297 return $this->get_meta( Gateways_Meta::class )->query( $form_id );
298 }
299
300 public function get_validation( $form_id ) {
301 return $this->get_meta( Validation_Meta::class )->query( $form_id );
302 }
303
304 /**
305 * @param $meta_key
306 * @param $form_id
307 *
308 * @return array|mixed
309 * @deprecated since 3.0.0
310 */
311 public function get_form_meta( $meta_key, $form_id ) {
312 return Tools::decode_json(
313 get_post_meta(
314 $form_id,
315 $meta_key,
316 true
317 )
318 );
319 }
320
321 public function maybe_get_jet_sm_ready_styles( $form_id ) {
322 return Compatibility::has_jet_sm() ? get_post_meta( $form_id, '_jet_sm_ready_style', true ) : '';
323 }
324
325
326 }
327