PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.0.10.4
Pods – Custom Content Types and Fields v3.0.10.4
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 / front / form.php
pods / ui / front Last commit date
display 2 weeks ago pagination 2 weeks ago filters.php 2 weeks ago form.php 2 weeks ago view.php 2 weeks ago widgets.php 2 weeks ago
form.php
225 lines
1 <?php
2 // Don't load directly.
3 if ( ! defined( 'ABSPATH' ) ) {
4 die( '-1' );
5 }
6
7 /**
8 * @var array $fields
9 * @var boolean $fields_only
10 * @var Pods $pod
11 * @var array $params
12 * @var string $label
13 * @var string $thank_you
14 * @var string $output_type
15 */
16 pods_form_enqueue_style( 'pods-form' );
17 pods_form_enqueue_script( 'pods' );
18
19 $pod_name = $pod->pod;
20 $id = $pod->id();
21
22 // Set up fields.
23 foreach ( $fields as $k => $field ) {
24 // Make sure all required array keys exist.
25 if ( ! $field instanceof \Pods\Whatsit\Field ) {
26 $field = wp_parse_args( $field, [
27 'name' => '',
28 'type' => '',
29 'label' => '',
30 'help' => '',
31 ] );
32
33 $fields[ $k ] = $field;
34 }
35
36 if ( in_array( $field['name'], [ 'created', 'modified' ], true ) ) {
37 unset( $fields[ $k ] );
38 } elseif ( ! pods_permission( $field ) ) {
39 if ( pods_v( 'hidden', $field, false ) ) {
40 $fields[ $k ]['type'] = 'hidden';
41 } elseif ( pods_v( 'read_only', $field, false ) ) {
42 $fields[ $k ]['readonly'] = true;
43 } else {
44 unset( $fields[ $k ] );
45 }
46 } elseif ( ! pods_has_permissions( $field ) ) {
47 if ( pods_v( 'hidden', $field, false ) ) {
48 $fields[ $k ]['type'] = 'hidden';
49 } elseif ( pods_v( 'read_only', $field, false ) ) {
50 $fields[ $k ]['readonly'] = true;
51 }
52 }
53 }
54
55 $submittable_fields = $fields;
56
57 foreach ( $submittable_fields as $k => $field ) {
58 if ( ! pods_v( 'readonly', $field, false ) ) {
59 continue;
60 }
61
62 unset( $submittable_fields[ $k ] );
63 }
64
65 $uri_hash = wp_create_nonce( 'pods_uri_' . pods_current_path() );
66 $field_hash = wp_create_nonce( 'pods_fields_' . implode( ',', array_keys( $submittable_fields ) ) );
67
68 if ( is_user_logged_in() ) {
69 $uid = 'user_' . get_current_user_id();
70 } else {
71 $uid = pods_session_id();
72 }
73
74 $nonce = wp_create_nonce( 'pods_form_' . $pod_name . '_' . $uid . '_' . $id . '_' . $uri_hash . '_' . $field_hash );
75
76 if ( isset( $_POST['_pods_nonce'] ) ) {
77 try {
78 $id = $pod->api->process_form( $_POST, $pod, $submittable_fields, $thank_you );
79 } catch ( Exception $e ) {
80 echo '<div class="pods-message pods-message-error">' . $e->getMessage() . '</div>';
81 }
82 }
83
84 $field_prefix = '';
85
86 $counter = (int) pods_static_cache_get( $pod->pod . '-counter', 'pods-forms' );
87
88 // Shift counter by 1 so that it always starts at 1.
89 $counter ++;
90
91 // Enforce the counter.
92 PodsForm::$form_counter = $counter;
93
94 pods_static_cache_set( $pod->pod . '-counter', $counter, 'pods-forms' );
95 ?>
96
97 <?php if ( ! $fields_only ) : ?>
98 <?php $field_prefix = 'pods_field_'; ?>
99 <form
100 action=""
101 method="post"
102 class="pods-submittable pods-form pods-form-front pods-form-pod-<?php echo esc_attr( $pod_name ); ?> pods-submittable-ajax"
103 data-location="<?php echo esc_attr( pods_enforce_safe_url( $thank_you ) ); ?>"
104 id="pods-form-<?php echo esc_attr( $pod_name . '-' . $counter ); ?>"
105 data-pods-pod-name="<?php echo esc_attr( $pod_name ); ?>"
106 data-pods-item-id="<?php echo esc_attr( $id ); ?>"
107 data-pods-form-counter="<?php echo esc_attr( $counter ); ?>"
108 >
109 <div class="pods-submittable-fields">
110 <?php echo PodsForm::field( 'action', 'pods_admin', 'hidden' ); ?>
111 <?php echo PodsForm::field( 'method', 'process_form', 'hidden' ); ?>
112 <?php echo PodsForm::field( 'do', ( ! empty( $id ) ? 'save' : 'create' ), 'hidden' ); ?>
113 <?php echo PodsForm::field( '_pods_nonce', $nonce, 'hidden' ); ?>
114 <?php echo PodsForm::field( '_pods_pod', $pod_name, 'hidden' ); ?>
115 <?php echo PodsForm::field( '_pods_id', $id, 'hidden' ); ?>
116 <?php echo PodsForm::field( '_pods_uri', $uri_hash, 'hidden' ); ?>
117 <?php echo PodsForm::field( '_pods_form', implode( ',', array_keys( $submittable_fields ) ), 'hidden' ); ?>
118 <?php echo PodsForm::field( '_pods_location', $_SERVER['REQUEST_URI'], 'hidden' ); ?>
119 <?php endif; ?>
120
121 <?php
122 /**
123 * Runs before fields are outputted.
124 *
125 * @params array $fields Fields of the form.
126 * @params object $pod The current Pod object.
127 * @params array $params The form's parameters.
128 *
129 * @since 2.3.19
130 */
131 do_action( 'pods_form_pre_fields', $fields, $pod, $params );
132
133 $field_row_classes = 'pods-field-html-class';
134 $heading_tag = 'h3';
135
136 $pre_callback = static function ( $field_name, $id, $field, $pod ) use ( $fields, $params ) {
137 /**
138 * Runs before a field is output.
139 *
140 * @since 2.3.19
141 *
142 * @param array $field The current field.
143 * @param array $fields All fields of the form.
144 * @param object $pod The current Pod object.
145 * @param array $params The form's parameters.
146 */
147 do_action( 'pods_form_pre_field', $field, $fields, $pod, $params );
148 };
149
150 $post_callback = static function ( $field_name, $id, $field, $pod ) use ( $fields, $params ) {
151 /**
152 * Runs after a field is output.
153 *
154 * @since 2.3.19
155 *
156 * @params array $field The current field.
157 * @params array $fields All fields of the form.
158 * @params object $pod The current Pod object.
159 * @params array $params The form's parameters.
160 */
161 do_action( 'pods_form_after_field', $field, $fields, $pod, $params );
162 };
163
164 $template = 'ui/forms/list-rows.php';
165 $template_before = '';
166 $template_after = '';
167
168 if ( 'div' === $output_type ) {
169 $template = 'ui/forms/div-rows.php';
170 } elseif ( 'p' === $output_type ) {
171 $template = 'ui/forms/p-rows.php';
172 } elseif ( 'table' === $output_type ) {
173 $template = 'ui/forms/table-rows.php';
174 $template_before = '<table>';
175 $template_after = '</table>';
176 }
177
178 echo $template_before;
179
180 pods_view( PODS_DIR . $template, compact( array_keys( get_defined_vars() ) ) );
181
182 echo $template_after;
183
184 /**
185 * Runs after all fields are outputted.
186 *
187 * @params array $fields Fields of the form
188 * @params object $pod The current Pod object
189 * @params array $params The form's parameters.
190 *
191 * @since 2.3.19
192 */
193 do_action( 'pods_form_after_fields', $fields, $pod, $params );
194 ?>
195
196 <?php if ( ! $fields_only ) : ?>
197 <p class="pods-submit">
198 <img class="waiting" src="<?php echo esc_url( admin_url( '/images/wpspin_light.gif' ) ); ?>" alt="<?php esc_attr_e( 'Submitting...', 'pods' ); ?>">
199 <input type="submit" value=" <?php echo esc_attr( $label ); ?> " class="pods-submit-button" />
200
201 <?php do_action( 'pods_form_after_submit', $pod, $fields, $params ); ?>
202 </p>
203 </div>
204 </form>
205
206 <script type="text/javascript">
207 if ( 'undefined' === typeof pods_form_init ) {
208 var pods_form_init = true;
209
210 document.addEventListener( "DOMContentLoaded", function () {
211 if ( 'undefined' !== typeof jQuery( document ).Pods ) {
212
213 if ( 'undefined' === typeof ajaxurl ) {
214 window.ajaxurl = '<?php echo pods_slash( admin_url( 'admin-ajax.php' ) ); ?>';
215 }
216
217 jQuery( document ).Pods( 'validate' );
218 jQuery( document ).Pods( 'submit' );
219 jQuery( document ).Pods( 'dependency', true ); // Pass `true` to trigger init.
220 }
221 }, false );
222 }
223 </script>
224 <?php endif; ?>
225