PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.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 22.3.0, at lib/demo.php

67 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 * @global string $pagenow The name of the current admin page being viewed.
16 */
17 function gutenberg_redirect_demo() {
18 global $pagenow;
19
20 if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'gutenberg' === $_GET['page'] ) {
21 wp_safe_redirect( admin_url( 'post-new.php?gutenberg-demo' ) );
22 exit;
23 }
24 }
25 add_action( 'admin_init', 'gutenberg_redirect_demo' );
26
27 /**
28 * Assigns the default content for the Gutenberg demo post.
29 *
30 * @param string $content Default post content.
31 *
32 * @return string Demo content if creating a new Gutenberg demo post, or the
33 * default content otherwise.
34 */
35 function gutenberg_default_demo_content( $content ) {
36 $is_demo = isset( $_GET['gutenberg-demo'] );
37
38 if ( $is_demo ) {
39 // Prepopulate with some test content in demo.
40 ob_start();
41 include gutenberg_dir_path() . 'post-content.php';
42 return ob_get_clean();
43 }
44
45 return $content;
46 }
47 add_filter( 'default_content', 'gutenberg_default_demo_content' );
48
49 /**
50 * Assigns the default title for the Gutenberg demo post.
51 *
52 * @param string $title Default post title.
53 *
54 * @return string Demo title if creating a new Gutenberg demo post, or the
55 * default title otherwise.
56 */
57 function gutenberg_default_demo_title( $title ) {
58 $is_demo = isset( $_GET['gutenberg-demo'] );
59
60 if ( $is_demo ) {
61 return __( 'Welcome to the Gutenberg Editor', 'gutenberg' );
62 }
63
64 return $title;
65 }
66 add_filter( 'default_title', 'gutenberg_default_demo_title' );
67