From 221c2365f4675c62655144d30d6148f572656ee3 Mon Sep 17 00:00:00 2001 From: Markus Reis Date: Thu, 7 Jan 2021 08:57:20 +0100 Subject: [PATCH 1/2] adds mlsl_output_x_default_locale filter to allow for an x-default hreflang node if more than one alternate links exist --- includes/MslsOutput.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/MslsOutput.php b/includes/MslsOutput.php index 90cc01c6..f0c633b7 100644 --- a/includes/MslsOutput.php +++ b/includes/MslsOutput.php @@ -103,6 +103,7 @@ public function get_alternate_links() { $arr = []; $default = ''; + $defaultLocale = apply_filters('mlsl_output_x_default_locale', null); foreach ( $blogs->get_objects() as $blog ) { $url = apply_filters( 'mlsl_output_get_alternate_links', $blog->get_url( $options ), $blog ); @@ -114,14 +115,14 @@ public function get_alternate_links() { $description = $blog->get_description(); $format = ''; - if ( '' === $default ) { - $default = sprintf( $format, 'x-default', $url, esc_attr( $description ) ); + if ( '' === $default || $blog->get_language() === $defaultLocale ) { + $default = sprintf( $format, 'x-default', $url, esc_attr( $description ) ); } $arr[] = sprintf( $format, $hreflang->get( $blog->get_language() ), $url, esc_attr( $description ) ); } - return 1 === count( $arr ) ? $default : implode( PHP_EOL, $arr ); + return 1 === count( $arr ) ? $default : implode( PHP_EOL, $arr ) . (is_null($defaultLocale) ? '' : $default); } /** From f14c5372a92fd1fcfd12273845c1cdada88c4a70 Mon Sep 17 00:00:00 2001 From: Markus Reis Date: Thu, 7 Jan 2021 08:58:16 +0100 Subject: [PATCH 2/2] rename defaultLocale variable camelCase to snake_case --- includes/MslsOutput.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/MslsOutput.php b/includes/MslsOutput.php index f0c633b7..18b93a9a 100644 --- a/includes/MslsOutput.php +++ b/includes/MslsOutput.php @@ -103,7 +103,7 @@ public function get_alternate_links() { $arr = []; $default = ''; - $defaultLocale = apply_filters('mlsl_output_x_default_locale', null); + $default_locale = apply_filters('mlsl_output_x_default_locale', null); foreach ( $blogs->get_objects() as $blog ) { $url = apply_filters( 'mlsl_output_get_alternate_links', $blog->get_url( $options ), $blog ); @@ -115,14 +115,14 @@ public function get_alternate_links() { $description = $blog->get_description(); $format = ''; - if ( '' === $default || $blog->get_language() === $defaultLocale ) { + if ( '' === $default || $blog->get_language() === $default_locale ) { $default = sprintf( $format, 'x-default', $url, esc_attr( $description ) ); } $arr[] = sprintf( $format, $hreflang->get( $blog->get_language() ), $url, esc_attr( $description ) ); } - return 1 === count( $arr ) ? $default : implode( PHP_EOL, $arr ) . (is_null($defaultLocale) ? '' : $default); + return 1 === count( $arr ) ? $default : implode( PHP_EOL, $arr ) . (is_null($default_locale) ? '' : $default); } /**