labels->edit_item ); ?>

base !== 'post' ) { return false; } if ( isset( $_GET['classic-editor'] ) ) { return false; } if ( ! gutenberg_can_edit_post( $post ) ) { return false; } return true; } /** * Display a version notice and deactivate the Gutenberg plugin. * * @since 0.1.0 */ function gutenberg_wordpress_version_notice() { echo '

'; echo __( 'Gutenberg requires WordPress 4.9.6 or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ); echo '

'; deactivate_plugins( array( 'gutenberg/gutenberg.php' ) ); } /** * Display a build notice. * * @since 0.1.0 */ function gutenberg_build_files_notice() { echo '

'; echo __( 'Gutenberg development mode requires files to be built. Run npm install to install dependencies, npm run build to build the files or npm run dev to build the files and watch for changes. Read the contributing file for more information.', 'gutenberg' ); echo '

'; } /** * Verify that we can initialize the Gutenberg editor , then load it. * * @since 1.5.0 */ function gutenberg_pre_init() { if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) { add_action( 'admin_notices', 'gutenberg_build_files_notice' ); return; } // Get unmodified $wp_version. include ABSPATH . WPINC . '/version.php'; // Strip '-src' from the version string. Messes up version_compare(). $version = str_replace( '-src', '', $wp_version ); if ( version_compare( $version, '4.9.6', '<' ) ) { add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' ); return; } require_once dirname( __FILE__ ) . '/lib/load.php'; add_filter( 'replace_editor', 'gutenberg_init', 10, 2 ); } /** * Initialize Gutenberg. * * Load API functions, register scripts and actions, etc. * * @param bool $return Whether to replace the editor. Used in the `replace_editor` filter. * @param object $post The post to edit or an auto-draft. * @return bool Whether Gutenberg was initialized. */ function gutenberg_init( $return, $post ) { if ( true === $return && current_filter() === 'replace_editor' ) { return $return; } if ( ! is_gutenberg_page() ) { return false; } add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' ); add_filter( 'screen_options_show_screen', '__return_false' ); add_filter( 'admin_body_class', 'gutenberg_add_admin_body_class' ); /** * Remove the emoji script as it is incompatible with both React and any * contenteditable fields. */ remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); require_once ABSPATH . 'wp-admin/admin-header.php'; the_gutenberg_project(); 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. * * @since 1.5.0 */ function gutenberg_add_edit_link_filters() { // For hierarchical post types. add_filter( 'page_row_actions', 'gutenberg_add_edit_link', 10, 2 ); // For non-hierarchical post types. add_filter( 'post_row_actions', 'gutenberg_add_edit_link', 10, 2 ); } add_action( 'admin_init', 'gutenberg_add_edit_link_filters' ); /** * Registers an additional link in the post/page screens to edit any post/page in * the Classic editor. * * @since 1.5.0 * * @param array $actions Post actions. * @param WP_Post $post Edited post. * * @return array Updated post actions. */ function gutenberg_add_edit_link( $actions, $post ) { if ( ! gutenberg_can_edit_post( $post ) ) { return $actions; } $edit_url = get_edit_post_link( $post->ID, 'raw' ); $edit_url = add_query_arg( 'classic-editor', '', $edit_url ); // Build the classic edit action. See also: WP_Posts_List_Table::handle_row_actions(). $title = _draft_or_post_title( $post->ID ); $edit_action = array( 'classic' => sprintf( '%s', esc_url( $edit_url ), esc_attr( sprintf( /* translators: %s: post title */ __( 'Edit “%s” in the classic editor', 'gutenberg' ), $title ) ), __( 'Classic Editor', 'gutenberg' ) ), ); // Insert the Classic Edit action after the Edit action. $edit_offset = array_search( 'edit', array_keys( $actions ), true ); $actions = array_merge( array_slice( $actions, 0, $edit_offset + 1 ), $edit_action, array_slice( $actions, $edit_offset + 1 ) ); return $actions; } /** * Prints the JavaScript to replace the default "Add New" button.$_COOKIE * * @since 1.5.0 */ function gutenberg_replace_default_add_new_button() { global $typenow; if ( ! gutenberg_can_edit_post_type( $typenow ) ) { return; } ?>