| 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(); |