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