Advertisement
Guest User

custom CSS theme option

a guest
Oct 28th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('DB_NAME')) {
  4.     header('Location: ../../../');
  5. }
  6.  
  7. function add_my_custom_css() {
  8.     $mycustomcss = get_option('my_custom_css');
  9.     if (!empty($mycustomcss)) {
  10.         echo "\n<!-- My Custom CSS Start -->\n<style type=\"text/css\">\n/* Plugin Author: Salvatore Noschese\nDarkWolf: http://www.darkwolf.it/ */\n\n".$mycustomcss."\n</style>\n<!-- My Custom CSS End -->\n";
  11.     }
  12. }
  13.  
  14. function mccss_admin() {
  15.     $dir_url = get_template_directory_uri();
  16.     $icon_url = $dir_url."/images/css-icon.png";
  17.     $plugin_page = add_menu_page(__('My Custom CSS Panel','mccss'),__('Custom CSS','mccss'), 'manage_options', 'my_custom_css', 'mccss_options', '', 61);
  18.     add_action( 'admin_init', 'register_settings_mccss' );  
  19.     add_action( 'admin_head', 'mccss_syntax' );
  20. }
  21.  
  22.  
  23. function mccss_syntax() { ?>
  24. <!-- Syntax Support Start -->
  25. <link type="text/css" rel="stylesheet" href="<?php echo get_stylesheet_directory_uri()?>/syntax/codemirror.css"></link>
  26. <link type="text/css" rel="stylesheet" href="<?php echo get_stylesheet_directory_uri()?>/syntax/default.css"></link>
  27. <script language="javascript" src="<?php echo get_stylesheet_directory_uri()?>/syntax/codemirror.js"></script>
  28. <script language="javascript" src="<?php echo get_stylesheet_directory_uri()?>/syntax/css.js"></script>
  29. <!-- Syntax Support End -->
  30. <?php }
  31.  
  32. // register settings
  33. function register_settings_mccss(){
  34.     register_setting('mccss_settings','my_custom_css');
  35. }
  36. function mccss_options() {
  37. ?>
  38. <div class="wrap">
  39.     <h2><?php _e('Custom CSS Options','mccss')?></h2>
  40.     <form method="post" action="options.php">
  41.     <?php settings_fields( 'mccss_settings' ); ?>
  42.     <p><?php _e('Custom CSS Code:','mccss'); ?></p>
  43.     <textarea name="my_custom_css" id="my_custom_css" dir="ltr" cols="100" rows="10" class="css"><?php echo get_option('my_custom_css');?></textarea>
  44.     <script language="javascript">var editor = CodeMirror.fromTextArea(document.getElementById("my_custom_css"), { lineNumbers: true });</script>
  45.     <p class="submit">
  46.         <input type="submit" class="button-primary" value="<?php _e('Save') ?>" />
  47.     </p>
  48.     </form>
  49. </div>
  50. <?php
  51. }
  52.  
  53. add_action('admin_menu', 'mccss_admin');
  54. add_action('wp_head', 'add_my_custom_css');
  55. load_plugin_textdomain('mccss', false, get_stylesheet_directory_uri() . '/lang/' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement