Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/blogs-gentoo:master commit in: plugins/classic-editor/, plugins/classic-editor/js/
Date: Mon, 17 Feb 2020 17:04:07
Message-Id: 1581959034.2cf775d1948deb977ee8afe94884e7b269d00eb6.blueness@gentoo
1 commit: 2cf775d1948deb977ee8afe94884e7b269d00eb6
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Mon Feb 17 17:03:54 2020 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Mon Feb 17 17:03:54 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/blogs-gentoo.git/commit/?id=2cf775d1
7
8 Add classic-editor 1.5
9
10 Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org>
11
12 plugins/classic-editor/LICENSE.md | 400 ++++++++++
13 plugins/classic-editor/classic-editor.php | 941 +++++++++++++++++++++++
14 plugins/classic-editor/js/block-editor-plugin.js | 23 +
15 plugins/classic-editor/readme.txt | 119 +++
16 4 files changed, 1483 insertions(+)
17
18 diff --git a/plugins/classic-editor/LICENSE.md b/plugins/classic-editor/LICENSE.md
19 new file mode 100644
20 index 00000000..26279ac8
21 --- /dev/null
22 +++ b/plugins/classic-editor/LICENSE.md
23 @@ -0,0 +1,400 @@
24 +### WordPress - Web publishing software
25 +
26 + Copyright 2011-2019 by the contributors
27 +
28 +This program is free software; you can redistribute it and/or modify
29 +it under the terms of the GNU General Public License as published by
30 +the Free Software Foundation; either version 2 of the License, or
31 +(at your option) any later version.
32 +
33 +This program is distributed in the hope that it will be useful,
34 +but WITHOUT ANY WARRANTY; without even the implied warranty of
35 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 +GNU General Public License for more details.
37 +
38 +You should have received a copy of the GNU General Public License
39 +along with this program; if not, write to the Free Software
40 +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
41 +
42 +This program incorporates work covered by the following copyright and
43 +permission notices:
44 +
45 + b2 is (c) 2001, 2002 Michel Valdrighi - m@××××××××.com -
46 + http://tidakada.com
47 +
48 + Wherever third party code has been used, credit has been given in the code's
49 + comments.
50 +
51 + b2 is released under the GPL
52 +
53 +and
54 +
55 + WordPress - Web publishing software
56 +
57 + Copyright 2003-2010 by the contributors
58 +
59 + WordPress is released under the GPL
60 +
61 +---
62 +
63 +### GNU GENERAL PUBLIC LICENSE
64 +
65 +Version 2, June 1991
66 +
67 + Copyright (C) 1989, 1991 Free Software Foundation, Inc.
68 + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
69 +
70 + Everyone is permitted to copy and distribute verbatim copies
71 + of this license document, but changing it is not allowed.
72 +
73 +### Preamble
74 +
75 +The licenses for most software are designed to take away your freedom
76 +to share and change it. By contrast, the GNU General Public License is
77 +intended to guarantee your freedom to share and change free
78 +software--to make sure the software is free for all its users. This
79 +General Public License applies to most of the Free Software
80 +Foundation's software and to any other program whose authors commit to
81 +using it. (Some other Free Software Foundation software is covered by
82 +the GNU Lesser General Public License instead.) You can apply it to
83 +your programs, too.
84 +
85 +When we speak of free software, we are referring to freedom, not
86 +price. Our General Public Licenses are designed to make sure that you
87 +have the freedom to distribute copies of free software (and charge for
88 +this service if you wish), that you receive source code or can get it
89 +if you want it, that you can change the software or use pieces of it
90 +in new free programs; and that you know you can do these things.
91 +
92 +To protect your rights, we need to make restrictions that forbid
93 +anyone to deny you these rights or to ask you to surrender the rights.
94 +These restrictions translate to certain responsibilities for you if
95 +you distribute copies of the software, or if you modify it.
96 +
97 +For example, if you distribute copies of such a program, whether
98 +gratis or for a fee, you must give the recipients all the rights that
99 +you have. You must make sure that they, too, receive or can get the
100 +source code. And you must show them these terms so they know their
101 +rights.
102 +
103 +We protect your rights with two steps: (1) copyright the software, and
104 +(2) offer you this license which gives you legal permission to copy,
105 +distribute and/or modify the software.
106 +
107 +Also, for each author's protection and ours, we want to make certain
108 +that everyone understands that there is no warranty for this free
109 +software. If the software is modified by someone else and passed on,
110 +we want its recipients to know that what they have is not the
111 +original, so that any problems introduced by others will not reflect
112 +on the original authors' reputations.
113 +
114 +Finally, any free program is threatened constantly by software
115 +patents. We wish to avoid the danger that redistributors of a free
116 +program will individually obtain patent licenses, in effect making the
117 +program proprietary. To prevent this, we have made it clear that any
118 +patent must be licensed for everyone's free use or not licensed at
119 +all.
120 +
121 +The precise terms and conditions for copying, distribution and
122 +modification follow.
123 +
124 +### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
125 +
126 +**0.** This License applies to any program or other work which
127 +contains a notice placed by the copyright holder saying it may be
128 +distributed under the terms of this General Public License. The
129 +"Program", below, refers to any such program or work, and a "work
130 +based on the Program" means either the Program or any derivative work
131 +under copyright law: that is to say, a work containing the Program or
132 +a portion of it, either verbatim or with modifications and/or
133 +translated into another language. (Hereinafter, translation is
134 +included without limitation in the term "modification".) Each licensee
135 +is addressed as "you".
136 +
137 +Activities other than copying, distribution and modification are not
138 +covered by this License; they are outside its scope. The act of
139 +running the Program is not restricted, and the output from the Program
140 +is covered only if its contents constitute a work based on the Program
141 +(independent of having been made by running the Program). Whether that
142 +is true depends on what the Program does.
143 +
144 +**1.** You may copy and distribute verbatim copies of the Program's
145 +source code as you receive it, in any medium, provided that you
146 +conspicuously and appropriately publish on each copy an appropriate
147 +copyright notice and disclaimer of warranty; keep intact all the
148 +notices that refer to this License and to the absence of any warranty;
149 +and give any other recipients of the Program a copy of this License
150 +along with the Program.
151 +
152 +You may charge a fee for the physical act of transferring a copy, and
153 +you may at your option offer warranty protection in exchange for a
154 +fee.
155 +
156 +**2.** You may modify your copy or copies of the Program or any
157 +portion of it, thus forming a work based on the Program, and copy and
158 +distribute such modifications or work under the terms of Section 1
159 +above, provided that you also meet all of these conditions:
160 +
161 +
162 +**a)** You must cause the modified files to carry prominent notices
163 +stating that you changed the files and the date of any change.
164 +
165 +
166 +**b)** You must cause any work that you distribute or publish, that in
167 +whole or in part contains or is derived from the Program or any part
168 +thereof, to be licensed as a whole at no charge to all third parties
169 +under the terms of this License.
170 +
171 +
172 +**c)** If the modified program normally reads commands interactively
173 +when run, you must cause it, when started running for such interactive
174 +use in the most ordinary way, to print or display an announcement
175 +including an appropriate copyright notice and a notice that there is
176 +no warranty (or else, saying that you provide a warranty) and that
177 +users may redistribute the program under these conditions, and telling
178 +the user how to view a copy of this License. (Exception: if the
179 +Program itself is interactive but does not normally print such an
180 +announcement, your work based on the Program is not required to print
181 +an announcement.)
182 +
183 +These requirements apply to the modified work as a whole. If
184 +identifiable sections of that work are not derived from the Program,
185 +and can be reasonably considered independent and separate works in
186 +themselves, then this License, and its terms, do not apply to those
187 +sections when you distribute them as separate works. But when you
188 +distribute the same sections as part of a whole which is a work based
189 +on the Program, the distribution of the whole must be on the terms of
190 +this License, whose permissions for other licensees extend to the
191 +entire whole, and thus to each and every part regardless of who wrote
192 +it.
193 +
194 +Thus, it is not the intent of this section to claim rights or contest
195 +your rights to work written entirely by you; rather, the intent is to
196 +exercise the right to control the distribution of derivative or
197 +collective works based on the Program.
198 +
199 +In addition, mere aggregation of another work not based on the Program
200 +with the Program (or with a work based on the Program) on a volume of
201 +a storage or distribution medium does not bring the other work under
202 +the scope of this License.
203 +
204 +**3.** You may copy and distribute the Program (or a work based on it,
205 +under Section 2) in object code or executable form under the terms of
206 +Sections 1 and 2 above provided that you also do one of the following:
207 +
208 +
209 +**a)** Accompany it with the complete corresponding machine-readable
210 +source code, which must be distributed under the terms of Sections 1
211 +and 2 above on a medium customarily used for software interchange; or,
212 +
213 +
214 +**b)** Accompany it with a written offer, valid for at least three
215 +years, to give any third party, for a charge no more than your cost of
216 +physically performing source distribution, a complete machine-readable
217 +copy of the corresponding source code, to be distributed under the
218 +terms of Sections 1 and 2 above on a medium customarily used for
219 +software interchange; or,
220 +
221 +
222 +**c)** Accompany it with the information you received as to the offer
223 +to distribute corresponding source code. (This alternative is allowed
224 +only for noncommercial distribution and only if you received the
225 +program in object code or executable form with such an offer, in
226 +accord with Subsection b above.)
227 +
228 +The source code for a work means the preferred form of the work for
229 +making modifications to it. For an executable work, complete source
230 +code means all the source code for all modules it contains, plus any
231 +associated interface definition files, plus the scripts used to
232 +control compilation and installation of the executable. However, as a
233 +special exception, the source code distributed need not include
234 +anything that is normally distributed (in either source or binary
235 +form) with the major components (compiler, kernel, and so on) of the
236 +operating system on which the executable runs, unless that component
237 +itself accompanies the executable.
238 +
239 +If distribution of executable or object code is made by offering
240 +access to copy from a designated place, then offering equivalent
241 +access to copy the source code from the same place counts as
242 +distribution of the source code, even though third parties are not
243 +compelled to copy the source along with the object code.
244 +
245 +**4.** You may not copy, modify, sublicense, or distribute the Program
246 +except as expressly provided under this License. Any attempt otherwise
247 +to copy, modify, sublicense or distribute the Program is void, and
248 +will automatically terminate your rights under this License. However,
249 +parties who have received copies, or rights, from you under this
250 +License will not have their licenses terminated so long as such
251 +parties remain in full compliance.
252 +
253 +**5.** You are not required to accept this License, since you have not
254 +signed it. However, nothing else grants you permission to modify or
255 +distribute the Program or its derivative works. These actions are
256 +prohibited by law if you do not accept this License. Therefore, by
257 +modifying or distributing the Program (or any work based on the
258 +Program), you indicate your acceptance of this License to do so, and
259 +all its terms and conditions for copying, distributing or modifying
260 +the Program or works based on it.
261 +
262 +**6.** Each time you redistribute the Program (or any work based on
263 +the Program), the recipient automatically receives a license from the
264 +original licensor to copy, distribute or modify the Program subject to
265 +these terms and conditions. You may not impose any further
266 +restrictions on the recipients' exercise of the rights granted herein.
267 +You are not responsible for enforcing compliance by third parties to
268 +this License.
269 +
270 +**7.** If, as a consequence of a court judgment or allegation of
271 +patent infringement or for any other reason (not limited to patent
272 +issues), conditions are imposed on you (whether by court order,
273 +agreement or otherwise) that contradict the conditions of this
274 +License, they do not excuse you from the conditions of this License.
275 +If you cannot distribute so as to satisfy simultaneously your
276 +obligations under this License and any other pertinent obligations,
277 +then as a consequence you may not distribute the Program at all. For
278 +example, if a patent license would not permit royalty-free
279 +redistribution of the Program by all those who receive copies directly
280 +or indirectly through you, then the only way you could satisfy both it
281 +and this License would be to refrain entirely from distribution of the
282 +Program.
283 +
284 +If any portion of this section is held invalid or unenforceable under
285 +any particular circumstance, the balance of the section is intended to
286 +apply and the section as a whole is intended to apply in other
287 +circumstances.
288 +
289 +It is not the purpose of this section to induce you to infringe any
290 +patents or other property right claims or to contest validity of any
291 +such claims; this section has the sole purpose of protecting the
292 +integrity of the free software distribution system, which is
293 +implemented by public license practices. Many people have made
294 +generous contributions to the wide range of software distributed
295 +through that system in reliance on consistent application of that
296 +system; it is up to the author/donor to decide if he or she is willing
297 +to distribute software through any other system and a licensee cannot
298 +impose that choice.
299 +
300 +This section is intended to make thoroughly clear what is believed to
301 +be a consequence of the rest of this License.
302 +
303 +**8.** If the distribution and/or use of the Program is restricted in
304 +certain countries either by patents or by copyrighted interfaces, the
305 +original copyright holder who places the Program under this License
306 +may add an explicit geographical distribution limitation excluding
307 +those countries, so that distribution is permitted only in or among
308 +countries not thus excluded. In such case, this License incorporates
309 +the limitation as if written in the body of this License.
310 +
311 +**9.** The Free Software Foundation may publish revised and/or new
312 +versions of the General Public License from time to time. Such new
313 +versions will be similar in spirit to the present version, but may
314 +differ in detail to address new problems or concerns.
315 +
316 +Each version is given a distinguishing version number. If the Program
317 +specifies a version number of this License which applies to it and
318 +"any later version", you have the option of following the terms and
319 +conditions either of that version or of any later version published by
320 +the Free Software Foundation. If the Program does not specify a
321 +version number of this License, you may choose any version ever
322 +published by the Free Software Foundation.
323 +
324 +**10.** If you wish to incorporate parts of the Program into other
325 +free programs whose distribution conditions are different, write to
326 +the author to ask for permission. For software which is copyrighted by
327 +the Free Software Foundation, write to the Free Software Foundation;
328 +we sometimes make exceptions for this. Our decision will be guided by
329 +the two goals of preserving the free status of all derivatives of our
330 +free software and of promoting the sharing and reuse of software
331 +generally.
332 +
333 +**NO WARRANTY**
334 +
335 +**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
336 +WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
337 +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
338 +OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
339 +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
340 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
341 +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
342 +PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
343 +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
344 +
345 +**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
346 +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
347 +AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
348 +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
349 +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
350 +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
351 +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
352 +FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
353 +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
354 +DAMAGES.
355 +
356 +### END OF TERMS AND CONDITIONS
357 +
358 +### How to Apply These Terms to Your New Programs
359 +
360 +If you develop a new program, and you want it to be of the greatest
361 +possible use to the public, the best way to achieve this is to make it
362 +free software which everyone can redistribute and change under these
363 +terms.
364 +
365 +To do so, attach the following notices to the program. It is safest to
366 +attach them to the start of each source file to most effectively
367 +convey the exclusion of warranty; and each file should have at least
368 +the "copyright" line and a pointer to where the full notice is found.
369 +
370 + one line to give the program's name and an idea of what it does.
371 + Copyright (C) yyyy name of author
372 +
373 + This program is free software; you can redistribute it and/or
374 + modify it under the terms of the GNU General Public License
375 + as published by the Free Software Foundation; either version 2
376 + of the License, or (at your option) any later version.
377 +
378 + This program is distributed in the hope that it will be useful,
379 + but WITHOUT ANY WARRANTY; without even the implied warranty of
380 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
381 + GNU General Public License for more details.
382 +
383 + You should have received a copy of the GNU General Public License
384 + along with this program; if not, write to the Free Software
385 + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
386 +
387 +Also add information on how to contact you by electronic and paper
388 +mail.
389 +
390 +If the program is interactive, make it output a short notice like this
391 +when it starts in an interactive mode:
392 +
393 + Gnomovision version 69, Copyright (C) year name of author
394 + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
395 + type `show w'. This is free software, and you are welcome
396 + to redistribute it under certain conditions; type `show c'
397 + for details.
398 +
399 +The hypothetical commands \`show w' and \`show c' should show the
400 +appropriate parts of the General Public License. Of course, the
401 +commands you use may be called something other than \`show w' and
402 +\`show c'; they could even be mouse-clicks or menu items--whatever
403 +suits your program.
404 +
405 +You should also get your employer (if you work as a programmer) or
406 +your school, if any, to sign a "copyright disclaimer" for the program,
407 +if necessary. Here is a sample; alter the names:
408 +
409 + Yoyodyne, Inc., hereby disclaims all copyright
410 + interest in the program `Gnomovision'
411 + (which makes passes at compilers) written
412 + by James Hacker.
413 +
414 + signature of Ty Coon, 1 April 1989
415 + Ty Coon, President of Vice
416 +
417 +This General Public License does not permit incorporating your program
418 +into proprietary programs. If your program is a subroutine library,
419 +you may consider it more useful to permit linking proprietary
420 +applications with the library. If this is what you want to do, use the
421 +[GNU Lesser General Public
422 +License](http://www.gnu.org/licenses/lgpl.html) instead of this
423 +License.
424
425 diff --git a/plugins/classic-editor/classic-editor.php b/plugins/classic-editor/classic-editor.php
426 new file mode 100644
427 index 00000000..afac3c20
428 --- /dev/null
429 +++ b/plugins/classic-editor/classic-editor.php
430 @@ -0,0 +1,941 @@
431 +<?php
432 +/**
433 + * Classic Editor
434 + *
435 + * Plugin Name: Classic Editor
436 + * Plugin URI: https://wordpress.org/plugins/classic-editor/
437 + * Description: Enables the WordPress classic editor and the old-style Edit Post screen with TinyMCE, Meta Boxes, etc. Supports the older plugins that extend this screen.
438 + * Version: 1.5
439 + * Author: WordPress Contributors
440 + * Author URI: https://github.com/WordPress/classic-editor/
441 + * License: GPLv2 or later
442 + * License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
443 + * Text Domain: classic-editor
444 + * Domain Path: /languages
445 + *
446 + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
447 + * General Public License version 2, as published by the Free Software Foundation. You may NOT assume
448 + * that you can use any other version of the GPL.
449 + *
450 + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
451 + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
452 + */
453 +
454 +if ( ! defined( 'ABSPATH' ) ) {
455 + die( 'Invalid request.' );
456 +}
457 +
458 +if ( ! class_exists( 'Classic_Editor' ) ) :
459 +class Classic_Editor {
460 + private static $settings;
461 + private static $supported_post_types = array();
462 +
463 + private function __construct() {}
464 +
465 + public static function init_actions() {
466 + $block_editor = has_action( 'enqueue_block_assets' );
467 + $gutenberg = function_exists( 'gutenberg_register_scripts_and_styles' );
468 +
469 + register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
470 + register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
471 +
472 + $settings = self::get_settings();
473 +
474 + if ( is_multisite() ) {
475 + add_action( 'wpmu_options', array( __CLASS__, 'network_settings' ) );
476 + add_action( 'update_wpmu_options', array( __CLASS__, 'save_network_settings' ) );
477 + }
478 +
479 + if ( ! $settings['hide-settings-ui'] ) {
480 + // Add a link to the plugin's settings and/or network admin settings in the plugins list table.
481 + add_filter( 'plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
482 + add_filter( 'network_admin_plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
483 +
484 + add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
485 +
486 + if ( $settings['allow-users'] ) {
487 + // User settings.
488 + add_action( 'personal_options_update', array( __CLASS__, 'save_user_settings' ) );
489 + add_action( 'profile_personal_options', array( __CLASS__, 'user_settings' ) );
490 + }
491 + }
492 +
493 + // Always remove the "Try Gutenberg" dashboard widget. See https://core.trac.wordpress.org/ticket/44635.
494 + remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
495 +
496 + if ( ! $block_editor && ! $gutenberg ) {
497 + return;
498 + }
499 +
500 + if ( $settings['allow-users'] ) {
501 + // Also used in Gutenberg.
502 + add_filter( 'use_block_editor_for_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
503 +
504 + if ( $gutenberg ) {
505 + // Support older Gutenberg versions.
506 + add_filter( 'gutenberg_can_edit_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
507 +
508 + if ( $settings['editor'] === 'classic' ) {
509 + self::remove_gutenberg_hooks( 'some' );
510 + }
511 + }
512 +
513 + add_filter( 'get_edit_post_link', array( __CLASS__, 'get_edit_post_link' ) );
514 + add_filter( 'redirect_post_location', array( __CLASS__, 'redirect_location' ) );
515 + add_action( 'edit_form_top', array( __CLASS__, 'add_redirect_helper' ) );
516 + add_action( 'admin_head-edit.php', array( __CLASS__, 'add_edit_php_inline_style' ) );
517 +
518 + add_action( 'edit_form_top', array( __CLASS__, 'remember_classic_editor' ) );
519 + add_filter( 'block_editor_settings', array( __CLASS__, 'remember_block_editor' ), 10, 2 );
520 +
521 + // Post state (edit.php)
522 + add_filter( 'display_post_states', array( __CLASS__, 'add_post_state' ), 10, 2 );
523 + // Row actions (edit.php)
524 + add_filter( 'page_row_actions', array( __CLASS__, 'add_edit_links' ), 15, 2 );
525 + add_filter( 'post_row_actions', array( __CLASS__, 'add_edit_links' ), 15, 2 );
526 +
527 + // Switch editors while editing a post
528 + add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_box' ), 10, 2 );
529 + add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) );
530 + } else {
531 + if ( $settings['editor'] === 'classic' ) {
532 + // Also used in Gutenberg.
533 + // Consider disabling other Block Editor functionality.
534 + add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
535 +
536 + if ( $gutenberg ) {
537 + // Support older Gutenberg versions.
538 + add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 );
539 + self::remove_gutenberg_hooks();
540 + }
541 + } else {
542 + // `$settings['editor'] === 'block'`, nothing to do :)
543 + return;
544 + }
545 + }
546 +
547 + if ( $block_editor ) {
548 + // Move the Privacy Page notice back under the title.
549 + add_action( 'admin_init', array( __CLASS__, 'on_admin_init' ) );
550 + }
551 + if ( $gutenberg ) {
552 + // These are handled by this plugin. All are older, not used in 5.3+.
553 + remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' );
554 + remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' );
555 + remove_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts' );
556 + remove_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state' );
557 + remove_action( 'edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts' );
558 + }
559 + }
560 +
561 + public static function remove_gutenberg_hooks( $remove = 'all' ) {
562 + remove_action( 'admin_menu', 'gutenberg_menu' );
563 + remove_action( 'admin_init', 'gutenberg_redirect_demo' );
564 +
565 + if ( $remove !== 'all' ) {
566 + return;
567 + }
568 +
569 + // Gutenberg 5.3+
570 + remove_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
571 + remove_action( 'admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
572 + remove_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
573 + remove_action( 'rest_api_init', 'gutenberg_register_rest_widget_updater_routes' );
574 + remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' );
575 + remove_action( 'admin_print_scripts', 'gutenberg_block_editor_admin_print_scripts' );
576 + remove_action( 'admin_print_footer_scripts', 'gutenberg_block_editor_admin_print_footer_scripts' );
577 + remove_action( 'admin_footer', 'gutenberg_block_editor_admin_footer' );
578 + remove_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' );
579 + remove_action( 'admin_notices', 'gutenberg_build_files_notice' );
580 +
581 + remove_filter( 'load_script_translation_file', 'gutenberg_override_translation_file' );
582 + remove_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
583 + remove_filter( 'default_content', 'gutenberg_default_demo_content' );
584 + remove_filter( 'default_title', 'gutenberg_default_demo_title' );
585 + remove_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' );
586 + remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
587 +
588 + // Previously used, compat for older Gutenberg versions.
589 + remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
590 + remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
591 + remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
592 +
593 + remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
594 + remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
595 + remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );
596 +
597 + remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save' );
598 + remove_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' );
599 + remove_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' );
600 + remove_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' );
601 + remove_action( 'edit_form_advanced', 'gutenberg_intercept_meta_box_render' );
602 + remove_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect' );
603 + remove_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' );
604 +
605 + remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' );
606 + remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' ); // old
607 + remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' );
608 + remove_filter( 'register_post_type_args', 'gutenberg_filter_post_type_labels' );
609 +
610 + // Keep
611 + // remove_filter( 'wp_kses_allowed_html', 'gutenberg_kses_allowedtags', 10, 2 ); // not needed in 5.0
612 + // remove_filter( 'bulk_actions-edit-wp_block', 'gutenberg_block_bulk_actions' );
613 + // remove_filter( 'wp_insert_post_data', 'gutenberg_remove_wpcom_markdown_support' );
614 + // remove_filter( 'the_content', 'do_blocks', 9 );
615 + // remove_action( 'init', 'gutenberg_register_post_types' );
616 +
617 + // Continue to manage wpautop for posts that were edited in Gutenberg.
618 + // remove_filter( 'wp_editor_settings', 'gutenberg_disable_editor_settings_wpautop' );
619 + // remove_filter( 'the_content', 'gutenberg_wpautop', 8 );
620 +
621 + }
622 +
623 + private static function get_settings( $refresh = 'no' ) {
624 + /**
625 + * Can be used to override the plugin's settings. Always hides the settings UI when used (as users cannot change the settings).
626 + *
627 + * Has to return an associative array with two keys.
628 + * The defaults are:
629 + * 'editor' => 'classic', // Accepted values: 'classic', 'block'.
630 + * 'allow-users' => false,
631 + *
632 + * @param boolean To override the settings return an array with the above keys.
633 + */
634 + $settings = apply_filters( 'classic_editor_plugin_settings', false );
635 +
636 + if ( is_array( $settings ) ) {
637 + return array(
638 + 'editor' => ( isset( $settings['editor'] ) && $settings['editor'] === 'block' ) ? 'block' : 'classic',
639 + 'allow-users' => ! empty( $settings['allow-users'] ),
640 + 'hide-settings-ui' => true,
641 + );
642 + }
643 +
644 + if ( ! empty( self::$settings ) && $refresh === 'no' ) {
645 + return self::$settings;
646 + }
647 +
648 + if ( is_multisite() ) {
649 + $defaults = array(
650 + 'editor' => get_network_option( null, 'classic-editor-replace' ) === 'block' ? 'block' : 'classic',
651 + 'allow-users' => false,
652 + );
653 +
654 + /**
655 + * Filters the default network options.
656 + *
657 + * @param array $defaults The default options array. See `classic_editor_plugin_settings` for supported keys and values.
658 + */
659 + $defaults = apply_filters( 'classic_editor_network_default_settings', $defaults );
660 +
661 + if ( get_network_option( null, 'classic-editor-allow-sites' ) !== 'allow' ) {
662 + // Per-site settings are disabled. Return default network options nad hide the settings UI.
663 + $defaults['hide-settings-ui'] = true;
664 + return $defaults;
665 + }
666 +
667 + // Override with the site options.
668 + $editor_option = get_option( 'classic-editor-replace' );
669 + $allow_users_option = get_option( 'classic-editor-allow-users' );
670 +
671 + if ( $editor_option ) {
672 + $defaults['editor'] = $editor_option;
673 + }
674 + if ( $allow_users_option ) {
675 + $defaults['allow-users'] = ( $allow_users_option === 'allow' );
676 + }
677 +
678 + $editor = ( isset( $defaults['editor'] ) && $defaults['editor'] === 'block' ) ? 'block' : 'classic';
679 + $allow_users = ! empty( $defaults['allow-users'] );
680 + } else {
681 + $allow_users = ( get_option( 'classic-editor-allow-users' ) === 'allow' );
682 + $option = get_option( 'classic-editor-replace' );
683 +
684 + // Normalize old options.
685 + if ( $option === 'block' || $option === 'no-replace' ) {
686 + $editor = 'block';
687 + } else {
688 + // empty( $option ) || $option === 'classic' || $option === 'replace'.
689 + $editor = 'classic';
690 + }
691 + }
692 +
693 + // Override the defaults with the user options.
694 + if ( ( ! isset( $GLOBALS['pagenow'] ) || $GLOBALS['pagenow'] !== 'options-writing.php' ) && $allow_users ) {
695 + $user_options = get_user_option( 'classic-editor-settings' );
696 +
697 + if ( $user_options === 'block' || $user_options === 'classic' ) {
698 + $editor = $user_options;
699 + }
700 + }
701 +
702 + self::$settings = array(
703 + 'editor' => $editor,
704 + 'hide-settings-ui' => false,
705 + 'allow-users' => $allow_users,
706 + );
707 +
708 + return self::$settings;
709 + }
710 +
711 + private static function is_classic( $post_id = 0 ) {
712 + if ( ! $post_id ) {
713 + $post_id = self::get_edited_post_id();
714 + }
715 +
716 + if ( $post_id ) {
717 + $settings = self::get_settings();
718 +
719 + if ( $settings['allow-users'] && ! isset( $_GET['classic-editor__forget'] ) ) {
720 + $which = get_post_meta( $post_id, 'classic-editor-remember', true );
721 +
722 + if ( $which ) {
723 + // The editor choice will be "remembered" when the post is opened in either Classic or Block editor.
724 + if ( 'classic-editor' === $which ) {
725 + return true;
726 + } elseif ( 'block-editor' === $which ) {
727 + return false;
728 + }
729 + }
730 +
731 + return ( ! self::has_blocks( $post_id ) );
732 + }
733 + }
734 +
735 + if ( isset( $_GET['classic-editor'] ) ) {
736 + return true;
737 + }
738 +
739 + return false;
740 + }
741 +
742 + /**
743 + * Get the edited post ID (early) when loading the Edit Post screen.
744 + */
745 + private static function get_edited_post_id() {
746 + if (
747 + ! empty( $_GET['post'] ) &&
748 + ! empty( $_GET['action'] ) &&
749 + $_GET['action'] === 'edit' &&
750 + ! empty( $GLOBALS['pagenow'] ) &&
751 + $GLOBALS['pagenow'] === 'post.php'
752 + ) {
753 + return (int) $_GET['post']; // post_ID
754 + }
755 +
756 + return 0;
757 + }
758 +
759 + public static function register_settings() {
760 + // Add an option to Settings -> Writing
761 + register_setting( 'writing', 'classic-editor-replace', array(
762 + 'sanitize_callback' => array( __CLASS__, 'validate_option_editor' ),
763 + ) );
764 +
765 + register_setting( 'writing', 'classic-editor-allow-users', array(
766 + 'sanitize_callback' => array( __CLASS__, 'validate_option_allow_users' ),
767 + ) );
768 +
769 + add_option_whitelist( array(
770 + 'writing' => array( 'classic-editor-replace', 'classic-editor-allow-users' ),
771 + ) );
772 +
773 + $heading_1 = __( 'Default editor for all users', 'classic-editor' );
774 + $heading_2 = __( 'Allow users to switch editors', 'classic-editor' );
775 +
776 + add_settings_field( 'classic-editor-1', $heading_1, array( __CLASS__, 'settings_1' ), 'writing' );
777 + add_settings_field( 'classic-editor-2', $heading_2, array( __CLASS__, 'settings_2' ), 'writing' );
778 + }
779 +
780 + public static function save_user_settings( $user_id ) {
781 + if (
782 + isset( $_POST['classic-editor-user-settings'] ) &&
783 + isset( $_POST['classic-editor-replace'] ) &&
784 + wp_verify_nonce( $_POST['classic-editor-user-settings'], 'allow-user-settings' )
785 + ) {
786 + $user_id = (int) $user_id;
787 +
788 + if ( $user_id !== get_current_user_id() && ! current_user_can( 'edit_user', $user_id ) ) {
789 + return;
790 + }
791 +
792 + $editor = self::validate_option_editor( $_POST['classic-editor-replace'] );
793 + update_user_option( $user_id, 'classic-editor-settings', $editor );
794 + }
795 + }
796 +
797 + /**
798 + * Validate
799 + */
800 + public static function validate_option_editor( $value ) {
801 + if ( $value === 'block' ) {
802 + return 'block';
803 + }
804 +
805 + return 'classic';
806 + }
807 +
808 + public static function validate_option_allow_users( $value ) {
809 + if ( $value === 'allow' ) {
810 + return 'allow';
811 + }
812 +
813 + return 'disallow';
814 + }
815 +
816 + public static function settings_1() {
817 + $settings = self::get_settings( 'refresh' );
818 +
819 + ?>
820 + <div class="classic-editor-options">
821 + <p>
822 + <input type="radio" name="classic-editor-replace" id="classic-editor-classic" value="classic"<?php if ( $settings['editor'] === 'classic' ) echo ' checked'; ?> />
823 + <label for="classic-editor-classic"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></label>
824 + </p>
825 + <p>
826 + <input type="radio" name="classic-editor-replace" id="classic-editor-block" value="block"<?php if ( $settings['editor'] !== 'classic' ) echo ' checked'; ?> />
827 + <label for="classic-editor-block"><?php _ex( 'Block Editor', 'Editor Name', 'classic-editor' ); ?></label>
828 + </p>
829 + </div>
830 + <script>
831 + jQuery( 'document' ).ready( function( $ ) {
832 + if ( window.location.hash === '#classic-editor-options' ) {
833 + $( '.classic-editor-options' ).closest( 'td' ).addClass( 'highlight' );
834 + }
835 + } );
836 + </script>
837 + <?php
838 + }
839 +
840 + public static function settings_2() {
841 + $settings = self::get_settings( 'refresh' );
842 +
843 + ?>
844 + <div class="classic-editor-options">
845 + <p>
846 + <input type="radio" name="classic-editor-allow-users" id="classic-editor-allow" value="allow"<?php if ( $settings['allow-users'] ) echo ' checked'; ?> />
847 + <label for="classic-editor-allow"><?php _e( 'Yes', 'classic-editor' ); ?></label>
848 + </p>
849 + <p>
850 + <input type="radio" name="classic-editor-allow-users" id="classic-editor-disallow" value="disallow"<?php if ( ! $settings['allow-users'] ) echo ' checked'; ?> />
851 + <label for="classic-editor-disallow"><?php _e( 'No', 'classic-editor' ); ?></label>
852 + </p>
853 + </div>
854 + <?php
855 + }
856 +
857 + /**
858 + * Shown on the Profile page when allowed by admin.
859 + */
860 + public static function user_settings() {
861 + global $user_can_edit;
862 + $settings = self::get_settings( 'update' );
863 +
864 + if (
865 + ! defined( 'IS_PROFILE_PAGE' ) ||
866 + ! IS_PROFILE_PAGE ||
867 + ! $user_can_edit ||
868 + ! $settings['allow-users']
869 + ) {
870 + return;
871 + }
872 +
873 + ?>
874 + <table class="form-table">
875 + <tr class="classic-editor-user-options">
876 + <th scope="row"><?php _e( 'Default Editor', 'classic-editor' ); ?></th>
877 + <td>
878 + <?php wp_nonce_field( 'allow-user-settings', 'classic-editor-user-settings' ); ?>
879 + <?php self::settings_1(); ?>
880 + </td>
881 + </tr>
882 + </table>
883 + <script>jQuery( 'tr.user-rich-editing-wrap' ).before( jQuery( 'tr.classic-editor-user-options' ) );</script>
884 + <?php
885 + }
886 +
887 + public static function network_settings() {
888 + $editor = get_network_option( null, 'classic-editor-replace' );
889 + $is_checked = ( get_network_option( null, 'classic-editor-allow-sites' ) === 'allow' );
890 +
891 + ?>
892 + <h2 id="classic-editor-options"><?php _e( 'Editor Settings', 'classic-editor' ); ?></h2>
893 + <table class="form-table">
894 + <?php wp_nonce_field( 'allow-site-admin-settings', 'classic-editor-network-settings' ); ?>
895 + <tr>
896 + <th scope="row"><?php _e( 'Default editor for all sites', 'classic-editor' ); ?></th>
897 + <td>
898 + <p>
899 + <input type="radio" name="classic-editor-replace" id="classic-editor-classic" value="classic"<?php if ( $editor !== 'block' ) echo ' checked'; ?> />
900 + <label for="classic-editor-classic"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></label>
901 + </p>
902 + <p>
903 + <input type="radio" name="classic-editor-replace" id="classic-editor-block" value="block"<?php if ( $editor === 'block' ) echo ' checked'; ?> />
904 + <label for="classic-editor-block"><?php _ex( 'Block Editor', 'Editor Name', 'classic-editor' ); ?></label>
905 + </p>
906 + </td>
907 + </tr>
908 + <tr>
909 + <th scope="row"><?php _e( 'Change settings', 'classic-editor' ); ?></th>
910 + <td>
911 + <input type="checkbox" name="classic-editor-allow-sites" id="classic-editor-allow-sites" value="allow"<?php if ( $is_checked ) echo ' checked'; ?>>
912 + <label for="classic-editor-allow-sites"><?php _e( 'Allow site admins to change settings', 'classic-editor' ); ?></label>
913 + <p class="description"><?php _e( 'By default the Block Editor is replaced with the Classic Editor and users cannot switch editors.', 'classic-editor' ); ?></p>
914 + </td>
915 + </tr>
916 + </table>
917 + <?php
918 + }
919 +
920 + public static function save_network_settings() {
921 + if (
922 + isset( $_POST['classic-editor-network-settings'] ) &&
923 + current_user_can( 'manage_network_options' ) &&
924 + wp_verify_nonce( $_POST['classic-editor-network-settings'], 'allow-site-admin-settings' )
925 + ) {
926 + if ( isset( $_POST['classic-editor-replace'] ) && $_POST['classic-editor-replace'] === 'block' ) {
927 + update_network_option( null, 'classic-editor-replace', 'block' );
928 + } else {
929 + update_network_option( null, 'classic-editor-replace', 'classic' );
930 + }
931 + if ( isset( $_POST['classic-editor-allow-sites'] ) && $_POST['classic-editor-allow-sites'] === 'allow' ) {
932 + update_network_option( null, 'classic-editor-allow-sites', 'allow' );
933 + } else {
934 + update_network_option( null, 'classic-editor-allow-sites', 'disallow' );
935 + }
936 + }
937 + }
938 +
939 + /**
940 + * Add a hidden field in edit-form-advanced.php
941 + * to help redirect back to the Classic Editor on saving.
942 + */
943 + public static function add_redirect_helper() {
944 + ?>
945 + <input type="hidden" name="classic-editor" value="" />
946 + <?php
947 + }
948 +
949 + /**
950 + * Remember when the Classic Editor was used to edit a post.
951 + */
952 + public static function remember_classic_editor( $post ) {
953 + $post_type = get_post_type( $post );
954 +
955 + if ( $post_type && post_type_supports( $post_type, 'editor' ) ) {
956 + self::remember( $post->ID, 'classic-editor' );
957 + }
958 + }
959 +
960 + /**
961 + * Remember when the Block Editor was used to edit a post.
962 + */
963 + public static function remember_block_editor( $editor_settings, $post ) {
964 + $post_type = get_post_type( $post );
965 +
966 + if ( $post_type && self::can_edit_post_type( $post_type ) ) {
967 + self::remember( $post->ID, 'block-editor' );
968 + }
969 +
970 + return $editor_settings;
971 + }
972 +
973 + private static function remember( $post_id, $editor ) {
974 + if ( get_post_meta( $post_id, 'classic-editor-remember', true ) !== $editor ) {
975 + update_post_meta( $post_id, 'classic-editor-remember', $editor );
976 + }
977 + }
978 +
979 + /**
980 + * Choose which editor to use for a post.
981 + *
982 + * Passes through `$which_editor` for Block Editor (it's sets to `true` but may be changed by another plugin).
983 + *
984 + * @uses `use_block_editor_for_post` filter.
985 + *
986 + * @param boolean $use_block_editor True for Block Editor, false for Classic Editor.
987 + * @param WP_Post $post The post being edited.
988 + * @return boolean True for Block Editor, false for Classic Editor.
989 + */
990 + public static function choose_editor( $use_block_editor, $post ) {
991 + $settings = self::get_settings();
992 + $editors = self::get_enabled_editors_for_post( $post );
993 +
994 + // If no editor is supported, pass through `$use_block_editor`.
995 + if ( ! $editors['block_editor'] && ! $editors['classic_editor'] ) {
996 + return $use_block_editor;
997 + }
998 +
999 + // Open the default editor when no $post and for "Add New" links,
1000 + // or the alternate editor when the user is switching editors.
1001 + if ( empty( $post->ID ) || $post->post_status === 'auto-draft' ) {
1002 + if (
1003 + ( $settings['editor'] === 'classic' && ! isset( $_GET['classic-editor__forget'] ) ) || // Add New
1004 + ( isset( $_GET['classic-editor'] ) && isset( $_GET['classic-editor__forget'] ) ) // Switch to Classic Editor when no draft post.
1005 + ) {
1006 + $use_block_editor = false;
1007 + }
1008 + } elseif ( self::is_classic( $post->ID ) ) {
1009 + $use_block_editor = false;
1010 + }
1011 +
1012 + // Enforce the editor if set by plugins.
1013 + if ( $use_block_editor && ! $editors['block_editor'] ) {
1014 + $use_block_editor = false;
1015 + } elseif ( ! $use_block_editor && ! $editors['classic_editor'] && $editors['block_editor'] ) {
1016 + $use_block_editor = true;
1017 + }
1018 +
1019 + return $use_block_editor;
1020 + }
1021 +
1022 + /**
1023 + * Keep the `classic-editor` query arg through redirects when saving posts.
1024 + */
1025 + public static function redirect_location( $location ) {
1026 + if (
1027 + isset( $_REQUEST['classic-editor'] ) ||
1028 + ( isset( $_POST['_wp_http_referer'] ) && strpos( $_POST['_wp_http_referer'], '&classic-editor' ) !== false )
1029 + ) {
1030 + $location = add_query_arg( 'classic-editor', '', $location );
1031 + }
1032 +
1033 + return $location;
1034 + }
1035 +
1036 + /**
1037 + * Keep the `classic-editor` query arg when looking at revisions.
1038 + */
1039 + public static function get_edit_post_link( $url ) {
1040 + $settings = self::get_settings();
1041 +
1042 + if ( isset( $_REQUEST['classic-editor'] ) || $settings['editor'] === 'classic' ) {
1043 + $url = add_query_arg( 'classic-editor', '', $url );
1044 + }
1045 +
1046 + return $url;
1047 + }
1048 +
1049 + public static function add_meta_box( $post_type, $post ) {
1050 + $editors = self::get_enabled_editors_for_post( $post );
1051 +
1052 + if ( ! $editors['block_editor'] || ! $editors['classic_editor'] ) {
1053 + // Editors cannot be switched.
1054 + return;
1055 + }
1056 +
1057 + $id = 'classic-editor-switch-editor';
1058 + $title = __( 'Editor', 'classic-editor' );
1059 + $callback = array( __CLASS__, 'do_meta_box' );
1060 + $args = array(
1061 + '__back_compat_meta_box' => true,
1062 + );
1063 +
1064 + add_meta_box( $id, $title, $callback, null, 'side', 'default', $args );
1065 + }
1066 +
1067 + public static function do_meta_box( $post ) {
1068 + $edit_url = get_edit_post_link( $post->ID, 'raw' );
1069 +
1070 + // Switching to Block Editor.
1071 + $edit_url = remove_query_arg( 'classic-editor', $edit_url );
1072 + // Forget the previous value when going to a specific editor.
1073 + $edit_url = add_query_arg( 'classic-editor__forget', '', $edit_url );
1074 +
1075 + ?>
1076 + <p style="margin: 1em 0;">
1077 + <a href="<?php echo esc_url( $edit_url ); ?>"><?php _e( 'Switch to Block Editor', 'classic-editor' ); ?></a>
1078 + </p>
1079 + <?php
1080 + }
1081 +
1082 + public static function enqueue_block_editor_scripts() {
1083 + $editors = self::get_enabled_editors_for_post( $GLOBALS['post'] );
1084 +
1085 + if ( ! $editors['classic_editor'] ) {
1086 + // Editor cannot be switched.
1087 + return;
1088 + }
1089 +
1090 + wp_enqueue_script(
1091 + 'classic-editor-plugin',
1092 + plugins_url( 'js/block-editor-plugin.js', __FILE__ ),
1093 + array( 'wp-element', 'wp-components', 'lodash' ),
1094 + '1.4',
1095 + true
1096 + );
1097 +
1098 + wp_localize_script(
1099 + 'classic-editor-plugin',
1100 + 'classicEditorPluginL10n',
1101 + array( 'linkText' => __( 'Switch to Classic Editor', 'classic-editor' ) )
1102 + );
1103 + }
1104 +
1105 + /**
1106 + * Add a link to the settings on the Plugins screen.
1107 + */
1108 + public static function add_settings_link( $links, $file ) {
1109 + $settings = self::get_settings();
1110 +
1111 + if ( $file === 'classic-editor/classic-editor.php' && ! $settings['hide-settings-ui'] && current_user_can( 'manage_options' ) ) {
1112 + if ( current_filter() === 'plugin_action_links' ) {
1113 + $url = admin_url( 'options-writing.php#classic-editor-options' );
1114 + } else {
1115 + $url = admin_url( '/network/settings.php#classic-editor-options' );
1116 + }
1117 +
1118 + // Prevent warnings in PHP 7.0+ when a plugin uses this filter incorrectly.
1119 + $links = (array) $links;
1120 + $links[] = sprintf( '<a href="%s">%s</a>', $url, __( 'Settings', 'classic-editor' ) );
1121 + }
1122 +
1123 + return $links;
1124 + }
1125 +
1126 + private static function can_edit_post_type( $post_type ) {
1127 + $can_edit = false;
1128 +
1129 + if ( function_exists( 'gutenberg_can_edit_post_type' ) ) {
1130 + $can_edit = gutenberg_can_edit_post_type( $post_type );
1131 + } elseif ( function_exists( 'use_block_editor_for_post_type' ) ) {
1132 + $can_edit = use_block_editor_for_post_type( $post_type );
1133 + }
1134 +
1135 + return $can_edit;
1136 + }
1137 +
1138 + /**
1139 + * Checks which editors are enabled for the post type.
1140 + *
1141 + * @param string $post_type The post type.
1142 + * @return array Associative array of the editors and whether they are enabled for the post type.
1143 + */
1144 + private static function get_enabled_editors_for_post_type( $post_type ) {
1145 + if ( isset( self::$supported_post_types[ $post_type ] ) ) {
1146 + return self::$supported_post_types[ $post_type ];
1147 + }
1148 +
1149 + $classic_editor = post_type_supports( $post_type, 'editor' );
1150 + $block_editor = self::can_edit_post_type( $post_type );
1151 +
1152 + $editors = array(
1153 + 'classic_editor' => $classic_editor,
1154 + 'block_editor' => $block_editor,
1155 + );
1156 +
1157 + /**
1158 + * Filters the editors that are enabled for the post type.
1159 + *
1160 + * @param array $editors Associative array of the editors and whether they are enabled for the post type.
1161 + * @param string $post_type The post type.
1162 + */
1163 + $editors = apply_filters( 'classic_editor_enabled_editors_for_post_type', $editors, $post_type );
1164 + self::$supported_post_types[ $post_type ] = $editors;
1165 +
1166 + return $editors;
1167 + }
1168 +
1169 + /**
1170 + * Checks which editors are enabled for the post.
1171 + *
1172 + * @param WP_Post $post The post object.
1173 + * @return array Associative array of the editors and whether they are enabled for the post.
1174 + */
1175 + private static function get_enabled_editors_for_post( $post ) {
1176 + $post_type = get_post_type( $post );
1177 +
1178 + if ( ! $post_type ) {
1179 + return array(
1180 + 'classic_editor' => false,
1181 + 'block_editor' => false,
1182 + );
1183 + }
1184 +
1185 + $editors = self::get_enabled_editors_for_post_type( $post_type );
1186 +
1187 + /**
1188 + * Filters the editors that are enabled for the post.
1189 + *
1190 + * @param array $editors Associative array of the editors and whether they are enabled for the post.
1191 + * @param WP_Post $post The post object.
1192 + */
1193 + return apply_filters( 'classic_editor_enabled_editors_for_post', $editors, $post );
1194 + }
1195 +
1196 + /**
1197 + * Adds links to the post/page screens to edit any post or page in
1198 + * the Classic Editor or Block Editor.
1199 + *
1200 + * @param array $actions Post actions.
1201 + * @param WP_Post $post Edited post.
1202 + * @return array Updated post actions.
1203 + */
1204 + public static function add_edit_links( $actions, $post ) {
1205 + // This is in Gutenberg, don't duplicate it.
1206 + if ( array_key_exists( 'classic', $actions ) ) {
1207 + unset( $actions['classic'] );
1208 + }
1209 +
1210 + if ( ! array_key_exists( 'edit', $actions ) ) {
1211 + return $actions;
1212 + }
1213 +
1214 + $edit_url = get_edit_post_link( $post->ID, 'raw' );
1215 +
1216 + if ( ! $edit_url ) {
1217 + return $actions;
1218 + }
1219 +
1220 + $editors = self::get_enabled_editors_for_post( $post );
1221 +
1222 + // Do not show the links if only one editor is available.
1223 + if ( ! $editors['classic_editor'] || ! $editors['block_editor'] ) {
1224 + return $actions;
1225 + }
1226 +
1227 + // Forget the previous value when going to a specific editor.
1228 + $edit_url = add_query_arg( 'classic-editor__forget', '', $edit_url );
1229 +
1230 + // Build the edit actions. See also: WP_Posts_List_Table::handle_row_actions().
1231 + $title = _draft_or_post_title( $post->ID );
1232 +
1233 + // Link to the Block Editor.
1234 + $url = remove_query_arg( 'classic-editor', $edit_url );
1235 + $text = _x( 'Edit (Block Editor)', 'Editor Name', 'classic-editor' );
1236 + /* translators: %s: post title */
1237 + $label = sprintf( __( 'Edit &#8220;%s&#8221; in the Block Editor', 'classic-editor' ), $title );
1238 + $edit_block = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
1239 +
1240 + // Link to the Classic Editor.
1241 + $url = add_query_arg( 'classic-editor', '', $edit_url );
1242 + $text = _x( 'Edit (Classic Editor)', 'Editor Name', 'classic-editor' );
1243 + /* translators: %s: post title */
1244 + $label = sprintf( __( 'Edit &#8220;%s&#8221; in the Classic Editor', 'classic-editor' ), $title );
1245 + $edit_classic = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
1246 +
1247 + $edit_actions = array(
1248 + 'classic-editor-block' => $edit_block,
1249 + 'classic-editor-classic' => $edit_classic,
1250 + );
1251 +
1252 + // Insert the new Edit actions instead of the Edit action.
1253 + $edit_offset = array_search( 'edit', array_keys( $actions ), true );
1254 + array_splice( $actions, $edit_offset, 1, $edit_actions );
1255 +
1256 + return $actions;
1257 + }
1258 +
1259 + /**
1260 + * Show the editor that will be used in a "post state" in the Posts list table.
1261 + */
1262 + public static function add_post_state( $post_states, $post ) {
1263 + if ( get_post_status( $post ) === 'trash' ) {
1264 + return $post_states;
1265 + }
1266 +
1267 + $editors = self::get_enabled_editors_for_post( $post );
1268 +
1269 + if ( ! $editors['classic_editor'] && ! $editors['block_editor'] ) {
1270 + return $post_states;
1271 + } elseif ( $editors['classic_editor'] && ! $editors['block_editor'] ) {
1272 + // Forced to Classic Editor.
1273 + $state = '<span class="classic-editor-forced-state">' . _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) . '</span>';
1274 + } elseif ( ! $editors['classic_editor'] && $editors['block_editor'] ) {
1275 + // Forced to Block Editor.
1276 + $state = '<span class="classic-editor-forced-state">' . _x( 'Block Editor', 'Editor Name', 'classic-editor' ) . '</span>';
1277 + } else {
1278 + $last_editor = get_post_meta( $post->ID, 'classic-editor-remember', true );
1279 +
1280 + if ( $last_editor ) {
1281 + $is_classic = ( $last_editor === 'classic-editor' );
1282 + } elseif ( ! empty( $post->post_content ) ) {
1283 + $is_classic = ! self::has_blocks( $post->post_content );
1284 + } else {
1285 + $settings = self::get_settings();
1286 + $is_classic = ( $settings['editor'] === 'classic' );
1287 + }
1288 +
1289 + $state = $is_classic ? _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) : _x( 'Block Editor', 'Editor Name', 'classic-editor' );
1290 + }
1291 +
1292 + // Fix PHP 7+ warnings if another plugin returns unexpected type.
1293 + $post_states = (array) $post_states;
1294 + $post_states['classic-editor-plugin'] = $state;
1295 +
1296 + return $post_states;
1297 + }
1298 +
1299 + public static function add_edit_php_inline_style() {
1300 + ?>
1301 + <style>
1302 + .classic-editor-forced-state {
1303 + font-style: italic;
1304 + font-weight: 400;
1305 + color: #72777c;
1306 + font-size: small;
1307 + }
1308 + </style>
1309 + <?php
1310 + }
1311 +
1312 + public static function on_admin_init() {
1313 + global $pagenow;
1314 +
1315 + if ( $pagenow !== 'post.php' ) {
1316 + return;
1317 + }
1318 +
1319 + $settings = self::get_settings();
1320 + $post_id = self::get_edited_post_id();
1321 +
1322 + if ( $post_id && ( $settings['editor'] === 'classic' || self::is_classic( $post_id ) ) ) {
1323 + // Move the Privacy Policy help notice back under the title field.
1324 + remove_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'notice' ) );
1325 + add_action( 'edit_form_after_title', array( 'WP_Privacy_Policy_Content', 'notice' ) );
1326 + }
1327 + }
1328 +
1329 + // Need to support WP < 5.0
1330 + private static function has_blocks( $post = null ) {
1331 + if ( ! is_string( $post ) ) {
1332 + $wp_post = get_post( $post );
1333 +
1334 + if ( $wp_post instanceof WP_Post ) {
1335 + $post = $wp_post->post_content;
1336 + }
1337 + }
1338 +
1339 + return false !== strpos( (string) $post, '<!-- wp:' );
1340 + }
1341 +
1342 + /**
1343 + * Set defaults on activation.
1344 + */
1345 + public static function activate() {
1346 + if ( is_multisite() ) {
1347 + add_network_option( null, 'classic-editor-replace', 'classic' );
1348 + add_network_option( null, 'classic-editor-allow-sites', 'disallow' );
1349 + }
1350 +
1351 + add_option( 'classic-editor-replace', 'classic' );
1352 + add_option( 'classic-editor-allow-users', 'disallow' );
1353 + }
1354 +
1355 + /**
1356 + * Delete the options on uninstall.
1357 + */
1358 + public static function uninstall() {
1359 + if ( is_multisite() ) {
1360 + delete_network_option( null, 'classic-editor-replace' );
1361 + delete_network_option( null, 'classic-editor-allow-sites' );
1362 + }
1363 +
1364 + delete_option( 'classic-editor-replace' );
1365 + delete_option( 'classic-editor-allow-users' );
1366 + }
1367 +}
1368 +
1369 +add_action( 'plugins_loaded', array( 'Classic_Editor', 'init_actions' ) );
1370 +
1371 +endif;
1372
1373 diff --git a/plugins/classic-editor/js/block-editor-plugin.js b/plugins/classic-editor/js/block-editor-plugin.js
1374 new file mode 100644
1375 index 00000000..5b365974
1376 --- /dev/null
1377 +++ b/plugins/classic-editor/js/block-editor-plugin.js
1378 @@ -0,0 +1,23 @@
1379 +( function( wp ) {
1380 + if ( ! wp ) {
1381 + return;
1382 + }
1383 +
1384 + wp.plugins.registerPlugin( 'classic-editor-plugin', {
1385 + render: function() {
1386 + var createElement = wp.element.createElement;
1387 + var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem;
1388 + var url = wp.url.addQueryArgs( document.location.href, { 'classic-editor': '', 'classic-editor__forget': '' } );
1389 + var linkText = lodash.get( window, [ 'classicEditorPluginL10n', 'linkText' ] ) || 'Switch to Classic Editor';
1390 +
1391 + return createElement(
1392 + PluginMoreMenuItem,
1393 + {
1394 + icon: 'editor-kitchensink',
1395 + href: url,
1396 + },
1397 + linkText
1398 + );
1399 + },
1400 + } );
1401 +} )( window.wp );
1402
1403 diff --git a/plugins/classic-editor/readme.txt b/plugins/classic-editor/readme.txt
1404 new file mode 100644
1405 index 00000000..71438f26
1406 --- /dev/null
1407 +++ b/plugins/classic-editor/readme.txt
1408 @@ -0,0 +1,119 @@
1409 +=== Classic Editor ===
1410 +Contributors: wordpressdotorg, azaozz, melchoyce, chanthaboune, alexislloyd, pento, youknowriad, desrosj, luciano-croce
1411 +Tags: gutenberg, disable, disable gutenberg, editor, classic editor, block editor
1412 +Requires at least: 4.9
1413 +Tested up to: 5.3
1414 +Stable tag: 1.4
1415 +Requires PHP: 5.2.4
1416 +License: GPLv2 or later
1417 +License URI: http://www.gnu.org/licenses/gpl-2.0.html
1418 +
1419 +Enables the previous "classic" editor and the old-style Edit Post screen with TinyMCE, Meta Boxes, etc. Supports all plugins that extend this screen.
1420 +
1421 +== Description ==
1422 +
1423 +Classic Editor is an official plugin maintained by the WordPress team that restores the previous ("classic") WordPress editor and the "Edit Post" screen. It makes it possible to use plugins that extend that screen, add old-style meta boxes, or otherwise depend on the previous editor.
1424 +
1425 +Classic Editor is an official WordPress plugin, and will be fully supported and maintained until at least 2022, or as long as is necessary.
1426 +
1427 +At a glance, this plugin adds the following:
1428 +
1429 +* Administrators can select the default editor for all users.
1430 +* Administrators can allow users to change their default editor.
1431 +* When allowed, the users can choose which editor to use for each post.
1432 +* Each post opens in the last editor used regardless of who edited it last. This is important for maintaining a consistent experience when editing content.
1433 +
1434 +In addition, the Classic Editor plugin includes several filters that let other plugins control the settings, and the editor choice per post and per post type.
1435 +
1436 +By default, this plugin hides all functionality available in the new Block Editor ("Gutenberg").
1437 +
1438 +== Changelog ==
1439 +
1440 += 1.5 =
1441 +* Updated for WordPress 5.2 and Gutenberg 5.3+.
1442 +* Enhanced and fixed the "open posts in the last editor used to edit them" logic.
1443 +* Fixed adding post state so it can easily be accessed from other plugins.
1444 +
1445 += 1.4 =
1446 +* On network installations removed the restriction for only network activation.
1447 +* Added support for network administrators to choose the default network-wide editor.
1448 +* Fixed the settings link in the warning on network About screen.
1449 +* Properly added the "Switch to Classic Editor" menu item to the Block Editor menu.
1450 +
1451 += 1.3 =
1452 +* Fixed removal of the "Try Gutenberg" dashboard widget.
1453 +* Fixed condition for displaying of the after upgrade notice on the "What's New" screen. Shown when the Classic Editor is selected and users cannot switch editors.
1454 +
1455 += 1.2 =
1456 +* Fixed switching editors from the Add New (post) screen before a draft post is saved.
1457 +* Fixed typo that was appending the edit URL to the `classic-editor` query var.
1458 +* Changed detecting of WordPress 5.0 to not use version check. Fixes a bug when testing 5.1-alpha.
1459 +* Changed the default value of the option to allow users to switch editors to false.
1460 +* Added disabling of the Gutenberg plugin and lowered the required WordPress version to 4.9.
1461 +* Added `classic_editor_network_default_settings` filter.
1462 +
1463 += 1.1 =
1464 +Fixed a bug where it may attempt to load the Block Editor for post types that do not support editor when users are allowed to switch editors.
1465 +
1466 += 1.0 =
1467 +* Updated for WordPress 5.0.
1468 +* Changed all "Gutenberg" names/references to "Block Editor".
1469 +* Refreshed the settings UI.
1470 +* Removed disabling of the Gutenberg plugin. This was added for testing in WordPress 4.9. Users who want to continue following the development of Gutenberg in WordPress 5.0 and beyond will not need another plugin to disable it.
1471 +* Added support for per-user settings of default editor.
1472 +* Added support for admins to set the default editor for the site.
1473 +* Added support for admins to allow users to change their default editor.
1474 +* Added support for network admins to prevent site admins from changing the default settings.
1475 +* Added support to store the last editor used for each post and open it next time. Enabled when users can choose default editor.
1476 +* Added "post editor state" in the listing of posts on the Posts screen. Shows the editor that will be opened for the post. Enabled when users can choose default editor.
1477 +* Added `classic_editor_enabled_editors_for_post` and `classic_editor_enabled_editors_for_post_type` filters. Can be used by other plugins to control or override the editor used for a particular post of post type.
1478 +* Added `classic_editor_plugin_settings` filter. Can be used by other plugins to override the settings and disable the settings UI.
1479 +
1480 += 0.5 =
1481 +* Updated for Gutenberg 4.1 and WordPress 5.0-beta1.
1482 +* Removed some functionality that now exists in Gutenberg.
1483 +* Fixed redirecting back to the Classic Editor after looking at post revisions.
1484 +
1485 += 0.4 =
1486 +* Fixed removing of the "Try Gutenberg" call-out when the Gutenberg plugin is not activated.
1487 +* Fixed to always show the settings and the settings link in the plugins list table.
1488 +* Updated the readme text.
1489 +
1490 += 0.3 =
1491 +* Updated the option from a checkbox to couple of radio buttons, seems clearer. Thanks to @designsimply for the label text suggestions.
1492 +* Some general updates and cleanup.
1493 +
1494 += 0.2 =
1495 +* Update for Gutenberg 1.9.
1496 +* Remove warning and automatic deactivation when Gutenberg is not active.
1497 +
1498 += 0.1 =
1499 +Initial release.
1500 +
1501 +== Frequently Asked Questions ==
1502 +
1503 += Default settings =
1504 +
1505 +When activated this plugin will restore the previous ("classic") WordPress editor and hide the new Block Editor ("Gutenberg").
1506 +These settings can be changed at the Settings => Writing screen.
1507 +
1508 += Default settings for network installation =
1509 +
1510 +There are two options:
1511 +
1512 +* When network-activated this plugin will set the Classic Editor as default and prevent site administrators and users from changing editors.
1513 +The settings can be changed and default network-wide editor can be selected on the Network Settings screen.
1514 +* When not network-activated each site administrator will be able to activate the plugin and choose options for their users.
1515 +
1516 += Cannot find the "Switch to Classic Editor" link =
1517 +
1518 +It is in the main Block Editor menu, see this [screenshot](https://ps.w.org/classic-editor/assets/screenshot-7.png?rev=2023480).
1519 +
1520 +== Screenshots ==
1521 +1. Admin settings on the Settings -> Writing screen.
1522 +2. User settings on the Profile screen. Visible when the users are allowed to switch editors.
1523 +3. "Action links" to choose alternative editor. Visible when the users are allowed to switch editors.
1524 +4. Link to switch to the Block Editor while editing a post in the Classic Editor. Visible when the users are allowed to switch editors.
1525 +5. Link to switch to the Classic Editor while editing a post in the Block Editor. Visible when the users are allowed to switch editors.
1526 +6. Network settings to select the default editor for the network and allow site admins to change it.
1527 +7. The "Switch to Classic Editor" link.