From e570c38ef3c8f74cdc89aa5736171291822c9245 Mon Sep 17 00:00:00 2001 From: Giovanni Cascione <43221199+spleen1981@users.noreply.github.com> Date: Fri, 25 Mar 2022 23:17:42 +0100 Subject: [PATCH] QTS: refactor language setup with internal `q_config` (#1130) --- .../slugs/includes/class-qtranslate-slug.php | 80 +++++-------------- 1 file changed, 19 insertions(+), 61 deletions(-) diff --git a/modules/slugs/includes/class-qtranslate-slug.php b/modules/slugs/includes/class-qtranslate-slug.php index 60a74a96..7e38cd3a 100644 --- a/modules/slugs/includes/class-qtranslate-slug.php +++ b/modules/slugs/includes/class-qtranslate-slug.php @@ -10,13 +10,6 @@ class QtranslateSlug { */ protected $options; - /** - * Array with old data system. - * @var bool - */ - //TODO: seems to be unused: remove - private $old_data = null; - /** * Stores permalink_structure option, for save queries to db. * @var string @@ -29,25 +22,6 @@ class QtranslateSlug { */ private $lang = false; - /** - * Variable for current language. - */ - //TODO: Check why not using QTX directly - private $current_lang = false; - - /** - * Variable for default language. - */ - //TODO: Check why not using QTX directly - private $default_language = false; - - /** - * Array of enabled languages. - * @var array - */ - //TODO: Check why not using QTX directly - private $enabled_languages = array(); - /** * Slug in meta_key name in meta tables. * @var string @@ -167,10 +141,6 @@ function init() { if ( is_admin() ) { include_once( dirname( __FILE__ ) . '/qtranslate-slug-settings.php' ); } - // until we get a proper function, this will make it for it. - $this->current_lang = $q_config['language']; - $this->enabled_languages = $q_config['enabled_languages']; - $this->default_language = $q_config['default_language']; if ( is_admin() ) { // add filters @@ -240,12 +210,14 @@ function init() { * @global array $q_config available languages */ public function qtranslate_slug_header_extended() { + global $q_config; if ( is_404() ) { return; } + //TODO: double check following comment: // taken from qtx but see our #341 ticket for clarification - echo '' . PHP_EOL; - foreach ( $this->get_enabled_languages() as $language ) { + echo '' . PHP_EOL; + foreach ( $q_config['enabled_languages'] as $language ) { echo '' . "\n"; } @@ -499,6 +471,7 @@ public function query_vars( $query_vars ) { * @return array $query processed */ function filter_request( $query ) { + global $q_config; global $wp; // FIXME: why is this here? it breaks custom variables getter // https://wordpress.org/support/topic/cant-retrieve-public-query-variables @@ -618,7 +591,7 @@ function filter_request( $query ) { if ( isset( $function ) ) { // parse all languages links - foreach ( $this->get_enabled_languages() as $lang ) { + foreach ( $q_config['enabled_languages'] as $lang ) { $this->lang = $lang; $this->current_url[ $lang ] = esc_url( apply_filters( 'qts_url_args', call_user_func( $function, $id ) ) ); @@ -661,6 +634,7 @@ public function get_current_url( $lang = false ) { * @return string Home url link with optional path appended. */ public function home_url( $url, $path, $scheme, $blog_id ) { + global $q_config; if ( ! in_array( $scheme, array( 'http', 'https' ) ) ) { $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; } @@ -1124,7 +1098,7 @@ public function draw_meta_box( $post ) { echo "