Making WordPress.org


Ignore:
Timestamp:
06/19/2016 07:34:19 PM (8 years ago)
Author:
obenland
Message:

Plugin Directory: Whitelist oembed providers for the directory.

Fixes #1769.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3468 r3476  
    3939        add_action( 'template_redirect', array( $this, 'redirect_old_plugin_urls' ) );
    4040        add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
     41
     42        // oEmbed whitlisting.
     43        add_filter( 'embed_oembed_discover', '__return_false' );
     44        add_filter( 'oembed_providers', array( $this, 'oembed_whitelist' ) );
    4145
    4246        // Shim in postmeta support for data which doesn't yet live in postmeta
     
    688692            die();
    689693        }
     694    }
     695
     696    /**
     697     * Whitelists the oembed providers whitelist.
     698     *
     699     * Limited to providers that add video support to plugin readme files.
     700     *
     701     * @param array $providers An array of popular oEmbed providers.
     702     * @return array
     703     */
     704    public function oembed_whitelist( $providers ) {
     705        return array_filter( $providers, function ( $provider ) {
     706            $whitelist = array(
     707                'youtube.com',
     708                'vimeo.com',
     709                'wordpress.com',
     710                'wordpress.tv',
     711                'vine.co',
     712                'soundcloud.com',
     713                'instagram.com',
     714                'mixcloud.com',
     715                'cloudup.com',
     716            );
     717
     718            foreach ( $whitelist as $url ) {
     719                if ( false !== strpos( $provider[0], $url ) ) {
     720                    return true;
     721                }
     722            }
     723            return false;
     724        } );
    690725    }
    691726
Note: See TracChangeset for help on using the changeset viewer.