Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-inclu...
File: class-wp-block-styles-registry.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Blocks API: WP_Block_Styles_Registry class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Blocks
[5] Fix | Delete
* @since 5.3.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Class used for interacting with block styles.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 5.3.0
[12] Fix | Delete
*/
[13] Fix | Delete
#[AllowDynamicProperties]
[14] Fix | Delete
final class WP_Block_Styles_Registry {
[15] Fix | Delete
/**
[16] Fix | Delete
* Registered block styles, as `$block_name => $block_style_name => $block_style_properties` multidimensional arrays.
[17] Fix | Delete
*
[18] Fix | Delete
* @since 5.3.0
[19] Fix | Delete
*
[20] Fix | Delete
* @var array[]
[21] Fix | Delete
*/
[22] Fix | Delete
private $registered_block_styles = array();
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Container for the main instance of the class.
[26] Fix | Delete
*
[27] Fix | Delete
* @since 5.3.0
[28] Fix | Delete
*
[29] Fix | Delete
* @var WP_Block_Styles_Registry|null
[30] Fix | Delete
*/
[31] Fix | Delete
private static $instance = null;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Registers a block style for the given block type.
[35] Fix | Delete
*
[36] Fix | Delete
* If the block styles are present in a standalone stylesheet, register it and pass
[37] Fix | Delete
* its handle as the `style_handle` argument. If the block styles should be inline,
[38] Fix | Delete
* use the `inline_style` argument. Usually, one of them would be used to pass CSS
[39] Fix | Delete
* styles. However, you could also skip them and provide CSS styles in any stylesheet
[40] Fix | Delete
* or with an inline tag.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 5.3.0
[43] Fix | Delete
* @since 6.6.0 Added ability to register style across multiple block types along with theme.json-like style data.
[44] Fix | Delete
*
[45] Fix | Delete
* @link https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/
[46] Fix | Delete
*
[47] Fix | Delete
* @param string|string[] $block_name Block type name including namespace or array of namespaced block type names.
[48] Fix | Delete
* @param array $style_properties {
[49] Fix | Delete
* Array containing the properties of the style.
[50] Fix | Delete
*
[51] Fix | Delete
* @type string $name The identifier of the style used to compute a CSS class.
[52] Fix | Delete
* @type string $label A human-readable label for the style.
[53] Fix | Delete
* @type string $inline_style Inline CSS code that registers the CSS class required
[54] Fix | Delete
* for the style.
[55] Fix | Delete
* @type string $style_handle The handle to an already registered style that should be
[56] Fix | Delete
* enqueued in places where block styles are needed.
[57] Fix | Delete
* @type bool $is_default Whether this is the default style for the block type.
[58] Fix | Delete
* @type array $style_data Theme.json-like object to generate CSS from.
[59] Fix | Delete
* }
[60] Fix | Delete
* @return bool True if the block style was registered with success and false otherwise.
[61] Fix | Delete
*/
[62] Fix | Delete
public function register( $block_name, $style_properties ) {
[63] Fix | Delete
[64] Fix | Delete
if ( ! is_string( $block_name ) && ! is_array( $block_name ) ) {
[65] Fix | Delete
_doing_it_wrong(
[66] Fix | Delete
__METHOD__,
[67] Fix | Delete
__( 'Block name must be a string or array.' ),
[68] Fix | Delete
'6.6.0'
[69] Fix | Delete
);
[70] Fix | Delete
return false;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( ! isset( $style_properties['name'] ) || ! is_string( $style_properties['name'] ) ) {
[74] Fix | Delete
_doing_it_wrong(
[75] Fix | Delete
__METHOD__,
[76] Fix | Delete
__( 'Block style name must be a string.' ),
[77] Fix | Delete
'5.3.0'
[78] Fix | Delete
);
[79] Fix | Delete
return false;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
if ( str_contains( $style_properties['name'], ' ' ) ) {
[83] Fix | Delete
_doing_it_wrong(
[84] Fix | Delete
__METHOD__,
[85] Fix | Delete
__( 'Block style name must not contain any spaces.' ),
[86] Fix | Delete
'5.9.0'
[87] Fix | Delete
);
[88] Fix | Delete
return false;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
$block_style_name = $style_properties['name'];
[92] Fix | Delete
$block_names = is_string( $block_name ) ? array( $block_name ) : $block_name;
[93] Fix | Delete
[94] Fix | Delete
foreach ( $block_names as $name ) {
[95] Fix | Delete
if ( ! isset( $this->registered_block_styles[ $name ] ) ) {
[96] Fix | Delete
$this->registered_block_styles[ $name ] = array();
[97] Fix | Delete
}
[98] Fix | Delete
$this->registered_block_styles[ $name ][ $block_style_name ] = $style_properties;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
return true;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Unregisters a block style of the given block type.
[106] Fix | Delete
*
[107] Fix | Delete
* @since 5.3.0
[108] Fix | Delete
*
[109] Fix | Delete
* @param string $block_name Block type name including namespace.
[110] Fix | Delete
* @param string $block_style_name Block style name.
[111] Fix | Delete
* @return bool True if the block style was unregistered with success and false otherwise.
[112] Fix | Delete
*/
[113] Fix | Delete
public function unregister( $block_name, $block_style_name ) {
[114] Fix | Delete
if ( ! $this->is_registered( $block_name, $block_style_name ) ) {
[115] Fix | Delete
_doing_it_wrong(
[116] Fix | Delete
__METHOD__,
[117] Fix | Delete
/* translators: 1: Block name, 2: Block style name. */
[118] Fix | Delete
sprintf( __( 'Block "%1$s" does not contain a style named "%2$s".' ), $block_name, $block_style_name ),
[119] Fix | Delete
'5.3.0'
[120] Fix | Delete
);
[121] Fix | Delete
return false;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
unset( $this->registered_block_styles[ $block_name ][ $block_style_name ] );
[125] Fix | Delete
[126] Fix | Delete
return true;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Retrieves the properties of a registered block style for the given block type.
[131] Fix | Delete
*
[132] Fix | Delete
* @since 5.3.0
[133] Fix | Delete
*
[134] Fix | Delete
* @param string $block_name Block type name including namespace.
[135] Fix | Delete
* @param string $block_style_name Block style name.
[136] Fix | Delete
* @return array Registered block style properties.
[137] Fix | Delete
*/
[138] Fix | Delete
public function get_registered( $block_name, $block_style_name ) {
[139] Fix | Delete
if ( ! $this->is_registered( $block_name, $block_style_name ) ) {
[140] Fix | Delete
return null;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
return $this->registered_block_styles[ $block_name ][ $block_style_name ];
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Retrieves all registered block styles.
[148] Fix | Delete
*
[149] Fix | Delete
* @since 5.3.0
[150] Fix | Delete
*
[151] Fix | Delete
* @return array[] Array of arrays containing the registered block styles properties grouped by block type.
[152] Fix | Delete
*/
[153] Fix | Delete
public function get_all_registered() {
[154] Fix | Delete
return $this->registered_block_styles;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Retrieves registered block styles for a specific block type.
[159] Fix | Delete
*
[160] Fix | Delete
* @since 5.3.0
[161] Fix | Delete
*
[162] Fix | Delete
* @param string $block_name Block type name including namespace.
[163] Fix | Delete
* @return array[] Array whose keys are block style names and whose values are block style properties.
[164] Fix | Delete
*/
[165] Fix | Delete
public function get_registered_styles_for_block( $block_name ) {
[166] Fix | Delete
if ( isset( $this->registered_block_styles[ $block_name ] ) ) {
[167] Fix | Delete
return $this->registered_block_styles[ $block_name ];
[168] Fix | Delete
}
[169] Fix | Delete
return array();
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Checks if a block style is registered for the given block type.
[174] Fix | Delete
*
[175] Fix | Delete
* @since 5.3.0
[176] Fix | Delete
*
[177] Fix | Delete
* @param string $block_name Block type name including namespace.
[178] Fix | Delete
* @param string $block_style_name Block style name.
[179] Fix | Delete
* @return bool True if the block style is registered, false otherwise.
[180] Fix | Delete
*/
[181] Fix | Delete
public function is_registered( $block_name, $block_style_name ) {
[182] Fix | Delete
return isset( $this->registered_block_styles[ $block_name ][ $block_style_name ] );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Utility method to retrieve the main instance of the class.
[187] Fix | Delete
*
[188] Fix | Delete
* The instance will be created if it does not exist yet.
[189] Fix | Delete
*
[190] Fix | Delete
* @since 5.3.0
[191] Fix | Delete
*
[192] Fix | Delete
* @return WP_Block_Styles_Registry The main instance.
[193] Fix | Delete
*/
[194] Fix | Delete
public static function get_instance() {
[195] Fix | Delete
if ( null === self::$instance ) {
[196] Fix | Delete
self::$instance = new self();
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
return self::$instance;
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function