Skip to content

Commit 2982a9c

Browse files
author
Askupa Software
committed
Merge origin/master
2 parents fdaac71 + e06a5d6 commit 2982a9c

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ A library for generating static stylesheets from dynamic content, to be used in
2626
* [Enqueueing Dynamic Stylesheets](#enqueueing-dynamic-stylesheets)
2727
* [Loading the Compiled CSS as an External Stylesheet](#loading-the-compiled-css-as-an-external-stylesheet)
2828
* [Setting the Value Callback](#setting-the-value-callback)
29+
* [API Reference](#api-reference)
30+
* [wp_dynamic_css_enqueue](#wp_dynamic_css_enqueue)
31+
* [wp_dynamic_css_set_callback](#wp_dynamic_css_set_callback)
2932

3033
## Overview
3134

32-
**WordPress Dynamic CSS** is a lightweight library for generating CSS stylesheets from dynamic content (i.e. content that can be modified by the user). The most obvious use case for this library is for creating stylesheets based on Customizer options. Using the special dynamic CSS syntax you can write CSS rules with variables that will be replaced by static values using a custom callback function that you provide.
35+
**WordPress Dynamic CSS** is a lightweight library for generating CSS stylesheets from dynamic content (i.e. content that can be modified by the user). The most obvious use case for this library is for creating stylesheets based on Customizer options. Using the special dynamic CSS syntax you can write CSS rules with variables that will be replaced by static values using a custom callback function that you provide.
3336
**As of version 1.0.2** this library supports multiple callback functions, thus making it safe to use by multiple plugins/themes at the same time.
3437

3538
### Basic Example
@@ -53,7 +56,7 @@ wp_dynamic_css_set_callback( 'my_dynamic_style', 'my_dynamic_css_callback' );
5356
// 4. Nope, only three steps
5457
```
5558

56-
Then, create a file called `my-style.css` and write this in it:
59+
Then, create a file called `my-style.css` and write your (dynamic) CSS in it:
5760

5861
```css
5962
body {
@@ -201,6 +204,37 @@ body {
201204
}
202205
```
203206

207+
## API Reference
208+
209+
### wp_dynamic_css_enqueue
210+
211+
*Enqueue a dynamic stylesheet*
212+
213+
```php
214+
function wp_dynamic_css_enqueue( $handle, $path, $print = true )
215+
```
216+
217+
This function will either print the compiled version of the stylesheet to the document's <head> section, or load it as an external stylesheet if `$print` is set to false.
218+
219+
**Parameters**
220+
* `$handle` (*string*) The stylesheet's name/id
221+
* `$path` (*string*) The absolute path to the dynamic CSS file
222+
* `$print` (*boolean*) Whether to print the compiled CSS to the document head, or load it as an external CSS file via an http request
223+
224+
### wp_dynamic_css_set_callback
225+
226+
*Set the value retrieval callback function*
227+
228+
```php
229+
function wp_dynamic_css_set_callback( $handle, $callback )
230+
```
231+
232+
Set a callback function that will be used to convert variables to actual values. The registered function will be used when the dynamic CSS file that is associated with the name in `$handle` is compiled. The callback function accepts 1 parameter which is the name of the variable, without the $ sign.
233+
234+
**Parameters**
235+
* `$handle` (*string*) The name of the stylesheet to be associated with this callback function.
236+
* `$callback` (*callable*) A callback (or "callable" as of PHP 5.4) can either be a reference to a function name or method within a class/object.
237+
204238
## TODO
205239

206240
* ~~Add support for loading the compiled CSS externally instead of printing to the document head~~ (Added in 1.0.1)

bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Plugin Name: WordPress Dynamic CSS
1414
* Plugin URI: https://github.com/askupasoftware/wp-dynamic-css
1515
* Description: Dynamic CSS compiler for WordPress
16-
* Version: 1.0.1
16+
* Version: 1.0.2
1717
* Author: Askupa Software
1818
* Author URI: http://www.askupasoftware.com
1919
* Text Domain: wp-dynamic-css

functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* Enqueue a dynamic stylesheet
1414
*
1515
* This will either print the compiled version of the stylesheet to the
16-
* document's <head> section, or load it as an external stylesheet if the
17-
* second parameter is set to false
16+
* document's <head> section, or load it as an external stylesheet if $print
17+
* is set to false
1818
*
1919
* @param string $handle The stylesheet's name/id
2020
* @param string $path The absolute path to the dynamic CSS file
@@ -48,4 +48,4 @@ function wp_dynamic_css_set_callback( $handle, $callback )
4848
$dcss = DynamicCSSCompiler::get_instance();
4949
$dcss->register_callback( $handle, $callback );
5050
}
51-
}
51+
}

0 commit comments

Comments
 (0)