class-deodar-block-style.php
File: lib/models/class-deodar-block-style.php
Package: Deodar
Since: 2.0.0
Author: Brock Cataldi
Overview
The Deodar_Block_Style class manages WordPress block style registration and enqueuing. It provides a clean interface for registering block styles with WordPress using the wp_enqueue_block_style function.
Class Declaration
class Deodar_Block_Style
Properties
$name
public string $name = '';
The name of the block.
$block_namespace
public string $block_namespace = '';
The namespace of the block.
Methods
Constructor
__construct($name, $block_namespace)
public function __construct(string $name, string $block_namespace)
Since: 2.0.0
Parameters:
string $name- The name of the blockstring $block_namespace- The namespace of the block
Returns: void
Initializes the block style with the provided name and namespace.
Public Methods
get_block_type_name()
public function get_block_type_name(): string
Since: 2.0.0
Returns: string - The full block type name in format {namespace}/{name}
Gets the complete block type name by combining the namespace and block name.
get_variations_path($blocks_dir_path)
public function get_variations_path(string $blocks_dir_path): string
Since: 2.0.0
Parameters:
string $blocks_dir_path- The file path of the blocks directory
Returns: string - The path to the variations file
Gets the path to the block variations file. Expected file structure:
blocks/
└── {namespace}/
└── {name}/
└── {name}.variations.php
enqueue($blocks_dir_path, $blocks_dir_url)
public function enqueue(string $blocks_dir_path, string $blocks_dir_url)
Since: 2.0.0
Parameters:
string $blocks_dir_path- The file path of the block stylestring $blocks_dir_url- The URL path of the block style
Returns: void
Enqueues the block style using WordPress's wp_enqueue_block_style function. The method constructs the appropriate file paths and URLs for the block style CSS file.
File Structure Expected:
blocks/
└── {namespace}/
└── {name}/
└── build/
└── {name}.build.css
WordPress Integration
This class integrates with WordPress's block system by:
- Block Identification: Uses the namespace and block name to create the full block identifier (
{namespace}/{block-name}) - Style Registration: Registers the block style with WordPress using
wp_enqueue_block_style - File Path Resolution: Automatically constructs the correct file paths and URLs for the CSS file
- Handle Generation: Creates a unique handle for the style (
deodar-{namespace}-{block-name}) - Variations Support: Provides path resolution for block variations files
Related Classes
Deodar- Main class that automatically manages block stylesDeodar_Style- General stylesheet managementDeodar_Enqueuable- Base class for asset management
Related Functions
wp_enqueue_block_style()- WordPress function used internally_deodar_scan_for_directories()- Used by Deodar to discover blocks_deodar_safe_include()- Used to safely include variation files