PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.2
Pods – Custom Content Types and Fields v3.2.2
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 / src / Pods / Admin / Settings.php
pods / src / Pods / Admin Last commit date
Config 2 years ago Service_Provider.php 3 years ago Settings.php 2 years ago
Settings.php
404 lines
1 <?php
2
3 namespace Pods\Admin;
4
5 use PodsForm;
6
7 /**
8 * Settings specific functionality.
9 *
10 * @since 2.8.0
11 */
12 class Settings {
13
14 const OPTION_NAME = 'pods_settings';
15
16 /**
17 * Add the class hooks.
18 *
19 * @since 2.8.0
20 */
21 public function hook() {
22 add_filter( 'pods_admin_settings_fields', [ $this, 'add_settings_fields' ], 9 );
23 }
24
25 /**
26 * Remove the class hooks.
27 *
28 * @since 2.8.0
29 */
30 public function unhook() {
31 remove_filter( 'pods_admin_settings_fields', [ $this, 'add_settings_fields' ], 9 );
32 }
33
34 /**
35 * Get the value for a Pods setting.
36 *
37 * @since 2.8.0
38 *
39 * @param string $setting_name The setting name.
40 * @param null $default The default value if the setting is not yet set.
41 *
42 * @return mixed The setting value.
43 */
44 public function get_setting( $setting_name, $default = null ) {
45 $settings = $this->get_settings();
46
47 $setting = pods_v( $setting_name, $settings, $default );
48
49 if ( null !== $default && ( null === $setting || '' === $setting ) ) {
50 return $default;
51 }
52
53 return $setting;
54 }
55
56 /**
57 * Get the Pods settings.
58 *
59 * @since 2.8.0
60 *
61 * @return array The setting values.
62 */
63 public function get_settings() {
64 $settings = get_option( self::OPTION_NAME, [] );
65
66 if ( ! $settings ) {
67 $settings = [];
68 }
69
70 // Register settings with Wisdom Tracker.
71 $settings['wisdom_registered_setting'] = 1;
72
73 static $defaults;
74
75 if ( null === $defaults ) {
76 $defaults = $this->get_setting_fields();
77 }
78
79 $layout_field_types = PodsForm::layout_field_types();
80
81 // Set up defaults as needed.
82 foreach ( $defaults as $setting_name => $setting ) {
83 // Skip layout field types.
84 if ( isset( $setting['type'] ) && in_array( $setting['type'], $layout_field_types, true ) ) {
85 continue;
86 }
87
88 // Skip if we do not have a default to set.
89 if ( ! isset( $setting['default'] ) ) {
90 continue;
91 }
92
93 // Skip if we do not
94 if ( isset( $settings[ $setting_name ] ) && ! in_array( $settings[ $setting_name ], [ null, '' ], true ) ) {
95 continue;
96 }
97
98 $settings[ $setting_name ] = $setting['default'];
99 }
100
101 return $settings;
102 }
103
104 /**
105 * Update the value for a Pods setting.
106 *
107 * @since 2.8.0
108 *
109 * @param string $setting_name The setting name.
110 * @param mixed $setting_value The setting value.
111 */
112 public function update_setting( $setting_name, $setting_value ) {
113 $settings = $this->get_settings();
114
115 if ( null !== $setting_value ) {
116 $settings[ $setting_name ] = $setting_value;
117 } elseif ( isset( $settings[ $setting_name ] ) ) {
118 unset( $settings[ $setting_name ] );
119 }
120
121 $this->update_option( $settings );
122 }
123
124 /**
125 * Update the settings for a Pods.
126 *
127 * @since 2.8.0
128 *
129 * @param array $setting_values The list of settings to update, pass null as a value to remove it.
130 */
131 public function update_settings( array $setting_values ) {
132 $settings = $this->get_settings();
133 $settings = array_merge( $settings, $setting_values );
134
135 foreach ( $settings as $setting_name => $setting_value ) {
136 if ( null === $setting_value ) {
137 unset( $settings[ $setting_name ] );
138 }
139 }
140
141 $this->update_option( $settings );
142 }
143
144 /**
145 * Handle saving the Pods settings to the option.
146 *
147 * @param array $settings The Pods settings to be saved.
148 */
149 private function update_option( array $settings ) {
150 /**
151 * Allow filtering whether Pods settings are set to autoload.
152 *
153 * @param string $autoload Whether Pods settings should be saved as autoload, set to 'yes' to autoload (default) and 'no' to not autoload.
154 */
155 $autoload = apply_filters( 'pods_admin_settings_autoload', 'yes' );
156
157 update_option( self::OPTION_NAME, $settings, $autoload );
158 }
159
160 /**
161 * Get the list of Pods settings fields.
162 *
163 * @since 2.8.0
164 *
165 * @return array The list of Pods settings fields.
166 */
167 public function get_setting_fields() {
168 $disabled_text = __( 'This setting is disabled because it is forced through the constant/filter elsewhere.', 'pods' );
169 $current_value = __( 'Current value', 'pods' );
170
171 $fields['core'] = [
172 'label' => __( 'Core', 'pods' ),
173 'type' => 'heading',
174 ];
175
176 $is_types_only = pods_is_types_only( true );
177 $is_types_only_overridden = null !== $is_types_only;
178
179 $is_types_only_disabled_text = sprintf(
180 '%1$s<br /><strong>%2$s: %3$s</strong>',
181 $disabled_text,
182 $current_value,
183 ! $is_types_only ? __( 'Enabled', 'pods' ) : __( 'Disabled', 'pods' )
184 );
185
186 $fields['types_only'] = [
187 'name' => 'types_only',
188 'label' => __( 'Allow Pods to create and manage custom fields on any content type created/extended through Pods', 'pods' ),
189 'help' => __( 'By default, Pods allows you to create custom fields for any content type that you create/extend with Pods. If you only intend to use Pods for content types themselves and not to add custom fields, Disabling Custom Fields can improve performance on your site. When disabled, this is known as the types-only mode feature.', 'pods' ),
190 'type' => 'pick',
191 'default' => '0',
192 'readonly' => $is_types_only_overridden,
193 'description' => $is_types_only_overridden ? $is_types_only_disabled_text : '',
194 'pick_format_type' => 'single',
195 'pick_format_single' => 'radio',
196 'data' => [
197 '0' => __( 'Enable creating custom fields with Pods', 'pods' ),
198 '1' => __( 'Disable creating custom fields with Pods (for when using Pods only for content types)', 'pods' ),
199 ],
200 'site_health_data' => [
201 '0' => __( 'Enable', 'pods' ),
202 '1' => __( 'Disable', 'pods' ),
203 ],
204 'site_health_include_in_info' => true,
205 ];
206
207 $fields['performance'] = [
208 'label' => __( 'Performance', 'pods' ),
209 'type' => 'heading',
210 ];
211
212 $first_pods_version = get_option( 'pods_framework_version_first' );
213 $first_pods_version = '' === $first_pods_version ? PODS_VERSION : $first_pods_version;
214
215 $fields['watch_changed_fields'] = [
216 'name' => 'watch_changed_fields',
217 'label' => __( 'Watch changed fields for use in hooks', 'pods' ),
218 'help' => __( 'By default, Pods does not watch changed fields when a post, term, user, or other Pods items are saved. Enabling this will allow you to use PHP hooks to reference the previous values of those fields after the save has happened.', 'pods' ),
219 'type' => 'pick',
220 'default' => version_compare( $first_pods_version, '2.8.21', '<' ) ? '1' : '0',
221 'pick_format_type' => 'single',
222 'pick_format_single' => 'radio',
223 'data' => [
224 '1' => __( 'Enable watching changed fields (may reduce performance with large processes)', 'pods' ),
225 '0' => __( 'Disable watching changed fields', 'pods' ),
226 ],
227 'site_health_data' => [
228 '1' => __( 'Enable', 'pods' ),
229 '0' => __( 'Disable', 'pods' ),
230 ],
231 'site_health_include_in_info' => true,
232 ];
233
234 $fields['metadata_integration'] = [
235 'name' => 'metadata_integration',
236 'label' => __( 'Watch WP Metadata calls', 'pods' ),
237 'help' => __( 'By default, Pods will watch Metadata calls and send any values to table-based fields as well as index relationship IDs when they are saved. You can disable this if you do not use table-based Pods and you only want to query meta-based Pods or settings.', 'pods' ),
238 'type' => 'pick',
239 'default' => ( function_exists( 'wc_get_product' ) || version_compare( $first_pods_version, '2.9.14', '<' ) ) ? '1' : '0',
240 'pick_format_type' => 'single',
241 'pick_format_single' => 'radio',
242 'data' => [
243 '1' => __( 'Enable watching WP Metadata calls (may reduce performance with large processes)', 'pods' ),
244 '0' => __( 'Disable watching WP Metadata calls', 'pods' ),
245 ],
246 'site_health_data' => [
247 '1' => __( 'Enable', 'pods' ),
248 '0' => __( 'Disable', 'pods' ),
249 ],
250 'dependency' => true,
251 'site_health_include_in_info' => true,
252 ];
253
254 $fields['metadata_override_get'] = [
255 'name' => 'metadata_override_get',
256 'label' => __( 'Override WP Metadata values', 'pods' ),
257 'help' => __( 'By default, Pods will override Metadata values when calling functions like get_post_meta() so that it can provide more Relationship / File field context.', 'pods' ),
258 'type' => 'pick',
259 'default' => version_compare( $first_pods_version, '2.8.21', '<' ) ? '1' : '0',
260 'pick_format_type' => 'single',
261 'pick_format_single' => 'radio',
262 'data' => [
263 '1' => __( 'Enable overriding WP Metadata values (may conflict with certain plugins and decrease performance with large processes)', 'pods' ),
264 '0' => __( 'Disable overriding WP Metadata values', 'pods' ),
265 ],
266 'site_health_data' => [
267 '1' => __( 'Enable', 'pods' ),
268 '0' => __( 'Disable', 'pods' ),
269 ],
270 'depends-on' => [ 'metadata_integration' => '1' ],
271 'site_health_include_in_info' => true,
272 ];
273
274 $fields['register_meta_integration'] = [
275 'name' => 'register_meta_integration',
276 'label' => __( 'Register meta fields', 'pods' ),
277 'help' => [
278 __( 'If you register meta fields within WordPress using the register_meta() API then WordPress and other plugins can be aware of the details of that specific field configuration.', 'pods' ),
279 'https://developer.wordpress.org/reference/functions/register_meta/',
280 ],
281 'type' => 'pick',
282 'default' => '0',
283 'pick_format_type' => 'single',
284 'pick_format_single' => 'radio',
285 'data' => [
286 '1' => __( 'Enable registering meta fields through the WP Meta API (may reduce performance on sites with many Pods and fields)', 'pods' ),
287 '0' => __( 'Disable registering meta fields through the WP Meta API', 'pods' ),
288 ],
289 'site_health_data' => [
290 '1' => __( 'Enable', 'pods' ),
291 '0' => __( 'Disable', 'pods' ),
292 ],
293 'site_health_include_in_info' => true,
294 ];
295
296 $fields['media_modal_fields'] = [
297 'name' => 'media_modal_fields',
298 'label' => __( 'Show Pods fields in Media Library modals', 'pods' ),
299 'help' => __( 'This feature is only used when you have extended the WordPress Media object with Pods', 'pods' ),
300 'type' => 'pick',
301 'default' => version_compare( $first_pods_version, '2.9.16', '<' ) ? '1' : '0',
302 'pick_format_type' => 'single',
303 'pick_format_single' => 'radio',
304 'data' => [
305 '1' => __( 'Enable showing Pods fields in Media Library modals (may decrease performance with large numbers of items on admin screens with media grids)', 'pods' ),
306 '0' => __( 'Disable showing Pods fields in Media Library modals and only show them when in the full edit screen for an attachment', 'pods' ),
307 ],
308 'site_health_data' => [
309 '0' => __( 'Enable', 'pods' ),
310 '1' => __( 'Disable', 'pods' ),
311 ],
312 'site_health_include_in_info' => true,
313 ];
314
315 $session_auto_start = pods_session_auto_start( true );
316 $session_auto_start_overridden = null !== $session_auto_start;
317
318 $fields['security'] = [
319 'label' => __( 'Security', 'pods' ),
320 'type' => 'heading',
321 ];
322
323 $session_auto_start_disabled_text = sprintf(
324 '%1$s<br /><strong>%2$s: %3$s</strong>',
325 $disabled_text,
326 $current_value,
327 $session_auto_start ? __( 'Enabled', 'pods' ) : __( 'Disabled', 'pods' )
328 );
329
330 $fields['session_auto_start'] = [
331 'name' => 'session_auto_start',
332 'label' => __( 'Secure anonymous public form submissions using PHP sessions (potential performance impacts)', 'pods' ),
333 'help' => __( 'Sessions will be used to secure submissions from public forms from logged out visitors to ensure they do not submit fields they are not allowed to access. Auto-detecting sessions will automatically turn this setting on the first anonymous submission so that future submissions will be secured going forward.', 'pods' ),
334 'type' => 'pick',
335 'default' => '0',
336 'readonly' => $session_auto_start_overridden,
337 'description' => $session_auto_start_overridden ? $session_auto_start_disabled_text : '',
338 'pick_format_type' => 'single',
339 'pick_format_single' => 'radio',
340 'data' => [
341 'auto' => __( 'Auto-detect sessions (enable on first anonymous submission)', 'pods' ),
342 '1' => __( 'Enable sessions (may decrease performance)', 'pods' ),
343 '0' => __( 'Disable sessions', 'pods' ),
344 ],
345 'site_health_data' => [
346 'auto' => __( 'Auto-detect', 'pods' ),
347 '1' => __( 'Enable', 'pods' ),
348 '0' => __( 'Disable', 'pods' ),
349 ],
350 'site_health_include_in_info' => true,
351 ];
352
353 $access_fields = pods_access_settings_config();
354
355 if ( $access_fields ) {
356 $fields = array_merge( $fields, $access_fields );
357 }
358
359 $pods_init = pods_init();
360
361 $is_wisdom_opted_out = ! $pods_init->stats_tracking || ! $pods_init->stats_tracking->get_is_tracking_allowed();
362
363 $fields['wisdom-opt-in'] = [
364 'label' => __( 'Stats Tracking', 'pods' ),
365 'type' => 'heading',
366 ];
367
368 // Only register if they are already opted-in.
369 $fields['wisdom_opt_out'] = [
370 'name' => 'wisdom_opt_out',
371 'label' => __( 'Would you like to opt-out of tracking?', 'pods' ),
372 'description' => __( 'Thank you for installing our plugin. We\'d like your permission to track its usage on your site. We won\'t record any sensitive data, only information regarding the WordPress environment and your plugin settings. We will only use this information help us make improvements to the plugin and provide better support when you reach out. Tracking is completely optional.', 'pods' )
373 . "\n\n"
374 . __( 'Any information collected is not shared with third-parties and you will not be signed up for mailing lists.', 'pods' ),
375 'type' => 'pick',
376 'default' => $is_wisdom_opted_out ? '1' : '',
377 'pick_format_type' => 'single',
378 'pick_format_single' => 'radio',
379 'data' => [
380 '' => __( 'Track usage on my site', 'pods' ),
381 '1' => __( 'DO NOT track usage on my site', 'pods' ),
382 ],
383 ];
384
385 return $fields;
386 }
387
388 /**
389 * Add custom settings fields.
390 *
391 * @since 2.8.0
392 *
393 * @param array $fields List of fields to filter.
394 *
395 * @return array List of filtered fields.
396 */
397 public function add_settings_fields( $fields ) {
398 $setting_fields = $this->get_setting_fields();
399
400 return array_merge( $fields, $setting_fields );
401 }
402
403 }
404