| 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 |
|