function test_get_post_embed_url_with_ugly_permalinks()
 {
     $post_id = self::factory()->post->create();
     $permalink = get_permalink($post_id);
     $embed_url = get_post_embed_url($post_id);
     $this->assertEquals($permalink . '&embed=true', $embed_url);
 }
 /**
  * @ticket 34971
  */
 function test_static_front_page_conflicts_with_embed_slug()
 {
     $this->set_permalink_structure('/%postname%/');
     // Create a post with the 'embed' post_name
     add_filter('wp_unique_post_slug', array($this, 'filter_unique_post_slug'));
     $post_embed_slug = self::factory()->post->create(array('post_name' => 'embed'));
     remove_filter('wp_unique_post_slug', array($this, 'filter_unique_post_slug'));
     $page_front = self::factory()->post->create(array('post_type' => 'page'));
     update_option('show_on_front', 'page');
     update_option('page_on_front', $page_front);
     $this->assertSame(home_url() . '/embed/embed/', get_post_embed_url($post_embed_slug));
     $this->assertSame(home_url() . '/?embed=true', get_post_embed_url($page_front));
     update_option('show_on_front', 'posts');
 }
Exemplo n.º 3
0
 public function data_template_requests()
 {
     $post = self::factory()->post->create_and_get(array('post_type' => 'post', 'post_name' => 'post-name'));
     set_post_format($post, 'quote');
     $page = self::factory()->post->create_and_get(array('post_type' => 'page', 'post_name' => 'page-name'));
     add_post_meta($page->ID, '_wp_page_template', 'templates/page.php');
     $data = array();
     // Single post embed
     $data[] = array(get_post_embed_url($post), array('embed-post-quote.php', 'embed-post.php', 'embed.php', 'single-post-post-name.php', 'single-post.php', 'single.php', 'singular.php'));
     // Search
     $data[] = array(add_query_arg('s', 'foo', home_url()), array('search.php'));
     // Single page
     $data[] = array(get_permalink($page), array('templates/page.php', 'page-page-name.php', "page-{$page->ID}.php", 'page.php', 'singular.php'));
     // Single post
     $data[] = array(get_permalink($post), array('single-post-post-name.php', 'single-post.php', 'single.php', 'singular.php'));
     return $data;
 }
Exemplo n.º 4
0
/**
 * Retrieves the embed code for a specific post.
 *
 * @since 4.4.0
 *
 * @param int         $width  The width for the response.
 * @param int         $height The height for the response.
 * @param int|WP_Post $post   Optional. Post ID or object. Default is global `$post`.
 * @return string|false Embed code on success, false if post doesn't exist.
 */
function get_post_embed_html($width, $height, $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $embed_url = get_post_embed_url($post);
    $output = '<blockquote class="wp-embedded-content"><a href="' . esc_url(get_permalink($post)) . '">' . get_the_title($post) . "</a></blockquote>\n";
    $output .= "<script type='text/javascript'>\n";
    $output .= "<!--//--><![CDATA[//><!--\n";
    if (SCRIPT_DEBUG) {
        $output .= file_get_contents(ABSPATH . WPINC . '/js/wp-embed.js');
    } else {
        /*
         * If you're looking at a src version of this file, you'll see an "include"
         * statement below. This is used by the `grunt build` process to directly
         * include a minified version of wp-embed.js, instead of using the
         * file_get_contents() method from above.
         *
         * If you're looking at a build version of this file, you'll see a string of
         * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
         * and edit wp-embed.js directly.
         */
        $output .= <<<JS
\t\t!function(a,b){"use strict";function c(){if(!e){e=!0;var a,c,d,f,g=-1!==navigator.appVersion.indexOf("MSIE 10"),h=!!navigator.userAgent.match(/Trident.*rv:11\\./),i=b.querySelectorAll("iframe.wp-embedded-content"),j=b.querySelectorAll("blockquote.wp-embedded-content");for(c=0;c<j.length;c++)j[c].style.display="none";for(c=0;c<i.length;c++)d=i[c],d.style.display="",d.getAttribute("data-secret")||(f=Math.random().toString(36).substr(2,10),d.src+="#?secret="+f,d.setAttribute("data-secret",f)),(g||h)&&d.getAttribute("security")&&(a=d.cloneNode(!0),a.removeAttribute("security"),d.parentNode.replaceChild(a,d))}}var d=b.querySelector&&a.addEventListener,e=!1;a.wp=a.wp||{},a.wp.receiveEmbedMessage||(a.wp.receiveEmbedMessage=function(c){var d=c.data;if(d.secret||d.message||d.value){var e,f,g,h,i,j=b.querySelectorAll('iframe[data-secret="'+d.secret+'"]'),k=b.querySelectorAll('blockquote[data-secret="'+d.secret+'"]');for(e=0;e<k.length;e++)k[e].style.display="none";for(e=0;e<j.length;e++)f=j[e],f.style.display="","height"===d.message&&(g=parseInt(d.value,10),g>1e3?g=1e3:200>~~g&&(g=200),f.height=g),"link"===d.message&&(h=b.createElement("a"),i=b.createElement("a"),h.href=f.getAttribute("src"),i.href=d.value,i.host===h.host&&b.activeElement===f&&(a.top.location.href=d.value))}},d&&(a.addEventListener("message",a.wp.receiveEmbedMessage,!1),b.addEventListener("DOMContentLoaded",c,!1),a.addEventListener("load",c,!1)))}(window,document);
JS;
    }
    $output .= "\n//--><!]]>";
    $output .= "\n</script>";
    $output .= sprintf('<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>', esc_url($embed_url), absint($width), absint($height), esc_attr__('Embedded WordPress Post'));
    /**
     * Filter the embed HTML output for a given post.
     *
     * @since 4.4.0
     *
     * @param string  $output The default HTML.
     * @param WP_Post $post   Current post object.
     * @param int     $width  Width of the response.
     * @param int     $height Height of the response.
     */
    return apply_filters('embed_html', $output, $post, $width, $height);
}
Exemplo n.º 5
0
/**
 * Retrieves the embed code for a specific post.
 *
 * @since 4.4.0
 *
 * @param int         $width  The width for the response.
 * @param int         $height The height for the response.
 * @param int|WP_Post $post   Optional. Post ID or object. Default is global `$post`.
 * @return string|false Embed code on success, false if post doesn't exist.
 */
function get_post_embed_html($width, $height, $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $embed_url = get_post_embed_url($post);
    $output = '<blockquote class="wp-embedded-content"><a href="' . esc_url(get_permalink($post)) . '">' . get_the_title($post) . "</a></blockquote>\n";
    $output .= "<script type='text/javascript'>\n";
    $output .= "<!--//--><![CDATA[//><!--\n";
    if (SCRIPT_DEBUG) {
        $output .= file_get_contents(ABSPATH . WPINC . '/js/wp-embed.js');
    } else {
        /*
         * If you're looking at a src version of this file, you'll see an "include"
         * statement below. This is used by the `grunt build` process to directly
         * include a minified version of wp-embed.js, instead of using the
         * file_get_contents() method from above.
         *
         * If you're looking at a build version of this file, you'll see a string of
         * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
         * and edit wp-embed.js directly.
         */
        $output .= <<<JS
\t\tinclude "js/wp-embed.min.js"
JS;
    }
    $output .= "\n//--><!]]>";
    $output .= "\n</script>";
    $output .= sprintf('<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>', esc_url($embed_url), absint($width), absint($height), esc_attr(sprintf(__('&#8220;%1$s&#8221; &#8212; %2$s'), get_the_title($post), get_bloginfo('name'))));
    /**
     * Filters the embed HTML output for a given post.
     *
     * @since 4.4.0
     *
     * @param string  $output The default HTML.
     * @param WP_Post $post   Current post object.
     * @param int     $width  Width of the response.
     * @param int     $height Height of the response.
     */
    return apply_filters('embed_html', $output, $post, $width, $height);
}
Exemplo n.º 6
0
 /**
  * Test the get_post_embed_html function.
  */
 function test_get_post_embed_html()
 {
     $post_id = $this->factory->post->create();
     $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"></iframe>';
     $this->assertEquals($expected, get_post_embed_html($post_id, 200, 200));
 }
Exemplo n.º 7
0
/**
 * Custom old slug redirection function.
 *
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 * @SuppressWarnings(PHPMD.NPathComplexity)
 * @codeCoverageIgnore
 */
function wp_oembed_old_slug_redirect()
{
    global $wp_query, $wpdb;
    if (false === get_query_var('embed', false)) {
        return;
    }
    if (!is_404() || false === get_query_var('name', false)) {
        return;
    }
    // Guess the current post_type based on the query vars.
    $post_type = 'post';
    if (get_query_var('post_type')) {
        $post_type = get_query_var('post_type');
    } elseif (get_query_var('pagename', false)) {
        $post_type = 'page';
    }
    if (is_array($post_type)) {
        if (count($post_type) > 1) {
            return;
        }
        $post_type = reset($post_type);
    }
    // Do not attempt redirect for hierarchical post types.
    if (is_post_type_hierarchical($post_type)) {
        return;
    }
    $query = $wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta}, {$wpdb->posts} WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']);
    if (get_query_var('year', false)) {
        $query .= $wpdb->prepare(' AND YEAR(post_date) = %d', $wp_query->query_vars['year']);
    }
    if (get_query_var('monthnum', false)) {
        $query .= $wpdb->prepare(' AND MONTH(post_date) = %d', $wp_query->query_vars['monthnum']);
    }
    if (get_query_var('day', false)) {
        $query .= $wpdb->prepare(' AND DAYOFMONTH(post_date) = %d', $wp_query->query_vars['day']);
    }
    $post_id = (int) $wpdb->get_var($query);
    if (!$post_id) {
        return;
    }
    wp_redirect(get_post_embed_url($post_id), 301);
    exit;
}
Exemplo n.º 8
0
 function test_get_post_embed_html()
 {
     $post_id = self::factory()->post->create();
     $title = esc_attr(sprintf(__('&#8220;%1$s&#8221; &#8212; %2$s'), get_the_title($post_id), get_bloginfo('name')));
     $expected = '<iframe sandbox="allow-scripts" security="restricted" src="' . esc_url(get_post_embed_url($post_id)) . '" width="200" height="200" title="' . $title . '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>';
     $this->assertStringEndsWith($expected, get_post_embed_html(200, 200, $post_id));
 }
Exemplo n.º 9
0
/**
 * Get the embed code for a specific post.
 *
 * @param int|WP_Post $post   Optional. Post ID or object. Defaults to the current post.
 * @param int         $width  The width for the response.
 * @param int         $height The height for the response.
 * @return string|false Embed code on success, false if post doesn't exist.
 */
function get_post_embed_html($post = null, $width, $height)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $embed_url = get_post_embed_url($post);
    $output = sprintf('<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>', esc_url($embed_url), $width, $height, __('Embedded WordPress Post', 'oembed-api'));
    /**
     * Filters the oEmbed HTML output.
     *
     * @param string  $output The default HTML.
     * @param WP_Post $post   Current post object.
     * @param int     $width  Width of the response.
     * @param int     $height Height of the response.
     */
    return apply_filters('oembed_html', $output, $post, $width, $height);
}
Exemplo n.º 10
0
/**
 * Retrieves the embed code for a specific post.
 *
 * @since 4.4.0
 *
 * @param int|WP_Post $post   Optional. Post ID or object. Default is global `$post`.
 * @param int         $width  The width for the response.
 * @param int         $height The height for the response.
 * @return string|false Embed code on success, false if post doesn't exist.
 */
function get_post_embed_html($post = null, $width, $height)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $embed_url = get_post_embed_url($post);
    $output = "<script type='text/javascript'>\n";
    if (SCRIPT_DEBUG) {
        $output .= file_get_contents(ABSPATH . WPINC . '/js/wp-embed.js');
    } else {
        /*
         * If you're looking at a src version of this file, you'll see an "include"
         * statement below. This is used by the `grunt build` process to directly
         * include a minified version of wp-embed.js, instead of using the
         * file_get_contents() method from above.
         *
         * If you're looking at a build version of this file, you'll see a string of
         * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
         * and edit wp-embed.js directly.
         */
        $output .= <<<JS
\t\t!function(a,b){"use strict";function c(){var a=-1!==navigator.appVersion.indexOf("MSIE 10"),c=!!navigator.userAgent.match(/Trident.*rv\\:11\\./);if(a||c)for(var d,e=b.querySelectorAll(".wp-embedded-content[security]"),f=0;f<e.length;f++)d=e[f].cloneNode(!0),d.removeAttribute("security"),e[f].parentNode.insertBefore(d,e[f].nextSibling),e[f].parentNode.removeChild(e[f])}a.wp=a.wp||{},a.wp.receiveEmbedMessage||(a.wp.receiveEmbedMessage=function(c){var d=c.data;if(d.secret||d.message||d.value)for(var e=b.querySelectorAll('.wp-embedded-content[data-secret="'+d.secret+'"]'),f=0;f<e.length;f++){var g=e[f];if("height"===d.message){var h=d.value;h>1e3?h=1e3:200>h&&(h=200),g.height=h+"px"}if("link"===d.message){var i=b.createElement("a"),j=b.createElement("a");i.href=g.getAttribute("src"),j.href=d.value,j.host===i.host&&b.activeElement===g&&(a.top.location.href=d.value)}}},a.addEventListener("message",a.wp.receiveEmbedMessage,!1),b.addEventListener("DOMContentLoaded",c,!1))}(window,document);
JS;
    }
    $output .= "\n</script>";
    $output .= sprintf('<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>', esc_url($embed_url), absint($width), absint($height), esc_attr__('Embedded WordPress Post'));
    /**
     * Filter the embed HTML output for a given post.
     *
     * @since 4.4.0
     *
     * @param string  $output The default HTML.
     * @param WP_Post $post   Current post object.
     * @param int     $width  Width of the response.
     * @param int     $height Height of the response.
     */
    return apply_filters('embed_html', $output, $post, $width, $height);
}
Exemplo n.º 11
0
 function test_get_post_embed_html()
 {
     $post_id = self::factory()->post->create();
     $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>';
     $this->assertStringEndsWith($expected, get_post_embed_html(200, 200, $post_id));
 }
Exemplo n.º 12
0
 /**
  * Test excerpt function.
  */
 function test_wp_oembed_excerpt_more()
 {
     $post_id = $this->factory->post->create(array('post_content' => 'Foo Bar'));
     $this->assertEquals('', wp_oembed_excerpt_more(''));
     $this->go_to(get_post_embed_url($post_id));
     $actual = wp_oembed_excerpt_more('');
     $expected = sprintf('&hellip; <a class="wp-embed-more" href="%s" target="_top">Read more</a>', get_the_permalink());
     $this->assertEquals($expected, $actual);
 }
Exemplo n.º 13
0
 /**
  * Test is_embed.
  */
 function test_is_embed()
 {
     $this->assertFalse(is_embed());
     $post_id = $this->factory->post->create();
     $this->go_to(get_post_embed_url($post_id));
     $this->assertTrue(is_embed());
     $file = DIR_TESTDATA . '/images/canola.jpg';
     $attachment_id = $this->factory->attachment->create_object($file, $post_id, array('post_mime_type' => 'image/jpeg'));
     $this->go_to(get_post_embed_url($attachment_id));
     $this->assertTrue(is_embed());
     $this->go_to(home_url('/?p=123&embed=true'));
     $this->assertTrue(is_embed());
 }
 public function test_embed_template_hierarchy_for_page()
 {
     $this->assertTemplateHierarchy(get_post_embed_url(self::$page), array('embed-page.php', 'embed.php', 'templates/page.php', 'page-page-name-😀.php', 'page-page-name-%f0%9f%98%80.php', 'page-' . self::$page->ID . '.php', 'page.php', 'singular.php'));
 }