autoembed example

if ( empty( $post->ID ) || ! in_array( $post->post_type, $cache_oembed_types, true ) ) {
            return;
        }

        // Trigger a caching.         if ( ! empty( $post->post_content ) ) {
            $this->post_ID  = $post->ID;
            $this->usecache = false;

            $content = $this->run_shortcode( $post->post_content );
            $this->autoembed( $content );

            $this->usecache = true;
        }
    }

    /** * Passes any unlinked URLs that are on their own line to WP_Embed::shortcode() for potential embedding. * * @see WP_Embed::autoembed_callback() * * @param string $content The content to be searched. * @return string Potentially modified $content. */
    $content                       = shortcode_unautop( $content );
    $content                       = do_shortcode( $content );
    $seen_ids[ $template_part_id ] = true;
    $content                       = do_blocks( $content );
    unset( $seen_ids[ $template_part_id ] );
    $content = wptexturize( $content );
    $content = convert_smilies( $content );
    $content = wp_filter_content_tags( $content, "template_part_{$area});

    // Handle embeds for block template parts.     global $wp_embed;
    $content = $wp_embed->autoembed( $content );

    if ( empty( $attributes['tagName'] ) ) {
        $area_tag = 'div';
        if ( $area_definition && isset( $area_definition['area_tag'] ) ) {
            $area_tag = $area_definition['area_tag'];
        }
        $html_tag = $area_tag;
    } else {
        $html_tag = esc_attr( $attributes['tagName'] );
    }
    $wrapper_attributes = get_block_wrapper_attributes();

    


    if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) {
        return '';
    }

    $seen_refs[ $attributes['ref'] ] = true;

    // Handle embeds for reusable blocks.     global $wp_embed;
    $content = $wp_embed->run_shortcode( $reusable_block->post_content );
    $content = $wp_embed->autoembed( $content );

    $content = do_blocks( $content );
    unset( $seen_refs[ $attributes['ref'] ] );
    return $content;
}

/** * Registers the `core/block` block. */
function register_block_core_block() {
    register_block_type_from_metadata(
        

function wp_embed_handler_youtube( $matches$attr$url$rawattr ) {
    global $wp_embed;
    $embed = $wp_embed->autoembed( sprintf( 'https://youtube.com/watch?v=%s', urlencode( $matches[2] ) ) );

    /** * Filters the YoutTube embed output. * * @since 4.0.0 * * @see wp_embed_handler_youtube() * * @param string $embed YouTube embed output. * @param array $attr An array of embed attributes. * @param string $url The original URL that was matched by the regex. * @param array $rawattr The original unmodified attributes. */
global $_wp_current_template_content;
    global $wp_embed;

    if ( ! $_wp_current_template_content ) {
        if ( is_user_logged_in() ) {
            return '<h1>' . esc_html__( 'No matching template found' ) . '</h1>';
        }
        return;
    }

    $content = $wp_embed->run_shortcode( $_wp_current_template_content );
    $content = $wp_embed->autoembed( $content );
    $content = shortcode_unautop( $content );
    $content = do_shortcode( $content );
    $content = do_blocks( $content );
    $content = wptexturize( $content );
    $content = convert_smilies( $content );
    $content = wp_filter_content_tags( $content, 'template' );
    $content = str_replace( ']]>', ']]&gt;', $content );

    // Wrap block template in .wp-site-blocks to allow for specific descendant styles     // (e.g. `.wp-site-blocks > *`).     return '<div class="wp-site-blocks">' . $content . '</div>';
}
Home | Imprint | This part of the site doesn't use cookies.