PluginProbe
Gutenberg / 23.6.0
Gutenberg v23.6.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / demo.php

demo.php in Gutenberg 23.6.0, at lib/demo.php

279 lines 12.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gutenberg demo content.
4 *
5 * Surfaces the classic Gutenberg demo content through an "Insert demo content"
6 * command (Cmd/Ctrl+K), keeping it available for testing ideas without a
7 * dedicated admin page.
8 *
9 * @package gutenberg
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 die( 'Silence is golden.' );
14 }
15
16 /**
17 * Returns the block markup for the Gutenberg demo content.
18 *
19 * @return string Serialized block content.
20 */
21 function gutenberg_demo_content() {
22 ob_start();
23 ?>
24 <!-- wp:cover {"url":"https://cldup.com/Fz-ASbo2s3.jpg","dimRatio":50,"align":"wide"} -->
25 <div class="wp-block-cover alignwide is-light"><img class="wp-block-cover__image-background" src="https://cldup.com/Fz-ASbo2s3.jpg" data-object-fit="cover"/><span aria-hidden="true" class="wp-block-cover__background has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","textColor":"white","fontSize":"large"} -->
26 <p class="has-text-align-center has-white-color has-text-color has-large-font-size"><?php _e( 'Of Mountains &amp; Printing Presses', 'gutenberg' ); ?></p>
27 <!-- /wp:paragraph --></div></div>
28 <!-- /wp:cover -->
29
30 <!-- wp:paragraph -->
31 <p><?php _e( 'The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of <em>pieces of content</em>—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you&#8217;ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.', 'gutenberg' ); ?></p>
32 <!-- /wp:paragraph -->
33
34 <!-- wp:paragraph -->
35 <p><?php _e( 'What you are reading now is a <strong>text block</strong> the most basic block of all. The text block has its own controls to be moved freely around the post...', 'gutenberg' ); ?></p>
36 <!-- /wp:paragraph -->
37
38 <!-- wp:paragraph {"align":"right"} -->
39 <p class="has-text-align-right"><?php _e( '... like this one, which is right aligned.', 'gutenberg' ); ?></p>
40 <!-- /wp:paragraph -->
41
42 <!-- wp:paragraph -->
43 <p><?php _e( 'Headings are separate blocks as well, which helps with the outline and organization of your content.', 'gutenberg' ); ?></p>
44 <!-- /wp:paragraph -->
45
46 <!-- wp:heading -->
47 <h2 class="wp-block-heading"><?php _e( 'A Picture is Worth a Thousand Words', 'gutenberg' ); ?></h2>
48 <!-- /wp:heading -->
49
50 <!-- wp:paragraph -->
51 <p><?php _e( 'Handling images and media with the utmost care is a primary focus of the new editor. Hopefully, you&#8217;ll find aspects of adding captions or going full-width with your pictures much easier and robust than before.', 'gutenberg' ); ?></p>
52 <!-- /wp:paragraph -->
53
54 <!-- wp:image {"align":"center"} -->
55 <figure class="wp-block-image aligncenter"><img src="https://cldup.com/cXyG__fTLN.jpg" alt="<?php esc_attr_e( 'Beautiful landscape', 'gutenberg' ); ?>" />
56 <figcaption class="wp-element-caption"><?php _e( 'If your theme supports it, you&#8217;ll see the "wide" button on the image toolbar. Give it a try.', 'gutenberg' ); ?></figcaption>
57 </figure>
58 <!-- /wp:image -->
59
60 <!-- wp:paragraph -->
61 <p><?php _e( 'Try selecting and removing or editing the caption, now you don&#8217;t have to be careful about selecting the image or other text by mistake and ruining the presentation.', 'gutenberg' ); ?></p>
62 <!-- /wp:paragraph -->
63
64 <!-- wp:heading -->
65 <h2 class="wp-block-heading"><?php _e( 'The <em>Inserter</em> Tool', 'gutenberg' ); ?></h2>
66 <!-- /wp:heading -->
67
68 <!-- wp:paragraph -->
69 <p><?php _e( 'Imagine everything that WordPress can do is available to you quickly and in the same place on the interface. No need to figure out HTML tags, classes, or remember complicated shortcode syntax. That&#8217;s the spirit behind the inserter—the <code>(+)</code> button you&#8217;ll see around the editor—which allows you to browse all available content blocks and add them into your post. Plugins and themes are able to register their own, opening up all sort of possibilities for rich editing and publishing.', 'gutenberg' ); ?></p>
70 <!-- /wp:paragraph -->
71
72 <!-- wp:paragraph -->
73 <p><?php _e( 'Go give it a try, you may discover things WordPress can already add into your posts that you didn&#8217;t know about. Here&#8217;s a short list of what you can currently find there:', 'gutenberg' ); ?></p>
74 <!-- /wp:paragraph -->
75
76 <!-- wp:list {"className":"wp-block-list"} -->
77 <ul class="wp-block-list">
78 <!-- wp:list-item -->
79 <li><?php _e( 'Text &amp; Headings', 'gutenberg' ); ?></li>
80 <!-- /wp:list-item -->
81 <!-- wp:list-item -->
82 <li><?php _e( 'Images &amp; Videos', 'gutenberg' ); ?></li>
83 <!-- /wp:list-item -->
84 <!-- wp:list-item -->
85 <li><?php _e( 'Galleries', 'gutenberg' ); ?></li>
86 <!-- /wp:list-item -->
87 <!-- wp:list-item -->
88 <li><?php _e( 'Embeds, like YouTube, Tweets, or other WordPress posts.', 'gutenberg' ); ?></li>
89 <!-- /wp:list-item -->
90 <!-- wp:list-item -->
91 <li><?php _e( 'Layout blocks, like Buttons, Hero Images, Separators, etc.', 'gutenberg' ); ?></li>
92 <!-- /wp:list-item -->
93 <!-- wp:list-item -->
94 <li><?php _e( 'And <em>Lists</em> like this one of course :)', 'gutenberg' ); ?></li>
95 <!-- /wp:list-item -->
96 </ul>
97 <!-- /wp:list -->
98
99 <!-- wp:separator {"opacity":"css"} -->
100 <hr class="wp-block-separator has-css-opacity" />
101 <!-- /wp:separator -->
102
103 <!-- wp:heading -->
104 <h2 class="wp-block-heading"><?php _e( 'Visual Editing', 'gutenberg' ); ?></h2>
105 <!-- /wp:heading -->
106
107 <!-- wp:paragraph -->
108 <p><?php _e( 'A huge benefit of blocks is that you can edit them in place and manipulate your content directly. Instead of having fields for editing things like the source of a quote, or the text of a button, you can directly change the content. Try editing the following quote:', 'gutenberg' ); ?></p>
109 <!-- /wp:paragraph -->
110
111 <!-- wp:quote -->
112 <blockquote class="wp-block-quote">
113 <!-- wp:paragraph -->
114 <p><?php _e( 'The editor will endeavor to create a new page and post building experience that makes writing rich posts effortless, and has “blocks” to make it easy what today might take shortcodes, custom HTML, or “mystery meat” embed discovery.', 'gutenberg' ); ?></p>
115 <!-- /wp:paragraph -->
116 <cite><?php _e( 'Matt Mullenweg, 2017', 'gutenberg' ); ?></cite>
117 </blockquote>
118 <!-- /wp:quote -->
119
120 <!-- wp:paragraph -->
121 <p><?php _e( 'The information corresponding to the source of the quote is a separate text field, similar to captions under images, so the structure of the quote is protected even if you select, modify, or remove the source. It&#8217;s always easy to add it back.', 'gutenberg' ); ?></p>
122 <!-- /wp:paragraph -->
123
124 <!-- wp:paragraph -->
125 <p><?php _e( 'Blocks can be anything you need. For instance, you may want to add a subdued quote as part of the composition of your text, or you may prefer to display a giant stylized one. All of these options are available in the inserter.', 'gutenberg' ); ?></p>
126 <!-- /wp:paragraph -->
127
128 <!-- wp:gallery {"columns":2,"linkTo":"none"} -->
129 <figure class="wp-block-gallery has-nested-images columns-2 is-cropped">
130 <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
131 <figure class="wp-block-image size-large"><img src="https://cldup.com/n0g6ME5VKC.jpg" alt="" /></figure>
132 <!-- /wp:image -->
133 <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
134 <figure class="wp-block-image size-large"><img src="https://cldup.com/ZjESfxPI3R.jpg" alt="" /></figure>
135 <!-- /wp:image -->
136 <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
137 <figure class="wp-block-image size-large"><img src="https://cldup.com/EKNF8xD2UM.jpg" alt="" /></figure>
138 <!-- /wp:image -->
139 </figure>
140 <!-- /wp:gallery -->
141
142 <!-- wp:paragraph -->
143 <p><?php _e( 'You can change the amount of columns in your galleries by dragging a slider in the block inspector in the sidebar.', 'gutenberg' ); ?></p>
144 <!-- /wp:paragraph -->
145
146 <!-- wp:heading -->
147 <h2 class="wp-block-heading"><?php _e( 'Media Rich', 'gutenberg' ); ?></h2>
148 <!-- /wp:heading -->
149
150 <!-- wp:paragraph -->
151 <p><?php _e( 'If you combine the new <strong>wide</strong> and <strong>full-wide</strong> alignments with galleries, you can create a very media rich layout, very quickly:', 'gutenberg' ); ?></p>
152 <!-- /wp:paragraph -->
153
154 <!-- wp:image {"align":"full"} -->
155 <figure class="wp-block-image alignfull"><img src="https://cldup.com/8lhI-gKnI2.jpg" alt="<?php _e( 'Accessibility is important &mdash; don&#8217;t forget image alt attribute', 'gutenberg' ); ?>" /></figure>
156 <!-- /wp:image -->
157
158 <!-- wp:paragraph -->
159 <p><?php _e( 'Sure, the full-wide image can be pretty big. But sometimes the image is worth it.', 'gutenberg' ); ?></p>
160 <!-- /wp:paragraph -->
161
162 <!-- wp:gallery {"linkTo":"none","align":"wide"} -->
163 <figure class="wp-block-gallery alignwide has-nested-images columns-default is-cropped">
164 <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
165 <figure class="wp-block-image size-large"><img src="https://cldup.com/_rSwtEeDGD.jpg" alt="" /></figure>
166 <!-- /wp:image -->
167 <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
168 <figure class="wp-block-image size-large"><img src="https://cldup.com/L-cC3qX2DN.jpg" alt="" /></figure>
169 <!-- /wp:image -->
170 </figure>
171 <!-- /wp:gallery -->
172
173 <!-- wp:paragraph -->
174 <p><?php _e( 'The above is a gallery with just two images. It&#8217;s an easier way to create visually appealing layouts, without having to deal with floats. You can also easily convert the gallery back to individual images again, by using the block switcher.', 'gutenberg' ); ?></p>
175 <!-- /wp:paragraph -->
176
177 <!-- wp:paragraph -->
178 <p><?php _e( 'Any block can opt into these alignments. The embed block has them also, and is responsive out of the box:', 'gutenberg' ); ?></p>
179 <!-- /wp:paragraph -->
180
181 <!-- wp:embed {"url":"https://vimeo.com/22439234","type":"video","providerNameSlug":"vimeo","responsive":true,"align":"wide","className":"wp-has-aspect-ratio wp-embed-aspect-16-9"} -->
182 <figure class="wp-block-embed alignwide is-type-video is-provider-vimeo wp-block-embed-vimeo wp-has-aspect-ratio wp-embed-aspect-16-9"><div class="wp-block-embed__wrapper">
183 https://vimeo.com/22439234
184 </div></figure>
185 <!-- /wp:embed -->
186
187 <!-- wp:paragraph -->
188 <p><?php _e( 'You can build any block you like, static or dynamic, decorative or plain. Here&#8217;s a pullquote block:', 'gutenberg' ); ?></p>
189 <!-- /wp:paragraph -->
190
191 <!-- wp:pullquote -->
192 <figure class="wp-block-pullquote"><blockquote><p><?php _e( 'Code is Poetry', 'gutenberg' ); ?></p><cite><?php _e( 'The WordPress community', 'gutenberg' ); ?></cite></blockquote></figure>
193 <!-- /wp:pullquote -->
194
195 <!-- wp:paragraph {"align":"center"} -->
196 <p class="has-text-align-center">
197 <em>
198 <?php
199 printf(
200 /* translators: %s: Gutenberg GitHub repository URL */
201 __( 'If you want to learn more about how to build additional blocks, or if you are interested in helping with the project, head over to the <a href="%s">GitHub repository</a>.', 'gutenberg' ),
202 'https://github.com/WordPress/gutenberg'
203 );
204 ?>
205 </em>
206 </p>
207 <!-- /wp:paragraph -->
208
209 <!-- wp:button {"className":"aligncenter"} -->
210 <div class="wp-block-button aligncenter"><a class="wp-block-button__link wp-element-button" href="https://github.com/WordPress/gutenberg"><?php _e( 'Help build Gutenberg', 'gutenberg' ); ?></a></div>
211 <!-- /wp:button -->
212
213 <!-- wp:separator {"opacity":"css"} -->
214 <hr class="wp-block-separator has-css-opacity" />
215 <!-- /wp:separator -->
216
217 <!-- wp:paragraph {"align":"center"} -->
218 <p class="has-text-align-center"><?php _e( 'Thanks for testing Gutenberg!', 'gutenberg' ); ?></p>
219 <!-- /wp:paragraph -->
220
221 <!-- wp:paragraph {"align":"center"} -->
222 <p class="has-text-align-center">👋</p>
223 <!-- /wp:paragraph -->
224 <?php
225 return ob_get_clean();
226 }
227
228 /**
229 * Registers an editor command that inserts the Gutenberg demo content.
230 *
231 * The demo content is exposed to the editor as an inline variable and the
232 * command is registered with an inline script, so the whole demo feature stays
233 * contained in this file.
234 */
235 function gutenberg_enqueue_demo_command() {
236 $handle = 'gutenberg-demo-command';
237
238 wp_register_script(
239 $handle,
240 false,
241 array( 'wp-commands', 'wp-data', 'wp-blocks', 'wp-block-editor', 'wp-i18n' ),
242 false,
243 true
244 );
245 wp_enqueue_script( $handle );
246
247 // Expose the demo content directly so the command can insert it without a
248 // REST round-trip to look the hidden pattern back up.
249 wp_add_inline_script(
250 $handle,
251 'window.gutenbergDemoContent = ' . wp_json_encode( gutenberg_demo_content() ) . ';',
252 'before'
253 );
254
255 $script = <<<'JS'
256 ( function () {
257 wp.data.dispatch( 'core/commands' ).registerCommand( {
258 name: 'gutenberg/insert-demo-content',
259 label: wp.i18n.__( 'Insert demo content', 'gutenberg' ),
260 searchLabel: wp.i18n.__( 'Insert Gutenberg demo content', 'gutenberg' ),
261 keywords: [ 'demo', 'gutenberg', 'sample', 'test' ],
262 category: 'command',
263 callback: function ( { close } ) {
264 close();
265 if ( ! window.gutenbergDemoContent ) {
266 return;
267 }
268 wp.data
269 .dispatch( 'core/block-editor' )
270 .insertBlocks( wp.blocks.parse( window.gutenbergDemoContent ) );
271 },
272 } );
273 } )();
274 JS;
275
276 wp_add_inline_script( $handle, $script );
277 }
278 add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_demo_command' );
279