| @@ -5,30 +5,8 @@ | ||
| 5 | 5 | * @package gutenberg |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * Retrieves registered social link blocks | |
| 10 | - * | |
| 11 | - * @return array Array of strings containing the registered social link block names. | |
| 12 | - */ | |
| 13 | -function gutenberg_get_registered_social_link_blocks() { | |
| 14 | - $social_link_prefix = 'core/social-link'; | |
| 15 | - $social_link_prefix_length = strlen( $social_link_prefix ); | |
| 16 | - | |
| 17 | - $registry = WP_Block_Type_Registry::get_instance(); | |
| 18 | - $block_types = $registry->get_all_registered(); | |
| 19 | - | |
| 20 | - $registered_social_link_blocks = array(); | |
| 21 | - foreach ( $block_types as $block_type ) { | |
| 22 | - // Block type name starts with $social_link_prefix. | |
| 23 | - if ( strncmp( $block_type->name, $social_link_prefix, $social_link_prefix_length ) === 0 ) { | |
| 24 | - $registered_social_link_blocks[] = $block_type->name; | |
| 25 | - } | |
| 26 | - } | |
| 27 | - return $registered_social_link_blocks; | |
| 28 | -} | |
| 29 | - | |
| 30 | -/** | |
| 31 | 9 | * Substitutes the implementation of a core-registered block type, if exists, |
| 32 | 10 | * with the built result from the plugin. |
| 33 | 11 | */ |
| 34 | 12 | function gutenberg_reregister_core_block_types() { |
| @@ -38,28 +16,32 @@ | ||
| 38 | 16 | return; |
| 39 | 17 | } |
| 40 | 18 | |
| 41 | 19 | $block_names = array( |
| 42 | - 'archives.php' => 'core/archives', | |
| 43 | - 'block.php' => 'core/block', | |
| 44 | - 'calendar.php' => 'core/calendar', | |
| 45 | - 'categories.php' => 'core/categories', | |
| 46 | - 'latest-comments.php' => 'core/latest-comments', | |
| 47 | - 'latest-posts.php' => 'core/latest-posts', | |
| 48 | - 'legacy-widget.php' => 'core/legacy-widget', | |
| 49 | - 'navigation.php' => 'core/navigation', | |
| 50 | - 'rss.php' => 'core/rss', | |
| 51 | - 'shortcode.php' => 'core/shortcode', | |
| 52 | - 'search.php' => 'core/search', | |
| 53 | - 'social-link.php' => gutenberg_get_registered_social_link_blocks(), | |
| 54 | - 'tag-cloud.php' => 'core/tag-cloud', | |
| 55 | - 'site-title.php' => 'core/site-title', | |
| 56 | - 'template-part.php' => 'core/template-part', | |
| 57 | - 'post-title.php' => 'core/post-title', | |
| 58 | - 'post-content.php' => 'core/post-content', | |
| 59 | - 'post-author.php' => 'core/post-author', | |
| 60 | - 'post-date.php' => 'core/post-date', | |
| 61 | - 'post-excerpt.php' => 'core/post-excerpt', | |
| 20 | + 'archives.php' => 'core/archives', | |
| 21 | + 'block.php' => 'core/block', | |
| 22 | + 'calendar.php' => 'core/calendar', | |
| 23 | + 'categories.php' => 'core/categories', | |
| 24 | + 'latest-comments.php' => 'core/latest-comments', | |
| 25 | + 'latest-posts.php' => 'core/latest-posts', | |
| 26 | + 'legacy-widget.php' => 'core/legacy-widget', | |
| 27 | + 'navigation.php' => 'core/navigation', | |
| 28 | + 'rss.php' => 'core/rss', | |
| 29 | + 'shortcode.php' => 'core/shortcode', | |
| 30 | + 'search.php' => 'core/search', | |
| 31 | + 'social-link.php' => 'core/social-link', | |
| 32 | + 'tag-cloud.php' => 'core/tag-cloud', | |
| 33 | + 'site-title.php' => 'core/site-title', | |
| 34 | + 'template-part.php' => 'core/template-part', | |
| 35 | + 'post-title.php' => 'core/post-title', | |
| 36 | + 'post-content.php' => 'core/post-content', | |
| 37 | + 'post-author.php' => 'core/post-author', | |
| 38 | + 'post-comments-count.php' => 'core/post-comments-count', | |
| 39 | + 'post-comments-form.php' => 'core/post-comments-form', | |
| 40 | + 'post-date.php' => 'core/post-date', | |
| 41 | + 'post-excerpt.php' => 'core/post-excerpt', | |
| 42 | + 'post-featured-image.php' => 'core/post-featured-image', | |
| 43 | + 'post-tags.php' => 'core/post-tags', | |
| 62 | 44 | ); |
| 63 | 45 | |
| 64 | 46 | $registry = WP_Block_Type_Registry::get_instance(); |
| 65 | 47 | |
| @@ -83,8 +65,89 @@ | ||
| 83 | 65 | require $blocks_dir . $file; |
| 84 | 66 | } |
| 85 | 67 | } |
| 86 | 68 | add_action( 'init', 'gutenberg_reregister_core_block_types' ); |
| 69 | + | |
| 70 | +/** | |
| 71 | + * Complements the implementation of block type `core/social-icon`, whether it | |
| 72 | + * be provided by core or the plugin, with derived block types for each | |
| 73 | + * "service" (WordPress, Twitter, etc.) supported by Social Links. | |
| 74 | + * | |
| 75 | + * This ensures backwards compatibility for any users running the Gutenberg | |
| 76 | + * plugin who have used Social Links prior to their conversion to block | |
| 77 | + * variations. | |
| 78 | + * | |
| 79 | + * This shim is INTENTIONALLY left out of core, as Social Links haven't yet | |
| 80 | + * landed there. | |
| 81 | + * | |
| 82 | + * @see https://github.com/WordPress/gutenberg/pull/19887 | |
| 83 | + */ | |
| 84 | +function gutenberg_register_legacy_social_link_blocks() { | |
| 85 | + $services = array( | |
| 86 | + 'amazon', | |
| 87 | + 'bandcamp', | |
| 88 | + 'behance', | |
| 89 | + 'chain', | |
| 90 | + 'codepen', | |
| 91 | + 'deviantart', | |
| 92 | + 'dribbble', | |
| 93 | + 'dropbox', | |
| 94 | + 'etsy', | |
| 95 | + 'facebook', | |
| 96 | + 'feed', | |
| 97 | + 'fivehundredpx', | |
| 98 | + 'flickr', | |
| 99 | + 'foursquare', | |
| 100 | + 'goodreads', | |
| 101 | + 'google', | |
| 102 | + 'github', | |
| 103 | + 'instagram', | |
| 104 | + 'lastfm', | |
| 105 | + 'linkedin', | |
| 106 | + 'mail', | |
| 107 | + 'mastodon', | |
| 108 | + 'meetup', | |
| 109 | + 'medium', | |
| 110 | + 'pinterest', | |
| 111 | + 'pocket', | |
| 112 | + 'reddit', | |
| 113 | + 'skype', | |
| 114 | + 'snapchat', | |
| 115 | + 'soundcloud', | |
| 116 | + 'spotify', | |
| 117 | + 'tumblr', | |
| 118 | + 'twitch', | |
| 119 | + 'twitter', | |
| 120 | + 'vimeo', | |
| 121 | + 'vk', | |
| 122 | + 'wordpress', | |
| 123 | + 'yelp', | |
| 124 | + 'youtube', | |
| 125 | + ); | |
| 126 | + | |
| 127 | + foreach ( $services as $service ) { | |
| 128 | + register_block_type( | |
| 129 | + 'core/social-link-' . $service, | |
| 130 | + array( | |
| 131 | + 'category' => 'widgets', | |
| 132 | + 'attributes' => array( | |
| 133 | + 'url' => array( | |
| 134 | + 'type' => 'string', | |
| 135 | + ), | |
| 136 | + 'service' => array( | |
| 137 | + 'type' => 'string', | |
| 138 | + 'default' => $service, | |
| 139 | + ), | |
| 140 | + 'label' => array( | |
| 141 | + 'type' => 'string', | |
| 142 | + ), | |
| 143 | + ), | |
| 144 | + 'render_callback' => 'gutenberg_render_block_core_social_link', | |
| 145 | + ) | |
| 146 | + ); | |
| 147 | + } | |
| 148 | +} | |
| 149 | +add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' ); | |
| 87 | 150 | |
| 88 | 151 | if ( ! function_exists( 'register_block_style' ) ) { |
| 89 | 152 | /** |
| 90 | 153 | * Registers a new block style. |