loadHTML( utf8_decode( $content ) ); $imgs = $document->getElementsByTagName( 'img' ); $body = $document->getElementsByTagName( 'body' ); if ( empty( $body ) ) return $content; $body = $body->item(0); foreach ( $imgs as $img ) { $existing_class = $img->getAttribute( 'class' ); preg_match( '/wp-image-(?P\d+)/i', $existing_class, $matches ); if ( count( $matches ) > 0 ) { $id = $matches['id']; $attached = get_post_meta( $matches['id'], '_asi_link', true ); if ( !empty( $attached ) ) { $existing_class = $img->getAttribute( 'class' ); $img->setAttribute( 'class', "$existing_class asi-img" ); $img->setAttribute( 'asi-id', $id ); $div = $body->appendChild( $document->createElement( "asi-audio" ) ); $div->setAttribute( 'asi-id', $id ); $src = $div->appendChild( $document->createElement( "source" ) ); $src->setAttribute( 'src', wp_get_attachment_url( $attached ) ); } } } $html = $document->saveHTML(); return $html; } } ?>