10up/CSS_Customizer

Name: CSS_Customizer

Owner: 10up

Description: Drop in class for implementing a custom CSS editor either as a standalone settings page or a meta box.

Created: 2013-02-08 16:05:54.0

Updated: 2017-06-03 03:11:26.0

Pushed: 2013-10-30 17:13:14.0

Homepage: null

Size: 249

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

CSS_Customizer

Drop in class for implementing a custom CSS editor either as a standalone settings page or a meta box.

Use in Plugins
  1. Simply clone the repository to a convenient location, like /plugin-name/includes/css-customizer
  2. Include the TenUp_CSS_Customizer.php class in your plugin
  3. Instantiate the class for use either as a standalone settings page or as a meta box
Instantiation

The TenUp_CSS_Customizer class takes several options opon instantiation:

  1. $handle - The first parameter is the unique string used to identify the instance. This string will be used in rewrites, option names, and permalinks, so it should be URL and database safe. Defaults to 'tenup_css'.
  2. $scheme - Either 'page' when using the class in a settings page or 'meta' when using the page as a meta box. Defaults to 'page.'
  3. $settings - Associative array of translated labels and post types for use with the meta box.
Settings Array
Actions/Filters
Instance Filter

The 'tenup_css_customizer_instances' filter will return an associative array of all instances. For example, if the class is instantiated with default options:

new TenUp_CSS_Customizer();

The filter will return:

array(
    'tenup_css' => object of type TenUp_CSS_Customizer
)

If multiple instances exist, they will all be returned by the filter.

Rewrite Registration

The class uses a set of custom permalinks to fetch and return the custom CSS document. However, these permalinks will not work unless rewrite rules are flushed after they're added.

To make life easier, you can add a do_action() call to your plugin activation hook to force the rewrite rules into the system.

new TenUp_CSS_Customizer();

function my_plugin_activation() {
    do_action( 'tenup_css_register_rewrites' );
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_plugin_activation' );

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.