<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[8480] sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php: Gutenberg: Reinstate copy of `gutenberg_editor_scripts_and_styles()` that was deleted from the Gutenberg plugin.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/8480">8480</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/8480","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coffee2code</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-03-20 22:36:09 +0000 (Wed, 20 Mar 2019)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Gutenberg: Reinstate copy of `gutenberg_editor_scripts_and_styles()` that was deleted from the Gutenberg plugin.
Includes a tweak to ensure the `$locked` variable is set so as to prevent a PHP warning.
We should eventually have the site use the code packaged with WP and not the plugin.
Props aduth, coffee2code.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubgutenbergfunctionsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubgutenbergfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php 2019-03-20 21:25:43 UTC (rev 8479)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php 2019-03-20 22:36:09 UTC (rev 8480)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,6 +21,364 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * This function was removed from the Gutenberg plugin in v5.3.
+ */
+if ( ! function_exists( 'gutenberg_editor_scripts_and_styles' ) ) {
+/**
+ * Scripts & Styles.
+ *
+ * Enqueues the needed scripts and styles when visiting the top-level page of
+ * the Gutenberg editor.
+ *
+ * @since 0.1.0
+ *
+ * @param string $hook Screen name.
+ */
+function gutenberg_editor_scripts_and_styles( $hook ) {
+ global $wp_meta_boxes;
+
+ // Enqueue heartbeat separately as an "optional" dependency of the editor.
+ // Heartbeat is used for automatic nonce refreshing, but some hosts choose
+ // to disable it outright.
+ wp_enqueue_script( 'heartbeat' );
+
+ wp_enqueue_script( 'wp-edit-post' );
+ wp_enqueue_script( 'wp-format-library' );
+ wp_enqueue_style( 'wp-format-library' );
+
+ global $post;
+
+ // Set initial title to empty string for auto draft for duration of edit.
+ // Otherwise, title defaults to and displays as "Auto Draft".
+ $is_new_post = 'auto-draft' === $post->post_status;
+
+ // Set the post type name.
+ $post_type = get_post_type( $post );
+ $post_type_object = get_post_type_object( $post_type );
+ $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
+
+ $preload_paths = array(
+ '/',
+ '/wp/v2/types?context=edit',
+ '/wp/v2/taxonomies?per_page=-1&context=edit',
+ '/wp/v2/themes?status=active',
+ sprintf( '/wp/v2/%s/%s?context=edit', $rest_base, $post->ID ),
+ sprintf( '/wp/v2/types/%s?context=edit', $post_type ),
+ sprintf( '/wp/v2/users/me?post_type=%s&context=edit', $post_type ),
+ array( '/wp/v2/media', 'OPTIONS' ),
+ array( '/wp/v2/blocks', 'OPTIONS' ),
+ );
+
+ /**
+ * Preload common data by specifying an array of REST API paths that will be preloaded.
+ *
+ * Filters the array of paths that will be preloaded.
+ *
+ * @param array $preload_paths Array of paths to preload
+ * @param object $post The post resource data.
+ */
+ $preload_paths = apply_filters( 'block_editor_preload_paths', $preload_paths, $post );
+
+ // Ensure the global $post remains the same after
+ // API data is preloaded. Because API preloading
+ // can call the_content and other filters, callbacks
+ // can unexpectedly modify $post resulting in issues
+ // like https://github.com/WordPress/gutenberg/issues/7468.
+ $backup_global_post = $post;
+
+ $preload_data = array_reduce(
+ $preload_paths,
+ 'rest_preload_api_request',
+ array()
+ );
+
+ // Restore the global $post as it was before API preloading.
+ $post = $backup_global_post;
+
+ wp_add_inline_script(
+ 'wp-api-fetch',
+ sprintf( 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', wp_json_encode( $preload_data ) ),
+ 'after'
+ );
+
+ wp_add_inline_script(
+ 'wp-blocks',
+ sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ),
+ 'after'
+ );
+
+ // 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 ) {
+ // Override "(Auto Draft)" new post default title with empty string,
+ // or filtered value.
+ $initial_edits = array(
+ 'title' => $post->post_title,
+ 'content' => $post->post_content,
+ 'excerpt' => $post->post_excerpt,
+ );
+ } else {
+ $initial_edits = null;
+ }
+
+ // Preload server-registered block schemas.
+ wp_add_inline_script(
+ 'wp-blocks',
+ 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . json_encode( get_block_editor_server_block_settings() ) . ');'
+ );
+
+ // Get admin url for handling meta boxes.
+ $meta_box_url = admin_url( 'post.php' );
+ $meta_box_url = add_query_arg(
+ array(
+ 'post' => $post->ID,
+ 'action' => 'edit',
+ 'meta-box-loader' => true,
+ '_wpnonce' => wp_create_nonce( 'meta-box-loader' ),
+ ),
+ $meta_box_url
+ );
+ wp_localize_script( 'wp-editor', '_wpMetaBoxUrl', $meta_box_url );
+
+ // Initialize the editor.
+ $align_wide = get_theme_support( 'align-wide' );
+ $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
+ $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
+
+ /**
+ * Filters the allowed block types for the editor, defaulting to true (all
+ * block types supported).
+ *
+ * @param bool|array $allowed_block_types Array of block type slugs, or
+ * boolean to enable/disable all.
+ * @param object $post The post resource data.
+ */
+ $allowed_block_types = apply_filters( 'allowed_block_types', true, $post );
+
+ // Get all available templates for the post/page attributes meta-box.
+ // The "Default template" array element should only be added if the array is
+ // not empty so we do not trigger the template select element without any options
+ // besides the default value.
+ $available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) );
+ $available_templates = ! empty( $available_templates ) ? array_merge(
+ array(
+ '' => apply_filters( 'default_page_template_title', __( 'Default template', 'gutenberg' ), 'rest-api' ),
+ ),
+ $available_templates
+ ) : $available_templates;
+
+ // Media settings.
+ $max_upload_size = wp_max_upload_size();
+ if ( ! $max_upload_size ) {
+ $max_upload_size = 0;
+ }
+
+ // Editor Styles.
+ global $editor_styles;
+ $styles = array(
+ array(
+ 'css' => file_get_contents(
+ ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
+ ),
+ ),
+ );
+
+ /* Translators: Use this to specify the CSS font family for the default font */
+ $locale_font_family = esc_html_x( 'Noto Serif', 'CSS Font Family for Editor Font', 'gutenberg' );
+ $styles[] = array(
+ 'css' => "body { font-family: '$locale_font_family' }",
+ );
+
+ if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
+ foreach ( $editor_styles as $style ) {
+ if ( filter_var( $style, FILTER_VALIDATE_URL ) ) {
+ $styles[] = array(
+ 'css' => file_get_contents( $style ),
+ );
+ } else {
+ $file = get_theme_file_path( $style );
+ if ( file_exists( $file ) ) {
+ $styles[] = array(
+ 'css' => file_get_contents( $file ),
+ 'baseURL' => get_theme_file_uri( $style ),
+ );
+ }
+ }
+ }
+ }
+
+ // Lock settings.
+ $user_id = wp_check_post_lock( $post->ID );
+ if ( $user_id ) {
+ /**
+ * Filters whether to show the post locked dialog.
+ *
+ * Returning a falsey value to the filter will short-circuit displaying the dialog.
+ *
+ * @since 3.6.0
+ *
+ * @param bool $display Whether to display the dialog. Default true.
+ * @param WP_Post $post Post object.
+ * @param WP_User|bool $user The user id currently editing the post.
+ */
+ if ( apply_filters( 'show_post_locked_dialog', true, $post, $user_id ) ) {
+ $locked = true;
+ } else {
+ $locked = false;
+ }
+
+ $user_details = null;
+ if ( $locked ) {
+ $user = get_userdata( $user_id );
+ $user_details = array(
+ 'name' => $user->display_name,
+ );
+ $avatar = get_avatar( $user_id, 64 );
+ if ( $avatar ) {
+ if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) {
+ $user_details['avatar'] = $matches[1];
+ }
+ }
+ }
+
+ $lock_details = array(
+ 'isLocked' => $locked,
+ 'user' => $user_details,
+ );
+ } else {
+
+ // Lock the post.
+ $active_post_lock = wp_set_post_lock( $post->ID );
+ $lock_details = array(
+ 'isLocked' => false,
+ 'activePostLock' => esc_attr( implode( ':', $active_post_lock ) ),
+ );
+ }
+
+ $editor_settings = array(
+ 'alignWide' => $align_wide,
+ 'availableTemplates' => $available_templates,
+ 'allowedBlockTypes' => $allowed_block_types,
+ 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
+ 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
+ 'disablePostFormats' => ! current_theme_supports( 'post-formats' ),
+ 'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title', 'gutenberg' ), $post ),
+ 'bodyPlaceholder' => apply_filters( 'write_your_story', __( 'Start writing or type / to choose a block', 'gutenberg' ), $post ),
+ 'isRTL' => is_rtl(),
+ 'autosaveInterval' => 10,
+ 'maxUploadFileSize' => $max_upload_size,
+ 'allowedMimeTypes' => get_allowed_mime_types(),
+ 'styles' => $styles,
+ 'imageSizes' => gutenberg_get_available_image_sizes(),
+ 'richEditingEnabled' => user_can_richedit(),
+
+ // Ideally, we'd remove this and rely on a REST API endpoint.
+ 'postLock' => $lock_details,
+ 'postLockUtils' => array(
+ 'nonce' => wp_create_nonce( 'lock-post_' . $post->ID ),
+ 'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
+ 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
+ ),
+
+ // Whether or not to load the 'postcustom' meta box is stored as a user meta
+ // field so that we're not always loading its assets.
+ 'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
+ );
+
+ $post_autosave = gutenberg_get_autosave_newer_than_post_save( $post );
+ if ( $post_autosave ) {
+ $editor_settings['autosave'] = array(
+ 'editLink' => get_edit_post_link( $post_autosave->ID ),
+ );
+ }
+
+ if ( false !== $color_palette ) {
+ $editor_settings['colors'] = $color_palette;
+ }
+
+ if ( false !== $font_sizes ) {
+ $editor_settings['fontSizes'] = $font_sizes;
+ }
+
+ if ( ! empty( $post_type_object->template ) ) {
+ $editor_settings['template'] = $post_type_object->template;
+ $editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
+ }
+
+ $current_screen = get_current_screen();
+ $core_meta_boxes = array();
+
+ // Make sure the current screen is set as well as the normal core metaboxes.
+ if ( isset( $current_screen->id ) && isset( $wp_meta_boxes[ $current_screen->id ]['normal']['core'] ) ) {
+ $core_meta_boxes = $wp_meta_boxes[ $current_screen->id ]['normal']['core'];
+ }
+
+ // Check if the Custom Fields meta box has been removed at some point.
+ if ( ! isset( $core_meta_boxes['postcustom'] ) || ! $core_meta_boxes['postcustom'] ) {
+ unset( $editor_settings['enableCustomFields'] );
+ }
+
+ /**
+ * Filters the settings to pass to the block editor.
+ *
+ * @since 3.7.0
+ *
+ * @param array $editor_settings Default editor settings.
+ * @param WP_Post $post Post being edited.
+ */
+ $editor_settings = apply_filters( 'block_editor_settings', $editor_settings, $post );
+
+ $init_script = <<<JS
+( function() {
+ window._wpLoadBlockEditor = new Promise( function( resolve ) {
+ wp.domReady( function() {
+ resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, %s, %s ) );
+ } );
+ } );
+} )();
+JS;
+
+ $script = sprintf(
+ $init_script,
+ $post->post_type,
+ $post->ID,
+ wp_json_encode( $editor_settings ),
+ wp_json_encode( $initial_edits )
+ );
+ wp_add_inline_script( 'wp-edit-post', $script );
+
+ /**
+ * Scripts
+ */
+ wp_enqueue_media(
+ array(
+ 'post' => $post->ID,
+ )
+ );
+ wp_tinymce_inline_scripts();
+ wp_enqueue_editor();
+
+ /**
+ * Styles
+ */
+ wp_enqueue_style( 'wp-edit-post' );
+
+ /**
+ * Fires after block assets have been enqueued for the editing interface.
+ *
+ * Call `add_action` on any hook before 'admin_enqueue_scripts'.
+ *
+ * In the function call you supply, simply use `wp_enqueue_script` and
+ * `wp_enqueue_style` to add your functionality to the Gutenberg editor.
+ *
+ * @since 0.4.0
+ */
+ do_action( 'enqueue_block_editor_assets' );
+}
+
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> add_action( 'template_redirect', function() {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_page( 'test' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -169,6 +527,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> }, 11 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'wp_enqueue_scripts', function( $hook ) {
+ // Gutenberg requires the post-locking functions defined within:
+ // See `show_post_locked_dialog` and `get_post_metadata` filters below.
+ include_once ABSPATH . 'wp-admin/includes/post.php';
+
+ gutenberg_editor_scripts_and_styles( $hook );
+ } );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> add_action( 'enqueue_block_editor_assets', function() {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script( 'button-readonly', get_template_directory_uri() . '/js/button-readonly.js', array( 'wp-blocks', 'wp-element' ), null );
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span></span></pre>
</div>
</div>
</body>
</html>