PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
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 / admin / settings-settings.php
pods / ui / admin Last commit date
callouts 1 year ago upgrade 2 years ago widgets 2 years ago components-admin.php 2 years ago help-addons-row.php 2 years ago help-addons.php 2 years ago help.php 2 years ago postbox-header.php 2 years ago settings-reset.php 9 months ago settings-settings.php 11 months ago settings-tools.php 2 years ago settings.php 2 years ago setup-add.php 11 months ago setup-edit.php 2 years ago shortcode.php 2 years ago view.php 2 years ago
settings-settings.php
173 lines
1 <?php
2
3 use Pods\Whatsit\Field;
4
5 // Don't load directly.
6 if ( ! defined( 'ABSPATH' ) || ! pods_is_admin( 'pods_settings' ) ) {
7 die( '-1' );
8 }
9
10 wp_enqueue_script( 'pods' );
11 pods_form_enqueue_style( 'pods-form' );
12
13 /**
14 * Allow filtering the list of fields for the settings page.
15 *
16 * @since 2.8.0
17 *
18 * @param array $fields List of fields for the settings page.
19 */
20 $fields = apply_filters( 'pods_admin_settings_fields', array() );
21
22 // Convert into Field objects.
23 foreach ( $fields as $key => $field ) {
24 if ( ! $field instanceof Field ) {
25 $field['name'] = ! empty( $field['name'] ) ? $field['name'] : $key;
26
27 $field = new Field( $field );
28
29 // Replace dependency logic with conditional logic.
30 $field->maybe_migrate_dependency();
31
32 $fields[ $key ] = $field;
33 }
34 }
35
36 if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'pods-settings' ) ) {
37 if ( isset( $_POST['pods_cache_flush'] ) ) {
38 // Handle clearing cache.
39 $api = pods_api();
40
41 $api->cache_flush_pods();
42
43 if ( defined( 'PODS_PRELOAD_CONFIG_AFTER_FLUSH' ) && PODS_PRELOAD_CONFIG_AFTER_FLUSH ) {
44 $api->load_pods( array( 'bypass_cache' => true ) );
45 }
46
47 pods_redirect( pods_query_arg( array( 'pods_cache_flushed' => 1 ), array( 'page', 'tab' ) ) );
48 } else {
49 // Handle saving settings.
50 $action = __( 'saved', 'pods' );
51
52 $params = pods_unslash( (array) $_POST );
53
54 $settings_to_save = [];
55
56 $layout_field_types = PodsForm::layout_field_types();
57
58 foreach ( $fields as $key => $field ) {
59 // Auto set the field name.
60 if ( ! isset( $field['name'] ) ) {
61 $field['name'] = $key;
62 }
63
64 // Skip layout field types.
65 if ( isset( $field['type'] ) && in_array( $field['type'], $layout_field_types, true ) ) {
66 continue;
67 }
68
69 $value = '';
70
71 if ( isset( $params[ 'pods_field_' . $field['name'] ] ) ) {
72 $value = $params[ 'pods_field_' . $field['name'] ];
73 } elseif ( 'boolean' === $field['type'] ) {
74 $value = '0';
75 }
76
77 $sanitize_callback = pods_v( 'sanitize_callback', $field, 'sanitize_text_field', true );
78
79 // Sanitize value if needed.
80 if ( is_callable( $sanitize_callback ) ) {
81 if ( is_array( $value ) ) {
82 $value = array_map( $sanitize_callback, $value );
83 } else {
84 $value = $sanitize_callback( $value );
85 }
86 }
87
88 $settings_to_save[ $field['name'] ] = $value;
89 }
90
91 if ( $settings_to_save ) {
92 pods_update_settings( $settings_to_save );
93
94 // Flush cache after changing settings.
95 pods_api()->cache_flush_pods();
96
97 $message = sprintf( __( '<strong>Success!</strong> %1$s %2$s successfully.', 'pods' ), __( 'Settings', 'pods' ), $action );
98
99 pods_message( $message );
100 } else {
101 $error = sprintf( __( '<strong>Error:</strong> %1$s %2$s successfully.', 'pods' ), __( 'Settings', 'pods' ), $action );
102
103 pods_message( $error, 'error' );
104 }
105 }
106 } elseif ( 1 === (int) pods_v( 'pods_cache_flushed' ) ) {
107 pods_message( __( 'Pods transients and cache have been cleared.', 'pods' ) );
108 }
109
110 $do = 'save';
111 ?>
112
113 <h3><?php _e( 'Pods Cache Reset', 'pods' ); ?></h3>
114
115 <p><?php esc_html_e( 'You can clear all of the transients and object caches that are used by Pods and your site.', 'pods' ); ?></p>
116
117 <p class="submit">
118 <input type="submit" class="button button-secondary" name="pods_cache_flush" value="<?php esc_attr_e( 'Clear Pods Cache', 'pods' ); ?>" />
119 </p>
120
121 <hr />
122
123 <div class="pods-submittable-fields pods-dependency">
124 <?php echo PodsForm::field( 'do', $do, 'hidden' ); ?>
125
126 <?php
127 foreach ( $fields as $key => $field ) {
128 // Auto set the field name.
129 if ( ! isset( $field['name'] ) ) {
130 $fields[ $key ]['name'] = $key;
131 }
132
133 // Skip if not hidden.
134 if ( 'hidden' !== $field['type'] ) {
135 continue;
136 }
137
138 $field['name_prefix'] = 'pods_field_';
139
140 // Output hidden field at top.
141 echo PodsForm::field( $field['name'], pods_get_setting( $field['name'], pods_v( 'default', $field ) ), 'hidden' );
142
143 // Remove from list of fields to render below.
144 unset( $fields[ $key ] );
145 }
146 ?>
147 <table class="form-table pods-manage-field">
148 <?php
149 $field_prefix = 'pods_field_';
150 $field_row_classes = '';
151 $id = '';
152 $value_callback = static function( $field_name, $id, $field, $pod ) {
153 return pods_get_setting( $field_name, pods_v( 'default', $field ) );
154 };
155
156 pods_view( PODS_DIR . 'ui/forms/table-rows.php', compact( array_keys( get_defined_vars() ) ) );
157 ?>
158 </table>
159
160 <p class="submit">
161 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Settings', 'pods' ); ?>">
162 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
163 </p>
164 </div>
165
166 <script type="text/javascript">
167 jQuery( function ( $ ) {
168 $( document ).Pods( 'validate' );
169 $( document ).Pods( 'dependency', true );
170 $( document ).Pods( 'qtip', '.pods-submittable' );
171 } );
172 </script>
173