Making WordPress.org

Changeset 11586


Ignore:
Timestamp:
02/21/2022 06:34:52 AM (3 years ago)
Author:
dd32
Message:

Trac: oEmbed: Adjust the oEmbed for the new header.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/oembed/index.php

    r11412 r11586  
    4646    $id = sha1( $url . microtime() );
    4747
     48    $embed = [
     49        'version'       => '1.0',
     50        'provider_name' => 'WordPress.org Trac',
     51        'provider_url'  => $m['baseurl'],
     52        'title'         => 'WordPress.org Trac',
     53        'type'          => 'rich',
     54        'width'         => 600,
     55        'height'        => 300,
     56        'html'          => '',
     57    ];
     58
     59    // Default milestone embeds to 120px height.
     60    if ( 'milestone' === $type ) {
     61        $embed['height'] = 120;
     62    }
     63
    4864    $embed_url = add_query_arg(
    4965        [
     
    6177
    6278    $html = sprintf(
    63         '<iframe sandbox="allow-scripts allow-top-navigation-by-user-activation" security="restricted" src="%s" id="%s" width="600" height="300" title="WordPress.org Trac" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content wporg-trac"></iframe>',
     79        '<iframe sandbox="allow-scripts allow-top-navigation-by-user-activation" security="restricted" src="%s" id="%s" width="%d" height="%d" title="WordPress.org Trac" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content wporg-trac"></iframe>',
    6480        esc_url( $embed_url ),
    65         esc_attr( 'el-' . $id )
     81        esc_attr( 'el-' . $id ),
     82        esc_attr( $embed['width'] ),
     83        esc_attr( $embed['height'] )
    6684    );
    6785
     
    84102    );
    85103
    86     $embed = [
    87         'version'       => '1.0',
    88         'provider_name' => 'WordPress.org Trac',
    89         'provider_url'  => $m['baseurl'],
    90         'title'         => 'WordPress.org Trac',
    91         'type'          => 'rich',
    92         'width'         => 600,
    93         'height'        => 300,
    94         'html'          => $html,
    95     ];
    96 
    97     // Default milestone embeds to 120px.
    98     if ( 'milestone' === $type ) {
    99         $embed['height'] = 120;
    100     }
     104    $embed['html'] = $html;
    101105
    102106    echo wp_json_encode( $embed );
     
    131135// IDs of elements to remove
    132136$remove_elements = [
    133     'wporg-header', 'wporg-footer',
    134137    'headline', 'banner', 'mainnav',
    135138    'ctxtnav', 'help', 'altlinks',
    136139    'prefs',
     140    'wporg-global-header-script-js',
     141    'wporg-global-header-script-js-extra',
     142    'wporg-global-header-footer-css',
    137143];
    138144
    139 // Tags to just strip out.
     145// Tags, with optional class specification to just strip out.
    140146$remove_tags = [
    141     'form'
     147    'form',
     148    'header.global-header',
     149    'footer.global-footer',
    142150];
    143151
     
    171179// Remove any tags
    172180foreach ( $remove_tags as $tag ) {
     181    list( $tag, $class ) = explode( '.', $tag, 2 );
    173182    foreach ( $doc->getElementsByTagName( $tag ) as $el ) {
     183        if ( $class && ! str_contains( $el->getAttribute( 'class' ), $class ) ) {
     184            continue;
     185        }
     186
    174187        $el->parentNode->removeChild( $el );
    175188    }
     
    243256$doc->getElementsByTagName( 'head' )[0]->appendChild( $doc->createElement( 'script', $js ) );
    244257
     258$css = <<<CSS
     259html {
     260    --wp-global-header-height: 0;
     261    --wp-admin--admin-bar--height: 0;
     262}
     263CSS;
     264$doc->getElementsByTagName( 'head' )[0]->appendChild( $doc->createElement( 'style', $css ) );
     265
    245266$data = $doc->saveHTML();
    246267
Note: See TracChangeset for help on using the changeset viewer.