Created
August 10, 2016 13:37
-
-
Save y-krn/518542b8e8872a3e6f84d753a0eb0803 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
new Embed_Link_Builder(); | |
/** | |
* Class Name: Embed_Link Builder | |
*@author @ottanxyz | |
*/ | |
class Embed_Link_Builder { | |
function __construct() { | |
wp_embed_register_handler( | |
'external_link_builder', | |
'/^(https?:\\/\\/.*)$/i', | |
array( &$this, 'handler' ) | |
); | |
add_shortcode( 'embed_links', array( &$this, 'display' ) ); | |
} | |
public function handler( $matches, $attr, $url, $rawattr ) { | |
$args = preg_split( '/#/', $matches[1] ); | |
return "[embed_links url=\"{$args[0]}\"]"; | |
} | |
public function display( $p ) { | |
if ( ! isset( $p['url'] ) || ! $p['url'] ) { | |
return; | |
} | |
return '<a class="embedly-card" href="' . $p['url'] . '">' . $p['url'] . '</a>'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment