Skip to content

Commit

Permalink
Update plugin to version 3.0. (#7116)
Browse files Browse the repository at this point in the history
* Update plugin to version 3.0.

* Framework: Increase minimum WP version to 4.9.6
  • Loading branch information
mtias authored and mcsf committed Jun 4, 2018
1 parent f897235 commit 94889af
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 157 deletions.
158 changes: 3 additions & 155 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Gutenberg
* Plugin URI: https://github.com/WordPress/gutenberg
* Description: Printing since 1440. This is the development plugin for the new block editor in core.
* Version: 2.9.2
* Version: 3.0.0
* Author: Gutenberg Team
*
* @package gutenberg
Expand Down Expand Up @@ -86,7 +86,7 @@ function gutenberg_menu() {
*/
function gutenberg_wordpress_version_notice() {
echo '<div class="error"><p>';
echo __( 'Gutenberg requires WordPress 4.9 or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' );
echo __( 'Gutenberg requires WordPress 4.9.6 or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' );
echo '</p></div>';

deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
Expand Down Expand Up @@ -120,19 +120,13 @@ function gutenberg_pre_init() {
// Strip '-src' from the version string. Messes up version_compare().
$version = str_replace( '-src', '', $wp_version );

if ( version_compare( $version, '4.9', '<' ) ) {
if ( version_compare( $version, '4.9.6', '<' ) ) {
add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
return;
}

require_once dirname( __FILE__ ) . '/lib/load.php';

if ( version_compare( $version, '4.9-beta1-41829', '<' ) ) {
add_action( 'load-post.php', 'gutenberg_intercept_edit_post' );
add_action( 'load-post-new.php', 'gutenberg_intercept_post_new' );
return;
}

add_filter( 'replace_editor', 'gutenberg_init', 10, 2 );
}

Expand Down Expand Up @@ -174,152 +168,6 @@ function gutenberg_init( $return, $post ) {
return true;
}

/**
* Emulate post.php
*/
function gutenberg_intercept_edit_post() {
global $post_type, $post_type_object, $post, $post_id, $post_ID, $title, $editing,
$typenow, $parent_file, $submenu_file, $post_new_file;

wp_reset_vars( array( 'action' ) );

// Other actions are handled in post.php.
if ( 'edit' !== $GLOBALS['action'] ) {
return;
}

if ( empty( $_GET['post'] ) || ! is_numeric( $_GET['post'] ) ) {
return;
}

$post_ID = (int) $_GET['post'];
$post_id = $post_ID;

$post = get_post( $post_id );

// Errors and invalid requests are handled in post.php, do not intercept.
if ( ! $post ) {
return;
}

$post_type = $post->post_type;
$post_type_object = get_post_type_object( $post_type );

if ( ! $post_type_object ) {
return;
}

if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) {
return;
}

if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}

if ( 'trash' === $post->post_status ) {
return;
}

if ( ! empty( $_GET['get-post-lock'] ) ) {
check_admin_referer( 'lock-post_' . $post_id );
wp_set_post_lock( $post_id );
wp_redirect( get_edit_post_link( $post_id, 'url' ) );
exit();
}

$editing = true;
$title = $post_type_object->labels->edit_item;

if ( 'post' === $post_type ) {
$parent_file = 'edit.php';
$submenu_file = 'edit.php';
$post_new_file = 'post-new.php';
} elseif ( 'attachment' === $post_type ) {
$parent_file = 'upload.php';
$submenu_file = 'upload.php';
$post_new_file = 'media-new.php';
} else {
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && true !== $post_type_object->show_in_menu ) {
$parent_file = $post_type_object->show_in_menu;
} else {
$parent_file = "edit.php?post_type=$post_type";
}

$submenu_file = "edit.php?post_type=$post_type";
$post_new_file = "post-new.php?post_type=$post_type";
}

if ( gutenberg_init( false, $post ) ) {
include ABSPATH . 'wp-admin/admin-footer.php';
exit;
}
}

/**
* Emulate post-new.php
*/
function gutenberg_intercept_post_new() {
global $post_type, $post_type_object, $post, $post_ID, $title, $editing,
$parent_file, $submenu_file, $_registered_pages;

if ( ! isset( $_GET['post_type'] ) ) {
$post_type = 'post';
} elseif ( in_array( $_GET['post_type'], get_post_types( array( 'show_ui' => true ) ), true ) ) {
$post_type = $_GET['post_type'];
} else {
return;
}
$post_type_object = get_post_type_object( $post_type );

if ( 'post' === $post_type ) {
$parent_file = 'edit.php';
$submenu_file = 'post-new.php';
} elseif ( 'attachment' === $post_type ) {
if ( wp_redirect( admin_url( 'media-new.php' ) ) ) {
exit;
}
} else {
$submenu_file = "post-new.php?post_type=$post_type";
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && true !== $post_type_object->show_in_menu ) {
$parent_file = $post_type_object->show_in_menu;
// What if there isn't a post-new.php item for this post type?
if ( ! isset( $_registered_pages[ get_plugin_page_hookname( "post-new.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
if ( isset( $_registered_pages[ get_plugin_page_hookname( "edit.php?post_type=$post_type", $post_type_object->show_in_menu ) ] ) ) {
// Fall back to edit.php for that post type, if it exists.
$submenu_file = "edit.php?post_type=$post_type";
} else {
// Otherwise, give up and highlight the parent.
$submenu_file = $parent_file;
}
}
} else {
$parent_file = "edit.php?post_type=$post_type";
}
}

$title = $post_type_object->labels->add_new_item;
$editing = true;

// Errors and invalid requests are handled in post-new.php, do not intercept.
if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_can( $post_type_object->cap->create_posts ) ) {
return;
}

// Schedule auto-draft cleanup.
if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
}

$post = get_default_post_to_edit( $post_type, true );
$post_ID = $post->ID;

if ( gutenberg_init( false, $post ) ) {
include ABSPATH . 'wp-admin/admin-footer.php';
exit;
}
}

/**
* Redirects the demo page to edit a new post.
*/
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gutenberg",
"version": "2.9.2",
"version": "3.0.0",
"private": true,
"description": "A new WordPress editor experience",
"repository": "git+https://github.com/WordPress/gutenberg.git",
Expand Down

0 comments on commit 94889af

Please sign in to comment.