class-deodar-style.php
File: lib/models/class-deodar-style.php
Package: Deodar
Since: 2.0.0
Author: Brock Cataldi
Overview
The Deodar_Style class extends Deodar_Enqueuable to provide CSS stylesheet management functionality. It handles the enqueuing of CSS files with WordPress's wp_enqueue_style function.
Class Declaration
class Deodar_Style extends Deodar_Enqueuable
Properties
$media
private string $media = '';
The media attribute of the stylesheet (e.g., 'all', 'screen', 'print').
Methods
Constructor
__construct($data)
public function __construct(array $data)
Since: 2.0.0
Parameters:
array $data- The style configuration data
Returns: void
Throws: InvalidArgumentException - If the style configuration is invalid
Inherited Fields from Deodar_Enqueuable:
handle(string, required) - The style handleurl(string, optional) - Absolute URL to the stylesheetfile(string, optional) - Relative file path to the stylesheetdependencies(array, optional) - Style dependenciesversion(string|bool|null, optional) - Style versiontemplate(string|array|null, optional) - Template restrictionsfrontend(bool, optional) - Load on frontend (default: true)backend(bool, optional) - Load on backend (default: false)
Additional Fields:
media(string, optional) - Media attribute for the stylesheet (default: 'all')
Note: Either url or file must be provided.
Public Methods
enqueue($url_root, $end)
public function enqueue(string $url_root, bool $end): void
Since: 2.0.0
Parameters:
string $url_root- The base source URLbool $end- Which end is being loaded (true = frontend, false = backend)
Returns: void
Enqueues the stylesheet using WordPress's wp_enqueue_style function. The method:
- Checks if the style should be enqueued using
should_enqueue() - Calls
wp_enqueue_style()with the appropriate parameters - Uses the resolved URL from
get_url()
Media Attribute Values
Common media attribute values for stylesheets:
'all'- All media types (default)'screen'- Computer screens'print'- Printers and print preview'handheld'- Handheld devices'projection'- Projected presentations'tv'- Television-type devices'braille'- Braille tactile feedback devices'embossed'- Paged braille printers'speech'- Speech synthesizers
WordPress Integration
This class integrates with WordPress's style system by:
- Style Registration: Uses
wp_enqueue_style()to register and enqueue stylesheets - Dependency Management: Handles stylesheet dependencies automatically
- Version Control: Supports versioning for cache busting
- Media Control: Supports media-specific stylesheet loading
- Conditional Loading: Supports template-based and frontend/backend conditional loading
Configuration Validation
The constructor validates the media field and throws InvalidArgumentException for:
- Invalid
mediatype (must be string or removed)
Related Classes
Deodar_Enqueuable- Parent class providing base functionalityDeodar_Script- Sister class for JavaScript managementDeodar- Main class that manages style instances
Related Functions
wp_enqueue_style()- WordPress function used internally_deodar_get_template_name()- Used for template matching