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

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

- Page: https://pluginprobe.com/plugins/searchpro/4.1.20/code/inc/thirdparty/plugin/Polylang.php
- Raw: https://pluginprobe.com/plugins/searchpro/4.1.20/raw/inc/thirdparty/plugin/Polylang.php
- Modified: 2026-10-06T13:24:46+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.1.20/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);
        add_filter('berqwp_site_url', [$this, 'set_home_url'], 10);
    }

	function set_home_url($home_url) {
		if (function_exists('pll_home_url')) {
			return pll_home_url();
		}
		return $home_url;
	}


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

```
