WordPress.org

Making WordPress.org

Changeset 2557


Ignore:
Timestamp:
02/23/2016 08:53:51 AM (4 years ago)
Author:
dd32
Message:

Plugins Directory: The plugins directory is available at many different localised domains, such as de.wordpress.org/plugins/ or fr.wordpress.org/plugins/.
This change works in conjuction with a sunrise.php hack to allow the plugins site to be loaded at all of the domains we need it to be, and yet respect the rosetta network customizations we've made (including language and extra plugins).

See #1584

File:
1 edited

Legend:

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

    r2555 r2557  
    122122        add_rewrite_endpoint( 'developers',   EP_PERMALINK );
    123123        add_rewrite_endpoint( 'other_notes',  EP_PERMALINK );
    124     }
    125 
    126     /**
    127      * Filter the permalink for the Packages to be /post_name/.
     124
     125        // When this plugin is used in the context of a Rosetta site, handle it gracefully
     126        if ( 'wordpress.org' != $_SERVER['HTTP_HOST'] && defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) {
     127            $this->add_rosetta_network_filters();   
     128        }
     129    }
     130
     131    /**
     132     * The Plugin Directory is available at multiple URLs (internationalised domains), this method allows
     133     * for the one blog (a single blog_id) to be presented at multiple URLs yet have correct localised links.
     134     */
     135    public function add_rosetta_network_filters() {
     136        // Filter the URLs to use the current localised domain name, rather than WordPress.org.
     137        foreach ( array( 'option_home', 'option_siteurl' ) as $filter ) {
     138            add_filter( $filter, function( $url ) {
     139                static $localized_url = null;
     140                if ( is_null( $localized_url ) ) {
     141                    $localized_url = 'https://' . preg_replace( '![^a-z.]+!', '', $_SERVER['HTTP_HOST'] );
     142                }
     143
     144                return preg_replace( '!^[https]+://wordpress\.org!i', $localized_url, $url );
     145            } );
     146        }
     147
     148        /*
     149        // This method works in conjuction with a filter in sunrise.php, duplicated here for transparency:
     150
     151        // Make the Plugin Directory available at /plugins/ on all rosetta sites.
     152        function wporg_plugins_on_rosetta_domains( $site, $domain, $path, $segments ) {
     153            // All non-rosetta networks define DOMAIN_CURRENT_SITE in wp-config.php
     154            if ( ! defined( 'DOMAIN_CURRENT_SITE' ) && 'wordpress.org' != $domain && '/plugins/' == substr( $path . '/', 0, 9 ) ) {
     155                $site = get_blog_details( WPORG_PLUGIN_DIRECTORY_BLOGID );
     156                if ( $site ) {
     157                    $site = clone $site;
     158                    // 6 = The Rosetta network, this causes the site to be loaded as part of the Rosetta network
     159                    $site->site_id = 6;
     160                    return $site;
     161                }
     162            }
     163       
     164            return $site;
     165        }
     166        add_filter( 'pre_get_site_by_path', 'wporg_plugins_on_rosetta_domains', 10, 4 );
     167        */
     168    }
     169
     170    /**
     171     * Filter the permalink for the Plugins to be /plugin-name/.
    128172     *
    129173     * @param string  $link The generated permalink.
Note: See TracChangeset for help on using the changeset viewer.