PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.0.10.5
Pods – Custom Content Types and Fields v3.0.10.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 1 day ago div-row.php 1 day ago div-rows.php 1 day ago form.php 1 day ago list-row.php 1 day ago list-rows.php 1 day ago p-row.php 1 day ago p-rows.php 1 day ago table-row.php 1 day ago table-rows.php 1 day ago
form.php
261 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 if ( $group['fields'][ $k ] instanceof \Pods\Whatsit\Field ) {
62 $group['fields'][ $k ] = clone $group['fields'][ $k ];
63 }
64
65 $group['fields'][ $k ]['type'] = 'hidden';
66 } elseif ( (boolean) pods_v( 'read_only', $field['options'], false ) ) {
67 $group['fields'][ $k ]['readonly'] = true;
68 } else {
69 unset( $group['fields'][ $k ] );
70
71 continue;
72 }
73 } elseif ( ! pods_has_permissions( $field ) ) {
74 if ( (boolean) pods_v( 'hidden', $field['options'], false ) ) {
75 if ( $group['fields'][ $k ] instanceof \Pods\Whatsit\Field ) {
76 $group['fields'][ $k ] = clone $group['fields'][ $k ];
77 }
78
79 $group['fields'][ $k ]['type'] = 'hidden';
80 } elseif ( (boolean) pods_v( 'read_only', $field['options'], false ) ) {
81 $group['fields'][ $k ]['readonly'] = true;
82 }
83 }//end if
84
85 if ( ! pods_v_sanitized( 'readonly', $field, false ) ) {
86 $submittable_fields[ $field['name'] ] = $group['fields'][ $k ];
87 }
88
89 $group_fields[ $field['name'] ] = $group['fields'][ $k ];
90 }//end foreach
91 $groups[ $g ] = $group;
92 }//end foreach
93
94 if ( ! isset( $thank_you_alt ) ) {
95 $thank_you_alt = $thank_you;
96 }
97
98 $uri_hash = pods_access_form_uri_hash();
99 $item_id = $duplicate ? 0 : $pod->id();
100
101 $submit_result = null;
102
103 if ( pods_access_form_nonce_present_in_request( 'form' ) ) {
104 try {
105 $params = pods_unslash( (array) $_POST );
106
107 $submit_result = 0 !== $pod->api->process_form( $params, $pod, $submittable_fields, $thank_you );
108 } catch ( Exception $e ) {
109 $obj->error( wp_kses_post( $e->getMessage() ) );
110 }
111 } elseif ( isset( $_GET['do'] ) ) {
112 $submit_result = 0 !== $pod->id();
113 }
114
115 if ( null !== $submit_result ) {
116 $messages = [
117 'success' => __( 'Success', 'pods' ),
118 'error' => __( 'Error', 'pods' ),
119 // translators: %s: The singular item label.
120 'view_item' => __( 'View %s', 'pods' ),
121 // translators: %s: The singular item label.
122 'success_saved' => _x( '%s saved successfully', 'The success message shown after saving form', 'pods' ),
123 // translators: %s: The singular item label.
124 'success_created' => _x( '%s created successfully', 'The success message shown after saving form', 'pods' ),
125 // translators: %s: The singular item label.
126 'success_duplicated' => _x( '%s duplicated successfully', 'The success message shown after saving form', 'pods' ),
127 // translators: %s: The singular item label.
128 'error_saved' => _x( '%s not saved', 'The error message shown after saving form', 'pods' ),
129 // translators: %s: The singular item label.
130 'error_created' => _x( '%s not created', 'The error message shown after saving form', 'pods' ),
131 // translators: %s: The singular item label.
132 'error_duplicated' => _x( '%s not duplicated', 'The error message shown after saving form', 'pods' ),
133 ];
134
135 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_saved'] );
136 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_saved'] );
137
138 if ( ! $is_settings_pod ) {
139 if ( 'create' === pods_v( 'do', 'post', pods_v( 'do', 'get', 'save' ) ) ) {
140 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_created'] );
141 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_created'] );
142 } elseif ( 'duplicate' === pods_v( 'do', 'get', 'save' ) ) {
143 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_duplicated'] );
144 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_duplicated'] );
145 }
146 }
147
148 if ( $submit_result ) {
149 $message = sprintf( $success_message, $obj->item );
150
151 if ( ! $is_settings_pod && ! empty( $pod_options['detail_url'] ) ) {
152 $message_view =
153 $message .= sprintf(
154 ' <a target="_blank" rel="noopener noreferrer" href="%1$s">%2$s</a>',
155 esc_url( $pod->field( 'detail_url' ) ),
156 esc_html( sprintf( $messages['view_item'], $obj->item ) )
157 );
158 }
159
160 echo $obj->message( wp_kses_post( $message ) );
161 } else {
162 $error = sprintf( $error_message, $obj->item );
163
164 echo $obj->error( wp_kses_post( $error ) );
165 }
166 }
167
168 if ( ! isset( $label ) ) {
169 $label = __( 'Save', 'pods' );
170 }
171
172 $do = 'create';
173
174 if ( 0 < $pod->id() ) {
175 if ( $duplicate ) {
176 $do = 'duplicate';
177 } else {
178 $do = 'save';
179 }
180 }
181
182 $counter = (int) pods_static_cache_get( $pod->pod . '-counter', 'pods-forms' );
183
184 // Shift counter by 1 so that it always starts at 1.
185 $counter ++;
186
187 // Enforce the counter.
188 PodsForm::$form_counter = $counter;
189
190 pods_static_cache_set( $pod->pod . '-counter', $counter, 'pods-forms' );
191 ?>
192
193 <form
194 action=""
195 method="post"
196 class="pods-submittable pods-form pods-form-pod-<?php echo esc_attr( $pod->pod ); ?> pods-submittable-ajax"
197 id="pods-form-<?php echo esc_attr( $pod->pod . '-' . $counter ); ?>"
198 data-pods-pod-name="<?php echo esc_attr( $pod->pod ); ?>"
199 data-pods-item-id="<?php echo esc_attr( $item_id ); ?>"
200 data-pods-form-counter="<?php echo esc_attr( $counter ); ?>"
201 >
202 <div class="pods-submittable-fields">
203 <?php
204 echo PodsForm::field( 'action', 'pods_admin', 'hidden' );
205 echo PodsForm::field( 'method', 'process_form', 'hidden' );
206 echo PodsForm::field( 'do', $do, 'hidden' );
207 pods_access_output_form_nonce_fields( $pod->pod, $item_id, $submittable_fields, pods_access_form_field_names( 'form' ), $uri_hash );
208 echo PodsForm::field( '_pods_form_key', ! empty( $form_key ) ? $form_key : '', 'hidden' );
209 echo PodsForm::field( '_pods_location', $_SERVER['REQUEST_URI'], 'hidden' );
210
211 // 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().
212 if ( $obj instanceof PodsUI ) {
213 echo PodsForm::field( $obj->num_prefix . '_wpnonce' . $obj->num, wp_create_nonce( 'pods-ui-save' ), 'hidden' );
214 }
215
216 pods_view( PODS_DIR . 'ui/forms/type/' . sanitize_title( $form_type ) . '.php', compact( array_keys( get_defined_vars() ) ) );
217 ?>
218 </div>
219 </form>
220
221 <script type="text/javascript">
222 if ( 'undefined' == typeof ajaxurl ) {
223 var ajaxurl = <?php echo json_encode( esc_url_raw( admin_url( 'admin-ajax.php' ) ) ); ?>;
224 }
225
226 if ( 'undefined' == typeof pods_form_thank_you ) {
227 var pods_form_thank_you = null;
228 }
229
230 <?php if ( $is_settings_pod ) : ?>
231 var pods_admin_submit_callback = function ( id ) {
232 document.location = <?php echo json_encode( esc_url_raw( pods_query_arg( array( 'do' => $do ) ) ) ); ?>;
233 }
234 <?php else : ?>
235 var pods_admin_submit_callback = function ( id ) {
236 id = parseInt( id, 10 );
237 var thank_you = <?php echo json_encode( esc_url_raw( $thank_you ) ); ?>;
238 var thank_you_alt = <?php echo json_encode( esc_url_raw( $thank_you_alt ) ); ?>;
239
240 if ( 'undefined' != typeof pods_form_thank_you && null !== pods_form_thank_you ) {
241 thank_you = pods_form_thank_you;
242 }
243
244 if ( isNaN( id ) ) {
245 document.location = thank_you_alt.replace( 'X_ID_X', String( 0 ) );
246 }
247 else {
248 document.location = thank_you.replace( 'X_ID_X', String( id ) );
249 }
250 }
251 <?php endif; ?>
252
253 jQuery( function ( $ ) {
254 $( document ).Pods( 'validate' );
255 $( document ).Pods( 'submit' );
256 $( document ).Pods( 'dependency', true );
257 $( document ).Pods( 'confirm' );
258 $( document ).Pods( 'exit_confirm' );
259 } );
260 </script>
261