Making WordPress.org


Ignore:
Timestamp:
12/04/2016 05:54:55 PM (8 years ago)
Author:
dd32
Message:

Login.WordPress.org: Allow user registration through login.wordpress.org

This change does many things, including, but not limited to:

  • Making all the routes have proper templates, rather than being template-parts
  • Removing all the extra WordPress functionalities and outputs
  • Adding the Registration pages and routes
  • Updating SSO to handle routes with URL params
  • Adding rest endpoints for username/email validation

See #148, #1524

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions.php

    r4417 r4470  
    55 * @package wporg-login
    66 */
     7
     8require __DIR__ . '/functions-restapi.php';
     9require __DIR__ . '/functions-registration.php';
    710
    811/**
     
    2629 */
    2730function wporg_login_body_class( $classes ) {
    28 //  $classes[] = 'wporg-responsive';
    29     $classes[] = 'wporg-login';
     31    if ( WP_WPOrg_SSO::$matched_route ) {
     32        $classes[] = 'route-' . WP_WPOrg_SSO::$matched_route;
     33    }
     34
     35    // Remove the 404 class..
     36    if ( false !== ( $pos = array_search( 'error404', $classes ) ) ) {
     37        unset( $classes[ $pos ] );
     38    }
    3039    return $classes;
    3140}
     
    4453 */
    4554function wporg_login_replace_css() {
    46     wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), 2.3 );
     55    wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), '20161204' );
    4756}
    4857add_action( 'login_init', 'wporg_login_replace_css' );
     
    5362function wporg_login_scripts() {
    5463    $script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
    55     $suffix       = $script_debug ? '' : '.min';
    5664
    5765    // Concatenates core scripts when possible.
     
    6169
    6270    wp_enqueue_style( 'wporg-normalize', get_template_directory_uri() . '/stylesheets/normalize.css', 3 );
    63     wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), 2.3 );
    64 
    65     // No emoji support needed.
    66     remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    67     remove_action( 'wp_print_styles', 'print_emoji_styles' );
    68 
    69     // No Jetpack styles needed.
    70     add_filter( 'jetpack_implode_frontend_css', '__return_false' );
    71 
    72     // No embeds needed.
    73     remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
    74     remove_action( 'wp_head', 'wp_oembed_add_host_js' );
     71    wp_enqueue_style( 'wporg-login', get_template_directory_uri() . '/stylesheets/login.css', array( 'login', 'dashicons', 'l10n' ), '20161204' );
    7572}
    7673add_action( 'wp_enqueue_scripts', 'wporg_login_scripts' );
     74
     75function wporg_login_register_scripts() {
     76    wp_register_script( 'recaptcha-api', 'https://www.google.com/recaptcha/api.js', array(), '2' );
     77
     78    wp_register_script( 'wporg-registration', get_template_directory_uri() . "/js/registration.js", array( 'recaptcha-api', 'jquery' ), '20161114' );
     79    wp_localize_script( 'wporg-registration', 'wporg_registration', array(
     80        'rest_url' => esc_url_raw( rest_url( "wporg/v1" ) )
     81    ) );
     82}
     83add_action( 'init', 'wporg_login_register_scripts' );
     84
     85/**
     86 * Avoid sending a 404 header but send a 200 with nocache headers.
     87 */
     88function wporg_login_pre_handle_404( $false, $wp_query ) {
     89    $wp_query->set_404(); // Set the query as 404 to avoid things running thinking it's a real page
     90    status_header( 200 ); // but return a 200
     91    return true;
     92}
     93add_filter( 'pre_handle_404', 'wporg_login_pre_handle_404', 10, 2 );
     94
     95/**
     96 * Filters the page template to load wporg-login/$route.php.
     97 *
     98 * @param array $templates The templates WordPress intends to load.
     99 * @return array The templates the theme intends to use.
     100 */
     101function wporg_login_filter_templates( $templates ) {
     102    $route = WP_WPOrg_SSO::$matched_route;
     103
     104    if ( ! $route || 'root' === $route ) {
     105        $route = 'login';
     106    }
     107
     108    return array( "{$route}.php", 'index.php' );
     109}
     110add_filter( 'index_template_hierarchy', 'wporg_login_filter_templates' );
     111
     112// No emoji support needed.
     113remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
     114remove_action( 'wp_print_styles', 'print_emoji_styles' );
     115
     116// No Jetpack styles needed.
     117add_filter( 'jetpack_implode_frontend_css', '__return_false' );
     118
     119// No embeds needed.
     120remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
     121remove_action( 'wp_head', 'wp_oembed_add_host_js' );
     122remove_action( 'rest_api_init', 'wp_oembed_register_route' );
     123
     124// Don't perform any WP_Query queries on this site..
     125add_filter( 'posts_request', '__return_empty_string' );
     126// Don't attempt to do canonical lookups..
     127remove_filter( 'template_redirect', 'redirect_canonical' );
     128// There's no need to edit the site..
     129remove_action( 'wp_head', 'wlwmanifest_link' );
     130remove_action( 'wp_head', 'rsd_link' );
     131// We don't need all the rest routes either..
     132remove_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
     133
     134// Don't need all the wp-admin specific user metas on user create/update
     135add_filter( 'insert_user_meta', '__return_empty_array', 1 );
Note: See TracChangeset for help on using the changeset viewer.