Settings'; array_unshift( $links, $settings_page ); return $links; } $plugin = plugin_basename( __FILE__ ); add_filter( "plugin_action_links_$plugin", 'sccss_settings_link' ); /** * Register text domain * * @since 1.0 */ function sccss_textdomain() { load_plugin_textdomain( 'sccss' ); } add_action( 'init', 'sccss_textdomain' ); /** * Delete Options on Uninstall * * @since 1.1 */ function sccss_uninstall() { delete_option( 'sccss_settings' ); } register_uninstall_hook( __FILE__, 'sccss_uninstall' ); /** * Enqueue link to add CSS through PHP * * This is a typical WP Enqueue statement, * except that the URL of the stylesheet is simply a query var. * This query var is passed to the URL, and when it is detected by sccss_add_trigger(), * It fires sccss_trigger_check, which writes its PHP/CSS to the browser. * * Credit for this technique: @Otto http://ottopress.com/2010/dont-include-wp-load-please/ * * @since 1.1 */ function sccss_register_style() { wp_register_style( 'sccss_style', home_url( '/?sccss=1' ) ); wp_enqueue_style( 'sccss_style' ); } add_action( 'wp_enqueue_scripts', 'sccss_register_style', 99 ); /** * Enqueues Scripts/Styles for Syntax Highlighter * * @since 3.0 * @param string Hook of admin screen * @return void */ function sccss_register_codemirror( $hook ) { if ( 'appearance_page_simple-custom-css' == $hook ) { wp_enqueue_style( 'codemirror-css', plugins_url( 'simple-custom-css/codemirror/codemirror.css' ) ); wp_enqueue_script( 'codemirror-js', plugins_url( 'simple-custom-css/codemirror/codemirror.js' ), array(), '20140329', true ); wp_enqueue_script( 'codemirror-css-js', plugins_url( 'simple-custom-css/codemirror/css.js' ), array(), '20140329', true ); } } add_action( 'admin_enqueue_scripts', 'sccss_register_codemirror' ); /** * Add Query Var Stylesheet trigger * * Adds a query var to our stylesheet, so it can trigger our psuedo-stylesheet * * @since 1.1 * @param string $vars * @return array $vars */ function sccss_add_trigger( $vars ) { $vars[] = 'sccss'; return $vars; } add_filter( 'query_vars', 'sccss_add_trigger' ); /** * If trigger (query var) is tripped, load our pseudo-stylesheet * * I'd prefer to esc $content at the very last moment, but we need to allow the > character. * * @since 1.1 */ function sccss_trigger_check() { if ( intval( get_query_var( 'sccss' ) ) == 1 ) { ob_start(); header( 'Content-type: text/css' ); $options = get_option( 'sccss_settings' ); $raw_content = isset( $options['sccss-content'] ) ? $options['sccss-content'] : ''; $content = wp_kses( $raw_content, array( '\'', '\"' ) ); $content = str_replace( '>', '>', $content ); echo $content; //xss okay exit; ob_clean(); } } add_action( 'template_redirect', 'sccss_trigger_check' ); /** * Register "Custom CSS" submenu in "Appearance" Admin Menu * * @since 1.0 */ function sccss_register_submenu_page() { add_theme_page( __( 'Simple Custom CSS', 'sccss' ), __( 'Custom CSS', 'sccss' ), 'edit_theme_options', basename( __FILE__ ), 'sccss_render_submenu_page' ); } add_action( 'admin_menu', 'sccss_register_submenu_page' ); /** * Register settings * * @since 1.0 */ function sccss_register_settings() { register_setting( 'sccss_settings_group', 'sccss_settings' ); } add_action( 'admin_init', 'sccss_register_settings' ); /** * Render Admin Menu page * * @since 1.0 */ function sccss_render_submenu_page() { $options = get_option( 'sccss_settings' ); $content = isset( $options['sccss-content'] ) && ! empty( $options['sccss-content'] ) ? $options['sccss-content'] : '/* Enter Your Custom CSS Here */'; if ( isset( $_GET['settings-updated'] ) ) : ?>