Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin: Populate demo content by default content filters #13553

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,6 @@ function gutenberg_init( $return, $post ) {
return true;
}

/**
* Redirects the demo page to edit a new post.
*/
function gutenberg_redirect_demo() {
global $pagenow;

if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'gutenberg' === $_GET['page'] ) {
wp_safe_redirect( admin_url( 'post-new.php?gutenberg-demo' ) );
exit;
}
}
add_action( 'admin_init', 'gutenberg_redirect_demo' );

/**
* Adds the filters to register additional links for the Gutenberg editor in
* the post/page screens.
Expand Down
14 changes: 1 addition & 13 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,6 @@ function gutenberg_get_available_image_sizes() {
* @param string $hook Screen name.
*/
function gutenberg_editor_scripts_and_styles( $hook ) {
$is_demo = isset( $_GET['gutenberg-demo'] );

global $wp_scripts, $wp_meta_boxes;

// Add "wp-hooks" as dependency of "heartbeat".
Expand Down Expand Up @@ -983,17 +981,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) {

// Assign initial edits, if applicable. These are not initially assigned
// to the persisted post, but should be included in its save payload.
if ( $is_new_post && $is_demo ) {
// Prepopulate with some test content in demo.
ob_start();
include gutenberg_dir_path() . 'post-content.php';
$demo_content = ob_get_clean();

$initial_edits = array(
'title' => __( 'Welcome to the Gutenberg Editor', 'gutenberg' ),
'content' => $demo_content,
);
} elseif ( $is_new_post ) {
if ( $is_new_post ) {
// Override "(Auto Draft)" new post default title with empty string,
// or filtered value.
$initial_edits = array(
Expand Down
64 changes: 64 additions & 0 deletions lib/demo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Supports for populating the Gutenberg demo content new post.
*
* @package gutenberg
*/

if ( ! defined( 'ABSPATH' ) ) {
die( 'Silence is golden.' );
}

/**
* Redirects the demo page to edit a new post.
*/
function gutenberg_redirect_demo() {
global $pagenow;

if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'gutenberg' === $_GET['page'] ) {
wp_safe_redirect( admin_url( 'post-new.php?gutenberg-demo' ) );
exit;
}
}
add_action( 'admin_init', 'gutenberg_redirect_demo' );

/**
* Assigns the default content for the Gutenberg demo post.
*
* @param string $content Default post content.
*
* @return string Demo content if creating a new Gutenberg demo post, or the
* default content otherwise.
*/
function gutenberg_default_demo_content( $content ) {
$is_demo = isset( $_GET['gutenberg-demo'] );

if ( $is_demo ) {
// Prepopulate with some test content in demo.
ob_start();
include gutenberg_dir_path() . 'post-content.php';
return ob_get_clean();
}

return $content;
}
add_filter( 'default_content', 'gutenberg_default_demo_content' );

/**
* Assigns the default title for the Gutenberg demo post.
*
* @param string $title Default post title.
*
* @return string Demo title if creating a new Gutenberg demo post, or the
* default title otherwise.
*/
function gutenberg_default_demo_title( $title ) {
$is_demo = isset( $_GET['gutenberg-demo'] );

if ( $is_demo ) {
return __( 'Welcome to the Gutenberg Editor', 'gutenberg' );
}

return $title;
}
add_filter( 'default_title', 'gutenberg_default_demo_title' );
2 changes: 1 addition & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
require dirname( __FILE__ ) . '/plugin-compat.php';
require dirname( __FILE__ ) . '/i18n.php';
require dirname( __FILE__ ) . '/register.php';

require dirname( __FILE__ ) . '/demo.php';

// Register server-side code for individual blocks.
if ( ! function_exists( 'render_block_core_archives' ) ) {
Expand Down