├── assets ├── icon-128x128.png ├── icon-256x256.png ├── screenshot-1.png ├── screenshot-2.png ├── screenshot-3.png ├── screenshot-4.png ├── screenshot-5.png ├── screenshot-6.png ├── screenshot-7.png ├── banner-1544x500.png ├── banner-772x250.png └── blueprints │ └── blueprint.json ├── js └── block-editor-plugin.js ├── .gitignore ├── readme.txt ├── scripts ├── post.min.js └── post.js ├── LICENSE.md └── classic-editor.php /assets/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/icon-128x128.png -------------------------------------------------------------------------------- /assets/icon-256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/icon-256x256.png -------------------------------------------------------------------------------- /assets/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/screenshot-1.png -------------------------------------------------------------------------------- /assets/screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/screenshot-2.png -------------------------------------------------------------------------------- /assets/screenshot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/screenshot-3.png -------------------------------------------------------------------------------- /assets/screenshot-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/screenshot-4.png -------------------------------------------------------------------------------- /assets/screenshot-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/screenshot-5.png -------------------------------------------------------------------------------- /assets/screenshot-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/screenshot-6.png -------------------------------------------------------------------------------- /assets/screenshot-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/screenshot-7.png -------------------------------------------------------------------------------- /assets/banner-1544x500.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/banner-1544x500.png -------------------------------------------------------------------------------- /assets/banner-772x250.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WordPress/classic-editor/HEAD/assets/banner-772x250.png -------------------------------------------------------------------------------- /js/block-editor-plugin.js: -------------------------------------------------------------------------------- 1 | ( function( wp ) { 2 | if ( ! wp ) { 3 | return; 4 | } 5 | 6 | wp.plugins.registerPlugin( 'classic-editor-plugin', { 7 | render: function() { 8 | var createElement = wp.element.createElement; 9 | var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem; 10 | var url = wp.url.addQueryArgs( document.location.href, { 'classic-editor': '', 'classic-editor__forget': '' } ); 11 | var linkText = lodash.get( window, [ 'classicEditorPluginL10n', 'linkText' ] ) || 'Switch to classic editor'; 12 | 13 | return createElement( 14 | PluginMoreMenuItem, 15 | { 16 | icon: 'editor-kitchensink', 17 | href: url, 18 | }, 19 | linkText 20 | ); 21 | }, 22 | } ); 23 | } )( window.wp ); 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ############ 2 | ## IDEs 3 | ############ 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | *.swp 9 | *~.nib 10 | local.properties 11 | .classpath 12 | .settings/ 13 | .loadpath 14 | .externalToolBuilders/ 15 | *.launch 16 | .cproject 17 | .buildpath 18 | nbproject/ 19 | 20 | ############ 21 | ## Vendor 22 | ############ 23 | 24 | node_modules/ 25 | vendor/ 26 | 27 | ############ 28 | ## OSes 29 | ############ 30 | 31 | [Tt]humbs.db 32 | [Dd]esktop.ini 33 | *.DS_store 34 | .DS_store? 35 | 36 | ############ 37 | ## Misc 38 | ############ 39 | 40 | tests/logs 41 | bin/ 42 | tmp/ 43 | *.tmp 44 | *.bak 45 | *.log 46 | *.[Cc]ache 47 | *.cpr 48 | *.orig 49 | *.php.in 50 | .idea/ 51 | .sass-cache/* 52 | temp/ 53 | ._* 54 | .Trashes 55 | .svn 56 | -------------------------------------------------------------------------------- /assets/blueprints/blueprint.json: -------------------------------------------------------------------------------- 1 | { 2 | "landingPage": "/wp-admin/post-new.php", 3 | "features": { 4 | "networking": true 5 | }, 6 | "steps": [ 7 | { 8 | "step": "login", 9 | "username": "admin", 10 | "password": "password" 11 | }, 12 | { 13 | "step": "installPlugin", 14 | "pluginZipFile": { 15 | "resource": "wordpress.org/plugins", 16 | "slug": "classic-editor" 17 | }, 18 | "options": { 19 | "activate": true 20 | } 21 | }, 22 | { 23 | "step": "writeFile", 24 | "path": "/wordpress/wp-content/mu-plugins/playground-notice.php", 25 | "data": "

This is a live preview of Classic Editor, powered by WordPress Playground.

'; } );" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Classic Editor === 2 | Contributors: wordpressdotorg, azaozz, melchoyce, chanthaboune, alexislloyd, pento, youknowriad, desrosj, luciano-croce, ironprogrammer 3 | Tags: classic editor, block editor, editor, gutenberg 4 | Requires at least: 4.9 5 | Tested up to: 6.9 6 | Stable tag: 1.6.7 7 | Requires PHP: 5.2.4 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Enables the previous "classic" editor and the old-style Edit Post screen with TinyMCE, Meta Boxes, etc. Supports all plugins that extend this screen. 12 | 13 | == Description == 14 | 15 | 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. 16 | 17 | Classic Editor is an official WordPress plugin, and will be fully supported and maintained until 2024, or as long as is necessary. 18 | 19 | At a glance, this plugin adds the following: 20 | 21 | * Administrators can select the default editor for all users. 22 | * Administrators can allow users to change their default editor. 23 | * When allowed, the users can choose which editor to use for each post. 24 | * 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. 25 | 26 | 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. 27 | 28 | By default, this plugin hides all functionality available in the new block editor ("Gutenberg"). 29 | 30 | == Changelog == 31 | 32 | = 1.6.7 = 33 | * Fixed loading of script translations when post.js is replaced in WordPress 6.7.1. 34 | 35 | = 1.6.6 = 36 | * Added fix for selecting/deselecting multiple unwanted categories in WordPress 6.7.1 when clicking on a category checkbox on the old Edit Post screen. 37 | 38 | = 1.6.5 = 39 | * Added fix for Safari 18 negative horizontal margin on floats. 40 | 41 | = 1.6.4 = 42 | * Added support for administrators to choose the default editor for other users. 43 | 44 | = 1.6.3 = 45 | * Added some WPCS fixes, props NicktheGeek on GitHub. 46 | * Updated "Tested up to" in the readme and removed it from classic-editor.php. This should fix false positive errors in security plugins in the future. 47 | 48 | = 1.6.2 = 49 | * Fixed bug that was preventing saving of the last used editor. 50 | 51 | = 1.6.1 = 52 | * Fixed a warning on the block editor based widgets screen. 53 | * Fixed use of a deprecated filter. 54 | 55 | = 1.6 = 56 | * Updated for WordPress 5.5. 57 | * Fixed minor issues with calling deprecated functions, needlessly registering uninstall hook, and capitalization of some strings. 58 | 59 | = 1.5 = 60 | * Updated for WordPress 5.2 and Gutenberg 5.3. 61 | * Enhanced and fixed the "open posts in the last editor used to edit them" logic. 62 | * Fixed adding post state so it can easily be accessed from other plugins. 63 | 64 | = 1.4 = 65 | * On network installations removed the restriction for only network activation. 66 | * Added support for network administrators to choose the default network-wide editor. 67 | * Fixed the settings link in the warning on network About screen. 68 | * Properly added the "Switch to classic editor" menu item to the block editor menu. 69 | 70 | = 1.3 = 71 | * Fixed removal of the "Try Gutenberg" dashboard widget. 72 | * 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. 73 | 74 | = 1.2 = 75 | * Fixed switching editors from the Add New (post) screen before a draft post is saved. 76 | * Fixed typo that was appending the edit URL to the `classic-editor` query var. 77 | * Changed detecting of WordPress 5.0 to not use version check. Fixes a bug when testing 5.1-alpha. 78 | * Changed the default value of the option to allow users to switch editors to false. 79 | * Added disabling of the Gutenberg plugin and lowered the required WordPress version to 4.9. 80 | * Added `classic_editor_network_default_settings` filter. 81 | 82 | = 1.1 = 83 | 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. 84 | 85 | = 1.0 = 86 | * Updated for WordPress 5.0. 87 | * Changed all "Gutenberg" names/references to "block editor". 88 | * Refreshed the settings UI. 89 | * 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. 90 | * Added support for per-user settings of default editor. 91 | * Added support for admins to set the default editor for the site. 92 | * Added support for admins to allow users to change their default editor. 93 | * Added support for network admins to prevent site admins from changing the default settings. 94 | * Added support to store the last editor used for each post and open it next time. Enabled when users can choose default editor. 95 | * 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. 96 | * 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. 97 | * Added `classic_editor_plugin_settings` filter. Can be used by other plugins to override the settings and disable the settings UI. 98 | 99 | = 0.5 = 100 | * Updated for Gutenberg 4.1 and WordPress 5.0-beta1. 101 | * Removed some functionality that now exists in Gutenberg. 102 | * Fixed redirecting back to the classic editor after looking at post revisions. 103 | 104 | = 0.4 = 105 | * Fixed removing of the "Try Gutenberg" call-out when the Gutenberg plugin is not activated. 106 | * Fixed to always show the settings and the settings link in the plugins list table. 107 | * Updated the readme text. 108 | 109 | = 0.3 = 110 | * Updated the option from a checkbox to couple of radio buttons, seems clearer. Thanks to @designsimply for the label text suggestions. 111 | * Some general updates and cleanup. 112 | 113 | = 0.2 = 114 | * Update for Gutenberg 1.9. 115 | * Remove warning and automatic deactivation when Gutenberg is not active. 116 | 117 | = 0.1 = 118 | Initial release. 119 | 120 | == Frequently Asked Questions == 121 | 122 | = Default settings = 123 | 124 | When activated and when using a classic (non-block) theme, this plugin will restore the previous ("classic") WordPress editor and hide the new block editor ("Gutenberg"). 125 | These settings can be changed at the Settings => Writing screen. 126 | 127 | = Default settings for network installation = 128 | 129 | There are two options: 130 | 131 | * When network-activated and when using a classic (non-block) theme, this plugin will set the classic editor as default and prevent site administrators and users from changing editors. 132 | The settings can be changed and default network-wide editor can be selected on the Network Settings screen. 133 | * When not network-activated each site administrator will be able to activate the plugin and choose options for their users. 134 | 135 | = Cannot find the "Switch to classic editor" link = 136 | 137 | It is in the main block editor menu, see this [screenshot](https://ps.w.org/classic-editor/assets/screenshot-7.png?rev=2023480). 138 | 139 | = Does this work with full site editing and block themes? = 140 | 141 | No, as block themes rely on blocks. [See Block themes article](https://wordpress.org/support/article/block-themes/) for more information. 142 | 143 | == Screenshots == 144 | 1. Admin settings on the Settings -> Writing screen. 145 | 2. User settings on the Profile screen. Visible when the users are allowed to switch editors. 146 | 3. "Action links" to choose alternative editor. Visible when the users are allowed to switch editors. 147 | 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. 148 | 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. 149 | 6. Network settings to select the default editor for the network and allow site admins to change it. 150 | 7. The "Switch to classic editor" link. 151 | -------------------------------------------------------------------------------- /scripts/post.min.js: -------------------------------------------------------------------------------- 1 | /*! This file is auto-generated */ 2 | window.makeSlugeditClickable=window.editPermalink=function(){},window.wp=window.wp||{},function(s){var t=!1,a=wp.i18n.__;window.commentsBox={st:0,get:function(t,e){var i=this.st;return this.st+=e=e||20,this.total=t,s("#commentsdiv .spinner").addClass("is-active"),t={action:"get-comments",mode:"single",_ajax_nonce:s("#add_comment_nonce").val(),p:s("#post_ID").val(),start:i,number:e},s.post(ajaxurl,t,function(t){t=wpAjax.parseAjaxResponse(t),s("#commentsdiv .widefat").show(),s("#commentsdiv .spinner").removeClass("is-active"),"object"==typeof t&&t.responses[0]?(s("#the-comment-list").append(t.responses[0].data),theList=theExtraList=null,s("a[className*=':']").off(),commentsBox.st>commentsBox.total?s("#show-comments").hide():s("#show-comments").show().children("a").text(a("Show more comments"))):1==t?s("#show-comments").text(a("No more comments found.")):s("#the-comment-list").append(''+wpAjax.broken+"")}),!1},load:function(t){this.st=jQuery("#the-comment-list tr.comment:visible").length,this.get(t)}},window.WPSetThumbnailHTML=function(t){s(".inside","#postimagediv").html(t)},window.WPSetThumbnailID=function(t){var e=s('input[value="_thumbnail_id"]',"#list-table");0",{class:"avatar avatar-64 photo",width:64,height:64,alt:"",src:e.lock_error.avatar_src,srcset:e.lock_error.avatar_src_2x?e.lock_error.avatar_src_2x+" 2x":void 0}),i.find("div.post-locked-avatar").empty().append(a)),i.show().find(".currently-editing").text(e.lock_error.text),i.find(".wp-tab-first").trigger("focus")):e.new_lock&&s("#active_post_lock").val(e.new_lock))}).on("before-autosave.update-post-slug",function(){t=document.activeElement&&"title"===document.activeElement.id}).on("after-autosave.update-post-slug",function(){s("#edit-slug-box > *").length||t||s.post(ajaxurl,{action:"sample-permalink",post_id:s("#post_ID").val(),new_title:s("#title").val(),samplepermalinknonce:s("#samplepermalinknonce").val()},function(t){"-1"!=t&&s("#edit-slug-box").html(t)})})}(jQuery),function(a){var n,t;function i(){n=!1,window.clearTimeout(t),t=window.setTimeout(function(){n=!0},3e5)}a(function(){i()}).on("heartbeat-send.wp-refresh-nonces",function(t,e){var i=a("#wp-auth-check-wrap");(n||i.length&&!i.hasClass("hidden"))&&(i=a("#post_ID").val())&&a("#_wpnonce").val()&&(e["wp-refresh-post-nonces"]={post_id:i})}).on("heartbeat-tick.wp-refresh-nonces",function(t,e){e=e["wp-refresh-post-nonces"];e&&(i(),e.replace&&a.each(e.replace,function(t,e){a("#"+t).val(e)}),e.heartbeatNonce)&&(window.heartbeatSettings.nonce=e.heartbeatNonce)})}(jQuery),jQuery(function(h){var d,e,i,a,n,s,o,l,r,t,c,p,u=h("#content"),v=h(document),f=h("#post_ID").val()||0,m=h("#submitpost"),w=!0,g=h("#post-visibility-select"),b=h("#timestampdiv"),k=h("#post-status-select"),_=!!window.navigator.platform&&-1!==window.navigator.platform.indexOf("Mac"),y=new ClipboardJS(".copy-attachment-url.edit-media"),x=wp.i18n.__,C=wp.i18n._x;function D(t){c.hasClass("wp-editor-expand")||(r?o.theme.resizeTo(null,l+t.pageY):u.height(Math.max(50,l+t.pageY)),t.preventDefault())}function j(){var t;c.hasClass("wp-editor-expand")||(t=r?(o.focus(),((t=parseInt(h("#wp-content-editor-container .mce-toolbar-grp").height(),10))<10||200 *").length&&(h("form#post").one("submit",function(){t=!0}),window.setTimeout(function(){!t&&wp.autosave&&wp.autosave.server.triggerSave()},200))}),v.on("autosave-disable-buttons.edit-post",function(){i.addClass("disabled")}).on("autosave-enable-buttons.edit-post",function(){wp.heartbeat&&wp.heartbeat.hasConnectionError()||i.removeClass("disabled")}).on("before-autosave.edit-post",function(){h(".autosave-message").text(x("Saving Draft\u2026"))}).on("after-autosave.edit-post",function(t,e){h(".autosave-message").text(e.message),h(document.body).hasClass("post-new-php")&&h(".submitbox .submitdelete").show()}),h(window).on("beforeunload.edit-post",function(t){var e=window.tinymce&&window.tinymce.get("content"),i=!1;if(wp.autosave?i=wp.autosave.server.postChanged():e&&(i=!e.isHidden()&&e.isDirty()),i)return t.preventDefault(),x("The changes you made will be lost if you navigate away from this page.")}).on("pagehide.edit-post",function(t){if(w&&(!t.target||"#document"==t.target.nodeName)){var t=h("#post_ID").val(),e=h("#active_post_lock").val();if(t&&e){t={action:"wp-remove-post-lock",_wpnonce:h("#_wpnonce").val(),post_ID:t,active_post_lock:e};if(window.FormData&&window.navigator.sendBeacon){var i=new window.FormData;if(h.each(t,function(t,e){i.append(t,e)}),window.navigator.sendBeacon(ajaxurl,i))return}h.post({async:!1,data:t,url:ajaxurl})}}}),h("#tagsdiv-post_tag").length?window.tagBox&&window.tagBox.init():h(".meta-box-sortables").children("div.postbox").each(function(){if(0===this.id.indexOf("tagsdiv-"))return window.tagBox&&window.tagBox.init(),!1}),h(".categorydiv").each(function(){var t,a,e,i=h(this).attr("id").split("-");i.shift(),a=i.join("-"),e="category"==a?"cats":a+"_tab",h("a","#"+a+"-tabs").on("click",function(t){t.preventDefault();t=h(this).attr("href");h(this).parent().addClass("tabs").siblings("li").removeClass("tabs"),h("#"+a+"-tabs").siblings(".tabs-panel").hide(),h(t).show(),"#"+a+"-all"==t?deleteUserSetting(e):setUserSetting(e,"pop")}),getUserSetting(e)&&h('a[href="#'+a+'-pop"]',"#"+a+"-tabs").trigger("click"),h("#new"+a).one("focus",function(){h(this).val("").removeClass("form-input-tip")}),h("#new"+a).on("keypress",function(t){13===t.keyCode&&(t.preventDefault(),h("#"+a+"-add-submit").trigger("click"))}),h("#"+a+"-add-submit").on("click",function(){h("#new"+a).trigger("focus")}),i=function(t){return!!h("#new"+a).val()&&(t.data+="&"+h(":checked","#"+a+"checklist").serialize(),h("#"+a+"-add-submit").prop("disabled",!0),t)},t=function(t,e){var i=h("#new"+a+"_parent");h("#"+a+"-add-submit").prop("disabled",!1),"undefined"!=e.parsed.responses[0]&&(e=e.parsed.responses[0].supplemental.newcat_parent)&&(i.before(e),i.remove())},h("#"+a+"checklist").wpList({alt:"",response:a+"-ajax-response",addBefore:i,addAfter:t}),h("#"+a+"-add-toggle").on("click",function(t){t.preventDefault(),h("#"+a+"-adder").toggleClass("wp-hidden-children"),h('a[href="#'+a+'-all"]',"#"+a+"-tabs").trigger("click"),h("#new"+a).trigger("focus")}),h("#"+a+"checklist, #"+a+"checklist-pop").on("click",'li.popular-category > label input[type="checkbox"]',function(){var t=h(this),e=t.is(":checked"),i=t.val();i&&t.parents("#taxonomy-"+a).length&&(h("input#in-"+a+"-"+i+', input[id^="in-'+a+"-"+i+'-"]').prop("checked",e),h("input#in-popular-"+a+"-"+i).prop("checked",e))})}),h("#postcustom").length&&h("#the-list").wpList({addBefore:function(t){return t.data+="&post_id="+h("#post_ID").val(),t},addAfter:function(){h("table#list-table").show()}}),h("#submitdiv").length&&(d=h("#timestamp").html(),e=h("#post-visibility-display").html(),a=function(){"public"!=g.find("input:radio:checked").val()?(h("#sticky").prop("checked",!1),h("#sticky-span").hide()):h("#sticky-span").show(),"password"!=g.find("input:radio:checked").val()?h("#password-span").hide():h("#password-span").show()},n=function(){if(b.length){var t,e=h("#post_status"),i=h('option[value="publish"]',e),a=h("#aa").val(),n=h("#mm").val(),s=h("#jj").val(),o=h("#hh").val(),l=h("#mn").val(),r=new Date(a,n-1,s,o,l),c=new Date(h("#hidden_aa").val(),h("#hidden_mm").val()-1,h("#hidden_jj").val(),h("#hidden_hh").val(),h("#hidden_mn").val()),p=new Date(h("#cur_aa").val(),h("#cur_mm").val()-1,h("#cur_jj").val(),h("#cur_hh").val(),h("#cur_mn").val());if(r.getFullYear()!=a||1+r.getMonth()!=n||r.getDate()!=s||r.getMinutes()!=l)return b.find(".timestamp-wrap").addClass("form-invalid"),!1;b.find(".timestamp-wrap").removeClass("form-invalid"),p"+x("%1$s %2$s, %3$s at %4$s:%5$s").replace("%1$s",h('option[value="'+n+'"]',"#mm").attr("data-text")).replace("%2$s",parseInt(s,10)).replace("%3$s",a).replace("%4$s",("00"+o).slice(-2)).replace("%5$s",("00"+l).slice(-2))+" "),"private"==g.find("input:radio:checked").val()?(h("#publish").val(x("Update")),0===i.length?e.append('"):i.html(x("Privately Published")),h('option[value="publish"]',e).prop("selected",!0),h("#misc-publishing-actions .edit-post-status").hide()):("future"==h("#original_post_status").val()||"draft"==h("#original_post_status").val()?i.length&&(i.remove(),e.val(h("#hidden_post_status").val())):i.html(x("Published")),e.is(":hidden")&&h("#misc-publishing-actions .edit-post-status").show()),h("#post-status-display").text(wp.sanitize.stripTagsAndEncodeText(h("option:selected",e).text())),"private"==h("option:selected",e).val()||"publish"==h("option:selected",e).val()?h("#save-post").hide():(h("#save-post").show(),"pending"==h("option:selected",e).val()?h("#save-post").show().val(x("Save as Pending")):h("#save-post").show().val(x("Save Draft")))}return!0},h("#visibility .edit-visibility").on("click",function(t){t.preventDefault(),g.is(":hidden")&&(a(),g.slideDown("fast",function(){g.find('input[type="radio"]').first().trigger("focus")}),h(this).hide())}),g.find(".cancel-post-visibility").on("click",function(t){g.slideUp("fast"),h("#visibility-radio-"+h("#hidden-post-visibility").val()).prop("checked",!0),h("#post_password").val(h("#hidden-post-password").val()),h("#sticky").prop("checked",h("#hidden-post-sticky").prop("checked")),h("#post-visibility-display").html(e),h("#visibility .edit-visibility").show().trigger("focus"),n(),t.preventDefault()}),g.find(".save-post-visibility").on("click",function(t){var e="",i=g.find("input:radio:checked").val();switch(g.slideUp("fast"),h("#visibility .edit-visibility").show().trigger("focus"),n(),"public"!==i&&h("#sticky").prop("checked",!1),i){case"public":e=h("#sticky").prop("checked")?x("Public, Sticky"):x("Public");break;case"private":e=x("Private");break;case"password":e=x("Password Protected")}h("#post-visibility-display").text(e),t.preventDefault()}),g.find("input:radio").on("change",function(){a()}),b.siblings("a.edit-timestamp").on("click",function(t){b.is(":hidden")&&(b.slideDown("fast",function(){h("input, select",b.find(".timestamp-wrap")).first().trigger("focus")}),h(this).hide()),t.preventDefault()}),b.find(".cancel-timestamp").on("click",function(t){b.slideUp("fast").siblings("a.edit-timestamp").show().trigger("focus"),h("#mm").val(h("#hidden_mm").val()),h("#jj").val(h("#hidden_jj").val()),h("#aa").val(h("#hidden_aa").val()),h("#hh").val(h("#hidden_hh").val()),h("#mn").val(h("#hidden_mn").val()),n(),t.preventDefault()}),b.find(".save-timestamp").on("click",function(t){n()&&(b.slideUp("fast"),b.siblings("a.edit-timestamp").show().trigger("focus")),t.preventDefault()}),h("#post").on("submit",function(t){n()||(t.preventDefault(),b.show(),wp.autosave&&wp.autosave.enableButtons(),h("#publishing-action .spinner").removeClass("is-active"))}),k.siblings("a.edit-post-status").on("click",function(t){k.is(":hidden")&&(k.slideDown("fast",function(){k.find("select").trigger("focus")}),h(this).hide()),t.preventDefault()}),k.find(".save-post-status").on("click",function(t){k.slideUp("fast").siblings("a.edit-post-status").show().trigger("focus"),n(),t.preventDefault()}),k.find(".cancel-post-status").on("click",function(t){k.slideUp("fast").siblings("a.edit-post-status").show().trigger("focus"),h("#post_status").val(h("#hidden_post_status").val()),n(),t.preventDefault()})),h("#titlediv").on("click",".edit-slug",function(){var t,e,a,i,n=0,s=h("#post_name"),o=s.val(),l=h("#sample-permalink"),r=l.html(),c=h("#sample-permalink a").html(),p=h("#edit-slug-buttons"),d=p.html(),u=h("#editable-post-name-full");for(u.find("img").replaceWith(function(){return this.alt}),u=u.html(),l.html(c),a=h("#editable-post-name"),i=a.html(),p.html(' "),p.children(".save").on("click",function(){var i=a.children("input").val();i==h("#editable-post-name-full").text()?p.children(".cancel").trigger("click"):h.post(ajaxurl,{action:"sample-permalink",post_id:f,new_slug:i,new_title:h("#title").val(),samplepermalinknonce:h("#samplepermalinknonce").val()},function(t){var e=h("#edit-slug-box");e.html(t),e.hasClass("hidden")&&e.fadeIn("fast",function(){e.removeClass("hidden")}),p.html(d),l.html(r),s.val(i),h(".edit-slug").trigger("focus"),wp.a11y.speak(x("Permalink saved"))})}),p.children(".cancel").on("click",function(){h("#view-post-btn").show(),a.html(i),p.html(d),l.html(r),s.val(o),h(".edit-slug").trigger("focus")}),t=0;tu.length/4?"":u,e=x("URL Slug"),a.html('').children("input").on("keydown",function(t){var e=t.which;13===e&&(t.preventDefault(),p.children(".save").trigger("click")),27===e&&p.children(".cancel").trigger("click")}).on("keyup",function(){s.val(this.value)}).trigger("focus")}),window.wptitlehint=function(t){var e=h("#"+(t=t||"title")),i=h("#"+t+"-prompt-text");""===e.val()&&i.removeClass("screen-reader-text"),e.on("input",function(){""===this.value?i.removeClass("screen-reader-text"):i.addClass("screen-reader-text")})},wptitlehint(),t=h("#post-status-info"),c=h("#postdivrich"),!u.length||"ontouchstart"in window?h("#content-resize-handle").hide():t.on("mousedown.wp-editor-resize",function(t){(o="undefined"!=typeof tinymce?tinymce.get("content"):o)&&!o.isHidden()?(r=!0,l=h("#content_ifr").height()-t.pageY):(r=!1,l=u.height()-t.pageY,u.trigger("blur")),v.on("mousemove.wp-editor-resize",D).on("mouseup.wp-editor-resize mouseleave.wp-editor-resize",j),t.preventDefault()}).on("mouseup.wp-editor-resize",j),"undefined"!=typeof tinymce&&(h("#post-formats-select input.post-format").on("change.set-editor-class",function(){var t,e,i=this.id;i&&h(this).prop("checked")&&(t=tinymce.get("content"))&&((e=t.getBody()).className=e.className.replace(/\bpost-format-[^ ]+/,""),t.dom.addClass(e,"post-format-0"==i?"post-format-standard":i),h(document).trigger("editor-classchange"))}),h("#page_template").on("change.set-editor-class",function(){var t,e,i=h(this).val()||"";(i=i.substr(i.lastIndexOf("/")+1,i.length).replace(/\.php$/,"").replace(/\./g,"-"))&&(t=tinymce.get("content"))&&((e=t.getBody()).className=e.className.replace(/\bpage-template-[^ ]+/,""),t.dom.addClass(e,"page-template-"+i),h(document).trigger("editor-classchange"))})),u.on("keydown.wp-autosave",function(t){83!==t.which||t.shiftKey||t.altKey||_&&(!t.metaKey||t.ctrlKey)||!_&&!t.ctrlKey||(wp.autosave&&wp.autosave.server.triggerSave(),t.preventDefault())}),"auto-draft"===h("#original_post_status").val()&&window.history.replaceState&&h("#publish").on("click",function(){p=(p=window.location.href)+(-1!==p.indexOf("?")?"&":"?")+"wp-post-new-reload=true",window.history.replaceState(null,null,p)}),y.on("success",function(t){var e=h(t.trigger),i=h(".success",e.closest(".copy-to-clipboard-container"));t.clearSelection(),clearTimeout(s),i.removeClass("hidden"),s=setTimeout(function(){i.addClass("hidden")},3e3),wp.a11y.speak(x("The file URL has been copied to your clipboard"))})}),function(t,o){t(function(){var i,e=t("#content"),a=t("#wp-word-count").find(".word-count"),n=0;function s(){var t=!i||i.isHidden()?e.val():i.getContent({format:"raw"}),t=o.count(t);t!==n&&a.text(t),n=t}t(document).on("tinymce-editor-init",function(t,e){"content"===e.id&&(i=e).on("nodechange keyup",_.debounce(s,1e3))}),e.on("input keyup",_.debounce(s,1e3)),s()})}(jQuery,new wp.utils.WordCounter); -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ### WordPress - Web publishing software 2 | 3 | Copyright 2011-2019 by the contributors 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | This program incorporates work covered by the following copyright and 20 | permission notices: 21 | 22 | b2 is (c) 2001, 2002 Michel Valdrighi - m@tidakada.com - 23 | http://tidakada.com 24 | 25 | Wherever third party code has been used, credit has been given in the code's 26 | comments. 27 | 28 | b2 is released under the GPL 29 | 30 | and 31 | 32 | WordPress - Web publishing software 33 | 34 | Copyright 2003-2010 by the contributors 35 | 36 | WordPress is released under the GPL 37 | 38 | --- 39 | 40 | ### GNU GENERAL PUBLIC LICENSE 41 | 42 | Version 2, June 1991 43 | 44 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 45 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 46 | 47 | Everyone is permitted to copy and distribute verbatim copies 48 | of this license document, but changing it is not allowed. 49 | 50 | ### Preamble 51 | 52 | The licenses for most software are designed to take away your freedom 53 | to share and change it. By contrast, the GNU General Public License is 54 | intended to guarantee your freedom to share and change free 55 | software--to make sure the software is free for all its users. This 56 | General Public License applies to most of the Free Software 57 | Foundation's software and to any other program whose authors commit to 58 | using it. (Some other Free Software Foundation software is covered by 59 | the GNU Lesser General Public License instead.) You can apply it to 60 | your programs, too. 61 | 62 | When we speak of free software, we are referring to freedom, not 63 | price. Our General Public Licenses are designed to make sure that you 64 | have the freedom to distribute copies of free software (and charge for 65 | this service if you wish), that you receive source code or can get it 66 | if you want it, that you can change the software or use pieces of it 67 | in new free programs; and that you know you can do these things. 68 | 69 | To protect your rights, we need to make restrictions that forbid 70 | anyone to deny you these rights or to ask you to surrender the rights. 71 | These restrictions translate to certain responsibilities for you if 72 | you distribute copies of the software, or if you modify it. 73 | 74 | For example, if you distribute copies of such a program, whether 75 | gratis or for a fee, you must give the recipients all the rights that 76 | you have. You must make sure that they, too, receive or can get the 77 | source code. And you must show them these terms so they know their 78 | rights. 79 | 80 | We protect your rights with two steps: (1) copyright the software, and 81 | (2) offer you this license which gives you legal permission to copy, 82 | distribute and/or modify the software. 83 | 84 | Also, for each author's protection and ours, we want to make certain 85 | that everyone understands that there is no warranty for this free 86 | software. If the software is modified by someone else and passed on, 87 | we want its recipients to know that what they have is not the 88 | original, so that any problems introduced by others will not reflect 89 | on the original authors' reputations. 90 | 91 | Finally, any free program is threatened constantly by software 92 | patents. We wish to avoid the danger that redistributors of a free 93 | program will individually obtain patent licenses, in effect making the 94 | program proprietary. To prevent this, we have made it clear that any 95 | patent must be licensed for everyone's free use or not licensed at 96 | all. 97 | 98 | The precise terms and conditions for copying, distribution and 99 | modification follow. 100 | 101 | ### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 102 | 103 | **0.** This License applies to any program or other work which 104 | contains a notice placed by the copyright holder saying it may be 105 | distributed under the terms of this General Public License. The 106 | "Program", below, refers to any such program or work, and a "work 107 | based on the Program" means either the Program or any derivative work 108 | under copyright law: that is to say, a work containing the Program or 109 | a portion of it, either verbatim or with modifications and/or 110 | translated into another language. (Hereinafter, translation is 111 | included without limitation in the term "modification".) Each licensee 112 | is addressed as "you". 113 | 114 | Activities other than copying, distribution and modification are not 115 | covered by this License; they are outside its scope. The act of 116 | running the Program is not restricted, and the output from the Program 117 | is covered only if its contents constitute a work based on the Program 118 | (independent of having been made by running the Program). Whether that 119 | is true depends on what the Program does. 120 | 121 | **1.** You may copy and distribute verbatim copies of the Program's 122 | source code as you receive it, in any medium, provided that you 123 | conspicuously and appropriately publish on each copy an appropriate 124 | copyright notice and disclaimer of warranty; keep intact all the 125 | notices that refer to this License and to the absence of any warranty; 126 | and give any other recipients of the Program a copy of this License 127 | along with the Program. 128 | 129 | You may charge a fee for the physical act of transferring a copy, and 130 | you may at your option offer warranty protection in exchange for a 131 | fee. 132 | 133 | **2.** You may modify your copy or copies of the Program or any 134 | portion of it, thus forming a work based on the Program, and copy and 135 | distribute such modifications or work under the terms of Section 1 136 | above, provided that you also meet all of these conditions: 137 | 138 | 139 | **a)** You must cause the modified files to carry prominent notices 140 | stating that you changed the files and the date of any change. 141 | 142 | 143 | **b)** You must cause any work that you distribute or publish, that in 144 | whole or in part contains or is derived from the Program or any part 145 | thereof, to be licensed as a whole at no charge to all third parties 146 | under the terms of this License. 147 | 148 | 149 | **c)** If the modified program normally reads commands interactively 150 | when run, you must cause it, when started running for such interactive 151 | use in the most ordinary way, to print or display an announcement 152 | including an appropriate copyright notice and a notice that there is 153 | no warranty (or else, saying that you provide a warranty) and that 154 | users may redistribute the program under these conditions, and telling 155 | the user how to view a copy of this License. (Exception: if the 156 | Program itself is interactive but does not normally print such an 157 | announcement, your work based on the Program is not required to print 158 | an announcement.) 159 | 160 | These requirements apply to the modified work as a whole. If 161 | identifiable sections of that work are not derived from the Program, 162 | and can be reasonably considered independent and separate works in 163 | themselves, then this License, and its terms, do not apply to those 164 | sections when you distribute them as separate works. But when you 165 | distribute the same sections as part of a whole which is a work based 166 | on the Program, the distribution of the whole must be on the terms of 167 | this License, whose permissions for other licensees extend to the 168 | entire whole, and thus to each and every part regardless of who wrote 169 | it. 170 | 171 | Thus, it is not the intent of this section to claim rights or contest 172 | your rights to work written entirely by you; rather, the intent is to 173 | exercise the right to control the distribution of derivative or 174 | collective works based on the Program. 175 | 176 | In addition, mere aggregation of another work not based on the Program 177 | with the Program (or with a work based on the Program) on a volume of 178 | a storage or distribution medium does not bring the other work under 179 | the scope of this License. 180 | 181 | **3.** You may copy and distribute the Program (or a work based on it, 182 | under Section 2) in object code or executable form under the terms of 183 | Sections 1 and 2 above provided that you also do one of the following: 184 | 185 | 186 | **a)** Accompany it with the complete corresponding machine-readable 187 | source code, which must be distributed under the terms of Sections 1 188 | and 2 above on a medium customarily used for software interchange; or, 189 | 190 | 191 | **b)** Accompany it with a written offer, valid for at least three 192 | years, to give any third party, for a charge no more than your cost of 193 | physically performing source distribution, a complete machine-readable 194 | copy of the corresponding source code, to be distributed under the 195 | terms of Sections 1 and 2 above on a medium customarily used for 196 | software interchange; or, 197 | 198 | 199 | **c)** Accompany it with the information you received as to the offer 200 | to distribute corresponding source code. (This alternative is allowed 201 | only for noncommercial distribution and only if you received the 202 | program in object code or executable form with such an offer, in 203 | accord with Subsection b above.) 204 | 205 | The source code for a work means the preferred form of the work for 206 | making modifications to it. For an executable work, complete source 207 | code means all the source code for all modules it contains, plus any 208 | associated interface definition files, plus the scripts used to 209 | control compilation and installation of the executable. However, as a 210 | special exception, the source code distributed need not include 211 | anything that is normally distributed (in either source or binary 212 | form) with the major components (compiler, kernel, and so on) of the 213 | operating system on which the executable runs, unless that component 214 | itself accompanies the executable. 215 | 216 | If distribution of executable or object code is made by offering 217 | access to copy from a designated place, then offering equivalent 218 | access to copy the source code from the same place counts as 219 | distribution of the source code, even though third parties are not 220 | compelled to copy the source along with the object code. 221 | 222 | **4.** You may not copy, modify, sublicense, or distribute the Program 223 | except as expressly provided under this License. Any attempt otherwise 224 | to copy, modify, sublicense or distribute the Program is void, and 225 | will automatically terminate your rights under this License. However, 226 | parties who have received copies, or rights, from you under this 227 | License will not have their licenses terminated so long as such 228 | parties remain in full compliance. 229 | 230 | **5.** You are not required to accept this License, since you have not 231 | signed it. However, nothing else grants you permission to modify or 232 | distribute the Program or its derivative works. These actions are 233 | prohibited by law if you do not accept this License. Therefore, by 234 | modifying or distributing the Program (or any work based on the 235 | Program), you indicate your acceptance of this License to do so, and 236 | all its terms and conditions for copying, distributing or modifying 237 | the Program or works based on it. 238 | 239 | **6.** Each time you redistribute the Program (or any work based on 240 | the Program), the recipient automatically receives a license from the 241 | original licensor to copy, distribute or modify the Program subject to 242 | these terms and conditions. You may not impose any further 243 | restrictions on the recipients' exercise of the rights granted herein. 244 | You are not responsible for enforcing compliance by third parties to 245 | this License. 246 | 247 | **7.** If, as a consequence of a court judgment or allegation of 248 | patent infringement or for any other reason (not limited to patent 249 | issues), conditions are imposed on you (whether by court order, 250 | agreement or otherwise) that contradict the conditions of this 251 | License, they do not excuse you from the conditions of this License. 252 | If you cannot distribute so as to satisfy simultaneously your 253 | obligations under this License and any other pertinent obligations, 254 | then as a consequence you may not distribute the Program at all. For 255 | example, if a patent license would not permit royalty-free 256 | redistribution of the Program by all those who receive copies directly 257 | or indirectly through you, then the only way you could satisfy both it 258 | and this License would be to refrain entirely from distribution of the 259 | Program. 260 | 261 | If any portion of this section is held invalid or unenforceable under 262 | any particular circumstance, the balance of the section is intended to 263 | apply and the section as a whole is intended to apply in other 264 | circumstances. 265 | 266 | It is not the purpose of this section to induce you to infringe any 267 | patents or other property right claims or to contest validity of any 268 | such claims; this section has the sole purpose of protecting the 269 | integrity of the free software distribution system, which is 270 | implemented by public license practices. Many people have made 271 | generous contributions to the wide range of software distributed 272 | through that system in reliance on consistent application of that 273 | system; it is up to the author/donor to decide if he or she is willing 274 | to distribute software through any other system and a licensee cannot 275 | impose that choice. 276 | 277 | This section is intended to make thoroughly clear what is believed to 278 | be a consequence of the rest of this License. 279 | 280 | **8.** If the distribution and/or use of the Program is restricted in 281 | certain countries either by patents or by copyrighted interfaces, the 282 | original copyright holder who places the Program under this License 283 | may add an explicit geographical distribution limitation excluding 284 | those countries, so that distribution is permitted only in or among 285 | countries not thus excluded. In such case, this License incorporates 286 | the limitation as if written in the body of this License. 287 | 288 | **9.** The Free Software Foundation may publish revised and/or new 289 | versions of the General Public License from time to time. Such new 290 | versions will be similar in spirit to the present version, but may 291 | differ in detail to address new problems or concerns. 292 | 293 | Each version is given a distinguishing version number. If the Program 294 | specifies a version number of this License which applies to it and 295 | "any later version", you have the option of following the terms and 296 | conditions either of that version or of any later version published by 297 | the Free Software Foundation. If the Program does not specify a 298 | version number of this License, you may choose any version ever 299 | published by the Free Software Foundation. 300 | 301 | **10.** If you wish to incorporate parts of the Program into other 302 | free programs whose distribution conditions are different, write to 303 | the author to ask for permission. For software which is copyrighted by 304 | the Free Software Foundation, write to the Free Software Foundation; 305 | we sometimes make exceptions for this. Our decision will be guided by 306 | the two goals of preserving the free status of all derivatives of our 307 | free software and of promoting the sharing and reuse of software 308 | generally. 309 | 310 | **NO WARRANTY** 311 | 312 | **11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO 313 | WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 314 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 315 | OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY 316 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 317 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 318 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 319 | PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME 320 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 321 | 322 | **12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 323 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 324 | AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU 325 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 326 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 327 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 328 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 329 | FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF 330 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 331 | DAMAGES. 332 | 333 | ### END OF TERMS AND CONDITIONS 334 | 335 | ### How to Apply These Terms to Your New Programs 336 | 337 | If you develop a new program, and you want it to be of the greatest 338 | possible use to the public, the best way to achieve this is to make it 339 | free software which everyone can redistribute and change under these 340 | terms. 341 | 342 | To do so, attach the following notices to the program. It is safest to 343 | attach them to the start of each source file to most effectively 344 | convey the exclusion of warranty; and each file should have at least 345 | the "copyright" line and a pointer to where the full notice is found. 346 | 347 | one line to give the program's name and an idea of what it does. 348 | Copyright (C) yyyy name of author 349 | 350 | This program is free software; you can redistribute it and/or 351 | modify it under the terms of the GNU General Public License 352 | as published by the Free Software Foundation; either version 2 353 | of the License, or (at your option) any later version. 354 | 355 | This program is distributed in the hope that it will be useful, 356 | but WITHOUT ANY WARRANTY; without even the implied warranty of 357 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 358 | GNU General Public License for more details. 359 | 360 | You should have received a copy of the GNU General Public License 361 | along with this program; if not, write to the Free Software 362 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 363 | 364 | Also add information on how to contact you by electronic and paper 365 | mail. 366 | 367 | If the program is interactive, make it output a short notice like this 368 | when it starts in an interactive mode: 369 | 370 | Gnomovision version 69, Copyright (C) year name of author 371 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details 372 | type `show w'. This is free software, and you are welcome 373 | to redistribute it under certain conditions; type `show c' 374 | for details. 375 | 376 | The hypothetical commands \`show w' and \`show c' should show the 377 | appropriate parts of the General Public License. Of course, the 378 | commands you use may be called something other than \`show w' and 379 | \`show c'; they could even be mouse-clicks or menu items--whatever 380 | suits your program. 381 | 382 | You should also get your employer (if you work as a programmer) or 383 | your school, if any, to sign a "copyright disclaimer" for the program, 384 | if necessary. Here is a sample; alter the names: 385 | 386 | Yoyodyne, Inc., hereby disclaims all copyright 387 | interest in the program `Gnomovision' 388 | (which makes passes at compilers) written 389 | by James Hacker. 390 | 391 | signature of Ty Coon, 1 April 1989 392 | Ty Coon, President of Vice 393 | 394 | This General Public License does not permit incorporating your program 395 | into proprietary programs. If your program is a subroutine library, 396 | you may consider it more useful to permit linking proprietary 397 | applications with the library. If this is what you want to do, use the 398 | [GNU Lesser General Public 399 | License](http://www.gnu.org/licenses/lgpl.html) instead of this 400 | License. 401 | -------------------------------------------------------------------------------- /classic-editor.php: -------------------------------------------------------------------------------- 1 | =' ) ) { 104 | add_filter( 'block_editor_settings_all', array( __CLASS__, 'remember_block_editor' ), 10, 2 ); 105 | } else { 106 | add_filter( 'block_editor_settings', array( __CLASS__, 'remember_block_editor' ), 10, 2 ); 107 | } 108 | 109 | // Post state (edit.php) 110 | add_filter( 'display_post_states', array( __CLASS__, 'add_post_state' ), 10, 2 ); 111 | // Row actions (edit.php) 112 | add_filter( 'page_row_actions', array( __CLASS__, 'add_edit_links' ), 15, 2 ); 113 | add_filter( 'post_row_actions', array( __CLASS__, 'add_edit_links' ), 15, 2 ); 114 | 115 | // Switch editors while editing a post 116 | add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_box' ), 10, 2 ); 117 | add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) ); 118 | } else { 119 | if ( $settings['editor'] === 'classic' ) { 120 | // Also used in Gutenberg. 121 | // Consider disabling other Block Editor functionality. 122 | add_filter( 'use_block_editor_for_post_type', '__return_false', 100 ); 123 | 124 | if ( $gutenberg ) { 125 | // Support older Gutenberg versions. 126 | add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 ); 127 | self::remove_gutenberg_hooks(); 128 | } 129 | } else { 130 | // $settings['editor'] === 'block', nothing to do :) 131 | return; 132 | } 133 | } 134 | 135 | if ( $block_editor ) { 136 | // Move the Privacy Page notice back under the title. 137 | add_action( 'admin_init', array( __CLASS__, 'on_admin_init' ) ); 138 | } 139 | if ( $gutenberg ) { 140 | // These are handled by this plugin. All are older, not used in 5.3+. 141 | remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' ); 142 | remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' ); 143 | remove_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts' ); 144 | remove_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state' ); 145 | remove_action( 'edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts' ); 146 | } 147 | } 148 | 149 | public static function remove_gutenberg_hooks( $remove = 'all' ) { 150 | remove_action( 'admin_menu', 'gutenberg_menu' ); 151 | remove_action( 'admin_init', 'gutenberg_redirect_demo' ); 152 | 153 | if ( $remove !== 'all' ) { 154 | return; 155 | } 156 | 157 | // Gutenberg 5.3+ 158 | remove_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles' ); 159 | remove_action( 'admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles' ); 160 | remove_action( 'admin_notices', 'gutenberg_wordpress_version_notice' ); 161 | remove_action( 'rest_api_init', 'gutenberg_register_rest_widget_updater_routes' ); 162 | remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' ); 163 | remove_action( 'admin_print_scripts', 'gutenberg_block_editor_admin_print_scripts' ); 164 | remove_action( 'admin_print_footer_scripts', 'gutenberg_block_editor_admin_print_footer_scripts' ); 165 | remove_action( 'admin_footer', 'gutenberg_block_editor_admin_footer' ); 166 | remove_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' ); 167 | remove_action( 'admin_notices', 'gutenberg_build_files_notice' ); 168 | 169 | remove_filter( 'load_script_translation_file', 'gutenberg_override_translation_file' ); 170 | remove_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' ); 171 | remove_filter( 'default_content', 'gutenberg_default_demo_content' ); 172 | remove_filter( 'default_title', 'gutenberg_default_demo_title' ); 173 | remove_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' ); 174 | remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' ); 175 | 176 | // Previously used, compat for older Gutenberg versions. 177 | remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' ); 178 | remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' ); 179 | remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' ); 180 | 181 | remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' ); 182 | remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' ); 183 | remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' ); 184 | 185 | remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save' ); 186 | remove_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' ); 187 | remove_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' ); 188 | remove_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' ); 189 | remove_action( 'edit_form_advanced', 'gutenberg_intercept_meta_box_render' ); 190 | remove_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect' ); 191 | remove_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' ); 192 | 193 | remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' ); 194 | remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' ); // old 195 | remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' ); 196 | remove_filter( 'register_post_type_args', 'gutenberg_filter_post_type_labels' ); 197 | 198 | // phpcs:disable Squiz.PHP.CommentedOutCode.Found 199 | // Keep 200 | // remove_filter( 'wp_kses_allowed_html', 'gutenberg_kses_allowedtags', 10, 2 ); // not needed in 5.0 201 | // remove_filter( 'bulk_actions-edit-wp_block', 'gutenberg_block_bulk_actions' ); 202 | // remove_filter( 'wp_insert_post_data', 'gutenberg_remove_wpcom_markdown_support' ); 203 | // remove_filter( 'the_content', 'do_blocks', 9 ); 204 | // remove_action( 'init', 'gutenberg_register_post_types' ); 205 | 206 | // Continue to manage wpautop for posts that were edited in Gutenberg. 207 | // remove_filter( 'wp_editor_settings', 'gutenberg_disable_editor_settings_wpautop' ); 208 | // remove_filter( 'the_content', 'gutenberg_wpautop', 8 ); 209 | // phpcs:enable Squiz.PHP.CommentedOutCode.Found 210 | 211 | } 212 | 213 | private static function get_settings( $refresh = 'no', $user_id = 0 ) { 214 | /** 215 | * Can be used to override the plugin's settings. Always hides the settings UI when used (as users cannot change the settings). 216 | * 217 | * Has to return an associative array with two keys. 218 | * The defaults are: 219 | * 'editor' => 'classic', // Accepted values: 'classic', 'block'. 220 | * 'allow-users' => false, 221 | * 222 | * @param boolean To override the settings return an array with the above keys. Default false. 223 | */ 224 | $settings = apply_filters( 'classic_editor_plugin_settings', false ); 225 | 226 | if ( is_array( $settings ) ) { 227 | return array( 228 | 'editor' => ( isset( $settings['editor'] ) && $settings['editor'] === 'block' ) ? 'block' : 'classic', 229 | 'allow-users' => ! empty( $settings['allow-users'] ), 230 | 'hide-settings-ui' => true, 231 | ); 232 | } 233 | 234 | if ( ! empty( self::$settings ) && $refresh === 'no' ) { 235 | return self::$settings; 236 | } 237 | 238 | if ( is_multisite() ) { 239 | $defaults = array( 240 | 'editor' => get_network_option( null, 'classic-editor-replace' ) === 'block' ? 'block' : 'classic', 241 | 'allow-users' => false, 242 | ); 243 | 244 | /** 245 | * Filters the default network options. 246 | * 247 | * @param array $defaults The default options array. See `classic_editor_plugin_settings` for supported keys and values. 248 | */ 249 | $defaults = apply_filters( 'classic_editor_network_default_settings', $defaults ); 250 | 251 | if ( get_network_option( null, 'classic-editor-allow-sites' ) !== 'allow' ) { 252 | // Per-site settings are disabled. Return default network options nad hide the settings UI. 253 | $defaults['hide-settings-ui'] = true; 254 | return $defaults; 255 | } 256 | 257 | // Override with the site options. 258 | $editor_option = get_option( 'classic-editor-replace' ); 259 | $allow_users_option = get_option( 'classic-editor-allow-users' ); 260 | 261 | if ( $editor_option ) { 262 | $defaults['editor'] = $editor_option; 263 | } 264 | if ( $allow_users_option ) { 265 | $defaults['allow-users'] = ( $allow_users_option === 'allow' ); 266 | } 267 | 268 | $editor = ( isset( $defaults['editor'] ) && $defaults['editor'] === 'block' ) ? 'block' : 'classic'; 269 | $allow_users = ! empty( $defaults['allow-users'] ); 270 | } else { 271 | $allow_users = ( get_option( 'classic-editor-allow-users' ) === 'allow' ); 272 | $option = get_option( 'classic-editor-replace' ); 273 | 274 | // Normalize old options. 275 | if ( $option === 'block' || $option === 'no-replace' ) { 276 | $editor = 'block'; 277 | } else { 278 | // empty( $option ) || $option === 'classic' || $option === 'replace' 279 | $editor = 'classic'; 280 | } 281 | } 282 | 283 | // Override the defaults with the user options. 284 | if ( ( ! isset( $GLOBALS['pagenow'] ) || $GLOBALS['pagenow'] !== 'options-writing.php' ) && $allow_users ) { 285 | 286 | $user_options = get_user_option( 'classic-editor-settings', $user_id ); 287 | 288 | if ( $user_options === 'block' || $user_options === 'classic' ) { 289 | $editor = $user_options; 290 | } 291 | } 292 | 293 | self::$settings = array( 294 | 'editor' => $editor, 295 | 'hide-settings-ui' => false, 296 | 'allow-users' => $allow_users, 297 | ); 298 | 299 | return self::$settings; 300 | } 301 | 302 | private static function is_classic( $post_id = 0 ) { 303 | if ( ! $post_id ) { 304 | $post_id = self::get_edited_post_id(); 305 | } 306 | 307 | if ( $post_id ) { 308 | $settings = self::get_settings(); 309 | 310 | if ( $settings['allow-users'] && ! isset( $_GET['classic-editor__forget'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended 311 | $which = get_post_meta( $post_id, 'classic-editor-remember', true ); 312 | 313 | if ( $which ) { 314 | // The editor choice will be "remembered" when the post is opened in either the classic or the block editor. 315 | if ( 'classic-editor' === $which ) { 316 | return true; 317 | } elseif ( 'block-editor' === $which ) { 318 | return false; 319 | } 320 | } 321 | 322 | return ( ! self::has_blocks( $post_id ) ); 323 | } 324 | } 325 | 326 | if ( isset( $_GET['classic-editor'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended 327 | return true; 328 | } 329 | 330 | return false; 331 | } 332 | 333 | /** 334 | * Get the edited post ID (early) when loading the Edit Post screen. 335 | */ 336 | private static function get_edited_post_id() { 337 | // phpcs:disable WordPress.Security.NonceVerification.Recommended 338 | if ( 339 | ! empty( $_GET['post'] ) && 340 | ! empty( $_GET['action'] ) && 341 | $_GET['action'] === 'edit' && 342 | ! empty( $GLOBALS['pagenow'] ) && 343 | $GLOBALS['pagenow'] === 'post.php' 344 | ) { 345 | return (int) $_GET['post']; // post_ID 346 | } 347 | // phpcs:enable WordPress.Security.NonceVerification.Recommended 348 | 349 | return 0; 350 | } 351 | 352 | public static function register_settings() { 353 | // Add an option to Settings -> Writing 354 | register_setting( 'writing', 'classic-editor-replace', array( 355 | 'sanitize_callback' => array( __CLASS__, 'validate_option_editor' ), 356 | ) ); 357 | 358 | register_setting( 'writing', 'classic-editor-allow-users', array( 359 | 'sanitize_callback' => array( __CLASS__, 'validate_option_allow_users' ), 360 | ) ); 361 | 362 | $allowed_options = array( 363 | 'writing' => array( 364 | 'classic-editor-replace', 365 | 'classic-editor-allow-users' 366 | ), 367 | ); 368 | 369 | if ( function_exists( 'add_allowed_options' ) ) { 370 | add_allowed_options( $allowed_options ); 371 | } else { 372 | add_option_whitelist( $allowed_options ); 373 | } 374 | 375 | $heading_1 = __( 'Default editor for all users', 'classic-editor' ); 376 | $heading_2 = __( 'Allow users to switch editors', 'classic-editor' ); 377 | 378 | add_settings_field( 'classic-editor-1', $heading_1, array( __CLASS__, 'settings_1' ), 'writing' ); 379 | add_settings_field( 'classic-editor-2', $heading_2, array( __CLASS__, 'settings_2' ), 'writing' ); 380 | } 381 | 382 | public static function save_user_settings( $user_id ) { 383 | if ( 384 | isset( $_POST['classic-editor-user-settings'] ) && 385 | isset( $_POST['classic-editor-replace'] ) && 386 | wp_verify_nonce( $_POST['classic-editor-user-settings'], 'allow-user-settings' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 387 | ) { 388 | $user_id = (int) $user_id; 389 | 390 | if ( $user_id !== get_current_user_id() && ! current_user_can( 'edit_user', $user_id ) ) { 391 | return; 392 | } 393 | 394 | $editor = self::validate_option_editor( $_POST['classic-editor-replace'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 395 | update_user_option( $user_id, 'classic-editor-settings', $editor ); 396 | } 397 | } 398 | 399 | /** 400 | * Validate 401 | */ 402 | public static function validate_option_editor( $value ) { 403 | if ( $value === 'block' ) { 404 | return 'block'; 405 | } 406 | 407 | return 'classic'; 408 | } 409 | 410 | public static function validate_option_allow_users( $value ) { 411 | if ( $value === 'allow' ) { 412 | return 'allow'; 413 | } 414 | 415 | return 'disallow'; 416 | } 417 | 418 | public static function settings_1( $user_id = 0 ) { 419 | $settings = self::get_settings( 'refresh', $user_id ); 420 | 421 | ?> 422 |
423 |

424 | /> 425 | 426 |

427 |

428 | /> 429 | 430 |

431 |
432 | 439 | 446 |
447 |

448 | /> 449 | 450 |

451 |

452 | /> 453 | 454 |

455 |
456 | ID; 472 | } else { 473 | $user_id = 0; 474 | } 475 | 476 | ?> 477 | 478 | 479 | 480 | 484 | 485 |
481 | 482 | 483 |
486 | 487 | 495 |

496 | 497 | 498 | 499 | 500 | 510 | 511 | 512 | 513 | 518 | 519 |
501 |

502 | /> 503 | 504 |

505 |

506 | /> 507 | 508 |

509 |
514 | > 515 | 516 |

517 |
520 | 548 | 549 | ID, 'classic-editor' ); 560 | } 561 | } 562 | 563 | /** 564 | * Remember when the block editor was used to edit a post. 565 | */ 566 | public static function remember_block_editor( $editor_settings, $context ) { 567 | if ( is_a( $context, 'WP_Post' ) ) { 568 | $post = $context; 569 | } elseif ( ! empty( $context->post ) ) { 570 | $post = $context->post; 571 | } else { 572 | return $editor_settings; 573 | } 574 | 575 | $post_type = get_post_type( $post ); 576 | 577 | if ( $post_type && self::can_edit_post_type( $post_type ) ) { 578 | self::remember( $post->ID, 'block-editor' ); 579 | } 580 | 581 | return $editor_settings; 582 | } 583 | 584 | private static function remember( $post_id, $editor ) { 585 | if ( get_post_meta( $post_id, 'classic-editor-remember', true ) !== $editor ) { 586 | update_post_meta( $post_id, 'classic-editor-remember', $editor ); 587 | } 588 | } 589 | 590 | /** 591 | * Choose which editor to use for a post. 592 | * 593 | * Passes through `$which_editor` for block editor (it's sets to `true` but may be changed by another plugin). 594 | * 595 | * @uses `use_block_editor_for_post` filter. 596 | * 597 | * @param boolean $use_block_editor True for block editor, false for classic editor. 598 | * @param WP_Post $post The post being edited. 599 | * @return boolean True for block editor, false for classic editor. 600 | */ 601 | public static function choose_editor( $use_block_editor, $post ) { 602 | $settings = self::get_settings(); 603 | $editors = self::get_enabled_editors_for_post( $post ); 604 | 605 | // If no editor is supported, pass through `$use_block_editor`. 606 | if ( ! $editors['block_editor'] && ! $editors['classic_editor'] ) { 607 | return $use_block_editor; 608 | } 609 | 610 | // Open the default editor when no $post and for "Add New" links, 611 | // or the alternate editor when the user is switching editors. 612 | // phpcs:disable WordPress.Security.NonceVerification.Recommended 613 | if ( empty( $post->ID ) || $post->post_status === 'auto-draft' ) { 614 | if ( 615 | ( $settings['editor'] === 'classic' && ! isset( $_GET['classic-editor__forget'] ) ) || // Add New 616 | ( isset( $_GET['classic-editor'] ) && isset( $_GET['classic-editor__forget'] ) ) // Switch to classic editor when no draft post. 617 | ) { 618 | $use_block_editor = false; 619 | } 620 | } elseif ( self::is_classic( $post->ID ) ) { 621 | $use_block_editor = false; 622 | } 623 | // phpcs:enable WordPress.Security.NonceVerification.Recommended 624 | 625 | // Enforce the editor if set by plugins. 626 | if ( $use_block_editor && ! $editors['block_editor'] ) { 627 | $use_block_editor = false; 628 | } elseif ( ! $use_block_editor && ! $editors['classic_editor'] && $editors['block_editor'] ) { 629 | $use_block_editor = true; 630 | } 631 | 632 | return $use_block_editor; 633 | } 634 | 635 | /** 636 | * Keep the `classic-editor` query arg through redirects when saving posts. 637 | */ 638 | public static function redirect_location( $location ) { 639 | if ( 640 | isset( $_REQUEST['classic-editor'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended 641 | ( isset( $_POST['_wp_http_referer'] ) && strpos( $_POST['_wp_http_referer'], '&classic-editor' ) !== false ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing 642 | ) { 643 | $location = add_query_arg( 'classic-editor', '', $location ); 644 | } 645 | 646 | return $location; 647 | } 648 | 649 | /** 650 | * Keep the `classic-editor` query arg when looking at revisions. 651 | */ 652 | public static function get_edit_post_link( $url ) { 653 | $settings = self::get_settings(); 654 | 655 | if ( isset( $_REQUEST['classic-editor'] ) || $settings['editor'] === 'classic' ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended 656 | $url = add_query_arg( 'classic-editor', '', $url ); 657 | } 658 | 659 | return $url; 660 | } 661 | 662 | public static function add_meta_box( $post_type, $post ) { 663 | $editors = self::get_enabled_editors_for_post( $post ); 664 | 665 | if ( ! $editors['block_editor'] || ! $editors['classic_editor'] ) { 666 | // Editors cannot be switched. 667 | return; 668 | } 669 | 670 | $id = 'classic-editor-switch-editor'; 671 | $title = __( 'Editor', 'classic-editor' ); 672 | $callback = array( __CLASS__, 'do_meta_box' ); 673 | $args = array( 674 | '__back_compat_meta_box' => true, 675 | ); 676 | 677 | add_meta_box( $id, $title, $callback, null, 'side', 'default', $args ); 678 | } 679 | 680 | public static function do_meta_box( $post ) { 681 | $edit_url = get_edit_post_link( $post->ID, 'raw' ); 682 | 683 | // Switching to block editor. 684 | $edit_url = remove_query_arg( 'classic-editor', $edit_url ); 685 | // Forget the previous value when going to a specific editor. 686 | $edit_url = add_query_arg( 'classic-editor__forget', '', $edit_url ); 687 | 688 | ?> 689 |

690 | 691 |

692 | __( 'Switch to classic editor', 'classic-editor' ) ) 720 | ); 721 | } 722 | 723 | /** 724 | * Add a link to the settings on the Plugins screen. 725 | */ 726 | public static function add_settings_link( $links, $file ) { 727 | $settings = self::get_settings(); 728 | 729 | if ( $file === 'classic-editor/classic-editor.php' && ! $settings['hide-settings-ui'] && current_user_can( 'manage_options' ) ) { 730 | if ( current_filter() === 'plugin_action_links' ) { 731 | $url = admin_url( 'options-writing.php#classic-editor-options' ); 732 | } else { 733 | $url = admin_url( '/network/settings.php#classic-editor-options' ); 734 | } 735 | 736 | // Prevent warnings in PHP 7.0+ when a plugin uses this filter incorrectly. 737 | $links = (array) $links; 738 | $links[] = sprintf( '%s', $url, __( 'Settings', 'classic-editor' ) ); 739 | } 740 | 741 | return $links; 742 | } 743 | 744 | private static function can_edit_post_type( $post_type ) { 745 | $can_edit = false; 746 | 747 | if ( function_exists( 'gutenberg_can_edit_post_type' ) ) { 748 | $can_edit = gutenberg_can_edit_post_type( $post_type ); 749 | } elseif ( function_exists( 'use_block_editor_for_post_type' ) ) { 750 | $can_edit = use_block_editor_for_post_type( $post_type ); 751 | } 752 | 753 | return $can_edit; 754 | } 755 | 756 | /** 757 | * Checks which editors are enabled for the post type. 758 | * 759 | * @param string $post_type The post type. 760 | * @return array Associative array of the editors and whether they are enabled for the post type. 761 | */ 762 | private static function get_enabled_editors_for_post_type( $post_type ) { 763 | if ( isset( self::$supported_post_types[ $post_type ] ) ) { 764 | return self::$supported_post_types[ $post_type ]; 765 | } 766 | 767 | $classic_editor = post_type_supports( $post_type, 'editor' ); 768 | $block_editor = self::can_edit_post_type( $post_type ); 769 | 770 | $editors = array( 771 | 'classic_editor' => $classic_editor, 772 | 'block_editor' => $block_editor, 773 | ); 774 | 775 | /** 776 | * Filters the editors that are enabled for the post type. 777 | * 778 | * @param array $editors Associative array of the editors and whether they are enabled for the post type. 779 | * @param string $post_type The post type. 780 | */ 781 | $editors = apply_filters( 'classic_editor_enabled_editors_for_post_type', $editors, $post_type ); 782 | self::$supported_post_types[ $post_type ] = $editors; 783 | 784 | return $editors; 785 | } 786 | 787 | /** 788 | * Checks which editors are enabled for the post. 789 | * 790 | * @param WP_Post $post The post object. 791 | * @return array Associative array of the editors and whether they are enabled for the post. 792 | */ 793 | private static function get_enabled_editors_for_post( $post ) { 794 | $post_type = get_post_type( $post ); 795 | 796 | if ( ! $post_type ) { 797 | return array( 798 | 'classic_editor' => false, 799 | 'block_editor' => false, 800 | ); 801 | } 802 | 803 | $editors = self::get_enabled_editors_for_post_type( $post_type ); 804 | 805 | /** 806 | * Filters the editors that are enabled for the post. 807 | * 808 | * @param array $editors Associative array of the editors and whether they are enabled for the post. 809 | * @param WP_Post $post The post object. 810 | */ 811 | return apply_filters( 'classic_editor_enabled_editors_for_post', $editors, $post ); 812 | } 813 | 814 | /** 815 | * Adds links to the post/page screens to edit any post or page in 816 | * the classic editor or block editor. 817 | * 818 | * @param array $actions Post actions. 819 | * @param WP_Post $post Edited post. 820 | * @return array Updated post actions. 821 | */ 822 | public static function add_edit_links( $actions, $post ) { 823 | // This is in Gutenberg, don't duplicate it. 824 | if ( array_key_exists( 'classic', $actions ) ) { 825 | unset( $actions['classic'] ); 826 | } 827 | 828 | if ( ! array_key_exists( 'edit', $actions ) ) { 829 | return $actions; 830 | } 831 | 832 | $edit_url = get_edit_post_link( $post->ID, 'raw' ); 833 | 834 | if ( ! $edit_url ) { 835 | return $actions; 836 | } 837 | 838 | $editors = self::get_enabled_editors_for_post( $post ); 839 | 840 | // Do not show the links if only one editor is available. 841 | if ( ! $editors['classic_editor'] || ! $editors['block_editor'] ) { 842 | return $actions; 843 | } 844 | 845 | // Forget the previous value when going to a specific editor. 846 | $edit_url = add_query_arg( 'classic-editor__forget', '', $edit_url ); 847 | 848 | // Build the edit actions. See also: WP_Posts_List_Table::handle_row_actions(). 849 | $title = _draft_or_post_title( $post->ID ); 850 | 851 | // Link to the block editor. 852 | $url = remove_query_arg( 'classic-editor', $edit_url ); 853 | $text = _x( 'Edit (block editor)', 'Editor Name', 'classic-editor' ); 854 | /* translators: %s: post title */ 855 | $label = sprintf( __( 'Edit “%s” in the block editor', 'classic-editor' ), $title ); 856 | $edit_block = sprintf( '%s', esc_url( $url ), esc_attr( $label ), $text ); 857 | 858 | // Link to the classic editor. 859 | $url = add_query_arg( 'classic-editor', '', $edit_url ); 860 | $text = _x( 'Edit (classic editor)', 'Editor Name', 'classic-editor' ); 861 | /* translators: %s: post title */ 862 | $label = sprintf( __( 'Edit “%s” in the classic editor', 'classic-editor' ), $title ); 863 | $edit_classic = sprintf( '%s', esc_url( $url ), esc_attr( $label ), $text ); 864 | 865 | $edit_actions = array( 866 | 'classic-editor-block' => $edit_block, 867 | 'classic-editor-classic' => $edit_classic, 868 | ); 869 | 870 | // Insert the new Edit actions instead of the Edit action. 871 | $edit_offset = array_search( 'edit', array_keys( $actions ), true ); 872 | array_splice( $actions, $edit_offset, 1, $edit_actions ); 873 | 874 | return $actions; 875 | } 876 | 877 | /** 878 | * Show the editor that will be used in a "post state" in the Posts list table. 879 | */ 880 | public static function add_post_state( $post_states, $post ) { 881 | if ( get_post_status( $post ) === 'trash' ) { 882 | return $post_states; 883 | } 884 | 885 | $editors = self::get_enabled_editors_for_post( $post ); 886 | 887 | if ( ! $editors['classic_editor'] && ! $editors['block_editor'] ) { 888 | return $post_states; 889 | } elseif ( $editors['classic_editor'] && ! $editors['block_editor'] ) { 890 | // Forced to classic editor. 891 | $state = '' . _x( 'classic editor', 'Editor Name', 'classic-editor' ) . ''; 892 | } elseif ( ! $editors['classic_editor'] && $editors['block_editor'] ) { 893 | // Forced to block editor. 894 | $state = '' . _x( 'block editor', 'Editor Name', 'classic-editor' ) . ''; 895 | } else { 896 | $last_editor = get_post_meta( $post->ID, 'classic-editor-remember', true ); 897 | 898 | if ( $last_editor ) { 899 | $is_classic = ( $last_editor === 'classic-editor' ); 900 | } elseif ( ! empty( $post->post_content ) ) { 901 | $is_classic = ! self::has_blocks( $post->post_content ); 902 | } else { 903 | $settings = self::get_settings(); 904 | $is_classic = ( $settings['editor'] === 'classic' ); 905 | } 906 | 907 | $state = $is_classic ? _x( 'Classic editor', 'Editor Name', 'classic-editor' ) : _x( 'Block editor', 'Editor Name', 'classic-editor' ); 908 | } 909 | 910 | // Fix PHP 7+ warnings if another plugin returns unexpected type. 911 | $post_states = (array) $post_states; 912 | $post_states['classic-editor-plugin'] = $state; 913 | 914 | return $post_states; 915 | } 916 | 917 | public static function add_edit_php_inline_style() { 918 | ?> 919 | 927 | post_content; 954 | } 955 | } 956 | 957 | return false !== strpos( (string) $post, '