Making WordPress.org


Ignore:
Timestamp:
12/05/2019 06:37:42 AM (5 years ago)
Author:
dd32
Message:

Translate: Localise links to Plugin/Theme pages within the project description when viewing on a locale-specific page.

Fixes #2768.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php

    r8751 r9312  
    362362        return $sub_projects;
    363363    }
     364
     365    /**
     366     * Localize any WordPress.org links.
     367     *
     368     * @param string $content   The content to search for WordPress.org links in.
     369     * @param string $wp_locale The WP_Locale subdomain that the content should reference.
     370     * @return string Filtered $content where any WordPress.org links have been replaced with $wp_locale subdomain links.
     371     */
     372    function localize_links( $content, $wp_locale = false ) {
     373        global $wpdb;
     374
     375        static $subdomains = null;
     376        if ( is_null( $subdomains ) && $wp_locale ) {
     377            $subdomains = $wpdb->get_results( 'SELECT locale, subdomain FROM wporg_locales', OBJECT_K );
     378        }
     379
     380        if ( $wp_locale && isset( $subdomains[ $wp_locale ] ) ) {
     381            $content = preg_replace(
     382                '!(?<=[\'"])https?://wordpress.org/!i', // Only match when it's a url within an attribute.
     383                'https://' . $subdomains[ $wp_locale ]->subdomain . '.wordpress.org/',
     384                $content
     385            );
     386        }
     387
     388        return $content;
     389    }
    364390}
Note: See TracChangeset for help on using the changeset viewer.