PluginProbe
Polylang / trunk
Polylang vtrunk
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / src / Switcher / Fields / Abstract_Fields.php

Abstract_Fields.php in Polylang trunk, at src/Switcher/Fields/Abstract_Fields.php

83 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 namespace WP_Syntex\Polylang\Switcher\Fields;
7
8 use WP_Syntex\Polylang\Switcher\Settings\Settings;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Abstract class to use to manage setting field data.
14 *
15 * @since 3.9
16 *
17 * @phpstan-type FieldsData array<
18 * non-falsy-string,
19 * array{
20 * label: string,
21 * choices?: array<string>,
22 * hide_if?: array<string, string|bool>,
23 * section?: string
24 * }
25 * >
26 */
27 abstract class Abstract_Fields {
28 /**
29 * Returns setting field data available for the language switcher.
30 *
31 * @since 3.9
32 *
33 * @return array[]
34 *
35 * @phpstan-return FieldsData
36 */
37 abstract public static function get(): array;
38
39 /**
40 * Removes the legacy keys that were stored in the database alongside the new ones in case of plugin rollback.
41 *
42 * This method is part of the plan to support rollbacks to versions < 3.9.
43 * Backward compatibility with Polylang < 3.9.
44 *
45 * @since 3.9
46 *
47 * @param array $raw_settings Raw settings.
48 * @return array
49 */
50 public static function remove_legacy_settings( array $raw_settings ): array {
51 if ( isset( $raw_settings['layout'] ) ) {
52 unset( $raw_settings['dropdown'], $raw_settings['show_names'] );
53 }
54 return $raw_settings;
55 }
56
57 /**
58 * Adds some legacy keys that we want to keep in the database alongside the new ones in case of plugin rollback.
59 * Must not be called before `Abstract_Fields::filter()`.
60 *
61 * This would be useful in case a user rollbacks to a version < 3.9.
62 * Backward compatibility with Polylang < 3.9.
63 *
64 * @since 3.9
65 *
66 * @param array $settings Switcher settings.
67 * @return array
68 */
69 abstract public static function add_legacy_settings( array $settings ): array;
70
71 /**
72 * Returns an array containing ONLY the values corresponding to the setting fields.
73 *
74 * @since 3.9
75 *
76 * @param Settings $settings Switcher settings.
77 * @return array
78 */
79 public static function filter( Settings $settings ): array {
80 return array_intersect_key( get_object_vars( $settings ), static::get() );
81 }
82 }
83