Making WordPress.org

Changeset 5339


Ignore:
Timestamp:
04/15/2017 03:01:20 PM (7 years ago)
Author:
ocean90
Message:

Rosetta: Add admin page to manage locale associations.

See #2003.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc
Files:
8 added
2 edited

Legend:

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

    r4110 r5339  
    66
    77    /**
    8      * @var Plugin The singleton instance.
     8     * @var \WordPressdotorg\Rosetta\Plugin The singleton instance.
    99     */
    1010    private static $instance;
     
    2020     * Returns always the same instance of this plugin.
    2121     *
    22      * @return Plugin
     22     * @return \WordPressdotorg\Rosetta\Plugin
    2323     */
    2424    public static function get_instance() {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-global-wordpress-org.php

    r4096 r5339  
    22namespace WordPressdotorg\Rosetta\Site;
    33
     4use WordPressdotorg\Rosetta\Admin\Network\Locale_Associations;
     5use WordPressdotorg\Rosetta\Admin\Network\Locale_Associations_View;
     6use WordPressdotorg\Rosetta\Database\Tables;
    47use WordPressdotorg\Rosetta\Jetpack;
    58use WP_Site;
     
    4346        add_action( 'wpmu_new_blog', [ $jetpack_connector, 'schedule_connect_event' ], 20, 1 );
    4447        add_action( $jetpack_connector->get_connect_event_name(), [ $jetpack_connector, 'connect_site' ] );
     48
     49        add_action( 'wpmu_new_blog', [ $this, 'set_new_blog_lang_id' ], 30, 1 );
     50
     51        add_action( 'network_admin_menu', function() {
     52            $locale_associations = new Locale_Associations( new Locale_Associations_View() );
     53            $locale_associations->register();
     54        } );
     55    }
     56
     57    /**
     58     * Sets 'lang_id' for new sites.
     59     *
     60     * @param int $blog_id ID of the new site.
     61     */
     62    public function set_new_blog_lang_id( $blog_id ) {
     63        global $wpdb;
     64
     65        $site = get_site( $blog_id );
     66        $subdomain = strtok( $site->domain, '.' );
     67
     68        $lang_id = $wpdb->get_var( $wpdb->prepare( 'SELECT locale_id FROM ' . Tables::LOCALES . ' WHERE subdomain = %s', $subdomain ) );
     69        if ( ! $lang_id ) {
     70            return;
     71        }
     72
     73        update_blog_details( $blog_id, [ 'lang_id' => $lang_id ] );
    4574    }
    4675}
Note: See TracChangeset for help on using the changeset viewer.