Skip to content

Instantly share code, notes, and snippets.

@gmazzap
Last active November 20, 2015 07:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gmazzap/c081ce03a68b00d983d5 to your computer and use it in GitHub Desktop.
Save gmazzap/c081ce03a68b00d983d5 to your computer and use it in GitHub Desktop.
WordPress plugins that allows to use the distraction-free mode that was active pre 4.1 WP version.
<?php namespace GM\FSDFM;
/**
* Plugin Name: Fullscreen Distraction-Free Mode (pre v4.1)
* Description: Allows to use the distraction-free mode that was active pre 4.1 WP version.
* Plugin URI: https://gist.github.com/Giuseppe-Mazzapica/c081ce03a68b00d983d5
* Author: Giuseppe Mazzapica
* Author URI: https://gm.zoomlab.it
* License: MIT
* Version: 1.0.0
*/
/*
The MIT License (MIT)
Copyright (c) 2015 Giuseppe Mazzapica
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
if (!is_admin())
return;
function should($editor_id = 'content')
{
return
(version_compare($GLOBALS['wp_version'], '4.1') >= 0)
&& in_array($GLOBALS['pagenow'], array('post.php','post-new.php'))
&& $editor_id === 'content';
}
function buttons($buttons, $editor_id)
{
return should($editor_id)
? array_diff(array_merge((array) $buttons, array('wp_fullscreen')), array('dfw'))
: $buttons;
}
function plugins($plugins)
{
return should()
? array_diff(array_merge((array) $plugins, array('wpfullscreen')), array('fullscreen'))
: $plugins;
}
function settings($settings, $editor_id)
{
if (should($editor_id)) {
$settings['_content_editor_dfw'] = false;
}
return $settings;
}
add_filter('wp_editor_settings', __NAMESPACE__.'\\settings', 30, 2);
add_filter('mce_buttons', __NAMESPACE__.'\\buttons', 30, 2);
add_filter('teeny_mce_buttons', __NAMESPACE__.'\\buttons', 30, 2);
add_filter('teeny_mce_plugins', __NAMESPACE__.'\\plugins');
add_filter('tiny_mce_plugins', __NAMESPACE__.'\\plugins');
@mths0x5f
Copy link

mths0x5f commented Feb 4, 2015

Really, really thank you!

@legolasmi
Copy link

Thanks a lot!!

@fernandotellado
Copy link

Beautiful, as the old and great distraction free editor

Thanks a lot! :)

@knutsp
Copy link

knutsp commented Jul 9, 2015

Will this plugin be ready for WP 4.3?

See https://make.wordpress.org/core/2015/07/09/editor-changes-in-wordpress-4-3/

Another change is the complete removal of the code for the old Distraction Free Writing mode. This code was disabled and has been unused since WordPress 4.1. We left it in core so the authors of plugins that were using it would have plenty of time to update.

@seraphyn
Copy link

Does not work in WP 4.3 anymore.
It leaves the Editor empty without any text in it.
Normal Text is available

@gmazzap
Copy link
Author

gmazzap commented Aug 18, 2015

@seraphyn @knutsp plugin was wrote as a result of WordPress stackexchange answer. See the Edit (added on 9th July) on top of the answer here http://wordpress.stackexchange.com/a/175254/35541 regarding the 4.3+ incompatibility.

@howtogeek
Copy link

I tried adding the old javascript file back from a 4.2 install and added a couple lines to the top of this plugin:

function olddistractionfree() {
    wp_enqueue_script( 'wpfullscreenscript', '/wp-includes/js/tinymce/plugins/wpfullscreen/plugin.min.js' );
}
add_action( 'admin_enqueue_scripts', 'olddistractionfree' );

This didn't work for me though. The distraction free button shows up but clicking it does nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment