PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.1
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / integrations / third-party / wpml.php

wpml.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.1, at src/integrations/third-party/wpml.php

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