0

I try to style the admin area with a dynamic css. I need to configure some elements regarding the frontend user defines. He can choose a color and this color should reflected in some elements in the admin area (e.g. buttons in admin area). My approach: Setting up a evacolor.css, but let apache interpret this as a php file. This works so fare:

.htaccess in the same dir, as my color.css:

<FilesMatch "\.css$">
    SetHandler application/x-httpd-php
    Header set Content-type "text/css"
</FilesMatch>

My evacolor.css looks like:

<?php
 $absolute_path = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
 $wp_load = $absolute_path[0] . 'wp-load.php';
  header("Content-type: text/css; charset: UTF-8");
  header('Cache-control: must-revalidate');

    $test = "#ff00ff";
?>
 
body {
  background: <?php echo $test;?>;
}
.... and so on

This works fine. Now I need to pull my color out from the wp_options table and all the problems starts.

  1. I tried $color_items = get_option( 'cornerstone_color_items' ); => Uncaught Error: Call to undefined function get_option() I tried to include include_once('wp-includes\option.php'); But this ends in => Call to undefined function wp_installing() Ok, let's includ this also include_once('wp-includes\load.php'); => Call to undefined function apply_filters()

Hence. Next try:

global $wpdb;    
$result = $wpdb->get_results( "SELECT * FROM wpeva_options WHERE option_name = 'cornerstone_color_items'");
print_r($result)

=> Uncaught Error: Call to a member function get_results()

I include require_once($wp_load); => Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

I give up. No more ideas.

Does anyone has an idea, how to use a dynamic css (for admin, resp. backend) and use inside this css a color value, which is stored in wp_option table? Even my attempt to define a global variable has had no success: $GLOBALS['color'] = '#ff00ff'; and also define('CICOLOR', '#ff00ff'); are empty in my dynamic css;

Any ideas? Any help? Thank you :)

2
  • 5
    This seems like overkill. You'd have a much easier time just using CSS variables in the CSS file and defining those variables in an inline style block added by the plugin. Apr 21, 2021 at 10:15
  • Thank you Jacob. But how to do this? I have a color value stored in my wp-table. This value can change. Now I need this value in my color.css from an admin color scheme. I don't know.... how can I setup this with css-variable. Any more advice? Thank you.
    – mickna
    Apr 21, 2021 at 10:19

1 Answer 1

1

Thank you @Jacob for pointing me in the right direction. This was an overkill!

=> in function php I call my values, set this in a global css variable. Pick this variable in my admin css.

Again: Thank you! Lifesaver :))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.