generated from alleyinteractive/create-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from alleyinteractive/feature/LEDE-2648/nb-image
LEDE-2648 Filter Image Block
- Loading branch information
Showing
5 changed files
with
101 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Core image block modifications. | ||
* | ||
* @package wp-newsletter-builder | ||
*/ | ||
|
||
namespace WP_Newsletter_Builder; | ||
|
||
/** | ||
* Registers assets so that they can be enqueued through Gutenberg in | ||
* the corresponding context. | ||
*/ | ||
function register_image_scripts(): void { | ||
wp_register_script( | ||
'plugin-newsletter-image', | ||
get_entry_asset_url( 'wp-newsletter-builder-image' ), | ||
get_asset_dependency_array( 'wp-newsletter-builder-image' ), | ||
get_asset_version( 'wp-newsletter-builder-image' ), | ||
true | ||
); | ||
wp_set_script_translations( 'plugin-newsletter-image' ); | ||
} | ||
add_action( 'init', __NAMESPACE__ . '\register_image_scripts' ); | ||
|
||
/** | ||
* Enqueue block editor assets for image. | ||
*/ | ||
function action_enqueue_image_assets(): void { | ||
$post_type = get_edit_post_type(); | ||
if ( ( 'nb_newsletter' !== $post_type ) && ( 'nb_template' !== $post_type ) ) { | ||
return; | ||
} | ||
wp_enqueue_script( 'plugin-newsletter-image' ); | ||
} | ||
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\action_enqueue_image_assets' ); |
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,61 @@ | ||
import { addFilter } from '@wordpress/hooks'; | ||
import domReady from '@wordpress/dom-ready'; | ||
import { unregisterBlockStyle } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Modifies supports for Image block. | ||
* | ||
* @param {Object} settings - The original block settings. | ||
* @param {string} name - The name of the block. | ||
* | ||
* @returns {Object} The modified block settings. | ||
*/ | ||
// @ts-ignore | ||
function modifyImageSupports(settings, name) { | ||
// Bail early if the block does not have supports. | ||
if (!settings?.supports) { | ||
return settings; | ||
} | ||
// Only apply to Image blocks. | ||
if ( | ||
name === 'core/image' | ||
) { | ||
return { | ||
...settings, | ||
attributes: Object.assign(settings.attributes, { | ||
allowResize: { type: 'boolean', default: false }, | ||
}), | ||
supports: Object.assign(settings.supports, { | ||
anchor: false, | ||
align: false, | ||
alignWide: false, | ||
customClassName: false, | ||
filter: { | ||
duotone: false, | ||
}, | ||
__experimentalBorder: { | ||
color: false, | ||
radius: true, | ||
width: false, | ||
__experimentalSkipSerialization: true, | ||
__experimentalDefaultControls: { | ||
color: false, | ||
radius: true, | ||
width: false, | ||
}, | ||
}, | ||
shadow: false, | ||
}), | ||
}; | ||
} | ||
return settings; | ||
} | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'wp-newsletter-builder/image', | ||
modifyImageSupports, | ||
); | ||
|
||
// @ts-ignore | ||
domReady(() => { unregisterBlockStyle('core/image', ['default', 'rounded']); }); |
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