PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / ui / forms / form.php
pods / ui / forms Last commit date
type 2 days ago div-row.php 2 days ago div-rows.php 2 days ago form.php 2 days ago list-row.php 2 days ago list-rows.php 2 days ago p-row.php 2 days ago p-rows.php 2 days ago table-row.php 2 days ago table-rows.php 2 days ago
form.php
254 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 /**
9 * @var string $form_type
10 * @var PodsUI $obj
11 * @var Pods $pod
12 * @var null|string $thank_you
13 * @var null|string $thank_you_alt
14 * @var null|string $label
15 */
16
17 use Pods\Static_Cache;
18
19 pods_form_enqueue_script( 'pods' );
20 pods_form_enqueue_style( 'pods-form' );
21
22 $is_settings_pod = 'settings' === $pod->pod_data['type'];
23
24 if ( empty( $fields ) || ! is_array( $fields ) ) {
25 $fields = $obj->pod->fields;
26 }
27
28 if ( ! isset( $duplicate ) || $is_settings_pod ) {
29 $duplicate = false;
30 } else {
31 $duplicate = (boolean) $duplicate;
32 }
33
34 $groups = PodsInit::$meta->groups_get( $pod->pod_data['type'], $pod->pod_data['name'], $fields );
35
36 if ( 1 === count( $groups ) ) {
37 $first_group = current( $groups );
38
39 if ( 0 === count( $first_group['fields'] ) ) {
40 $groups = [];
41 }
42 }
43
44 $pod_name = $pod->pod_data['name'];
45 $pod_options = $pod->pod_data['options'];
46 $pod_options = apply_filters( "pods_advanced_content_type_pod_data_{$pod_name}", $pod_options, $pod->pod_data['name'] );
47 $pod_options = apply_filters( 'pods_advanced_content_type_pod_data', $pod_options, $pod->pod_data['name'] );
48
49 $group_fields = array();
50 $submittable_fields = array();
51
52 foreach ( $groups as $g => $group ) {
53 // unset fields
54 foreach ( $group['fields'] as $k => $field ) {
55 if ( in_array( $field['name'], array( 'created', 'modified' ), true ) ) {
56 unset( $group['fields'][ $k ] );
57
58 continue;
59 } elseif ( ! pods_permission( $field ) ) {
60 if ( (boolean) pods_v( 'hidden', $field['options'], false ) ) {
61 $group['fields'][ $k ]['type'] = 'hidden';
62 } elseif ( (boolean) pods_v( 'read_only', $field['options'], false ) ) {
63 $group['fields'][ $k ]['readonly'] = true;
64 } else {
65 unset( $group['fields'][ $k ] );
66
67 continue;
68 }
69 } elseif ( ! pods_has_permissions( $field ) ) {
70 if ( (boolean) pods_v( 'hidden', $field['options'], false ) ) {
71 $group['fields'][ $k ]['type'] = 'hidden';
72 } elseif ( (boolean) pods_v( 'read_only', $field['options'], false ) ) {
73 $group['fields'][ $k ]['readonly'] = true;
74 }
75 }//end if
76
77 if ( ! pods_v_sanitized( 'readonly', $field, false ) ) {
78 $submittable_fields[ $field['name'] ] = $group['fields'][ $k ];
79 }
80
81 $group_fields[ $field['name'] ] = $group['fields'][ $k ];
82 }//end foreach
83 $groups[ $g ] = $group;
84 }//end foreach
85
86 if ( ! isset( $thank_you_alt ) ) {
87 $thank_you_alt = $thank_you;
88 }
89
90 $uri_hash = pods_access_form_uri_hash();
91 $item_id = $duplicate ? 0 : $pod->id();
92
93 $submit_result = null;
94
95 if ( pods_access_form_nonce_present_in_request( 'form' ) ) {
96 try {
97 $params = pods_unslash( (array) $_POST );
98 $new_id = $pod->api->process_form( $params, $pod, $submittable_fields, $thank_you );
99
100 $submit_result = 0 < $new_id;
101 } catch ( Exception $e ) {
102 echo $obj->error( wp_kses_post( $e->getMessage() ) );
103 }
104 } elseif ( isset( $_GET['do'] ) ) {
105 $submit_result = 0 < $pod->id();
106 }
107
108 if ( null !== $submit_result ) {
109 $messages = [
110 'success' => __( 'Success', 'pods' ),
111 'error' => __( 'Error', 'pods' ),
112 // translators: %s: The singular item label.
113 'view_item' => __( 'View %s', 'pods' ),
114 // translators: %s: The singular item label.
115 'success_saved' => _x( '%s saved successfully', 'The success message shown after saving form', 'pods' ),
116 // translators: %s: The singular item label.
117 'success_created' => _x( '%s created successfully', 'The success message shown after saving form', 'pods' ),
118 // translators: %s: The singular item label.
119 'success_duplicated' => _x( '%s duplicated successfully', 'The success message shown after saving form', 'pods' ),
120 // translators: %s: The singular item label.
121 'error_saved' => _x( '%s not saved', 'The error message shown after saving form', 'pods' ),
122 // translators: %s: The singular item label.
123 'error_created' => _x( '%s not created', 'The error message shown after saving form', 'pods' ),
124 // translators: %s: The singular item label.
125 'error_duplicated' => _x( '%s not duplicated', 'The error message shown after saving form', 'pods' ),
126 ];
127
128 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_saved'] );
129 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_saved'] );
130
131 if ( ! $is_settings_pod ) {
132 if ( 'create' === pods_v( 'do', 'post', pods_v( 'do', 'get', 'save' ) ) ) {
133 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_created'] );
134 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_created'] );
135 } elseif ( 'duplicate' === pods_v( 'do', 'get', 'save' ) ) {
136 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_duplicated'] );
137 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_duplicated'] );
138 }
139 }
140
141 if ( $submit_result ) {
142 $message = sprintf( $success_message, $obj->item );
143
144 if ( ! $is_settings_pod && ! empty( $pod_options['detail_url'] ) ) {
145 $message_view =
146 $message .= sprintf(
147 ' <a target="_blank" rel="noopener noreferrer" href="%1$s">%2$s</a>',
148 esc_url( $pod->field( 'detail_url' ) ),
149 esc_html( sprintf( $messages['view_item'], $obj->item ) )
150 );
151 }
152
153 echo $obj->message( wp_kses_post( $message ) );
154 } else {
155 $error = sprintf( $error_message, $obj->item );
156
157 echo $obj->error( wp_kses_post( $error ) );
158 }
159 }
160
161 if ( ! isset( $label ) ) {
162 $label = __( 'Save', 'pods' );
163 }
164
165 $do = 'create';
166
167 if ( 0 < $pod->id() ) {
168 if ( $duplicate ) {
169 $do = 'duplicate';
170 } else {
171 $do = 'save';
172 }
173 }
174
175 $counter = (int) pods_static_cache_get( $pod->pod . '-counter', 'pods-forms' );
176
177 // Shift counter by 1 so that it always starts at 1.
178 $counter ++;
179
180 // Enforce the counter.
181 PodsForm::$form_counter = $counter;
182
183 pods_static_cache_set( $pod->pod . '-counter', $counter, 'pods-forms' );
184 ?>
185
186 <form
187 action=""
188 method="post"
189 class="pods-submittable pods-form pods-form-pod-<?php echo esc_attr( $pod->pod ); ?> pods-submittable-ajax"
190 id="pods-form-<?php echo esc_attr( $pod->pod . '-' . $counter ); ?>"
191 data-pods-pod-name="<?php echo esc_attr( $pod->pod ); ?>"
192 data-pods-item-id="<?php echo esc_attr( $item_id ); ?>"
193 data-pods-form-counter="<?php echo esc_attr( $counter ); ?>"
194 >
195 <div class="pods-submittable-fields">
196 <?php
197 echo PodsForm::field( 'action', 'pods_admin', 'hidden' );
198 echo PodsForm::field( 'method', 'process_form', 'hidden' );
199 echo PodsForm::field( 'do', $do, 'hidden' );
200 pods_access_output_form_nonce_fields( $pod->pod, $item_id, $submittable_fields, pods_access_form_field_names( 'form' ), $uri_hash );
201 echo PodsForm::field( '_pods_form_key', ! empty( $form_key ) ? $form_key : '', 'hidden' );
202 echo PodsForm::field( '_pods_location', $_SERVER['REQUEST_URI'], 'hidden' );
203
204 // Nonce for the non-AJAX/direct-POST save path. With JavaScript the form submits via AJAX to process_form(); without JS it posts directly and is handled by PodsUI::go() -> save().
205 if ( $obj instanceof PodsUI ) {
206 echo PodsForm::field( $obj->num_prefix . '_wpnonce' . $obj->num, wp_create_nonce( 'pods-ui-save' ), 'hidden' );
207 }
208
209 pods_view( PODS_DIR . 'ui/forms/type/' . sanitize_title( $form_type ) . '.php', compact( array_keys( get_defined_vars() ) ) );
210 ?>
211 </div>
212 </form>
213
214 <script type="text/javascript">
215 if ( 'undefined' == typeof ajaxurl ) {
216 var ajaxurl = <?php echo json_encode( esc_url_raw( admin_url( 'admin-ajax.php' ) ) ); ?>;
217 }
218
219 if ( 'undefined' == typeof pods_form_thank_you ) {
220 var pods_form_thank_you = null;
221 }
222
223 <?php if ( $is_settings_pod ) : ?>
224 var pods_admin_submit_callback = function ( id ) {
225 document.location = <?php echo json_encode( esc_url_raw( pods_query_arg( array( 'do' => $do ) ) ) ); ?>;
226 }
227 <?php else : ?>
228 var pods_admin_submit_callback = function ( id ) {
229 id = parseInt( id, 10 );
230 var thank_you = <?php echo json_encode( esc_url_raw( $thank_you ) ); ?>;
231 var thank_you_alt = <?php echo json_encode( esc_url_raw( $thank_you_alt ) ); ?>;
232
233 if ( 'undefined' != typeof pods_form_thank_you && null !== pods_form_thank_you ) {
234 thank_you = pods_form_thank_you;
235 }
236
237 if ( isNaN( id ) ) {
238 document.location = thank_you_alt.replace( 'X_ID_X', String( 0 ) );
239 }
240 else {
241 document.location = thank_you.replace( 'X_ID_X', String( id ) );
242 }
243 }
244 <?php endif; ?>
245
246 jQuery( function ( $ ) {
247 $( document ).Pods( 'validate' );
248 $( document ).Pods( 'submit' );
249 $( document ).Pods( 'dependency', true );
250 $( document ).Pods( 'confirm' );
251 $( document ).Pods( 'exit_confirm' );
252 } );
253 </script>
254