Making WordPress.org

Changeset 12300


Ignore:
Timestamp:
12/07/2022 06:32:47 AM (19 months ago)
Author:
dd32
Message:

Support Forums: Blocks: Allow any user who can publish a reply/topic to access the oEmbed proxy endpoint.

See #6608.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-blocks.php

    r12295 r12300  
    2727        // Customize blocks for the Support Forums.
    2828        add_filter( 'blocks_everywhere_editor_settings', [ $this, 'editor_settings' ] );
     29
     30        // Allow the oEmbed proxy endpoint for any user who can publish a thread/reply..
     31        add_filter( 'rest_api_init', [ $this, 'overwrite_oembed_10_proxy_permission' ], 20 );
    2932    }
    3033
     
    7275        return $settings;
    7376    }
     77
     78    public function overwrite_oembed_10_proxy_permission() {
     79        // A register_route_args filter would be handy here... See https://core.trac.wordpress.org/ticket/54087
     80        $oembed_proxy_route_args = rest_get_server()->get_routes( 'oembed/1.0' )['/oembed/1.0/proxy'] ?? false;
     81        if ( ! $oembed_proxy_route_args ) {
     82            return;
     83        }
     84
     85        // Flip it from [ GET => true ] to [ GET ]
     86        $oembed_proxy_route_args[0]['methods'] = array_keys( $oembed_proxy_route_args[0]['methods'] );
     87
     88        // Overwrite the permission_callback, allow any user who can create replies to use embeds.
     89        $oembed_proxy_route_args[0]['permission_callback'] = function() {
     90            return bbp_current_user_can_publish_topics() || bbp_current_user_can_publish_replies();
     91        };
     92
     93        register_rest_route(
     94            'oembed/1.0',
     95            '/proxy',
     96            $oembed_proxy_route_args,
     97            true
     98        );
     99    }
    74100}
Note: See TracChangeset for help on using the changeset viewer.