Making WordPress.org

Changeset 12302


Ignore:
Timestamp:
12/07/2022 06:43:57 AM (15 months ago)
Author:
dd32
Message:

Support Forums: Disable Screencast oEmbed and fix Imgur embeds.

See #6608.

File:
1 edited

Legend:

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

    r12301 r12302  
    3333        // Allow the oEmbed proxy endpoint for any user who can publish a thread/reply..
    3434        add_filter( 'rest_api_init', [ $this, 'overwrite_oembed_10_proxy_permission' ], 20 );
     35
     36        // Hack to make Imgur embeds work. This should be fixed by Imgur.
     37        add_filter( 'oembed_remote_get_args', [ $this, 'oembed_remote_get_args' ], 10, 2 );
    3538    }
    3639
     
    8285        ];
    8386
    84         // TODO: To modify the available embeds modify $settings['iso']['allowEmbeds']
     87        $settings['iso']['allowEmbeds'] = array_diff(
     88            $settings['iso']['allowEmbeds'],
     89            [
     90                // Disable screencast, it seems not to work.
     91                'screencast',
     92            ]
     93        );
    8594
    8695        return $settings;
     
    109118        );
    110119    }
     120
     121    /**
     122     * Imgur oEmbed API appears to block any request with a lowercase 'wordpress' in the user-agent.
     123     *
     124     * @param array  $http_args    The args to pass to wp_safe_remote_get().
     125     * @param string $provider_url The URL of the oEmbed provider to be requested.
     126     * @return array The modified $http_args.
     127     */
     128    public function oembed_remote_get_args( $http_args, $provider_url ) {
     129        if ( str_contains( $provider_url, 'imgur.com' ) ) {
     130            $http_args['user-agent'] = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $provider_url );
     131            $http_args['user-agent'] = str_replace( 'wordpress', 'WordPress', $http_args['user-agent'] );
     132        }
     133
     134        return $http_args;
     135    }
    111136}
Note: See TracChangeset for help on using the changeset viewer.