Sunday, November 18, 2012

Thesis 2.0 multisite CSS (thesis_do=css)

Note: this is a quick patch to Thesis 2.0.1, not optimized, not approved by the Thesis authors and not tested thoroughly.

Problem:

In the WPMU environment, Thesis CSS link looks like:

...?thesis_do=css&ref=...

instead of "normal" link to a .css file

Details:

The code responsible for that resides in the lib/core/skin/box.php, in class class thesis_stylesheets_link :

'url' => !is_multisite() ? THESIS_USER_SKIN_URL . '/css.css' : site_url("?thesis_do=css&ref=". THESIS_MS_CSS_VAL . time()),

Note that the time() call at the end makes this link not cacheable.

The patch:

1. In the box.php:

public function html() {
global $wpdb;
$styles = $links = array();
$styles['layout'] = array(
'url' => THESIS_USER_SKIN_URL . '/css' . (is_multisite() ? $wpdb->blogid : '') . '.css',

2. In lib/core/skin/css.php

public function write($skin, $custom) {
global $wpdb;
$css = $this->reset() . $this->update(apply_filters('thesis_css', $skin), $custom);
$css = strip_tags($css);
if (is_multisite()) {
update_option('thesis_raw_css', $css);
wp_cache_flush();
$lid = @fopen(THESIS_USER_SKIN . '/css' . $wpdb->blogid . '.css', 'w');
@fwrite($lid, trim($css));
@fclose($lid); 
}