Skip to content

Instantly share code, notes, and snippets.

@krishna19
Forked from syamilmj/generate_options_css.php
Created October 3, 2016 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishna19/cb242b143bcd7aa2a8f1bf71718e47d0 to your computer and use it in GitHub Desktop.
Save krishna19/cb242b143bcd7aa2a8f1bf71718e47d0 to your computer and use it in GitHub Desktop.
generate_options_css()
function generate_options_css($newdata) {
/** Define some vars **/
$data = $newdata;
$uploads = wp_upload_dir();
$css_dir = get_template_directory() . '/css/'; // Shorten code, save 1 call
/** Save on different directory if on multisite **/
if(is_multisite()) {
$aq_uploads_dir = trailingslashit($uploads['basedir']);
} else {
$aq_uploads_dir = $css_dir;
}
/** Capture CSS output **/
ob_start();
require($css_dir . 'styles.php');
$css = ob_get_clean();
/** Write to options.css file **/
WP_Filesystem();
global $wp_filesystem;
if ( ! $wp_filesystem->put_contents( $aq_uploads_dir . 'options.css', $css, 0644) ) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment