Skip to content

Instantly share code, notes, and snippets.

@k4zuki02h4t4
Created December 21, 2015 03:12
Show Gist options
  • Save k4zuki02h4t4/1293c362b4ba53a2f2e8 to your computer and use it in GitHub Desktop.
Save k4zuki02h4t4/1293c362b4ba53a2f2e8 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: KUCKLU Test Plugin
* Plugin URI:
* Description: -_-
* Author: KUCKLU
* Version: 1.0.0
* Author URI: http://visualive.jp/
* Text Domain: kuck1u-test-plugin
* Domain Path: /langs
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
* @package WordPress
* @subpackage KUCKLU Test Plugin
* @author KUCKLU <kuck1u@visualive.jp>
* Copyright (C) 2015 KUCKLU & VisuAlive.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/gpl-2.0.txt
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Filter the URL embed handler callback.
*
* @since 1.0.0
*
* @param callable $handler URL embed handler callback function.
*/
add_action( 'plugins_loaded', function () {
$whitelist = apply_filters( 'kuck1u_test_plugin_whitelist', array(
'youtube\.com\/watch',
'youtube\.com\/playlist',
'youtu\.be',
'vimeo\.com',
'dailymotion\.com',
'dai\.ly',
'flickr\.com',
'flic\.kr',
'smugmug\.com',
'hulu\.com\/watch',
'photobucket.com\/albums',
'photobucket.com\/groups',
'scribd\.com\/doc',
'wordpress\.tv',
'polldaddy\.com',
'poll\.fm',
'funnyordie\.com\/videos',
'twitter\.com',
'vine\.co\/v',
'soundcloud\.com',
'slideshare\.net',
'instagr\.am\/p',
'instagram\.com\/p',
'rdio\.com',
'rd\.io\/x',
'spotify\.com',
'imgur\.com',
'meetu\.ps',
'meetup\.com',
'issuu\.com',
'collegehumor\.com\/video',
'mixcloud\.com',
'ted\.com\/talks',
'animoto\.com\/play',
'video214\.com\/play',
'tumblr\.com\/post',
'kickstarter\.com\/projects',
'kck\.st',
'cloudup\.com',
'reverbnation\.com',
'videopress.com\/v',
'reddit\.com\/r',
'speakerdeck\.com',
) );
$regex = '/^(https?:\/\/(?!.*(' . join( '|', $whitelist ) . ')).*[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/i';
wp_embed_register_handler( 'kuck1u_test_plugin', $regex, apply_filters( 'wp_kuck1u_test_plugin_embed_handler', 'wp_embed_handler_kuck1u_test_plugin' ) );
} );
/**
* VA Test embed.
*
* @param array $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
* @param array $attr Embed attributes.
* @param string $url The original URL that was matched by the regex.
* @param array $rawattr The original unmodified attributes.
*
* @return string The embed HTML.
*/
function wp_embed_handler_kuck1u_test_plugin( $matches, $attr, $url, $rawattr ) {
$embed = 'KUCKLU -_- oEmbed test.';
$output = apply_filters( 'kuck1u_test_plugin_embed', $embed, $matches, $attr, $url, $rawattr );
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment