<!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>[44121] General: Extract the code editor settings from `wp_enqueue_code_editor()`.</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="https://core.trac.wordpress.org/changeset/44121">44121</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/44121","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>desrosj</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-12-13 20:11:09 +0000 (Thu, 13 Dec 2018)</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'>General: Extract the code editor settings from `wp_enqueue_code_editor()`.

They're now returned by a new function, `wp_get_code_editor_settings()`, so they can be reused by the block editor.

Props pento.

Merges <a href="https://core.trac.wordpress.org/changeset/43761">[43761]</a> to trunk.

Fixes <a href="https://core.trac.wordpress.org/ticket/45127">#45127</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesgeneraltemplatephp">trunk/src/wp-includes/general-template.php</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#trunk">trunk/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: trunk
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- trunk        2018-12-13 19:28:26 UTC (rev 44120)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ trunk 2018-12-13 20:11:09 UTC (rev 44121)
</ins><a id="trunk"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: trunk</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/3.3:20543
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/3.4:21757
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/4.9:43557
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/branches/5.0:43681-43682,43684-43688,43719-43720,43723,43726-43727,43729-43731,43734-43744,43751-43754,43758
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/branches/5.0:43681-43682,43684-43688,43719-43720,43723,43726-43727,43729-43731,43734-43744,43751-43754,43758,43761
</ins><span class="cx" style="display: block; padding: 0 10px"> /trunk:18512
</span><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunksrcwpincludesgeneraltemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/general-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/general-template.php        2018-12-13 19:28:26 UTC (rev 44120)
+++ trunk/src/wp-includes/general-template.php  2018-12-13 20:11:09 UTC (rev 44121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3198,7 +3198,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 4.9.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @see wp_enqueue_editor()
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see wp_get_code_editor_settings();
</ins><span class="cx" style="display: block; padding: 0 10px">  * @see _WP_Editors::parse_settings()
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
</ins><span class="cx" style="display: block; padding: 0 10px">  * @param array $args {
</span><span class="cx" style="display: block; padding: 0 10px">  *     Args.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3211,7 +3213,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *     @type array    $jshint     JSHint rule overrides.
</span><span class="cx" style="display: block; padding: 0 10px">  *     @type array    $htmlhint   JSHint rule overrides.
</span><span class="cx" style="display: block; padding: 0 10px">  * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @returns array|false Settings for the enqueued code editor, or false if the editor was not enqueued .
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return array|false Settings for the enqueued code editor, or false if the editor was not enqueued.
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_enqueue_code_editor( $args ) {
</span><span class="cx" style="display: block; padding: 0 10px">        if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3218,6 +3220,93 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return false;
</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">+        $settings = wp_get_code_editor_settings( $args );
+
+       if ( empty( $settings ) || empty( $settings['codemirror'] ) ) {
+               return false;
+       }
+
+       wp_enqueue_script( 'code-editor' );
+       wp_enqueue_style( 'code-editor' );
+
+       if ( isset( $settings['codemirror']['mode'] ) ) {
+               $mode = $settings['codemirror']['mode'];
+               if ( is_string( $mode ) ) {
+                       $mode = array(
+                               'name' => $mode,
+                       );
+               }
+
+               if ( ! empty( $settings['codemirror']['lint'] ) ) {
+                       switch ( $mode['name'] ) {
+                               case 'css':
+                               case 'text/css':
+                               case 'text/x-scss':
+                               case 'text/x-less':
+                                       wp_enqueue_script( 'csslint' );
+                                       break;
+                               case 'htmlmixed':
+                               case 'text/html':
+                               case 'php':
+                               case 'application/x-httpd-php':
+                               case 'text/x-php':
+                                       wp_enqueue_script( 'htmlhint' );
+                                       wp_enqueue_script( 'csslint' );
+                                       wp_enqueue_script( 'jshint' );
+                                       if ( ! current_user_can( 'unfiltered_html' ) ) {
+                                               wp_enqueue_script( 'htmlhint-kses' );
+                                       }
+                                       break;
+                               case 'javascript':
+                               case 'application/ecmascript':
+                               case 'application/json':
+                               case 'application/javascript':
+                               case 'application/ld+json':
+                               case 'text/typescript':
+                               case 'application/typescript':
+                                       wp_enqueue_script( 'jshint' );
+                                       wp_enqueue_script( 'jsonlint' );
+                                       break;
+                       }
+               }
+       }
+
+       wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) );
+
+       /**
+        * Fires when scripts and styles are enqueued for the code editor.
+        *
+        * @since 4.9.0
+        *
+        * @param array $settings Settings for the enqueued code editor.
+        */
+       do_action( 'wp_enqueue_code_editor', $settings );
+
+       return $settings;
+}
+
+/**
+ * Generate and return code editor settings.
+ *
+ * @since 5.0.0
+ *
+ * @see wp_enqueue_code_editor()
+ *
+ * @param array $args {
+ *     Args.
+ *
+ *     @type string   $type       The MIME type of the file to be edited.
+ *     @type string   $file       Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
+ *     @type WP_Theme $theme      Theme being edited when on theme editor.
+ *     @type string   $plugin     Plugin being edited when on plugin editor.
+ *     @type array    $codemirror Additional CodeMirror setting overrides.
+ *     @type array    $csslint    CSSLint rule overrides.
+ *     @type array    $jshint     JSHint rule overrides.
+ *     @type array    $htmlhint   JSHint rule overrides.
+ * }
+ * @return array|false Settings for the code editor.
+ */
+function wp_get_code_editor_settings( $args ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         $settings = array(
</span><span class="cx" style="display: block; padding: 0 10px">                'codemirror' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'indentUnit'       => 4,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3550,7 +3639,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param array $settings The array of settings passed to the code editor. A falsey value disables the editor.
</span><span class="cx" style="display: block; padding: 0 10px">         * @param array $args {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *     Args passed when calling `wp_enqueue_code_editor()`.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  *     Args passed when calling `get_code_editor_settings()`.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string   $type       The MIME type of the file to be edited.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string   $file       Filename being edited.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3562,69 +3651,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type array    $htmlhint   JSHint rule overrides.
</span><span class="cx" style="display: block; padding: 0 10px">         * }
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $settings = apply_filters( 'wp_code_editor_settings', $settings, $args );
-
-       if ( empty( $settings ) || empty( $settings['codemirror'] ) ) {
-               return false;
-       }
-
-       wp_enqueue_script( 'code-editor' );
-       wp_enqueue_style( 'code-editor' );
-
-       if ( isset( $settings['codemirror']['mode'] ) ) {
-               $mode = $settings['codemirror']['mode'];
-               if ( is_string( $mode ) ) {
-                       $mode = array(
-                               'name' => $mode,
-                       );
-               }
-
-               if ( ! empty( $settings['codemirror']['lint'] ) ) {
-                       switch ( $mode['name'] ) {
-                               case 'css':
-                               case 'text/css':
-                               case 'text/x-scss':
-                               case 'text/x-less':
-                                       wp_enqueue_script( 'csslint' );
-                                       break;
-                               case 'htmlmixed':
-                               case 'text/html':
-                               case 'php':
-                               case 'application/x-httpd-php':
-                               case 'text/x-php':
-                                       wp_enqueue_script( 'htmlhint' );
-                                       wp_enqueue_script( 'csslint' );
-                                       wp_enqueue_script( 'jshint' );
-                                       if ( ! current_user_can( 'unfiltered_html' ) ) {
-                                               wp_enqueue_script( 'htmlhint-kses' );
-                                       }
-                                       break;
-                               case 'javascript':
-                               case 'application/ecmascript':
-                               case 'application/json':
-                               case 'application/javascript':
-                               case 'application/ld+json':
-                               case 'text/typescript':
-                               case 'application/typescript':
-                                       wp_enqueue_script( 'jshint' );
-                                       wp_enqueue_script( 'jsonlint' );
-                                       break;
-                       }
-               }
-       }
-
-       wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) );
-
-       /**
-        * Fires when scripts and styles are enqueued for the code editor.
-        *
-        * @since 4.9.0
-        *
-        * @param array $settings Settings for the enqueued code editor.
-        */
-       do_action( 'wp_enqueue_code_editor', $settings );
-
-       return $settings;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'wp_code_editor_settings', $settings, $args );
</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></pre>
</div>
</div>

</body>
</html>