Dynamic CSS
Hi guys,
I am using : Redux Framework v3.1.8 I embedded it into my theme folder.
Last time I was in a problem to generate dynamic css with redux which I solved later on... Thanks to Redux, It's really awesome.... Dovy and Kevin helped me to find my answers.
Now I am in an another problem... This is my code of a specific field : array( 'id' => 'primary-color', 'type' => 'color', 'output' => array('.site-title'), 'title' => __('Primary Color', 'redux-framework-demo'), 'subtitle' => __('Pick a Primary color for the theme (default: #fff).', 'redux-framework-demo'), 'compiler' => array('.menu ul.main-nav li a:hover','#navigation .menu ul > li.current > a','.column i','#feature .wrapper h2','#feature .ft-two','#feature .ft-one','.footer-wrap p span a','.slider-caption h2 span'), 'default' => '#FFFFFF', 'validate' => 'color', ), Here I used "color" as the css attribute... Its working really fine..
Now I want to use this field value to another css selector. Suppose for "background-color" for other group of selectors...
To be specific the user chosen value from this field will be used as another css property in another section. Thanks in advance....
Two different selectors from the same field? I don't think it's possible. You can change the selector via mode ('mode' => 'background-color'), but you wouldn't be able to use both. There would be no way to assign which mode to which class. The only workaround I can think of is to manipulate the output in the compiler_action function.
Yea, use the compiler to do this when they change a compiler field. We won't link fields in that way. That kind of logic is up to the developer. ;)
Hi, I'm having hard time to use create css compiler. I have follow step by step on this page http://docs.reduxframework.com/redux-framework/advanced/updating-a-css-file-dynamically/ but I didn't get anything work. There is no css file create or write. What should I do?
did you set the field you want to compile something like this?
'compiler' => array('body, #header, #footer'),
Yes already did it, follow exactly like on the documentation page. Should I create a style.css file on the same folder as config file? or it will create automatically?
Try a print_r of the $css variable passed like in the sample-config. There's actually a full working example there.
verify if the compiler run
add something on the compiler function like
function compiler_action($options, $css) {
add_action('admin_notices', 'compiler_notification');
function compiler_notification() {
echo '<div id="info-notice_success" class="redux-success redux-notice-field redux-field-info"><p class="redux-info-icon"><i class="el-icon-info-sign icon-large"></i></p><p class="redux-info-desc"><b>Compiler Run</b><br>You have successfully Updated the auto-generated files!</p></div>';
}
print_r($css); // Compiler selector CSS values compiler => array( CSS SELECTORS )
// Demo of how to use the dynamic CSS and write your own static CSS file
$content = '/*! ** This file is auto-generated from Theme Options, You should never edit this file directly! ***/'."\n". $css ;
$filename = CMK_DIR . '/output' . '.css';
global $wp_filesystem;
if( empty( $wp_filesystem ) ) {
require_once( ABSPATH .'/wp-admin/includes/file.php' );
WP_Filesystem();
}
if( $wp_filesystem ) {
$wp_filesystem->put_contents(
$filename,
$content,
FS_CHMOD_FILE // predefined mode settings for WP files
);
}
}
and make sure this the directory exist
$filename = CMK_DIR . '/output' . '.css';
you don't have to create any stylsheet
If you created your config file with the generator, you don't have the initSettings() function spoken of in the documentation. Instead, you have loadConfig()
Second, do not put the line
add_filter('redux/options/'.$this->args['opt_name'].'/compiler', array( $this, 'compiler_actions' ), 10, 3);
at the beginning of the function. At that point, $this->args['opt_name'] is undefined so your compiler_action will not run.
Thirdly, if you are putting that code in loadConfig(), then the array $args is defined in that same function. $this->args would refer to an array defined in the class. To pick the correct value, use $args['opt_name']
So, in loadConfig(), add
add_filter('redux/options/'.$args['opt_name'].'/compiler', array( $this, 'compiler_action' ), 10, 3);
just before
$ReduxFramework = new ReduxFramework($sections, $args);
Hi.
- Please do not piggyback old tickets. Create your own.
- Make sure you include the necessary info (https://github.com/ReduxFramework/redux-framework/blob/master/CONTRIBUTING.md)
- When you create the new ticket, you'll have to tell me where you are seeing 'loadConfig', because I cannot find it anywhere.