<!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>[6070] sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/gutenberg-tweaks.php: Gutenberg Tweaks: Make the "classic" editor the default for now.</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 { 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/6070">6070</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/6070","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>iandunn</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-11-01 22:04:32 +0000 (Wed, 01 Nov 2017)</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 Tweaks: Make the "classic" editor the default for now.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentmupluginsgutenbergtweaksphp">sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/gutenberg-tweaks.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentmupluginsgutenbergtweaksphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/gutenberg-tweaks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/gutenberg-tweaks.php   2017-11-01 22:04:29 UTC (rev 6069)
+++ sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/gutenberg-tweaks.php     2017-11-01 22:04:32 UTC (rev 6070)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,7 +4,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> defined( 'WPINC' ) || die();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+ * Customize Gutenberg for WordCamp.org
+ *
+ *   WARNING: This is tied to Gutenberg's hooks, which are likely to evolve quickly. This needs to
+ *   be tested and updated before pushing Gutenberg updates to production.
+ *
+ * Most of this deals with preventing Gutenberg from being the default editor for now.
+ *
+ * We want the beta plugin to be available for all organizers to use on an opt-in basis, but don't
+ * want to aggressively push them to use it if they don't want to.
+ *
+ * @see https://make.wordpress.org/community/2017/09/25/gutenberg-on-wordcamp-sites/#comment-24596
+ *
+ * @todo: Most of this can be removed once Gutenberg is refined enough to become the default editor
+ *        for organizers.
+ */
+
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'gutenberg_can_edit_post_type', __NAMESPACE__ . '\disable_gutenberg_on_cpts',           10, 2 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'get_edit_post_link',           __NAMESPACE__ . '\add_classic_param_to_edit_links'            );
+add_filter( 'page_row_actions',             __NAMESPACE__ . '\add_gutenberg_edit_link',             10, 2 );
+add_filter( 'post_row_actions',             __NAMESPACE__ . '\add_gutenberg_edit_link',             10, 2 );
+add_action( 'admin_print_scripts-edit.php', __NAMESPACE__ . '\add_classic_param_to_add_new_button', 11    );
+add_action( 'admin_print_scripts',          __NAMESPACE__ . '\add_classic_param_to_admin_menus',     1    );
</ins><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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,3 +40,81 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function disable_gutenberg_on_cpts( $bool, $post_type ) {
</span><span class="cx" style="display: block; padding: 0 10px">        return in_array( $post_type, array( 'post', 'page' ), true );
</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 the `classic-editor` trigger to all edit post URLs
+function add_classic_param_to_edit_links( $url ) {
+       return add_query_arg( 'classic-editor', '', $url );
+}
+
+// Add a "Gutenberg Editor" link to the post hover actions on the "All {Posts|Pages}" screen.
+function add_gutenberg_edit_link( $actions, $post ) {
+       if ( ! gutenberg_can_edit_post( $post ) ) {
+               return $actions;
+       }
+
+       remove_filter( 'get_edit_post_link', __NAMESPACE__ . '\add_classic_param_to_edit_links', 10 );
+       $edit_url = get_edit_post_link( $post->ID, 'raw' );
+       add_filter( 'get_edit_post_link', __NAMESPACE__ . '\add_classic_param_to_edit_links', 10 );
+
+       $title = _draft_or_post_title( $post->ID );
+       $edit_action = array(
+               'gutenberg' => sprintf(
+                       '<a href="%s" aria-label="%s">%s</a>',
+                       esc_url( $edit_url ),
+                       esc_attr( sprintf( 'Edit &#8220;%s&#8221; in the Gutenberg editor', $title ) ),
+                       'Gutenberg Editor'
+               ),
+       );
+
+       // Insert the Gutenberg 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;
+}
+
+// Add the `classic-editor` trigger to the modified Add New button on the "All {Posts|Pages" screen.
+function add_classic_param_to_add_new_button() {
+       ?>
+
+       <script type="text/javascript">
+               document.addEventListener( 'DOMContentLoaded', function() {
+                       jQuery( '.split-page-title-action' ).children( 'a' ).each( function( index, element ) {
+                               jQuery( element ).attr( 'href', jQuery( element ).attr( 'href' ) + 'classic-editor' );
+                       } );
+               } );
+       </script>
+
+       <?php
+}
+
+// Add the `classic-editor` trigger to post/page links in the admin menus
+// This is an ugly hack, but I'm not seeing a better way to do it, and this'll be thrown out soon anyway.
+function add_classic_param_to_admin_menus() {
+       ?>
+
+       <script>
+               document.addEventListener( 'DOMContentLoaded', function() {
+                       var adminBarNewContentLink = $( '#wp-admin-bar-new-content' ).children( 'a' ),
+                               adminBarNewPostLink    = $( '#wp-admin-bar-new-post'    ).children( 'a' ),
+                               adminBarNewPageLink    = $( '#wp-admin-bar-new-page'    ).children( 'a' ),
+                               adminMenuNewPostLink   = $( '#menu-posts'    ).children( '.wp-submenu' ).children( 'li' ).children( 'a[href="post-new.php"]' ),
+                               adminMenuNewPageLink   = $( '#menu-pages'    ).children( '.wp-submenu' ).children( 'li' ).children( 'a[href="post-new.php?post_type=page"]' );
+
+                       // Admin Bar
+                       $( adminBarNewContentLink ).attr( 'href', jQuery( adminBarNewContentLink ).attr( 'href' ) + '?classic-editor' );
+                       $( adminBarNewPostLink ).attr(    'href', jQuery( adminBarNewPostLink    ).attr( 'href' ) + '?classic-editor' );
+                       $( adminBarNewPageLink ).attr(    'href', jQuery( adminBarNewPageLink    ).attr( 'href' ) + '&classic-editor' );
+
+                       // Admin sidebar menu
+                       $( adminMenuNewPostLink ).attr( 'href', jQuery( adminMenuNewPostLink ).attr( 'href' ) + '?classic-editor' );
+                       $( adminMenuNewPageLink ).attr( 'href', jQuery( adminMenuNewPageLink ).attr( 'href' ) + '&classic-editor' );
+               } );
+       </script>
+
+       <?php
+}
</ins></span></pre>
</div>
</div>

</body>
</html>