| @@ -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() { |
| @@ -37,33 +15,106 @@ | ||
| 37 | 15 | if ( ! file_exists( $blocks_dir ) ) { |
| 38 | 16 | return; |
| 39 | 17 | } |
| 40 | 18 | |
| 19 | + $block_folders = array( | |
| 20 | + 'audio', | |
| 21 | + 'button', | |
| 22 | + 'buttons', | |
| 23 | + 'classic', | |
| 24 | + 'code', | |
| 25 | + 'column', | |
| 26 | + 'columns', | |
| 27 | + 'file', | |
| 28 | + 'gallery', | |
| 29 | + 'group', | |
| 30 | + 'heading', | |
| 31 | + 'html', | |
| 32 | + 'image', | |
| 33 | + 'list', | |
| 34 | + 'media-text', | |
| 35 | + 'missing', | |
| 36 | + 'more', | |
| 37 | + 'navigation-link', | |
| 38 | + 'nextpage', | |
| 39 | + 'paragraph', | |
| 40 | + 'preformatted', | |
| 41 | + 'pullquote', | |
| 42 | + 'quote', | |
| 43 | + 'separator', | |
| 44 | + 'social-links', | |
| 45 | + 'spacer', | |
| 46 | + 'subhead', | |
| 47 | + 'table', | |
| 48 | + 'text-columns', | |
| 49 | + 'verse', | |
| 50 | + 'video', | |
| 51 | + 'widget-area', | |
| 52 | + ); | |
| 53 | + | |
| 41 | 54 | $block_names = array( |
| 42 | 55 | 'archives.php' => 'core/archives', |
| 43 | 56 | 'block.php' => 'core/block', |
| 44 | 57 | 'calendar.php' => 'core/calendar', |
| 45 | 58 | 'categories.php' => 'core/categories', |
| 59 | + 'cover.php' => 'core/cover', | |
| 46 | 60 | 'latest-comments.php' => 'core/latest-comments', |
| 47 | 61 | 'latest-posts.php' => 'core/latest-posts', |
| 48 | 62 | 'legacy-widget.php' => 'core/legacy-widget', |
| 49 | 63 | 'navigation.php' => 'core/navigation', |
| 50 | 64 | 'rss.php' => 'core/rss', |
| 65 | + 'search.php' => 'core/search', | |
| 51 | 66 | 'shortcode.php' => 'core/shortcode', |
| 52 | - 'search.php' => 'core/search', | |
| 53 | - 'social-link.php' => gutenberg_get_registered_social_link_blocks(), | |
| 67 | + 'social-link.php' => 'core/social-link', | |
| 54 | 68 | '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', | |
| 62 | 69 | ); |
| 63 | 70 | |
| 71 | + if ( gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ) ) { | |
| 72 | + $block_names = array_merge( | |
| 73 | + $block_names, | |
| 74 | + array( | |
| 75 | + 'post-author.php' => 'core/post-author', | |
| 76 | + 'post-comments.php' => 'core/post-comments', | |
| 77 | + 'post-comments-count.php' => 'core/post-comments-count', | |
| 78 | + 'post-comments-form.php' => 'core/post-comments-form', | |
| 79 | + 'post-content.php' => 'core/post-content', | |
| 80 | + 'post-date.php' => 'core/post-date', | |
| 81 | + 'post-excerpt.php' => 'core/post-excerpt', | |
| 82 | + 'post-featured-image.php' => 'core/post-featured-image', | |
| 83 | + 'post-tags.php' => 'core/post-tags', | |
| 84 | + 'post-title.php' => 'core/post-title', | |
| 85 | + 'query.php' => 'core/query', | |
| 86 | + 'query-loop.php' => 'core/query-loop', | |
| 87 | + 'query-pagination.php' => 'core/query-pagination', | |
| 88 | + 'site-title.php' => 'core/site-title', | |
| 89 | + 'template-part.php' => 'core/template-part', | |
| 90 | + ) | |
| 91 | + ); | |
| 92 | + } | |
| 93 | + | |
| 64 | 94 | $registry = WP_Block_Type_Registry::get_instance(); |
| 65 | 95 | |
| 96 | + foreach ( $block_folders as $folder_name ) { | |
| 97 | + $block_json_file = $blocks_dir . '/' . $folder_name . '/block.json'; | |
| 98 | + if ( ! file_exists( $block_json_file ) ) { | |
| 99 | + return; | |
| 100 | + } | |
| 101 | + | |
| 102 | + // Ideally, all paths to block metadata files should be listed in | |
| 103 | + // WordPress core. In this place we should rather use filter | |
| 104 | + // to replace paths with overrides defined by the plugin. | |
| 105 | + $metadata = json_decode( file_get_contents( $block_json_file ), true ); | |
| 106 | + if ( ! is_array( $metadata ) || ! $metadata['name'] ) { | |
| 107 | + return false; | |
| 108 | + } | |
| 109 | + | |
| 110 | + if ( $registry->is_registered( $metadata['name'] ) ) { | |
| 111 | + $registry->unregister( $metadata['name'] ); | |
| 112 | + } | |
| 113 | + | |
| 114 | + register_block_type_from_metadata( $block_json_file ); | |
| 115 | + } | |
| 116 | + | |
| 66 | 117 | foreach ( $block_names as $file => $block_names ) { |
| 67 | 118 | if ( ! file_exists( $blocks_dir . $file ) ) { |
| 68 | 119 | return; |
| 69 | 120 | } |
| @@ -83,8 +134,89 @@ | ||
| 83 | 134 | require $blocks_dir . $file; |
| 84 | 135 | } |
| 85 | 136 | } |
| 86 | 137 | add_action( 'init', 'gutenberg_reregister_core_block_types' ); |
| 138 | + | |
| 139 | +/** | |
| 140 | + * Complements the implementation of block type `core/social-icon`, whether it | |
| 141 | + * be provided by core or the plugin, with derived block types for each | |
| 142 | + * "service" (WordPress, Twitter, etc.) supported by Social Links. | |
| 143 | + * | |
| 144 | + * This ensures backwards compatibility for any users running the Gutenberg | |
| 145 | + * plugin who have used Social Links prior to their conversion to block | |
| 146 | + * variations. | |
| 147 | + * | |
| 148 | + * This shim is INTENTIONALLY left out of core, as Social Links haven't yet | |
| 149 | + * landed there. | |
| 150 | + * | |
| 151 | + * @see https://github.com/WordPress/gutenberg/pull/19887 | |
| 152 | + */ | |
| 153 | +function gutenberg_register_legacy_social_link_blocks() { | |
| 154 | + $services = array( | |
| 155 | + 'amazon', | |
| 156 | + 'bandcamp', | |
| 157 | + 'behance', | |
| 158 | + 'chain', | |
| 159 | + 'codepen', | |
| 160 | + 'deviantart', | |
| 161 | + 'dribbble', | |
| 162 | + 'dropbox', | |
| 163 | + 'etsy', | |
| 164 | + 'facebook', | |
| 165 | + 'feed', | |
| 166 | + 'fivehundredpx', | |
| 167 | + 'flickr', | |
| 168 | + 'foursquare', | |
| 169 | + 'goodreads', | |
| 170 | + 'google', | |
| 171 | + 'github', | |
| 172 | + 'instagram', | |
| 173 | + 'lastfm', | |
| 174 | + 'linkedin', | |
| 175 | + 'mail', | |
| 176 | + 'mastodon', | |
| 177 | + 'meetup', | |
| 178 | + 'medium', | |
| 179 | + 'pinterest', | |
| 180 | + 'pocket', | |
| 181 | + 'reddit', | |
| 182 | + 'skype', | |
| 183 | + 'snapchat', | |
| 184 | + 'soundcloud', | |
| 185 | + 'spotify', | |
| 186 | + 'tumblr', | |
| 187 | + 'twitch', | |
| 188 | + 'twitter', | |
| 189 | + 'vimeo', | |
| 190 | + 'vk', | |
| 191 | + 'wordpress', | |
| 192 | + 'yelp', | |
| 193 | + 'youtube', | |
| 194 | + ); | |
| 195 | + | |
| 196 | + foreach ( $services as $service ) { | |
| 197 | + register_block_type( | |
| 198 | + 'core/social-link-' . $service, | |
| 199 | + array( | |
| 200 | + 'category' => 'widgets', | |
| 201 | + 'attributes' => array( | |
| 202 | + 'url' => array( | |
| 203 | + 'type' => 'string', | |
| 204 | + ), | |
| 205 | + 'service' => array( | |
| 206 | + 'type' => 'string', | |
| 207 | + 'default' => $service, | |
| 208 | + ), | |
| 209 | + 'label' => array( | |
| 210 | + 'type' => 'string', | |
| 211 | + ), | |
| 212 | + ), | |
| 213 | + 'render_callback' => 'gutenberg_render_block_core_social_link', | |
| 214 | + ) | |
| 215 | + ); | |
| 216 | + } | |
| 217 | +} | |
| 218 | +add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' ); | |
| 87 | 219 | |
| 88 | 220 | if ( ! function_exists( 'register_block_style' ) ) { |
| 89 | 221 | /** |
| 90 | 222 | * Registers a new block style. |