PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.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
pagination 2 days ago filters.php 2 days ago form.php 2 days ago view.php 2 days ago widgets.php 2 days ago
form.php
212 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 wp_enqueue_style( 'pods-form' );
9 wp_enqueue_script( 'pods' );
10
11 // unset fields
12 foreach ( $fields as $k => $field ) {
13
14 // Make sure all required array keys exist.
15 $field = wp_parse_args( $field, array(
16 'name' => '',
17 'type' => '',
18 'label' => '',
19 'help' => '',
20 'options' => array(),
21 ) );
22 $fields[ $k ] = $field;
23
24 if ( in_array( $field[ 'name' ], array( 'created', 'modified' ), true ) ) {
25 unset( $fields[ $k ] );
26 }
27 elseif ( false === PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
28 if ( pods_var( 'hidden', $field[ 'options' ], false ) ) {
29 $fields[ $k ][ 'type' ] = 'hidden';
30 }
31 elseif ( pods_var( 'read_only', $field[ 'options' ], false ) ) {
32 $fields[ $k ][ 'readonly' ] = true;
33 }
34 else {
35 unset( $fields[ $k ] );
36 }
37 }
38 elseif ( !pods_has_permissions( $field[ 'options' ] ) ) {
39 if ( pods_var( 'hidden', $field[ 'options' ], false ) ) {
40 $fields[ $k ][ 'type' ] = 'hidden';
41 }
42 elseif ( pods_var( 'read_only', $field[ 'options' ], false ) ) {
43 $fields[ $k ][ 'readonly' ] = true;
44 }
45 }
46 }
47
48 $submittable_fields = $fields;
49
50 foreach ( $submittable_fields as $k => $field ) {
51 if ( pods_var( 'readonly', $field, false ) ) {
52 unset( $submittable_fields[ $k ] );
53 }
54 }
55
56 $uri_hash = pods_access_form_uri_hash();
57
58 if ( pods_access_form_nonce_present_in_request( 'form' ) ) {
59 try {
60 $id = $pod->api->process_form( $_POST, $pod, $submittable_fields, $thank_you );
61 } catch ( Exception $e ) {
62 pods_message( esc_html( $e->getMessage() ), 'error' );
63 }
64 }
65
66 $field_prefix = '';
67
68 if ( !$fields_only ) {
69 $field_prefix = 'pods_field_';
70 ?>
71 <form action="" method="post" class="pods-submittable pods-form pods-form-front pods-form-pod-<?php echo esc_attr( $pod->pod ); ?> pods-submittable-ajax" data-location="<?php echo esc_attr( pods_enforce_safe_url( $thank_you ) ); ?>">
72 <div class="pods-submittable-fields">
73 <?php echo PodsForm::field( 'action', 'pods_admin', 'hidden' ); ?>
74 <?php echo PodsForm::field( 'method', 'process_form', 'hidden' ); ?>
75 <?php echo PodsForm::field( 'do', ( 0 < $pod->id() ? 'save' : 'create' ), 'hidden' ); ?>
76 <?php pods_access_output_form_nonce_fields( $pod->pod, $pod->id(), $submittable_fields, pods_access_form_field_names( 'form' ), $uri_hash ); ?>
77 <?php echo PodsForm::field( '_pods_form', implode( ',', array_keys( $submittable_fields ) ), 'hidden' ); ?>
78 <?php echo PodsForm::field( '_pods_location', $_SERVER[ 'REQUEST_URI' ], 'hidden' ); ?>
79 <?php
80 }
81
82 /**
83 * Runs before fields are outputted.
84 *
85 * @params array $fields Fields of the form.
86 * @params object $pod The current Pod object.
87 * @params array $params The form's parameters.
88 *
89 * @since 2.3.19
90 */
91 do_action( 'pods_form_pre_fields', $fields, $pod, $params );
92 ?>
93
94 <ul class="pods-form-fields pods-dependency">
95 <?php
96 foreach ( $fields as $field ) {
97 if ( 'hidden' == $field[ 'type' ] ) {
98 continue;
99 }
100
101 /**
102 * Runs before a field is outputted.
103 *
104 * @param array $field The current field.
105 * @param array $fields All fields of the form.
106 * @param object $pod The current Pod object.
107 * @param array $params The form's parameters.
108 *
109 * @since 2.3.19
110 */
111 do_action( 'pods_form_pre_field', $field, $fields, $pod, $params );
112
113 $default_class = ' pods-form-ui-row-type-' . $field[ 'type' ] . ' pods-form-ui-row-name-' . PodsForm::clean( $field[ 'name' ] );
114
115 // Setup field conditionals.
116 $dependencies = PodsForm::dependencies( $field, 'pods-field-' );
117 if ( ! empty( $dependencies['classes'] ) ) {
118 $default_class .= ' ' . $dependencies['classes'];
119 }
120 $dep_data = $dependencies['data'];
121
122 /**
123 * Filter the html class used on form field list item element.
124 *
125 * @param string $html_class The HTML class.
126 * @param array $field The current field.
127 *
128 * @since 2.7.2
129 */
130 $html_class = apply_filters( 'pods_form_html_class', 'pods-field-html-class', $field ) . $default_class;
131 ?>
132 <li class="pods-field <?php echo esc_attr( $html_class, true ); ?>" <?php PodsForm::data( $dep_data ); ?>>
133 <div class="pods-field-label">
134 <?php echo PodsForm::label( $field_prefix . $field[ 'name' ], $field[ 'label' ], $field[ 'help' ], $field ); ?>
135 </div>
136
137 <div class="pods-field-input">
138 <?php echo PodsForm::field( $field_prefix . $field[ 'name' ], $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ), $field[ 'type' ], $field, $pod, $pod->id() ); ?>
139
140 <?php echo PodsForm::comment( $field_prefix . $field[ 'name' ], null, $field ); ?>
141 </div>
142 </li>
143 <?php
144 /**
145 * Runs after a field is outputted.
146 *
147 * @params array $field The current field.
148 * @params array $fields All fields of the form.
149 * @params object $pod The current Pod object.
150 * @params array $params The form's parameters.
151 *
152 * @since 2.3.19
153 */
154 do_action( 'pods_form_after_field', $field, $fields, $pod, $params );
155 }
156 ?>
157 </ul>
158
159 <?php
160 foreach ( $fields as $field ) {
161 if ( 'hidden' != $field[ 'type' ] ) {
162 continue;
163 }
164
165 echo PodsForm::field( $field_prefix . $field[ 'name' ], $pod->field( array( 'name' => $field[ 'name' ], 'in_form' => true ) ), 'hidden', $field, $pod, $pod->id() );
166 }
167
168 /**
169 * Runs after all fields are outputted.
170 *
171 * @params array $fields Fields of the form
172 * @params object $pod The current Pod object
173 * @params array $params The form's parameters.
174 *
175 * @since 2.3.19
176 */
177 do_action( 'pods_form_after_fields', $fields, $pod, $params );
178 ?>
179
180 <?php
181 if ( !$fields_only ) {
182 ?>
183 <p class="pods-submit">
184 <img class="waiting" src="<?php echo esc_url( admin_url( '/images/wpspin_light.gif' ) ); ?>" alt="">
185 <input type="submit" value=" <?php echo esc_attr( $label ); ?> " class="pods-submit-button" />
186
187 <?php do_action( 'pods_form_after_submit', $pod, $fields, $params ); ?>
188 </p>
189 </div>
190 </form>
191
192 <script type="text/javascript">
193 if ( 'undefined' === typeof pods_form_init ) {
194 var pods_form_init = true;
195
196 document.addEventListener( "DOMContentLoaded", function() {
197 if ( 'undefined' !== typeof jQuery( document ).Pods ) {
198
199 if ( 'undefined' === typeof ajaxurl ) {
200 window.ajaxurl = <?php echo json_encode( esc_url_raw( admin_url( 'admin-ajax.php' ) ) ); ?>;
201 }
202
203 jQuery( document ).Pods( 'validate' );
204 jQuery( document ).Pods( 'submit' );
205 jQuery( document ).Pods( 'dependency', true ); // Pass `true` to trigger init.
206 }
207 }, false );
208 }
209 </script>
210 <?php
211 }
212