Skip to content

Instantly share code, notes, and snippets.

@moskowite
Created February 28, 2012 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moskowite/1935689 to your computer and use it in GitHub Desktop.
Save moskowite/1935689 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Make Project's oEmbed
Plugin URI: http://makeprojects.com/
Description: Embed a Make Project into your Wordpress blog, just copy and paste the URL of the project (e.g. http://makeprojects.com/Project/Build-a-Makerspace/1390/1 ). This plugin will automatically embed using wp_oembed_add_provider. Enjoy a interactive Make Project's experience right in your blog.
Author: whyisjake, tmoskowite
Version: 1.0
Author URI: www.makezine.com
*/
// Wordpress oEmbed function
wp_oembed_add_provider( 'http://makeprojects.com/Project/*' , 'http://makeprojects.com/Embed' );
// oEmbed finder which corrects the URL and accounts for multiple links in one post
function makeprojects_oembed_finder($content){
// url search and correction strings
$htmlSrc = 'src="http://cacher.dozuki.net/static/embed/ifixit-embed.3.js?id=';
$htmlAdd = '&site=makeprojects.com" data-dozuki-embed="3';
$idOffset = 4;
// find the url
$pos = strpos($content, $htmlSrc);
$srcLen = strlen($htmlSrc) + $idOffset;
// loop and make corrections until out of links
while($pos !== false){
$uniqueHtml = substr($content, $pos, $srcLen);
$newHtml = $uniqueHtml . $htmlAdd;
$content = str_replace($uniqueHtml, $newHtml, $content);
$pos = strpos($content, $htmlSrc, $pos + $srcLen);
}
return $content;
}
add_filter('the_content', 'makeprojects_oembed_finder');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment