# searchpro/4.0.30/inc/thirdparty/plugin/Polylang.php

BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS &amp; JavaScript, version 4.0.30. 42 lines.

- Page: https://pluginprobe.com/plugins/searchpro/4.0.30/code/inc/thirdparty/plugin/Polylang.php
- Raw: https://pluginprobe.com/plugins/searchpro/4.0.30/raw/inc/thirdparty/plugin/Polylang.php
- Modified: 2025-07-18T08:37:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/searchpro/4.0.30/code/inc/thirdparty/plugin/Polylang.php#L10-L20`.

```php
<?php

if (!defined('ABSPATH'))
    exit;

class berqPolylang extends berqIntegrations
{
    function __construct()
    {
        add_filter('berqwp_page_translation_urls', [$this, 'get_page_translations'], 10, 2);
    }

    function get_page_translations($translated_urls, $post_url)
    {
        // 1. Skip if Polylang isn’t active.
        if (!function_exists('pll_get_post')) {
            return $translated_urls;
        }

        // 2. Resolve the post ID from the passed-in URL.
        $post_id = url_to_postid($post_url);
        if (!$post_id) {
            return $translated_urls;                       // not a singular URL → nothing to add
        }

        // 3. Loop through every enabled language and get the translation ID.
        foreach (pll_languages_list() as $lang) {
            $tr_id = pll_get_post($post_id, $lang);

            // If a translation exists, push its permalink (numeric index).
            if ($tr_id) {
                $translated_urls[] = get_permalink($tr_id);
            }
        }

        return $translated_urls;
    }


}

new berqPolylang();
```
