Skip to content

Instantly share code, notes, and snippets.

@blobaugh
Created December 15, 2013 20:13
Show Gist options
  • Select an option

  • Save blobaugh/7977545 to your computer and use it in GitHub Desktop.

Select an option

Save blobaugh/7977545 to your computer and use it in GitHub Desktop.
server from wpcom
<?php
/*
Plugin Name: Serve from WordPress.com
Plugin URI: http://github.com/blobaugh/serve-from-wordpress-com
Description: Switches the URL on built-in WordPress javascript files to serve from WordPress.com rather than locally
Author: Ben Lobaugh
Version: 0.6
Author URI: http://ben.lobaugh.net
*/
// Show module in Jetpack
/**
* Singleton
**/
class Scripts_From_WPcom {
/**
* Holds the instance of Scripts_From_WPcom singleton
*
* @since 0.6
* @var Scripts_From_WPcom
**/
private static $instance = null;
/**
* Private singleton constructor
*
* @since 0.6
* @return Scripts_From_WPcom
**/
private function __construct() {
add_filter( 'script_loader_src', array( $this, 'rewrite_src' ), 1, 2 );
}
/**
* Gets a copy of the singleton to use
*
* @since 0.6
* @return Scripts_From_WPcom
**/
public static function instance() {
if( !is_null( self::$instance ) )
return self::$instance;
self::$instance = new Scripts_From_WPcom();
return self::$instance;
}
/**
* Rewrites the registered script urls to point to http://wordpress.com
*
* @since 0.6
**/
public function rewrite_src( $src, $handle ) {
if( strpos( $src, 'wp-includes' ) ) {
$src = str_replace( site_url(), 'http://wordpress.com', $src );
}
return $src;
}
}
Scripts_From_WPcom::instance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment