Download the PHP package askupa-software/wp-dynamic-css without Composer

On this page you can find all versions of the php package askupa-software/wp-dynamic-css. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-dynamic-css

WordPress Dynamic CSS License License License

A library for generating static stylesheets from dynamic content, to be used in WordPress themes and plugins.

Contributors: ykadosh
Tags: theme, mods, wordpress, dynamic, css, stylesheet
Tested up to: 4.7
Stable tag: 1.0.5
Requires: PHP 5.3.0 or newer
WordPress plugin: wordpress.org/plugins/wp-dynamic-css/
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

--

WordPress Dynamic CSS allows you to convert this:

into this:

Using dynamic user data.

Contents

Overview

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.
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.

Basic Example

First, add this to your functions.php file:

Then, create a file called my-style.css and write your (dynamic) CSS in it:

In the above example, the stylesheet will be automatically compiled and printed to the <head> of the document. The value of $body_bg_color will be replaced by the value of get_theme_mod('body_bg_color').

Now, let's say that get_theme_mod('body_bg_color') returns the value #fff, then my-style.css will be compiled to:

Simple, right?

Installation

Via Composer

If you are using the command line:

Or simply add the following to your composer.json file:

And run the command composer install

This will install the package in the directory wp-content/plugins. For custom install path, add this to your composer.json file:

Via WordPress.org

Install and activate the plugin hosted on WordPress.org: wordpress.org/plugins/wp-dynamic-css/

When the plugin is activated, all the library files are automatically included so you don't need to manually include them.

Manually

Download the package from github and include bootstrap.php in your project:

Dynamic CSS Syntax

This library allows you to use special CSS syntax that is similar to regular CSS syntax with added support for variables with the syntax $my_variable_name. Since these variables are replaced by values during run time (when the page loads), files that are using this syntax are therefore called dynamic CSS files. Any variable in the dynamic CSS file is replaced by a value that is retrieved by a custom 'value callback' function.

A dynamic CSS file will look exactly like a regular CSS file, only with variables. For example:

During run time, this file will be compiled into regular CSS by replacing all the variables to their corresponding values by calling the 'value callback' function and passing the variable name (without the $ sign) to that function.

Array variables (since 1.0.3)

Version 1.0.3 added support for array subscripts, using a syntax similar to that of PHP. For example:

The callback function should accept a second variable that will hold an array of subscript names. A more in-depth explanation can be found in the Setting the Value Callback section.

Future releases may support a more compex syntax, so any suggestions are welcome. You can make a suggestion by creating an issue or submitting a pull request.

Piped filters (since 1.0.5)

Version 1.0.5 added support for piped filters. Filters can be registered using the function wp_dynamic_css_register_filter( $handle, $filter_name, $callback ) where $filter_name corresponds to the name fo the filter to be used in the stylesheet. For example, if a filter named myFilter was registered, it can be applied using the following syntax:

Filters can also be stacked together:

And can even take additional parameters:

See Registering Filters to learn how to register filter callback functions.

Enqueueing Dynamic Stylesheets

To enqueue a dynamic CSS file, call the function wp_dynamic_css_enqueue and pass it a handle and the absolute path to your CSS file:

This will print the contents of dynamic-style.css into the document <head> section after replacing all the variables to their values using the given callback function set by wp_dynamic_css_set_callback().

The first argument - the stylesheet handle - is used as an id for associating a callback function to it.

If multiple calls to wp_dynamic_css_enqueue() are made with different CSS files, then their contents will be appended to the same <style> section in the document <head>.

Loading the Compiled CSS as an External Stylesheet

Instead of printing the compiled CSS to the head of the document, you can alternatively load it as an external stylesheet by setting the second parameter to false:

This will reduce the loading time of your document since the call to the compiler will be made asynchronously as an http request. Additionally, styelsheets that are loaded externally can be cached by the browser, as opposed to stylesheets that are printed to the head.

The disadvantage of this approach is that the Customizer's live preview will not show the changes take effect without manually reloading the page.

Setting the Value Callback

The example given in the overview section uses the get_theme_mod() function to retrieve the value of the variables:

However, the get_theme_mod() function also takes a second argument, which is the default value to be used when the modification name does not exists (e.g. no changes were made in Customizer since the theme was activated).

In that case, we can tweak our callback function to return default values as well:

Your CSS file can look something like this:

Which will be compiled to this (provided that no changes were made by the user in Customizer):

Array variables

It is also possible to access array values using subscripts. An example dynamic CSS file may look like:

However, in this case the callback function is passed 2 parameters: one holding the variable name, and a second holding an array of subscript names. The second variable is always going to be an array since there may be more than one subscript (multidimensional arrays). To retrieve to array value, the subscripts array is to be looped through to get each subscript. For example:

which compiles to:

Registering Filters

Filters are functions the alter the value of the variables. Filters can be registered using the function wp_dynamic_css_register_filter( $handle, $filter_name, $callback ). A registered filter can only be used within the stylesheet whose handle is given. A filter callback function takes the value of the variable as a parameter and should return the filtered value. For example:

The filter can then be applied using the | operator. For example:

Filters can also take additional arguments. For example:

To pass addidional arguments, use braces () and separate each argument with a comma (no spaces are allowd). For example:

Accepted argument types are strings, integers, floats and boolean values. Strings must have single quotes around them. For exmaple:

API Reference

wp_dynamic_css_enqueue

Enqueue a dynamic stylesheet

This function will either print the compiled version of the stylesheet to the document's section, or load it as an external stylesheet if $print is set to false. If $cache is set to true, a compiled version of the stylesheet will be stored in the database as soon as it is first compiled. The compiled version will be served thereafter until wp_dynamic_css_clear_cache() is called.

Parameters

wp_dynamic_css_set_callback

Set the value retrieval callback function

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 is passed the name of the variable as its first parameter (without the $), and the variable subscripts as its second parameter (if applicable). The callback function should return the variable's actual value.

Parameters

wp_dynamic_css_clear_cache

Clear the cached compiled CSS for the given handle.

Registered dynamic stylesheets that have the $cache flag set to true are compiled only once and then stored in cache. Subsequesnt requests are served statically from cache until wp_dynamic_css_clear_cache() is called and clears it, forcing the compiler to recompile the CSS.

Parameters

wp_dynamic_css_register_filter

Register a filter function for a given stylesheet handle.

A registered filter can be used to alter the value of a variable by using the | operator in the stylesheet. The callback function is passed the variable's value as its first argument, and any additional arguments thereafter.

Parameters


All versions of wp-dynamic-css with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package askupa-software/wp-dynamic-css contains the following files

Loading the files please wait ....