WordPress.org

Making WordPress.org

Changeset 7546


Ignore:
Timestamp:
07/31/2018 01:54:50 AM (3 years ago)
Author:
obenland
Message:

Gutenberg: Re-enable embeds and dynamic blocks.

See #3703.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php

    r7544 r7546  
    3535            sprintf(
    3636                'wp.apiFetch.use( function( options, next ) {
    37                     if ( options.method !== "GET" ) {
    38                         return Promise.resolve( options.data );
     37                    var is_whitelisted_endpoint = options.path.startsWith( "/oembed/1.0/proxy" ) || options.path.startsWith( "/gutenberg/v1/block-renderer" );
     38
     39                    if ( options.method !== "GET" && ! is_whitelisted_endpoint ) {
     40                        return Promise.resolve( options.data ); //not sure what this actually should be, etc.
    3941                    }
    4042
     
    6264    }
    6365    add_filter( 'wp_headers', 'disable_x_pingback' );
    64 
    65     // Embeds need further work.
    66     add_filter( 'block_categories', function( $cats ) {
    67         foreach ( $cats as $i => $cat ) {
    68             if ( $cat['slug'] === 'embed' )
    69                 unset( $cats[$i] );
    70         }
    71         return $cats;
    72     } );
    73 
    74 
    7566});
     67
     68/**
     69 * Let unauthenticated users embed media in Frontenberg.
     70 */
     71function frontenberg_enable_oembed( $all_caps ) {
     72    if (
     73        0 === strpos( $_SERVER['REQUEST_URI'], '/gutenberg/wp-json/oembed/1.0/proxy' )  ||
     74        0 === strpos( $_SERVER['REQUEST_URI'], '/gutenberg/wp-json/gutenberg/v1/block-renderer/core/archives' ) ||
     75        0 === strpos( $_SERVER['REQUEST_URI'], '/gutenberg/wp-json/gutenberg/v1/block-renderer/core/latest-comments' )
     76    ) {
     77        $all_caps['edit_posts'] = true;
     78    }
     79
     80    return $all_caps;
     81}
     82add_filter( 'user_has_cap', 'frontenberg_enable_oembed' );
    7683
    7784/**
Note: See TracChangeset for help on using the changeset viewer.