PluginProbe
Gutenberg / 12.1.0
Gutenberg v12.1.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 12.1.0, at lib/demo.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Supports for populating the Gutenberg demo content new post.
4 *
5 * @package gutenberg
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die( 'Silence is golden.' );
10 }
11
12 /**
13 * Redirects the demo page to edit a new post.
14 */
15 function gutenberg_redirect_demo() {
16 global $pagenow;
17
18 if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'gutenberg' === $_GET['page'] ) {
19 wp_safe_redirect( admin_url( 'post-new.php?gutenberg-demo' ) );
20 exit;
21 }
22 }
23 add_action( 'admin_init', 'gutenberg_redirect_demo' );
24
25 /**
26 * Assigns the default content for the Gutenberg demo post.
27 *
28 * @param string $content Default post content.
29 *
30 * @return string Demo content if creating a new Gutenberg demo post, or the
31 * default content otherwise.
32 */
33 function gutenberg_default_demo_content( $content ) {
34 $is_demo = isset( $_GET['gutenberg-demo'] );
35
36 if ( $is_demo ) {
37 // Prepopulate with some test content in demo.
38 ob_start();
39 include gutenberg_dir_path() . 'post-content.php';
40 return ob_get_clean();
41 }
42
43 return $content;
44 }
45 add_filter( 'default_content', 'gutenberg_default_demo_content' );
46
47 /**
48 * Assigns the default title for the Gutenberg demo post.
49 *
50 * @param string $title Default post title.
51 *
52 * @return string Demo title if creating a new Gutenberg demo post, or the
53 * default title otherwise.
54 */
55 function gutenberg_default_demo_title( $title ) {
56 $is_demo = isset( $_GET['gutenberg-demo'] );
57
58 if ( $is_demo ) {
59 return __( 'Welcome to the Gutenberg Editor', 'gutenberg' );
60 }
61
62 return $title;
63 }
64 add_filter( 'default_title', 'gutenberg_default_demo_title' );
65