Making WordPress.org

Changeset 9313


Ignore:
Timestamp:
12/05/2019 06:46:34 AM (7 years ago)
Author:
dd32
Message:

Translate: Only query for this locale.. not all of them.

This is the "more optimized" version that i intended to commit originally..

See r9312.
See #2768.

File:
1 edited

Legend:

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

    r9312 r9313  
    370370         * @return string Filtered $content where any WordPress.org links have been replaced with $wp_locale subdomain links.
    371371         */
    372         function localize_links( $content, $wp_locale = false ) {
     372        function localize_links( $content, $wp_locale ) {
    373373                global $wpdb;
    374374
    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 ] ) ) {
     375                static $subdomains = [];
     376                if ( ! isset( $subdomains[ $wp_locale ] ) ) {
     377                        $subdomain[ $wp_locale ] = $wpdb->get_var( $wpdb->prepare( 'SELECT subdomain FROM wporg_locales WHERE locale = %s LIMIT 1', $wp_locale ) );
     378                }
     379
     380                if ( $subdomains[ $wp_locale ] ) {
    381381                        $content = preg_replace(
    382382                                '!(?<=[\'"])https?://wordpress.org/!i', // Only match when it's a url within an attribute.
    383                                 'https://' . $subdomains[ $wp_locale ]->subdomain . '.wordpress.org/',
     383                                'https://' . $subdomains[ $wp_locale ] . '.wordpress.org/',
    384384                                $content
    385385                        );
Note: See TracChangeset for help on using the changeset viewer.