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