-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/image` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* Supports `duotone` attribute server side for `core/image`. | ||
* | ||
* @param array $attributes The block attributes. | ||
* @param string $content HTML content of the block. | ||
* | ||
* @return string Rendered HTML of the referenced block. | ||
*/ | ||
function render_block_core_image( $attributes, $content ) { | ||
if ( ! isset( $attributes['duotone'] ) ) { | ||
return $content; | ||
} | ||
|
||
$id = $attributes['duotone']['id']; | ||
$values = $attributes['duotone']['values']; | ||
$selectors = array( | ||
'div.wp-block-image .' . $id . ' img', | ||
'figure.wp-block-image.' . $id . ' img', | ||
); | ||
$selector = implode( ', ', $selectors ); | ||
|
||
$duotone = gutenberg_render_duotone_filter( $selector, $id, $values ); | ||
|
||
return $content . $duotone; | ||
} | ||
|
||
/** | ||
* Registers the `core/image` block. | ||
*/ | ||
function register_block_core_image() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/image', | ||
array( | ||
'render_callback' => 'render_block_core_image', | ||
) | ||
); | ||
} | ||
add_action( 'init', 'register_block_core_image' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters