PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / trunk
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript vtrunk
4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 All 169 releases
searchpro / inc / thirdparty / plugin / Polylang.php

Polylang.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript trunk, at inc/thirdparty/plugin/Polylang.php

42 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH'))
4 exit;
5
6 class berqPolylang extends berqIntegrations
7 {
8 function __construct()
9 {
10 add_filter('berqwp_page_translation_urls', [$this, 'get_page_translations'], 10, 2);
11 }
12
13 function get_page_translations($translated_urls, $post_url)
14 {
15 // 1. Skip if Polylang isn’t active.
16 if (!function_exists('pll_get_post')) {
17 return $translated_urls;
18 }
19
20 // 2. Resolve the post ID from the passed-in URL.
21 $post_id = url_to_postid($post_url);
22 if (!$post_id) {
23 return $translated_urls; // not a singular URL → nothing to add
24 }
25
26 // 3. Loop through every enabled language and get the translation ID.
27 foreach (pll_languages_list() as $lang) {
28 $tr_id = pll_get_post($post_id, $lang);
29
30 // If a translation exists, push its permalink (numeric index).
31 if ($tr_id) {
32 $translated_urls[] = get_permalink($tr_id);
33 }
34 }
35
36 return $translated_urls;
37 }
38
39
40 }
41
42 new berqPolylang();