1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?php
namespace Yoast\WP\SEO\Integrations\Third_Party;
use Yoast\WP\SEO\Conditionals\Third_Party\WPML_Conditional; use Yoast\WP\SEO\Integrations\Integration_Interface;
/** * WPML integration. */ class WPML implements Integration_Interface {
/** * Initializes the integration. * * This is the place to register hooks and filters. * * @return void */ public function register_hooks() { \add_action( 'wpseo_home_url', [ $this, 'filter_home_url_before' ] ); \add_filter( 'home_url', [ $this, 'filter_home_url_after' ], 100 ); }
/** * Returns the conditionals based in which this loadable should be active. * * @return array */ public static function get_conditionals() { return [ WPML_Conditional::class ]; }
/** * Adds a filter to WPML's wpml_get_home_url filter to ensure we get the unmanipulated home URL. */ public function filter_home_url_before() { \add_filter( 'wpml_get_home_url', [ $this, 'wpml_get_home_url' ], 10, 2 ); }
/** * Removes the wpml_get_home_url filter to return the WPML, language-enriched home URL. * * @param string $home_url The filtered home URL. * * @return string The unfiltered home URL. */ public function filter_home_url_after( $home_url ) { \remove_filter( 'wpml_get_home_url', [ $this, 'wpml_get_home_url' ], 10 );
return $home_url; }
/** * Returns the original URL instead of the language-enriched URL. * This method gets automatically triggered by the wpml_get_home_url filter. * * @param string $home_url The url altered by WPML. Unused. * @param string $url The url that isn't altered by WPML. * * @return string The original url. */ public function wpml_get_home_url( $home_url, $url ) { return $url; } }
|