PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.7
Pods – Custom Content Types and Fields v3.2.7
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 2 years 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 2 years ago settings-settings.php 2 years ago settings-tools.php 2 years ago settings.php 2 years ago setup-add.php 2 years ago setup-edit.php 2 years ago shortcode.php 2 years ago view.php 2 years ago
settings-settings.php
170 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 $message = sprintf( __( '<strong>Success!</strong> %1$s %2$s successfully.', 'pods' ), __( 'Settings', 'pods' ), $action );
95
96 pods_message( $message );
97 } else {
98 $error = sprintf( __( '<strong>Error:</strong> %1$s %2$s successfully.', 'pods' ), __( 'Settings', 'pods' ), $action );
99
100 pods_message( $error, 'error' );
101 }
102 }
103 } elseif ( 1 === (int) pods_v( 'pods_cache_flushed' ) ) {
104 pods_message( __( 'Pods transients and cache have been cleared.', 'pods' ) );
105 }
106
107 $do = 'save';
108 ?>
109
110 <h3><?php _e( 'Pods Cache Reset', 'pods' ); ?></h3>
111
112 <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>
113
114 <p class="submit">
115 <input type="submit" class="button button-secondary" name="pods_cache_flush" value="<?php esc_attr_e( 'Clear Pods Cache', 'pods' ); ?>" />
116 </p>
117
118 <hr />
119
120 <div class="pods-submittable-fields pods-dependency">
121 <?php echo PodsForm::field( 'do', $do, 'hidden' ); ?>
122
123 <?php
124 foreach ( $fields as $key => $field ) {
125 // Auto set the field name.
126 if ( ! isset( $field['name'] ) ) {
127 $fields[ $key ]['name'] = $key;
128 }
129
130 // Skip if not hidden.
131 if ( 'hidden' !== $field['type'] ) {
132 continue;
133 }
134
135 $field['name_prefix'] = 'pods_field_';
136
137 // Output hidden field at top.
138 echo PodsForm::field( $field['name'], pods_get_setting( $field['name'], pods_v( 'default', $field ) ), 'hidden' );
139
140 // Remove from list of fields to render below.
141 unset( $fields[ $key ] );
142 }
143 ?>
144 <table class="form-table pods-manage-field">
145 <?php
146 $field_prefix = 'pods_field_';
147 $field_row_classes = '';
148 $id = '';
149 $value_callback = static function( $field_name, $id, $field, $pod ) {
150 return pods_get_setting( $field_name, pods_v( 'default', $field ) );
151 };
152
153 pods_view( PODS_DIR . 'ui/forms/table-rows.php', compact( array_keys( get_defined_vars() ) ) );
154 ?>
155 </table>
156
157 <p class="submit">
158 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Settings', 'pods' ); ?>">
159 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
160 </p>
161 </div>
162
163 <script type="text/javascript">
164 jQuery( function ( $ ) {
165 $( document ).Pods( 'validate' );
166 $( document ).Pods( 'dependency', true );
167 $( document ).Pods( 'qtip', '.pods-submittable' );
168 } );
169 </script>
170