Skip to content

Instantly share code, notes, and snippets.

@doitmax
Last active March 8, 2016 15:01
Show Gist options
  • Save doitmax/1f37822681dfcb84b8b9 to your computer and use it in GitHub Desktop.
Save doitmax/1f37822681dfcb84b8b9 to your computer and use it in GitHub Desktop.
Redux CSS Media Query Replacement
if ( ! function_exists( '_compiler_action' ) ) {
function _css_replace_callback( $matches ) {
return '@'.$matches[1].'}';
}
}
if ( ! function_exists( '_compiler_action' ) ) {
function _compiler_action( $options, $css, $changed_values ) {
global $wp_filesystem;
$pattern = '/[@]+([^}]*})/';
$css = preg_replace_callback( $pattern, '_css_replace_callback', $css );
// The custom CSS file to output option related CSS.
$filename = get_template_directory() . '/assets/css/option-styles.css';
if ( empty( $wp_filesystem ) ) {
require_once( ABSPATH .'/wp-admin/includes/file.php' );
WP_Filesystem();
}
if ( $wp_filesystem ) {
$wp_filesystem->put_contents(
$filename,
$css,
FS_CHMOD_FILE // Predefined mode settings for WP files.
);
}
}
}
add_filter( 'redux/options/{opt_name}/compiler', '_compiler_action', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment