Making WordPress.org


Ignore:
Timestamp:
02/24/2022 05:16:50 AM (4 years ago)
Author:
dd32
Message:

Trac: oEmbed API: Avoid PHP Warnings from 'unexpected' tags by using internal libxml errors, avoid notices by checking if the definition includes a class.

File:
1 edited

Legend:

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

    r11586 r11598  
    1818 */
    1919include dirname( dirname( dirname( __DIR__ ) ) ) . '/wp-init.php';
     20
     21// Avoid warnings from DomDocument.
     22libxml_use_internal_errors( true );
    2023
    2124// Mark this as an oEmbed response for caching.
     
    143146];
    144147
    145 // Tags, with optional class specification to just strip out.
     148// Tags, with optional SINGLE class specification to just strip out.
    146149$remove_tags = [
    147150    'form',
     
    179182// Remove any tags
    180183foreach ( $remove_tags as $tag ) {
    181     list( $tag, $class ) = explode( '.', $tag, 2 );
     184    $class = false;
     185    if ( str_contains( $tag, '.' ) ) {
     186        list( $tag, $class ) = explode( '.', $tag );
     187    }
     188
    182189    foreach ( $doc->getElementsByTagName( $tag ) as $el ) {
    183190        if ( $class && ! str_contains( $el->getAttribute( 'class' ), $class ) ) {
Note: See TracChangeset for help on using the changeset viewer.