Making WordPress.org

Changeset 11451


Ignore:
Timestamp:
01/17/2022 06:48:02 AM (3 years ago)
Author:
dd32
Message:

Themes: Use a new method to fetch the localised site name.

This is to remove the reliance upon $wporg_global_header_options.

See https://github.com/WordPress/wporg-mu-plugins/issues/42

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/site-branding.php

    r11450 r11451  
    11<?php
    2 namespace WordPressdotorg\MU_Plugins\Site_Branding;
    32/**
    43 * Plugin Name: WordPress.org Site Branding
     
    65 */
    76
    8 add_filter( 'document_title_parts', __NAMESPACE__ . '\document_title_parts', 100 );
    9 function document_title_parts( $parts ) {
    10     global $rosetta;
     7namespace WordPressdotorg\MU_Plugins\Site_Branding {
    118
    12     // In some places on WordPress.org the document title is used within the theme, don't affect title calls after the </head>.
    13     if ( did_action( 'wp_body_open' ) ) {
     9    /**
     10     * Filter the document title parts to ensure that WordPress is replaced into it consistently.
     11     */
     12    function document_title_parts( $parts ) {
     13        global $rosetta;
     14
     15        // In some places on WordPress.org the document title is used within the theme, don't affect title calls after the </head>.
     16        if ( did_action( 'wp_body_open' ) ) {
     17            return $parts;
     18        }
     19
     20        $combined = implode( ' ', $parts );
     21
     22        // Ensure that 'WordPress' is present in the title of the URL
     23        if ( false === strpos( $combined, 'WordPress' ) ) {
     24            $parts['wporg-suffix'] = get_wordpress_brand();
     25        }
     26
     27        // Override anything that set part of the title directly to WordPress.org on rosetta sites.
     28        if ( isset( $rosetta ) ) {
     29            foreach ( [ 'site', 'tagline' ] as $field ) {
     30                if ( ! empty( $parts[ $field ] ) && 'WordPress.org' === $parts[ $field ] ) {
     31                    $parts[ $field ] = get_wordpress_brand();
     32                }
     33            }
     34        }
     35
    1436        return $parts;
    1537    }
     38    add_filter( 'document_title_parts', __NAMESPACE__ . '\document_title_parts', 100 );
    1639
    17     $combined = implode( ' ', $parts );
     40    /**
     41     * Always suffix the WordPress brand to bbPress titles.
     42     */
     43    function bbp_title( $title ) {
     44        return $title . get_wordpress_brand();
     45    }
     46    add_filter( 'bbp_title', __NAMESPACE__ . '\bbp_title', 100 );
    1847
    19     // Ensure that 'WordPress' is present in the title of the URL
    20     if ( false === strpos( $combined, 'WordPress' ) ) {
    21         $parts['wporg-suffix'] = get_wordpress_brand();
     48    /**
     49     * Filter Jetpack opengraph tags to reference the localised WordPress.org site.
     50     */
     51    function jetpack_opengraph( $fields ) {
     52        if ( isset( $fields['og:site_name'] ) && 'WordPress.org' === $fields['og:site_name'] ) {
     53            $fields['og:site_name'] = get_wordpress_brand();
     54        }
     55
     56        return $fields;
     57    }
     58    add_filter( 'jetpack_open_graph_tags', __NAMESPACE__ . '\jetpack_opengraph', 100 );
     59
     60    /**
     61     * Return the 'Brand' of the WordPress.org site.
     62     *
     63     * This is "WordPress.org" or a localised variant such as "WordPress Deutch".
     64     */
     65    function get_wordpress_brand() {
     66        global $rosetta;
     67
     68        if ( ! isset( $rosetta ) ) {
     69            return 'WordPress.org';
     70        }
     71
     72        $root_id = $rosetta->get_root_site_id();
     73        $name    = get_blog_option( $root_id, 'blogname' );
     74
     75        if ( false !== strpos( $name, 'WordPress' ) ) {
     76            return $name;
     77        }
     78
     79        return "WordPress.org $name";
    2280    }
    2381
    24     // Override anything that set part of the title directly to WordPress.org on rosetta sites.
    25     if ( isset( $rosetta ) ) {
    26         foreach ( [ 'site', 'tagline' ] as $field ) {
    27             if ( ! empty( $parts[ $field ] ) && 'WordPress.org' === $parts[ $field ] ) {
    28                 $parts[ $field ] = get_wordpress_brand();
    29             }
    30         }
     82    /**
     83     * Output the WordPress favicon on all WordPress.org themes.
     84     */
     85    function favicon_icon() {
     86        echo '<link rel="icon" href="https://s.w.org/favicon.ico?2" type="image/x-icon" />', "\n";
    3187    }
     88    add_action( 'wp_head', __NAMESPACE__ . '\favicon_icon', 1 );
    3289
    33     return $parts;
    3490}
    3591
    36 add_filter( 'bbp_title', __NAMESPACE__ . '\bbp_title', 100 );
    37 function bbp_title( $title ) {
    38     return $title . get_wordpress_brand();
     92namespace WordPressdotorg {
     93    /**
     94     * Function to call as `\WordPressdotorg\site_brand()` in other plugins.
     95     */
     96    function site_brand() {
     97        return \WordPressdotorg\MU_Plugins\Site_Branding\get_wordpress_brand();
     98    }
    3999}
    40 
    41 /**
    42  * Return the 'Brand' of the WordPress.org site.
    43  *
    44  * This is "WordPress.org" or a localised variant such as "WordPress Deutch".
    45  */
    46 function get_wordpress_brand() {
    47     global $rosetta;
    48 
    49     if ( ! isset( $rosetta ) ) {
    50         return 'WordPress.org';
    51     }
    52 
    53     $root_id = $rosetta->get_root_site_id();
    54     $name    = get_blog_option( $root_id, 'blogname' );
    55 
    56     if ( false !== strpos( $name, 'WordPress' ) ) {
    57         return $name;
    58     }
    59 
    60     return "WordPress.org $name";
    61 }
    62 
    63 /**
    64  * Output the WordPress favicon on all WordPress.org themes.
    65  */
    66 function favicon_icon() {
    67     echo '<link rel="icon" href="https://s.w.org/favicon.ico?2" type="image/x-icon" />', "\n";
    68 }
    69 add_action( 'wp_head', __NAMESPACE__ . '\favicon_icon', 1 );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/inc/page-meta-descriptions.php

    r11427 r11451  
    1818 */
    1919function custom_open_graph_tags( $tags = [] ) {
    20     global $wporg_global_header_options;
    21 
    2220    // Use `name=""` for description.
    2321    // See Jetpacks Twitter Card for where it happens for the twitter:* fields.
     
    2826    // Override the Front-page tags.
    2927    if ( is_front_page() ) {
    30         $site_title = ! empty( $wporg_global_header_options['rosetta_title'] ) ? $wporg_global_header_options['rosetta_title'] : 'WordPress';
    3128        return array(
    3229            'og:type'         => 'website',
     
    3532            'description'     => __( 'Open source software which you can use to easily create a beautiful website, blog, or app.', 'wporg' ),
    3633            'og:url'          => home_url( '/' ),
    37             'og:site_name'    => $site_title,
     34            'og:site_name'    => 'WordPress.org', // Rosetta title will automatically be inserted.
    3835            'og:image'        => 'https://s.w.org/images/home/screen-themes.png?3',
    3936            'og:locale'       => get_locale(),
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-patterns/functions.php

    r11215 r11451  
    284284 */
    285285function add_social_meta_tags() {
    286     global $wporg_global_header_options;
     286    $og_fields     = [];
    287287    $default_image = get_stylesheet_directory_uri() . '/images/social-image.png';
    288     $og_fields = [];
     288    $site_title    = function_exists( '\WordPressdotorg\site_brand' ) ? \WordPressdotorg\site_brand() : 'WordPress.org';
    289289
    290290    if ( is_front_page() || is_home() ) {
     
    292292            'og:title'       => __( 'Block Pattern Directory', 'wporg-patterns' ),
    293293            'og:description' => __( 'Add a beautifully designed, ready to go layout to any WordPress site with a simple copy/paste.', 'wporg-patterns' ),
    294             'og:site_name'   => $wporg_global_header_options['rosetta_title'] ?? 'WordPress.org',
     294            'og:site_name'   => $site_title,
    295295            'og:type'        => 'website',
    296296            'og:url'         => home_url(),
     
    301301            'og:title'       => sprintf( __( 'Block Patterns: %s', 'wporg-patterns' ), esc_attr( single_term_title( '', false ) ) ),
    302302            'og:description' => __( 'Add a beautifully designed, ready to go layout to any WordPress site with a simple copy/paste.', 'wporg-patterns' ),
    303             'og:site_name'   => esc_attr( $wporg_global_header_options['rosetta_title'] ?? 'WordPress.org' ),
     303            'og:site_name'   => $site_title,
    304304            'og:type'        => 'website',
    305305            'og:url'         => esc_url( get_term_link( get_queried_object_id() ) ),
     
    309309        $og_fields = [
    310310            'og:title'       => the_title_attribute( array( 'echo' => false ) ),
    311             'og:description' => esc_attr( strip_tags( get_post_meta( get_the_ID(), 'wpop_description', true ) ) ),
    312             'og:site_name'   => esc_attr( $wporg_global_header_options['rosetta_title'] ?? 'WordPress.org' ),
     311            'og:description' => strip_tags( get_post_meta( get_the_ID(), 'wpop_description', true ) ),
     312            'og:site_name'   => $site_title,
    313313            'og:type'        => 'website',
    314314            'og:url'         => esc_url( get_permalink() ),
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php

    r11449 r11451  
    331331 */
    332332function social_meta_data() {
    333     global $wporg_global_header_options;
     333    $site_title = function_exists( '\WordPressdotorg\site_brand' ) ? \WordPressdotorg\site_brand() : 'WordPress.org';
     334
    334335    if ( is_front_page() ) {
    335336        $og_fields = [
    336337            'og:title'       => __( 'WordPress Plugins', 'wporg-plugins' ),
    337338            'og:description' => __( 'Choose from thousands of free plugins to build, customize, and enhance your WordPress website.', 'wporg-plugins' ),
    338             'og:site_name'   => $wporg_global_header_options['rosetta_title'] ?? 'WordPress.org',
     339            'og:site_name'   => $site_title,
    339340            'og:type'        => 'website',
    340341            'og:url'         => home_url(),
     
    367368    printf( '<meta property="og:description" content="%s" />' . "\n", esc_attr( strip_tags( get_the_excerpt() ) ) );
    368369    printf( '<meta name="description" content="%s" />' . "\n", esc_attr( strip_tags( get_the_excerpt() ) ) );
    369     printf( '<meta property="og:site_name" content="%s" />' . "\n", esc_attr( $wporg_global_header_options['rosetta_title'] ?? 'WordPress.org' ) );
     370    printf( '<meta property="og:site_name" content="%s" />' . "\n", esc_attr( $site_title ) );
    370371    printf( '<meta property="og:type" content="website" />' . "\n" );
    371372    printf( '<meta property="og:url" content="%s" />' . "\n", esc_url( get_permalink() ) );
Note: See TracChangeset for help on using the changeset viewer.