1, 'show_names' => 1, 'display_names_as' => 1, 'item_spacing' => 1, 'admin_render' => 1, 'admin_current_lang' => 1, 'classes' => 1, ); /** * Legacy default settings. */ protected const DEFAULTS = array( 'dropdown' => 0, // Display as list and not as dropdown. 'hide_if_empty' => 1, // Hides languages with no posts (or pages). 'show_flags' => 0, // Don't show flags. 'show_names' => 1, // Show language names. 'display_names_as' => 'name', // Display the language name. 'force_home' => 0, // Tries to find a translation. 'hide_if_no_translation' => 0, // Don't hide the link if there is no translation. 'hide_current' => 0, // Don't hide the current language. 'post_id' => null, // Link to the translations of the current page. 'item_spacing' => 'preserve', // Preserve whitespace between list items. 'admin_render' => 0, // Make the switcher in a frontend context. 'admin_current_lang' => null, // Use the global current language. ); /** * Tells if the given settings list contain legacy settings. * * @since 3.9 * * @param array $settings Settings. * @return bool */ public static function is_legacy( array $settings ): bool { return ! empty( array_intersect_key( $settings, self::REMOVED_ENTRIES ) ); } /** * Returns the values as an array after converting them to the legacy format. * * @since 3.9 * * @return array */ public function get_legacy(): array { return $this->convert_to_legacy( get_object_vars( $this ) ); } /** * Converts new settings structure to the legacy one, then applies the deprecated filter `pll_the_languages_args`, * then converts it back to new settings structure. * This removes legacy settings. * * @since 3.9 * * @param array $settings Settings in new structure. * @return array */ protected function maybe_filter_legacy( array $settings ): array { if ( ! has_filter( 'pll_the_languages_args' ) ) { if ( ! self::is_legacy( $settings ) ) { return $settings; } return array_diff_key( $this->convert_from_legacy( $settings ), self::REMOVED_ENTRIES ); } if ( ! self::is_legacy( $settings ) ) { $settings = $this->convert_to_legacy( $settings ); } /** * Filter the arguments of the 'pll_the_languages' template tag. * * @since 1.5 * @since 3.9 Deprecated. * @deprecated * * @param array $args */ $settings = apply_filters_deprecated( 'pll_the_languages_args', array( $settings ), '3.9.0', 'pll_language_switcher_settings' ); return array_diff_key( $this->convert_from_legacy( $settings ), self::REMOVED_ENTRIES ); } /** * Converts the legacy structure to the new one. * This preserves the legacy structure's keys. * * @since 3.9 * * @param array $settings The settings. * @return array */ protected function convert_from_legacy( array $settings ): array { if ( ! isset( $settings['show_wrapper'] ) ) { // Legacy list and dropdown had no outer wrapper (div/nav). The `