diff --git a/src/wp-includes/class-wp-oembed-controller.php b/src/wp-includes/class-wp-oembed-controller.php index 2da7f3e5db..22c062be9f 100644 --- a/src/wp-includes/class-wp-oembed-controller.php +++ b/src/wp-includes/class-wp-oembed-controller.php @@ -142,12 +142,17 @@ final class WP_oEmbed_Controller { * @return string The XML response data. */ public function xml_response( $data ) { + if ( ! class_exists( 'SimpleXMLElement' ) ) { + status_header( 501 ); + return get_status_header_desc( 501 ); + } + $result = _oembed_create_xml( $data ); // Bail if there's no XML. if ( ! $result ) { status_header( 501 ); - return 'Not implemented'; + return get_status_header_desc( 501 ); } if ( ! headers_sent() ) { diff --git a/src/wp-includes/embed-functions.php b/src/wp-includes/embed-functions.php index b9eeee0538..35e6587963 100644 --- a/src/wp-includes/embed-functions.php +++ b/src/wp-includes/embed-functions.php @@ -351,7 +351,10 @@ function wp_oembed_add_discovery_links() { if ( is_singular() ) { $output .= '' . "\n"; - $output .= '' . "\n"; + + if ( class_exists( 'SimpleXMLElement' ) ) { + $output .= '' . "\n"; + } } /** diff --git a/tests/phpunit/tests/oembed/controller.php b/tests/phpunit/tests/oembed/controller.php index bf646f599e..34ce7dd4ee 100644 --- a/tests/phpunit/tests/oembed/controller.php +++ b/tests/phpunit/tests/oembed/controller.php @@ -164,9 +164,9 @@ class Test_oEmbed_Controller extends WP_UnitTestCase { function test_request_xml_invalid_data() { $legacy_controller = new WP_oEmbed_Controller(); - $this->assertEquals( 'Not implemented', $legacy_controller->xml_response( null ) ); - $this->assertEquals( 'Not implemented', $legacy_controller->xml_response( 123 ) ); - $this->assertEquals( 'Not implemented', $legacy_controller->xml_response( array() ) ); + $this->assertEquals( get_status_header_desc( 501 ), $legacy_controller->xml_response( null ) ); + $this->assertEquals( get_status_header_desc( 501 ), $legacy_controller->xml_response( 123 ) ); + $this->assertEquals( get_status_header_desc( 501 ), $legacy_controller->xml_response( array() ) ); } /**