-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compat: Social Links: Remove legacy renderers from packages #20098
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,28 +5,6 @@ | |||||
* @package gutenberg | ||||||
*/ | ||||||
|
||||||
/** | ||||||
* Retrieves registered social link blocks | ||||||
* | ||||||
* @return array Array of strings containing the registered social link block names. | ||||||
*/ | ||||||
function gutenberg_get_registered_social_link_blocks() { | ||||||
$social_link_prefix = 'core/social-link'; | ||||||
$social_link_prefix_length = strlen( $social_link_prefix ); | ||||||
|
||||||
$registry = WP_Block_Type_Registry::get_instance(); | ||||||
$block_types = $registry->get_all_registered(); | ||||||
|
||||||
$registered_social_link_blocks = array(); | ||||||
foreach ( $block_types as $block_type ) { | ||||||
// Block type name starts with $social_link_prefix. | ||||||
if ( strncmp( $block_type->name, $social_link_prefix, $social_link_prefix_length ) === 0 ) { | ||||||
$registered_social_link_blocks[] = $block_type->name; | ||||||
} | ||||||
} | ||||||
return $registered_social_link_blocks; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Substitutes the implementation of a core-registered block type, if exists, | ||||||
* with the built result from the plugin. | ||||||
|
@@ -50,7 +28,7 @@ function gutenberg_reregister_core_block_types() { | |||||
'rss.php' => 'core/rss', | ||||||
'shortcode.php' => 'core/shortcode', | ||||||
'search.php' => 'core/search', | ||||||
'social-link.php' => gutenberg_get_registered_social_link_blocks(), | ||||||
'social-link.php' => 'core/social-link', | ||||||
'tag-cloud.php' => 'core/tag-cloud', | ||||||
'site-title.php' => 'core/site-title', | ||||||
'template-part.php' => 'core/template-part', | ||||||
|
@@ -85,6 +63,87 @@ function gutenberg_reregister_core_block_types() { | |||||
} | ||||||
add_action( 'init', 'gutenberg_reregister_core_block_types' ); | ||||||
|
||||||
/** | ||||||
* Complements the implementation of block type `core/social-icon`, whether it | ||||||
* be provided by core or the plugin, with derived block types for each | ||||||
* "service" (WordPress, Twitter, etc.) supported by Social Links. | ||||||
* | ||||||
* This ensures backwards compatibility for any users running the Gutenberg | ||||||
* plugin who have used Social Links prior to their conversion to block | ||||||
* variations. | ||||||
* | ||||||
* This shim is INTENTIONALLY left out of core, as Social Links haven't yet | ||||||
* landed there. | ||||||
* | ||||||
* @see https://github.com/WordPress/gutenberg/pull/19887 | ||||||
*/ | ||||||
function gutenberg_register_legacy_social_link_blocks() { | ||||||
$sites = array( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably could be:
Suggested change
but I see why it is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That works — done. |
||||||
'amazon', | ||||||
'bandcamp', | ||||||
'behance', | ||||||
'chain', | ||||||
'codepen', | ||||||
'deviantart', | ||||||
'dribbble', | ||||||
'dropbox', | ||||||
'etsy', | ||||||
'facebook', | ||||||
'feed', | ||||||
'fivehundredpx', | ||||||
'flickr', | ||||||
'foursquare', | ||||||
'goodreads', | ||||||
'google', | ||||||
'github', | ||||||
'instagram', | ||||||
'lastfm', | ||||||
'linkedin', | ||||||
'mail', | ||||||
'mastodon', | ||||||
'meetup', | ||||||
'medium', | ||||||
'pinterest', | ||||||
'pocket', | ||||||
'reddit', | ||||||
'skype', | ||||||
'snapchat', | ||||||
'soundcloud', | ||||||
'spotify', | ||||||
'tumblr', | ||||||
'twitch', | ||||||
'twitter', | ||||||
'vimeo', | ||||||
'vk', | ||||||
'wordpress', | ||||||
'yelp', | ||||||
'youtube', | ||||||
); | ||||||
|
||||||
foreach ( $sites as $site ) { | ||||||
register_block_type( | ||||||
'core/social-link-' . $site, | ||||||
array( | ||||||
'category' => 'widgets', | ||||||
'attributes' => array( | ||||||
'url' => array( | ||||||
'type' => 'string', | ||||||
), | ||||||
'service' => array( | ||||||
'type' => 'string', | ||||||
'default' => $site, | ||||||
), | ||||||
'label' => array( | ||||||
'type' => 'string', | ||||||
), | ||||||
), | ||||||
'render_callback' => 'gutenberg_render_core_social_link', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will need rebasing after #20085. |
||||||
) | ||||||
); | ||||||
} | ||||||
} | ||||||
add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' ); | ||||||
|
||||||
if ( ! function_exists( 'register_block_style' ) ) { | ||||||
/** | ||||||
* Registers a new block style. | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where you are going with this, but I think we decided to leave the old name:
😃