PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
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 weeks ago div-row.php 2 weeks ago div-rows.php 2 weeks ago form.php 2 weeks ago list-row.php 2 weeks ago list-rows.php 2 weeks ago p-row.php 2 weeks ago p-rows.php 2 weeks ago table-row.php 2 weeks ago table-rows.php 2 weeks ago
form.php
256 lines
1 <?php
2 // Don't load directly.
3 if ( ! defined( 'ABSPATH' ) ) {
4 die( '-1' );
5 }
6
7 /**
8 * @var string $form_type
9 * @var PodsUI $obj
10 * @var Pods $pod
11 * @var null|string $thank_you
12 * @var null|string $thank_you_alt
13 * @var null|string $label
14 */
15
16 use Pods\Static_Cache;
17
18 pods_form_enqueue_script( 'pods' );
19 pods_form_enqueue_style( 'pods-form' );
20
21 $is_settings_pod = 'settings' === $pod->pod_data['type'];
22
23 if ( empty( $fields ) || ! is_array( $fields ) ) {
24 $fields = $obj->pod->fields;
25 }
26
27 if ( ! isset( $duplicate ) || $is_settings_pod ) {
28 $duplicate = false;
29 } else {
30 $duplicate = (boolean) $duplicate;
31 }
32
33 $groups = PodsInit::$meta->groups_get( $pod->pod_data['type'], $pod->pod_data['name'], $fields );
34
35 if ( 1 === count( $groups ) ) {
36 $first_group = current( $groups );
37
38 if ( 0 === count( $first_group['fields'] ) ) {
39 $groups = [];
40 }
41 }
42
43 $pod_name = $pod->pod_data['name'];
44 $pod_options = $pod->pod_data['options'];
45 $pod_options = apply_filters( "pods_advanced_content_type_pod_data_{$pod_name}", $pod_options, $pod->pod_data['name'] );
46 $pod_options = apply_filters( 'pods_advanced_content_type_pod_data', $pod_options, $pod->pod_data['name'] );
47
48 $group_fields = array();
49 $submittable_fields = array();
50
51 foreach ( $groups as $g => $group ) {
52 // unset fields
53 foreach ( $group['fields'] as $k => $field ) {
54 if ( in_array( $field['name'], array( 'created', 'modified' ), true ) ) {
55 unset( $group['fields'][ $k ] );
56
57 continue;
58 } elseif ( ! pods_permission( $field ) ) {
59 if ( (boolean) pods_v( 'hidden', $field['options'], false ) ) {
60 $group['fields'][ $k ]['type'] = 'hidden';
61 } elseif ( (boolean) pods_v( 'read_only', $field['options'], false ) ) {
62 $group['fields'][ $k ]['readonly'] = true;
63 } else {
64 unset( $group['fields'][ $k ] );
65
66 continue;
67 }
68 } elseif ( ! pods_has_permissions( $field ) ) {
69 if ( (boolean) pods_v( 'hidden', $field['options'], false ) ) {
70 $group['fields'][ $k ]['type'] = 'hidden';
71 } elseif ( (boolean) pods_v( 'read_only', $field['options'], false ) ) {
72 $group['fields'][ $k ]['readonly'] = true;
73 }
74 }//end if
75
76 if ( ! pods_v_sanitized( 'readonly', $field, false ) ) {
77 $submittable_fields[ $field['name'] ] = $group['fields'][ $k ];
78 }
79
80 $group_fields[ $field['name'] ] = $group['fields'][ $k ];
81 }//end foreach
82 $groups[ $g ] = $group;
83 }//end foreach
84
85 if ( ! isset( $thank_you_alt ) ) {
86 $thank_you_alt = $thank_you;
87 }
88
89 $uri_hash = wp_create_nonce( 'pods_uri_' . pods_current_path() );
90 $field_hash = wp_create_nonce( 'pods_fields_' . implode( ',', array_keys( $submittable_fields ) ) );
91
92 if ( is_user_logged_in() ) {
93 $uid = 'user_' . get_current_user_id();
94 } else {
95 $uid = pods_session_id();
96 }
97
98 $nonce = wp_create_nonce( 'pods_form_' . $pod->pod . '_' . $uid . '_' . ( $duplicate ? 0 : $pod->id() ) . '_' . $uri_hash . '_' . $field_hash );
99
100 $submit_result = null;
101
102 if ( isset( $_POST['_pods_nonce'] ) ) {
103 try {
104 $params = pods_unslash( (array) $_POST );
105 $id = $pod->api->process_form( $params, $pod, $submittable_fields, $thank_you );
106
107 $submit_result = 0 < $id;
108 } catch ( Exception $e ) {
109 echo $obj->error( $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( $message );
161 } else {
162 $error = sprintf( $error_message, $obj->item );
163
164 echo $obj->error( $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 $counter ++;
185
186 pods_static_cache_set( $pod->pod . '-counter', $counter, 'pods-forms' );
187 ?>
188
189 <form action="" method="post"
190 class="pods-submittable pods-form pods-form-pod-<?php echo esc_attr( $pod->pod ); ?> pods-submittable-ajax"
191 id="pods-form-<?php echo esc_attr( $pod->pod . '-' . $counter ); ?>"
192 >
193 <div class="pods-submittable-fields">
194 <?php
195 echo PodsForm::field( 'action', 'pods_admin', 'hidden' );
196 echo PodsForm::field( 'method', 'process_form', 'hidden' );
197 echo PodsForm::field( 'do', $do, 'hidden' );
198 echo PodsForm::field( '_pods_nonce', $nonce, 'hidden' );
199 echo PodsForm::field( '_pods_pod', $pod->pod, 'hidden' );
200 echo PodsForm::field( '_pods_id', ( $duplicate ? 0 : $pod->id() ), 'hidden' );
201 echo PodsForm::field( '_pods_uri', $uri_hash, 'hidden' );
202 echo PodsForm::field( '_pods_form', implode( ',', array_keys( $submittable_fields ) ), 'hidden' );
203 echo PodsForm::field( '_pods_location', $_SERVER['REQUEST_URI'], 'hidden' );
204
205 // 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().
206 if ( $obj instanceof PodsUI ) {
207 PodsForm::output_field( $obj->num_prefix . '_wpnonce' . $obj->num, wp_create_nonce( 'pods-ui-save' ), 'hidden' );
208 }
209
210 pods_view( PODS_DIR . 'ui/forms/type/' . sanitize_title( $form_type ) . '.php', compact( array_keys( get_defined_vars() ) ) );
211 ?>
212 </div>
213 </form>
214
215 <script type="text/javascript">
216 if ( 'undefined' == typeof ajaxurl ) {
217 var ajaxurl = '<?php echo pods_slash( admin_url( 'admin-ajax.php' ) ); ?>';
218 }
219
220 if ( 'undefined' == typeof pods_form_thank_you ) {
221 var pods_form_thank_you = null;
222 }
223
224 <?php if ( $is_settings_pod ) : ?>
225 var pods_admin_submit_callback = function ( id ) {
226 document.location = '<?php echo pods_slash( pods_query_arg( array( 'do' => $do ) ) ); ?>';
227 }
228 <?php else : ?>
229 var pods_admin_submit_callback = function ( id ) {
230
231 id = parseInt( id, 10 );
232 var thank_you = '<?php echo esc_url_raw( $thank_you ); ?>';
233 var thank_you_alt = '<?php echo esc_url_raw( $thank_you_alt ); ?>';
234
235 if ( 'undefined' != typeof pods_form_thank_you && null !== pods_form_thank_you ) {
236 thank_you = pods_form_thank_you;
237 }
238
239 if ( isNaN( id ) ) {
240 document.location = thank_you_alt.replace( 'X_ID_X', String( 0 ) );
241 }
242 else {
243 document.location = thank_you.replace( 'X_ID_X', String( id ) );
244 }
245 }
246 <?php endif; ?>
247
248 jQuery( function ( $ ) {
249 $( document ).Pods( 'validate' );
250 $( document ).Pods( 'submit' );
251 $( document ).Pods( 'dependency', true );
252 $( document ).Pods( 'confirm' );
253 $( document ).Pods( 'exit_confirm' );
254 } );
255 </script>
256