diff --git src/wp-includes/class-wp-oembed-controller.php src/wp-includes/class-wp-oembed-controller.php
index 0db5340..bc826c0 100644
|
|
|
final class WP_oEmbed_Controller { |
| 67 | 67 | $post_id = url_to_postid( $request['url'] ); |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | | * Filter the determined post id. |
| | 70 | * Filter the determined post ID. |
| 71 | 71 | * |
| 72 | 72 | * @since 4.4.0 |
| 73 | 73 | * |
| 74 | 74 | * @param int $post_id The post ID. |
| 75 | | * @param string $url The requestd URL. |
| | 75 | * @param string $url The requested URL. |
| 76 | 76 | */ |
| 77 | 77 | $post_id = apply_filters( 'oembed_request_post_id', $post_id, $request['url'] ); |
| 78 | 78 | |
| 79 | | $data = get_oembed_response_data( $post_id, $request['maxwidth'] ); |
| | 79 | $data = get_oembed_response_data( $request['maxwidth'], $post_id ); |
| 80 | 80 | |
| 81 | 81 | if ( ! $data ) { |
| 82 | 82 | return new WP_Error( 'oembed_invalid_url', get_status_header_desc( 404 ), array( 'status' => 404 ) ); |
diff --git src/wp-includes/embed-functions.php src/wp-includes/embed-functions.php
index 2f430b5..0649dae 100644
|
|
|
function get_oembed_endpoint_url( $permalink = '', $format = 'json' ) { |
| 446 | 446 | * |
| 447 | 447 | * @since 4.4.0 |
| 448 | 448 | * |
| 449 | | * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`. |
| 450 | 449 | * @param int $width The width for the response. |
| 451 | 450 | * @param int $height The height for the response. |
| | 451 | * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`. |
| 452 | 452 | * @return string|false Embed code on success, false if post doesn't exist. |
| 453 | 453 | */ |
| 454 | | function get_post_embed_html( $post = null, $width, $height ) { |
| | 454 | function get_post_embed_html( $width, $height, $post = null ) { |
| 455 | 455 | $post = get_post( $post ); |
| 456 | 456 | |
| 457 | 457 | if ( ! $post ) { |
| … |
… |
JS; |
| 510 | 510 | * |
| 511 | 511 | * @since 4.4.0 |
| 512 | 512 | * |
| 513 | | * @param WP_Post|int $post Optional. Post object or ID. Default is global `$post`. |
| 514 | 513 | * @param int $width The requested width. |
| | 514 | * @param WP_Post|int $post Optional. Post object or ID. Default is global `$post`. |
| 515 | 515 | * @return array|false Response data on success, false if post doesn't exist. |
| 516 | 516 | */ |
| 517 | | function get_oembed_response_data( $post = null, $width ) { |
| | 517 | function get_oembed_response_data( $width, $post = null ) { |
| 518 | 518 | $post = get_post( $post ); |
| 519 | 519 | |
| 520 | 520 | if ( ! $post ) { |
| … |
… |
function get_oembed_response_data_rich( $data, $post, $width, $height ) { |
| 590 | 590 | $data['width'] = absint( $width ); |
| 591 | 591 | $data['height'] = absint( $height ); |
| 592 | 592 | $data['type'] = 'rich'; |
| 593 | | $data['html'] = get_post_embed_html( $post, $width, $height ); |
| | 593 | $data['html'] = get_post_embed_html( $width, $height, $post ); |
| 594 | 594 | |
| 595 | 595 | // Add post thumbnail to response if available. |
| 596 | 596 | $thumbnail_id = false; |
diff --git tests/phpunit/tests/oembed/getResponseData.php tests/phpunit/tests/oembed/getResponseData.php
index 6dcdcbd..2c0b8a3 100644
|
|
|
|
| 5 | 5 | */ |
| 6 | 6 | class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 7 | 7 | function test_get_oembed_response_data_non_existent_post() { |
| 8 | | $this->assertFalse( get_oembed_response_data( 0, 100 ) ); |
| | 8 | $this->assertFalse( get_oembed_response_data( 100, 0 ) ); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function test_get_oembed_response_data() { |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 13 | 13 | 'post_title' => 'Some Post', |
| 14 | 14 | ) ); |
| 15 | 15 | |
| 16 | | $data = get_oembed_response_data( $post, 400 ); |
| | 16 | $data = get_oembed_response_data( 400, $post); |
| 17 | 17 | |
| 18 | 18 | $this->assertEqualSets( array( |
| 19 | 19 | 'version' => '1.0', |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 25 | 25 | 'type' => 'rich', |
| 26 | 26 | 'width' => 400, |
| 27 | 27 | 'height' => 225, |
| 28 | | 'html' => get_post_embed_html( $post, 400, 225 ), |
| | 28 | 'html' => get_post_embed_html( 400, 225, $post ), |
| 29 | 29 | ), $data ); |
| 30 | 30 | } |
| 31 | 31 | |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 42 | 42 | 'post_author' => $user_id, |
| 43 | 43 | ) ); |
| 44 | 44 | |
| 45 | | $data = get_oembed_response_data( $post, 400 ); |
| | 45 | $data = get_oembed_response_data( 400, $post); |
| 46 | 46 | |
| 47 | 47 | $this->assertEqualSets( array( |
| 48 | 48 | 'version' => '1.0', |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 54 | 54 | 'type' => 'rich', |
| 55 | 55 | 'width' => 400, |
| 56 | 56 | 'height' => 225, |
| 57 | | 'html' => get_post_embed_html( $post, 400, 225 ), |
| | 57 | 'html' => get_post_embed_html( 400, 225, $post ), |
| 58 | 58 | ), $data ); |
| 59 | 59 | } |
| 60 | 60 | |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 65 | 65 | 'post_title' => 'Some Post', |
| 66 | 66 | ) ); |
| 67 | 67 | |
| 68 | | $data = get_oembed_response_data( $post, 600 ); |
| | 68 | $data = get_oembed_response_data( 600, $post ); |
| 69 | 69 | |
| 70 | 70 | $this->assertEqualSets( array( |
| 71 | 71 | 'version' => '1.0', |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 85 | 85 | 'post_status' => 'draft', |
| 86 | 86 | ) ); |
| 87 | 87 | |
| 88 | | $this->assertFalse( get_oembed_response_data( $post, 100 ) ); |
| | 88 | $this->assertFalse( get_oembed_response_data( 100, $post ) ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function test_get_oembed_response_data_with_scheduled_post() { |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 94 | 94 | 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', strtotime( '+1 day' ) ), |
| 95 | 95 | ) ); |
| 96 | 96 | |
| 97 | | $this->assertFalse( get_oembed_response_data( $post, 100 ) ); |
| | 97 | $this->assertFalse( get_oembed_response_data( 100, $post ) ); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | function test_get_oembed_response_data_with_private_post() { |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 102 | 102 | 'post_status' => 'private', |
| 103 | 103 | ) ); |
| 104 | 104 | |
| 105 | | $this->assertFalse( get_oembed_response_data( $post, 100 ) ); |
| | 105 | $this->assertFalse( get_oembed_response_data( 100, $post ) ); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | function test_get_oembed_response_data_maxwidth_too_high() { |
| 109 | 109 | $post = self::factory()->post->create_and_get(); |
| 110 | 110 | |
| 111 | | $data = get_oembed_response_data( $post, 1000 ); |
| | 111 | $data = get_oembed_response_data( 1000, $post ); |
| 112 | 112 | |
| 113 | 113 | $this->assertEquals( 600, $data['width'] ); |
| 114 | 114 | $this->assertEquals( 338, $data['height'] ); |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 117 | 117 | function test_get_oembed_response_data_maxwidth_too_low() { |
| 118 | 118 | $post = self::factory()->post->create_and_get(); |
| 119 | 119 | |
| 120 | | $data = get_oembed_response_data( $post, 100 ); |
| | 120 | $data = get_oembed_response_data( 100, $post ); |
| 121 | 121 | |
| 122 | 122 | $this->assertEquals( 200, $data['width'] ); |
| 123 | 123 | $this->assertEquals( 200, $data['height'] ); |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 126 | 126 | function test_get_oembed_response_data_maxwidth_invalid() { |
| 127 | 127 | $post = self::factory()->post->create_and_get(); |
| 128 | 128 | |
| 129 | | $data = get_oembed_response_data( $post, '400;" DROP TABLES' ); |
| | 129 | $data = get_oembed_response_data('400;" DROP TABLES', $post ); |
| 130 | 130 | |
| 131 | 131 | $this->assertEquals( 400, $data['width'] ); |
| 132 | 132 | $this->assertEquals( 225, $data['height'] ); |
| 133 | 133 | |
| 134 | | $data = get_oembed_response_data( $post, "lol this isn't even a number?!?!?" ); |
| | 134 | $data = get_oembed_response_data( "lol this isn't even a number?!?!?", $post ); |
| 135 | 135 | |
| 136 | 136 | $this->assertEquals( 200, $data['width'] ); |
| 137 | 137 | $this->assertEquals( 200, $data['height'] ); |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 145 | 145 | ) ); |
| 146 | 146 | set_post_thumbnail( $post, $attachment_id ); |
| 147 | 147 | |
| 148 | | $data = get_oembed_response_data( $post, 400 ); |
| | 148 | $data = get_oembed_response_data( 400, $post ); |
| 149 | 149 | |
| 150 | 150 | $this->assertArrayHasKey( 'thumbnail_url', $data ); |
| 151 | 151 | $this->assertArrayHasKey( 'thumbnail_width', $data ); |
| … |
… |
class Tests_oEmbed_Response_Data extends WP_UnitTestCase { |
| 160 | 160 | 'post_mime_type' => 'image/jpeg', |
| 161 | 161 | ) ); |
| 162 | 162 | |
| 163 | | $data = get_oembed_response_data( $post, 400 ); |
| | 163 | $data = get_oembed_response_data( 400, $post ); |
| 164 | 164 | |
| 165 | 165 | $this->assertArrayHasKey( 'thumbnail_url', $data ); |
| 166 | 166 | $this->assertArrayHasKey( 'thumbnail_width', $data ); |
diff --git tests/phpunit/tests/oembed/template.php tests/phpunit/tests/oembed/template.php
index 644a6d5..ca07035 100644
|
|
|
class Tests_Embed_Template extends WP_UnitTestCase { |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | function test_get_post_embed_html_non_existent_post() { |
| 239 | | $this->assertFalse( get_post_embed_html( 0, 200, 200 ) ); |
| 240 | | $this->assertFalse( get_post_embed_html( null, 200, 200 ) ); |
| | 239 | $this->assertFalse( get_post_embed_html( 200, 200, 0 ) ); |
| | 240 | $this->assertFalse( get_post_embed_html( 200, 200 ) ); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | function test_get_post_embed_html() { |
| … |
… |
class Tests_Embed_Template extends WP_UnitTestCase { |
| 245 | 245 | |
| 246 | 246 | $expected = '<iframe sandbox="allow-scripts" security="restricted" src="' . esc_url( get_post_embed_url( $post_id ) ) . '" width="200" height="200" title="Embedded WordPress Post" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>'; |
| 247 | 247 | |
| 248 | | $this->assertStringEndsWith( $expected, get_post_embed_html( $post_id, 200, 200 ) ); |
| | 248 | $this->assertStringEndsWith( $expected, get_post_embed_html( 200, 200, $post_id ) ); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | function test_add_host_js() { |