Select Git revision
wp-cdn-rewrite.php
-
Curtis Loisel authoredCurtis Loisel authored
wp-cdn-rewrite.php 7.34 KiB
<?php
/*
Plugin Name: WP CDN Rewrite
Plugin URI: http://voceconnect.com/
Description: Rewrites asset URLs to CDN
Version: 0.1.5
Author: Chris Scott, Michael Pretty, Kevin Langley
Author URI: http://voceconnect.com/
*/
if(file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php' ) )
include_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php' );
if( !class_exists( 'CDN_Rewrite' ) ){
class CDN_Rewrite {
const OPTION_GENERAL = 'cdn_general';
private $cdn_root_url;
private $file_extensions;
private $css_file_extensions;
private $css_cdn_root_url;
private $js_file_extensions;
private $js_cdn_root_url;
private $blog_details;
public function __construct() {
$this->cdn_root_url = $this->css_cdn_root_url = $this->js_cdn_root_url = untrailingslashit($this->get_setting('root_url'));
if ($css_url = trim($this->get_setting('css_root_url'))) {
$this->css_cdn_root_url = untrailingslashit($css_url);
}
if ($js_url = trim($this->get_setting('js_root_url'))) {
$this->js_cdn_root_url = untrailingslashit($js_url);
}
$this->file_extensions = $this->get_setting('file_extensions');
$this->css_file_extensions = $this->get_setting('css_file_extensions');
$this->js_file_extensions = $this->get_setting('js_file_extensions');
}
public function initialize() {
if( !class_exists( 'Voce_Settings_API' ) )
return _doing_it_wrong( __CLASS__, 'The Voce Settings API plugin must be active for the CDN Rewrite plugin to work', NULL );
$this->add_options_page();
if ('' == $this->file_extensions || '' == $this->cdn_root_url) {
add_action('admin_notices', array($this, 'settings_warning'));
return;
}
if('/' != $this->cdn_root_url) {
$action = (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ? 'xmlrpc_call' : 'template_redirect';
add_action($action, array($this, 'start_buffer'), 1);
}
}
/**
* get general setting
*
* @param string $setting setting name
* @return mixed setting value or false if not set
*/
private function get_setting($setting) {
$settings = get_option(self::OPTION_GENERAL);