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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: class-wp-duotone.php
if ( isset( self::$global_styles_presets ) ) {
[1000] Fix | Delete
return self::$global_styles_presets;
[1001] Fix | Delete
}
[1002] Fix | Delete
// Get the per block settings from the theme.json.
[1003] Fix | Delete
$tree = wp_get_global_settings();
[1004] Fix | Delete
$presets_by_origin = isset( $tree['color']['duotone'] ) ? $tree['color']['duotone'] : array();
[1005] Fix | Delete
[1006] Fix | Delete
self::$global_styles_presets = array();
[1007] Fix | Delete
foreach ( $presets_by_origin as $presets ) {
[1008] Fix | Delete
foreach ( $presets as $preset ) {
[1009] Fix | Delete
$filter_id = self::get_filter_id( _wp_to_kebab_case( $preset['slug'] ) );
[1010] Fix | Delete
[1011] Fix | Delete
self::$global_styles_presets[ $filter_id ] = $preset;
[1012] Fix | Delete
}
[1013] Fix | Delete
}
[1014] Fix | Delete
[1015] Fix | Delete
return self::$global_styles_presets;
[1016] Fix | Delete
}
[1017] Fix | Delete
[1018] Fix | Delete
/**
[1019] Fix | Delete
* Scrape all block names from global styles and store in self::$global_styles_block_names.
[1020] Fix | Delete
*
[1021] Fix | Delete
* Used in conjunction with self::render_duotone_support to output the
[1022] Fix | Delete
* duotone filters defined in the theme.json global styles.
[1023] Fix | Delete
*
[1024] Fix | Delete
* @since 6.3.0
[1025] Fix | Delete
*
[1026] Fix | Delete
* @return string[] An array of global style block slugs, keyed on the block name.
[1027] Fix | Delete
*/
[1028] Fix | Delete
private static function get_all_global_style_block_names() {
[1029] Fix | Delete
if ( isset( self::$global_styles_block_names ) ) {
[1030] Fix | Delete
return self::$global_styles_block_names;
[1031] Fix | Delete
}
[1032] Fix | Delete
// Get the per block settings from the theme.json.
[1033] Fix | Delete
$tree = WP_Theme_JSON_Resolver::get_merged_data();
[1034] Fix | Delete
$block_nodes = $tree->get_styles_block_nodes();
[1035] Fix | Delete
$theme_json = $tree->get_raw_data();
[1036] Fix | Delete
[1037] Fix | Delete
self::$global_styles_block_names = array();
[1038] Fix | Delete
[1039] Fix | Delete
foreach ( $block_nodes as $block_node ) {
[1040] Fix | Delete
// This block definition doesn't include any duotone settings. Skip it.
[1041] Fix | Delete
if ( empty( $block_node['duotone'] ) ) {
[1042] Fix | Delete
continue;
[1043] Fix | Delete
}
[1044] Fix | Delete
[1045] Fix | Delete
// Value looks like this: 'var(--wp--preset--duotone--blue-orange)' or 'var:preset|duotone|blue-orange'.
[1046] Fix | Delete
$duotone_attr_path = array_merge( $block_node['path'], array( 'filter', 'duotone' ) );
[1047] Fix | Delete
$duotone_attr = _wp_array_get( $theme_json, $duotone_attr_path, array() );
[1048] Fix | Delete
[1049] Fix | Delete
if ( empty( $duotone_attr ) ) {
[1050] Fix | Delete
continue;
[1051] Fix | Delete
}
[1052] Fix | Delete
// If it has a duotone filter preset, save the block name and the preset slug.
[1053] Fix | Delete
$slug = self::get_slug_from_attribute( $duotone_attr );
[1054] Fix | Delete
[1055] Fix | Delete
if ( $slug && $slug !== $duotone_attr ) {
[1056] Fix | Delete
self::$global_styles_block_names[ $block_node['name'] ] = $slug;
[1057] Fix | Delete
}
[1058] Fix | Delete
}
[1059] Fix | Delete
return self::$global_styles_block_names;
[1060] Fix | Delete
}
[1061] Fix | Delete
[1062] Fix | Delete
/**
[1063] Fix | Delete
* Render out the duotone CSS styles and SVG.
[1064] Fix | Delete
*
[1065] Fix | Delete
* The hooks self::set_global_style_block_names and self::set_global_styles_presets
[1066] Fix | Delete
* must be called before this function.
[1067] Fix | Delete
*
[1068] Fix | Delete
* @since 6.3.0
[1069] Fix | Delete
*
[1070] Fix | Delete
* @param string $block_content Rendered block content.
[1071] Fix | Delete
* @param array $block Block object.
[1072] Fix | Delete
* @param WP_Block $wp_block The block instance.
[1073] Fix | Delete
* @return string Filtered block content.
[1074] Fix | Delete
*/
[1075] Fix | Delete
public static function render_duotone_support( $block_content, $block, $wp_block ) {
[1076] Fix | Delete
if ( ! $block['blockName'] ) {
[1077] Fix | Delete
return $block_content;
[1078] Fix | Delete
}
[1079] Fix | Delete
$duotone_selector = self::get_selector( $wp_block->block_type );
[1080] Fix | Delete
[1081] Fix | Delete
if ( ! $duotone_selector ) {
[1082] Fix | Delete
return $block_content;
[1083] Fix | Delete
}
[1084] Fix | Delete
[1085] Fix | Delete
$global_styles_block_names = self::get_all_global_style_block_names();
[1086] Fix | Delete
[1087] Fix | Delete
// The block should have a duotone attribute or have duotone defined in its theme.json to be processed.
[1088] Fix | Delete
$has_duotone_attribute = isset( $block['attrs']['style']['color']['duotone'] );
[1089] Fix | Delete
$has_global_styles_duotone = array_key_exists( $block['blockName'], $global_styles_block_names );
[1090] Fix | Delete
[1091] Fix | Delete
if ( ! $has_duotone_attribute && ! $has_global_styles_duotone ) {
[1092] Fix | Delete
return $block_content;
[1093] Fix | Delete
}
[1094] Fix | Delete
[1095] Fix | Delete
// Generate the pieces needed for rendering a duotone to the page.
[1096] Fix | Delete
if ( $has_duotone_attribute ) {
[1097] Fix | Delete
[1098] Fix | Delete
/*
[1099] Fix | Delete
* Possible values for duotone attribute:
[1100] Fix | Delete
* 1. Array of colors - e.g. array('#000000', '#ffffff').
[1101] Fix | Delete
* 2. Variable for an existing Duotone preset - e.g. 'var:preset|duotone|blue-orange' or 'var(--wp--preset--duotone--blue-orange)''
[1102] Fix | Delete
* 3. A CSS string - e.g. 'unset' to remove globally applied duotone.
[1103] Fix | Delete
*/
[1104] Fix | Delete
[1105] Fix | Delete
$duotone_attr = $block['attrs']['style']['color']['duotone'];
[1106] Fix | Delete
$is_preset = is_string( $duotone_attr ) && self::is_preset( $duotone_attr );
[1107] Fix | Delete
$is_css = is_string( $duotone_attr ) && ! $is_preset;
[1108] Fix | Delete
$is_custom = is_array( $duotone_attr );
[1109] Fix | Delete
[1110] Fix | Delete
if ( $is_preset ) {
[1111] Fix | Delete
[1112] Fix | Delete
$slug = self::get_slug_from_attribute( $duotone_attr ); // e.g. 'blue-orange'.
[1113] Fix | Delete
$filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'.
[1114] Fix | Delete
$filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'.
[1115] Fix | Delete
[1116] Fix | Delete
// CSS custom property, SVG filter, and block CSS.
[1117] Fix | Delete
self::enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value );
[1118] Fix | Delete
[1119] Fix | Delete
} elseif ( $is_css ) {
[1120] Fix | Delete
$slug = wp_unique_id( sanitize_key( $duotone_attr . '-' ) ); // e.g. 'unset-1'.
[1121] Fix | Delete
$filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-unset-1'.
[1122] Fix | Delete
$filter_value = $duotone_attr; // e.g. 'unset'.
[1123] Fix | Delete
[1124] Fix | Delete
// Just block CSS.
[1125] Fix | Delete
self::enqueue_block_css( $filter_id, $duotone_selector, $filter_value );
[1126] Fix | Delete
} elseif ( $is_custom ) {
[1127] Fix | Delete
$slug = wp_unique_id( sanitize_key( implode( '-', $duotone_attr ) . '-' ) ); // e.g. '000000-ffffff-2'.
[1128] Fix | Delete
$filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-000000-ffffff-2'.
[1129] Fix | Delete
$filter_value = self::get_filter_url( $filter_id ); // e.g. 'url(#wp-duotone-filter-000000-ffffff-2)'.
[1130] Fix | Delete
$filter_data = array(
[1131] Fix | Delete
'slug' => $slug,
[1132] Fix | Delete
'colors' => $duotone_attr,
[1133] Fix | Delete
);
[1134] Fix | Delete
[1135] Fix | Delete
// SVG filter and block CSS.
[1136] Fix | Delete
self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $filter_data );
[1137] Fix | Delete
}
[1138] Fix | Delete
} elseif ( $has_global_styles_duotone ) {
[1139] Fix | Delete
$slug = $global_styles_block_names[ $block['blockName'] ]; // e.g. 'blue-orange'.
[1140] Fix | Delete
$filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'.
[1141] Fix | Delete
$filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'.
[1142] Fix | Delete
[1143] Fix | Delete
// CSS custom property, SVG filter, and block CSS.
[1144] Fix | Delete
self::enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value );
[1145] Fix | Delete
}
[1146] Fix | Delete
[1147] Fix | Delete
// Like the layout hook, this assumes the hook only applies to blocks with a single wrapper.
[1148] Fix | Delete
$tags = new WP_HTML_Tag_Processor( $block_content );
[1149] Fix | Delete
if ( $tags->next_tag() ) {
[1150] Fix | Delete
$tags->add_class( $filter_id );
[1151] Fix | Delete
}
[1152] Fix | Delete
return $tags->get_updated_html();
[1153] Fix | Delete
}
[1154] Fix | Delete
[1155] Fix | Delete
/**
[1156] Fix | Delete
* Fixes the issue with our generated class name not being added to the block's outer container
[1157] Fix | Delete
* in classic themes due to gutenberg_restore_image_outer_container from layout block supports.
[1158] Fix | Delete
*
[1159] Fix | Delete
* @since 6.6.0
[1160] Fix | Delete
*
[1161] Fix | Delete
* @param string $block_content Rendered block content.
[1162] Fix | Delete
* @return string Filtered block content.
[1163] Fix | Delete
*/
[1164] Fix | Delete
public static function restore_image_outer_container( $block_content ) {
[1165] Fix | Delete
if ( wp_theme_has_theme_json() ) {
[1166] Fix | Delete
return $block_content;
[1167] Fix | Delete
}
[1168] Fix | Delete
[1169] Fix | Delete
$tags = new WP_HTML_Tag_Processor( $block_content );
[1170] Fix | Delete
$wrapper_query = array(
[1171] Fix | Delete
'tag_name' => 'div',
[1172] Fix | Delete
'class_name' => 'wp-block-image',
[1173] Fix | Delete
);
[1174] Fix | Delete
if ( ! $tags->next_tag( $wrapper_query ) ) {
[1175] Fix | Delete
return $block_content;
[1176] Fix | Delete
}
[1177] Fix | Delete
[1178] Fix | Delete
$tags->set_bookmark( 'wrapper-div' );
[1179] Fix | Delete
$tags->next_tag();
[1180] Fix | Delete
[1181] Fix | Delete
$inner_classnames = explode( ' ', $tags->get_attribute( 'class' ) );
[1182] Fix | Delete
foreach ( $inner_classnames as $classname ) {
[1183] Fix | Delete
if ( 0 === strpos( $classname, 'wp-duotone' ) ) {
[1184] Fix | Delete
$tags->remove_class( $classname );
[1185] Fix | Delete
$tags->seek( 'wrapper-div' );
[1186] Fix | Delete
$tags->add_class( $classname );
[1187] Fix | Delete
break;
[1188] Fix | Delete
}
[1189] Fix | Delete
}
[1190] Fix | Delete
[1191] Fix | Delete
return $tags->get_updated_html();
[1192] Fix | Delete
}
[1193] Fix | Delete
[1194] Fix | Delete
/**
[1195] Fix | Delete
* Appends the used block duotone filter declarations to the inline block supports CSS.
[1196] Fix | Delete
*
[1197] Fix | Delete
* Uses the declarations saved in earlier calls to self::enqueue_block_css.
[1198] Fix | Delete
*
[1199] Fix | Delete
* @since 6.3.0
[1200] Fix | Delete
*/
[1201] Fix | Delete
public static function output_block_styles() {
[1202] Fix | Delete
if ( ! empty( self::$block_css_declarations ) ) {
[1203] Fix | Delete
wp_style_engine_get_stylesheet_from_css_rules(
[1204] Fix | Delete
self::$block_css_declarations,
[1205] Fix | Delete
array(
[1206] Fix | Delete
'context' => 'block-supports',
[1207] Fix | Delete
)
[1208] Fix | Delete
);
[1209] Fix | Delete
}
[1210] Fix | Delete
}
[1211] Fix | Delete
[1212] Fix | Delete
/**
[1213] Fix | Delete
* Appends the used global style duotone filter presets (CSS custom
[1214] Fix | Delete
* properties) to the inline global styles CSS.
[1215] Fix | Delete
*
[1216] Fix | Delete
* Uses the declarations saved in earlier calls to self::enqueue_global_styles_preset.
[1217] Fix | Delete
*
[1218] Fix | Delete
* @since 6.3.0
[1219] Fix | Delete
*/
[1220] Fix | Delete
public static function output_global_styles() {
[1221] Fix | Delete
if ( ! empty( self::$used_global_styles_presets ) ) {
[1222] Fix | Delete
wp_add_inline_style( 'global-styles', self::get_global_styles_presets( self::$used_global_styles_presets ) );
[1223] Fix | Delete
}
[1224] Fix | Delete
}
[1225] Fix | Delete
[1226] Fix | Delete
/**
[1227] Fix | Delete
* Outputs all necessary SVG for duotone filters, CSS for classic themes.
[1228] Fix | Delete
*
[1229] Fix | Delete
* Uses the declarations saved in earlier calls to self::enqueue_global_styles_preset
[1230] Fix | Delete
* and self::enqueue_custom_filter.
[1231] Fix | Delete
*
[1232] Fix | Delete
* @since 6.3.0
[1233] Fix | Delete
*/
[1234] Fix | Delete
public static function output_footer_assets() {
[1235] Fix | Delete
if ( ! empty( self::$used_svg_filter_data ) ) {
[1236] Fix | Delete
echo self::get_svg_definitions( self::$used_svg_filter_data );
[1237] Fix | Delete
}
[1238] Fix | Delete
[1239] Fix | Delete
// In block themes, the CSS is added in the head via wp_add_inline_style in the wp_enqueue_scripts action.
[1240] Fix | Delete
if ( ! wp_is_block_theme() ) {
[1241] Fix | Delete
$style_tag_id = 'core-block-supports-duotone';
[1242] Fix | Delete
wp_register_style( $style_tag_id, false );
[1243] Fix | Delete
if ( ! empty( self::$used_global_styles_presets ) ) {
[1244] Fix | Delete
wp_add_inline_style( $style_tag_id, self::get_global_styles_presets( self::$used_global_styles_presets ) );
[1245] Fix | Delete
}
[1246] Fix | Delete
if ( ! empty( self::$block_css_declarations ) ) {
[1247] Fix | Delete
wp_add_inline_style( $style_tag_id, wp_style_engine_get_stylesheet_from_css_rules( self::$block_css_declarations ) );
[1248] Fix | Delete
}
[1249] Fix | Delete
wp_enqueue_style( $style_tag_id );
[1250] Fix | Delete
}
[1251] Fix | Delete
}
[1252] Fix | Delete
[1253] Fix | Delete
/**
[1254] Fix | Delete
* Adds the duotone SVGs and CSS custom properties to the editor settings.
[1255] Fix | Delete
*
[1256] Fix | Delete
* This allows the properties to be pulled in by the EditorStyles component
[1257] Fix | Delete
* in JS and rendered in the post editor.
[1258] Fix | Delete
*
[1259] Fix | Delete
* @since 6.3.0
[1260] Fix | Delete
*
[1261] Fix | Delete
* @param array $settings The block editor settings from the `block_editor_settings_all` filter.
[1262] Fix | Delete
* @return array The editor settings with duotone SVGs and CSS custom properties.
[1263] Fix | Delete
*/
[1264] Fix | Delete
public static function add_editor_settings( $settings ) {
[1265] Fix | Delete
$global_styles_presets = self::get_all_global_styles_presets();
[1266] Fix | Delete
if ( ! empty( $global_styles_presets ) ) {
[1267] Fix | Delete
if ( ! isset( $settings['styles'] ) ) {
[1268] Fix | Delete
$settings['styles'] = array();
[1269] Fix | Delete
}
[1270] Fix | Delete
[1271] Fix | Delete
$settings['styles'][] = array(
[1272] Fix | Delete
// For the editor we can add all of the presets by default.
[1273] Fix | Delete
'assets' => self::get_svg_definitions( $global_styles_presets ),
[1274] Fix | Delete
// The 'svgs' type is new in 6.3 and requires the corresponding JS changes in the EditorStyles component to work.
[1275] Fix | Delete
'__unstableType' => 'svgs',
[1276] Fix | Delete
// These styles not generated by global styles, so this must be false or they will be stripped out in wp_get_block_editor_settings.
[1277] Fix | Delete
'isGlobalStyles' => false,
[1278] Fix | Delete
);
[1279] Fix | Delete
[1280] Fix | Delete
$settings['styles'][] = array(
[1281] Fix | Delete
// For the editor we can add all of the presets by default.
[1282] Fix | Delete
'css' => self::get_global_styles_presets( $global_styles_presets ),
[1283] Fix | Delete
// This must be set and must be something other than 'theme' or they will be stripped out in the post editor <Editor> component.
[1284] Fix | Delete
'__unstableType' => 'presets',
[1285] Fix | Delete
// These styles are no longer generated by global styles, so this must be false or they will be stripped out in wp_get_block_editor_settings.
[1286] Fix | Delete
'isGlobalStyles' => false,
[1287] Fix | Delete
);
[1288] Fix | Delete
}
[1289] Fix | Delete
[1290] Fix | Delete
return $settings;
[1291] Fix | Delete
}
[1292] Fix | Delete
[1293] Fix | Delete
/**
[1294] Fix | Delete
* Migrates the experimental duotone support flag to the stabilized location.
[1295] Fix | Delete
*
[1296] Fix | Delete
* This moves `supports.color.__experimentalDuotone` to `supports.filter.duotone`.
[1297] Fix | Delete
*
[1298] Fix | Delete
* @since 6.3.0
[1299] Fix | Delete
*
[1300] Fix | Delete
* @param array $settings Current block type settings.
[1301] Fix | Delete
* @param array $metadata Block metadata as read in via block.json.
[1302] Fix | Delete
* @return array Filtered block type settings.
[1303] Fix | Delete
*/
[1304] Fix | Delete
public static function migrate_experimental_duotone_support_flag( $settings, $metadata ) {
[1305] Fix | Delete
$duotone_support = isset( $metadata['supports']['color']['__experimentalDuotone'] )
[1306] Fix | Delete
? $metadata['supports']['color']['__experimentalDuotone']
[1307] Fix | Delete
: null;
[1308] Fix | Delete
[1309] Fix | Delete
if ( ! isset( $settings['supports']['filter']['duotone'] ) && null !== $duotone_support ) {
[1310] Fix | Delete
_wp_array_set( $settings, array( 'supports', 'filter', 'duotone' ), (bool) $duotone_support );
[1311] Fix | Delete
}
[1312] Fix | Delete
[1313] Fix | Delete
return $settings;
[1314] Fix | Delete
}
[1315] Fix | Delete
[1316] Fix | Delete
/**
[1317] Fix | Delete
* Gets the CSS filter property value from a preset.
[1318] Fix | Delete
*
[1319] Fix | Delete
* Exported for the deprecated function wp_get_duotone_filter_id().
[1320] Fix | Delete
*
[1321] Fix | Delete
* @internal
[1322] Fix | Delete
*
[1323] Fix | Delete
* @since 6.3.0
[1324] Fix | Delete
* @deprecated 6.3.0
[1325] Fix | Delete
*
[1326] Fix | Delete
* @param array $preset The duotone preset.
[1327] Fix | Delete
* @return string The CSS filter property value.
[1328] Fix | Delete
*/
[1329] Fix | Delete
public static function get_filter_css_property_value_from_preset( $preset ) {
[1330] Fix | Delete
_deprecated_function( __FUNCTION__, '6.3.0' );
[1331] Fix | Delete
[1332] Fix | Delete
if ( isset( $preset['colors'] ) && is_string( $preset['colors'] ) ) {
[1333] Fix | Delete
return $preset['colors'];
[1334] Fix | Delete
}
[1335] Fix | Delete
[1336] Fix | Delete
$filter_id = self::get_filter_id_from_preset( $preset );
[1337] Fix | Delete
[1338] Fix | Delete
return 'url(#' . $filter_id . ')';
[1339] Fix | Delete
}
[1340] Fix | Delete
}
[1341] Fix | Delete
[1342] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function