Created
December 15, 2013 20:13
-
-
Save blobaugh/7977545 to your computer and use it in GitHub Desktop.
server from wpcom
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 | |
| /* | |
| 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