css - PHP - Send option to style.php using get_option -


i not sure how formulate question start saying in plugin folder have 2 files:

1 - "index.php"

add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );  function my_admin_setting() {     include('includes/my_admin.php');     include('css/wp-admin.php'); }  function custom_admin_actions() {     add_menu_page("customise-admin", "custom-admin", 1, "custom_admin", "my_admin_setting");     add_submenu_page('custom_admin', 'about', 'about', 1, 'info', "my_admin_info");  }  function my_admin_theme_style() {      wp_register_style('my-admin-theme', plugins_url('css/wp-admin.php', __file__));     wp_enqueue_style('my-admin-theme'); }   add_action('admin_enqueue_scripts', 'my_admin_theme_style'); add_action('login_enqueue_scripts', 'my_admin_theme_style'); add_action('admin_menu', 'custom_admin_actions');   add_option( 'my_adminbar_color', 'red' );  

2 - wp_admin.php (style)

<?php header('content-type: text/css'); ?>  <?php  $blue = '#0e70d1'; $dkgray = '#333'; $dkgreen = '#008400'; ?> <?php $myplugin_color = get_option( 'my_adminbar_color' ); ?>  #wpadminbar {    background-color: <?php echo $myplugin_color;?> !important; } 

the problem here trying pass option php style. when don't insert "get_option" function custom style visible however, pass value style not rendered anymore.

i can see option passed style file css code printed in plugin page, instead of running code css seems becomes formatted normal text.

could explain me why happens? , how pass option style file?

you're calling wp-admin.php file directly, wordpress not loaded inside file, , get_option not defined.

this solution (without use of external file wp-admin.php):

function my_admin_theme_style () {     $blue    = '#0e70d1';     $dkgray  = '#333';     $dkgreen = '#008400';     $myplugin_color = get_option( 'my_adminbar_color', 'red' );     return "         body {             background-color: $myplugin_color !important;         }     "; }  function add_my_style_to_admin () {     wp_add_inline_style( 'wp-admin', my_admin_theme_style() ); }  function add_my_style_to_login () {     echo '<style type="text/css">';     echo my_admin_theme_style();     echo '</style>'; }  add_action('admin_enqueue_scripts', 'add_my_style_to_admin'); add_action('login_enqueue_scripts', 'add_my_style_to_login'); 

i had make 2 functions because admin_enqueue_scripts , login_enqueue_scripts work in different ways.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -