File Editor
Directories:
.. (Back)
ID3
IXR
PHPMailer
Requests
SimplePie
Text
assets
block-bindings
block-patterns
block-supports
blocks
certificates
css
customize
fonts
html-api
images
interactivity-api
js
l10n
php-compat
pomo
rest-api
sitemaps
sodium_compat
style-engine
theme-compat
widgets
Files:
admin-bar.php
atomlib.php
author-template.php
block-bindings.php
block-editor.php
block-patterns.php
block-template-utils.php
block-template.php
blocks.php
bookmark-template.php
bookmark.php
cache-compat.php
cache.php
canonical.php
capabilities.php
category-template.php
category.php
class-IXR.php
class-avif-info.php
class-feed.php
class-http.php
class-json.php
class-oembed.php
class-phpass.php
class-phpmailer.php
class-pop3.php
class-requests.php
class-simplepie.php
class-smtp.php
class-snoopy.php
class-walker-category-dropdown.php
class-walker-category.php
class-walker-comment.php
class-walker-nav-menu.php
class-walker-page-dropdown.php
class-walker-page.php
class-wp-admin-bar.php
class-wp-ajax-response.php
class-wp-application-passwords.php
class-wp-block-bindings-registry.php
class-wp-block-bindings-source.php
class-wp-block-editor-context.php
class-wp-block-list.php
class-wp-block-parser-block.php
class-wp-block-parser-frame.php
class-wp-block-parser.php
class-wp-block-pattern-categories-registry.php
class-wp-block-patterns-registry.php
class-wp-block-styles-registry.php
class-wp-block-supports.php
class-wp-block-template.php
class-wp-block-type-registry.php
class-wp-block-type.php
class-wp-block.php
class-wp-classic-to-block-menu-converter.php
class-wp-comment-query.php
class-wp-comment.php
class-wp-customize-control.php
class-wp-customize-manager.php
class-wp-customize-nav-menus.php
class-wp-customize-panel.php
class-wp-customize-section.php
class-wp-customize-setting.php
class-wp-customize-widgets.php
class-wp-date-query.php
class-wp-dependencies.php
class-wp-dependency.php
class-wp-duotone.php
class-wp-editor.php
class-wp-embed.php
class-wp-error.php
class-wp-fatal-error-handler.php
class-wp-feed-cache-transient.php
class-wp-feed-cache.php
class-wp-hook.php
class-wp-http-cookie.php
class-wp-http-curl.php
class-wp-http-encoding.php
class-wp-http-ixr-client.php
class-wp-http-proxy.php
class-wp-http-requests-hooks.php
class-wp-http-requests-response.php
class-wp-http-response.php
class-wp-http-streams.php
class-wp-http.php
class-wp-image-editor-gd.php
class-wp-image-editor-imagick.php
class-wp-image-editor.php
class-wp-list-util.php
class-wp-locale-switcher.php
class-wp-locale.php
class-wp-matchesmapregex.php
class-wp-meta-query.php
class-wp-metadata-lazyloader.php
class-wp-navigation-fallback.php
class-wp-network-query.php
class-wp-network.php
class-wp-object-cache.php
class-wp-oembed-controller.php
class-wp-oembed.php
class-wp-paused-extensions-storage.php
class-wp-plugin-dependencies.php
class-wp-post-type.php
class-wp-post.php
class-wp-query.php
class-wp-recovery-mode-cookie-service.php
class-wp-recovery-mode-email-service.php
class-wp-recovery-mode-key-service.php
class-wp-recovery-mode-link-service.php
class-wp-recovery-mode.php
class-wp-rewrite.php
class-wp-role.php
class-wp-roles.php
class-wp-script-modules.php
class-wp-scripts.php
class-wp-session-tokens.php
class-wp-simplepie-file.php
class-wp-simplepie-sanitize-kses.php
class-wp-site-query.php
class-wp-site.php
class-wp-styles.php
class-wp-tax-query.php
class-wp-taxonomy.php
class-wp-term-query.php
class-wp-term.php
class-wp-text-diff-renderer-inline.php
class-wp-text-diff-renderer-table.php
class-wp-textdomain-registry.php
class-wp-theme-json-data.php
class-wp-theme-json-resolver.php
class-wp-theme-json-schema.php
class-wp-theme-json.php
class-wp-theme.php
class-wp-token-map.php
class-wp-user-meta-session-tokens.php
class-wp-user-query.php
class-wp-user-request.php
class-wp-user.php
class-wp-walker.php
class-wp-widget-factory.php
class-wp-widget.php
class-wp-xmlrpc-server.php
class-wp.php
class-wpdb.php
class.wp-dependencies.php
class.wp-scripts.php
class.wp-styles.php
comment-template.php
comment.php
compat.php
cron.php
date.php
default-constants.php
default-filters.php
default-widgets.php
deprecated.php
embed-template.php
embed.php
error-protection.php
feed-atom-comments.php
feed-atom.php
feed-rdf.php
feed-rss.php
feed-rss2-comments.php
feed-rss2.php
feed.php
fonts.php
formatting.php
functions.php
functions.wp-scripts.php
functions.wp-styles.php
general-template.php
global-styles-and-settings.php
http.php
https-detection.php
https-migration.php
kses.php
l10n.php
link-template.php
load.php
locale.php
media-template.php
media.php
meta.php
ms-blogs.php
ms-default-constants.php
ms-default-filters.php
ms-deprecated.php
ms-files.php
ms-functions.php
ms-load.php
ms-network.php
ms-settings.php
ms-site.php
nav-menu-template.php
nav-menu.php
option.php
pluggable-deprecated.php
pluggable.php
plugin.php
post-formats.php
post-template.php
post-thumbnail-template.php
post.php
query.php
registration-functions.php
registration.php
rest-api.php
revision.php
rewrite.php
robots-template.php
rss-functions.php
rss.php
script-loader.php
script-modules.php
session.php
shortcodes.php
sitemaps.php
spl-autoload-compat.php
style-engine.php
taxonomy.php
template-canvas.php
template-loader.php
template.php
theme-previews.php
theme-templates.php
theme.php
update.php
user.php
vars.php
version.php
widgets.php
wp-db.php
wp-diff.php
Create New File
Create
Edit File: class-wp-block-supports.php
<?php /** * Block support flags. * * @package WordPress * * @since 5.6.0 */ /** * Class encapsulating and implementing Block Supports. * * @since 5.6.0 * * @access private */ #[AllowDynamicProperties] class WP_Block_Supports { /** * Config. * * @since 5.6.0 * @var array */ private $block_supports = array(); /** * Tracks the current block to be rendered. * * @since 5.6.0 * @var array */ public static $block_to_render = null; /** * Container for the main instance of the class. * * @since 5.6.0 * @var WP_Block_Supports|null */ private static $instance = null; /** * Utility method to retrieve the main instance of the class. * * The instance will be created if it does not exist yet. * * @since 5.6.0 * * @return WP_Block_Supports The main instance. */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Initializes the block supports. It registers the block supports block attributes. * * @since 5.6.0 */ public static function init() { $instance = self::get_instance(); $instance->register_attributes(); } /** * Registers a block support. * * @since 5.6.0 * * @link https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/ * * @param string $block_support_name Block support name. * @param array $block_support_config Array containing the properties of the block support. */ public function register( $block_support_name, $block_support_config ) { $this->block_supports[ $block_support_name ] = array_merge( $block_support_config, array( 'name' => $block_support_name ) ); } /** * Generates an array of HTML attributes, such as classes, by applying to * the given block all of the features that the block supports. * * @since 5.6.0 * * @return string[] Array of HTML attribute values keyed by their name. */ public function apply_block_supports() { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( self::$block_to_render['blockName'] ); // If no render_callback, assume styles have been previously handled. if ( ! $block_type || empty( $block_type ) ) { return array(); } $block_attributes = array_key_exists( 'attrs', self::$block_to_render ) && is_array( self::$block_to_render['attrs'] ) ? self::$block_to_render['attrs'] : array(); $output = array(); foreach ( $this->block_supports as $block_support_config ) { if ( ! isset( $block_support_config['apply'] ) ) { continue; } $new_attributes = call_user_func( $block_support_config['apply'], $block_type, $block_attributes ); if ( ! empty( $new_attributes ) ) { foreach ( $new_attributes as $attribute_name => $attribute_value ) { if ( empty( $output[ $attribute_name ] ) ) { $output[ $attribute_name ] = $attribute_value; } else { $output[ $attribute_name ] .= " $attribute_value"; } } } } return $output; } /** * Registers the block attributes required by the different block supports. * * @since 5.6.0 */ private function register_attributes() { $block_registry = WP_Block_Type_Registry::get_instance(); $registered_block_types = $block_registry->get_all_registered(); foreach ( $registered_block_types as $block_type ) { if ( ! ( $block_type instanceof WP_Block_Type ) ) { continue; } if ( ! $block_type->attributes ) { $block_type->attributes = array(); } foreach ( $this->block_supports as $block_support_config ) { if ( ! isset( $block_support_config['register_attribute'] ) ) { continue; } call_user_func( $block_support_config['register_attribute'], $block_type ); } } } } /** * Generates a string of attributes by applying to the current block being * rendered all of the features that the block supports. * * @since 5.6.0 * * @param string[] $extra_attributes Optional. Array of extra attributes to render on the block wrapper. * @return string String of HTML attributes. */ function get_block_wrapper_attributes( $extra_attributes = array() ) { $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports(); if ( empty( $new_attributes ) && empty( $extra_attributes ) ) { return ''; } // This is hardcoded on purpose. // We only support a fixed list of attributes. $attributes_to_merge = array( 'style', 'class', 'id' ); $attributes = array(); foreach ( $attributes_to_merge as $attribute_name ) { if ( empty( $new_attributes[ $attribute_name ] ) && empty( $extra_attributes[ $attribute_name ] ) ) { continue; } if ( empty( $new_attributes[ $attribute_name ] ) ) { $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ]; continue; } if ( empty( $extra_attributes[ $attribute_name ] ) ) { $attributes[ $attribute_name ] = $new_attributes[ $attribute_name ]; continue; } $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ] . ' ' . $new_attributes[ $attribute_name ]; } foreach ( $extra_attributes as $attribute_name => $value ) { if ( ! in_array( $attribute_name, $attributes_to_merge, true ) ) { $attributes[ $attribute_name ] = $value; } } if ( empty( $attributes ) ) { return ''; } $normalized_attributes = array(); foreach ( $attributes as $key => $value ) { $normalized_attributes[] = $key . '="' . esc_attr( $value ) . '"'; } return implode( ' ', $normalized_attributes ); }
Save Changes
Rename File
Rename