Jump to content
Sign in to follow this  
agileapricot

CSS - Loaded inline inside of WP Multisite installations

Recommended Posts

umbrellagroup
This is a _huge_ problem and makes it basically impossible to style the system using child themes. Since you can't override inline styles from an external stylesheet, using a child theme becomes useless to a certain extent. So... here's the fix - note that this a 45 minute hack and I've not optimized the code: includes/library.templates.php - new "do_dynamic_css()" function: function do_dynamic_css(){ // Get Dynamic Styles // If multisite is used, then dynamic styles need to be inline. // TODO is there a better solution? if( pagelines_option('inline_dynamic_css') || !is_writable(PAGELINES_DCSS ) ){ get_dynamic_css(); } else if (is_multisite()) { $dynamic_css_uri = ""; $dynamic_css_uri = site_url() . "/files/pagelines/dynamic.css"; $dynamic_css_path = ""; $uploads_dir_array = wp_upload_dir(); if(is_dir($uploads_dir_array['basedir'] . "/pagelines")) { $dynamic_css_path = $uploads_dir_array['basedir'] . "/pagelines/dynamic.css"; } if($dynamic_css_path != "" && $dynamic_css_uri != "") { $date_modified = filemtime($dynamic_css_path); $dcss_cache_ver = str_replace('.', '', CORE_VERSION) .'-'. date('mdyGis', $date_modified); printf('%s', $dynamic_css_uri, $dcss_cache_ver, "n"); } else { get_dynamic_css(); } } else { $date_modified = filemtime(PAGELINES_DCSS); $dcss_cache_ver = str_replace('.', '', CORE_VERSION) .'-'. date('mdyGis', $date_modified); printf('%s', PAGELINES_DCSS_URI, $dcss_cache_ver, "n"); } } includes/library.functions.php - new "pagelines_make_uploads($txt = 'Load')" function function pagelines_make_uploads($txt = 'Load'){ add_filter('request_filesystem_credentials', '__return_true' ); $method = ''; $url = 'themes.php?page=pagelines'; $dynamic_css_path = ""; if(!is_multisite()) { $dynamic_css_path = PAGELINES_DCSS; } else { $uploads_dir_array = wp_upload_dir(); if(is_dir($uploads_dir_array['basedir'] . "/pagelines")) { $dynamic_css_path = $uploads_dir_array['basedir'] . "/pagelines/dynamic.css"; } } // if (is_writable($dynamic_css_path) && !is_multisite()){ if (is_writable($dynamic_css_path)){ $creds = request_filesystem_credentials($url, $method, false, false, null); if ( ! WP_Filesystem($creds) ) { // our credentials were no good, ask the user for them again request_filesystem_credentials($url, $method, true, false, null); return false; } global $wp_filesystem; if ( ! $wp_filesystem->put_contents( $dynamic_css_path, $txt, FS_CHMOD_FILE) ) { echo "error saving file!"; return false; } } return true; } includes/class.css.php - new "pagelines_build_dynamic_css( $trigger = 'N/A' )" function function pagelines_build_dynamic_css( $trigger = 'N/A' ){ // Create directories and folders for storing dynamic files if(!file_exists(PAGELINES_DCSS) ) { if ( false === pagelines_make_uploads() ); { pagelines_update_option( 'inline_dynamic_css', true ); return; } } // Write to dynamic files // The write check is done later and modifications make this work for multisite // if ( is_writable(PAGELINES_DCSS) && !is_multisite() ){ $pagelines_dynamic_css = new PageLinesCSS; $pagelines_dynamic_css->create('texturize'); pagelines_make_uploads($pagelines_dynamic_css->css ."nn/* Trigger: ". $trigger . '*/'); // } } Feel free to remove the comments or clean up. I've tested this on my multsite install and it is working well. Dynamic CSS written to multisite "files/pagelines" folder - unique to each blog. Dynamic CSS URL is matched against "files" folder. Should work via HTTP or HTTPS. Thanks, --Nate

Share this post


Link to post
Share on other sites
umbrellagroup
Also, I feel the dynamic css is difficult to work with. Because it loads after "style.css", you can't override any dynamic CSS settings (from a child theme's style.css). This may be by design since the dynamic CSS should probably be authoritative, but I'm still trying to figure out the best way to override styles using a child theme. I now can override because they are not inline, but I'm having to add another css file to load after the dynamic css file. It also might be better to have the "Custom CSS" (ie: user input css) file separate from the dynamic css so it can go like this in a child theme scenario: style.css (parent) dynamic.css override.css (child theme) custom.css (user changes) That's how my system is working now. I'm not sure if that is the best way, but it accomplishes what I need. Just food for thought. Thanks, --Nate

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×