Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ms-studio/9549133 to your computer and use it in GitHub Desktop.
Save ms-studio/9549133 to your computer and use it in GitHub Desktop.
Fix for webkit (Chrome, Safari) adding style="line-height: 1.55;" all over the place in the WordPress content editor.
<?php
/*
Plugin Name: Webkit Line Height Fixer
Plugin URI: https://gist.github.com/lumpysimon/8782859
Description: Remove the annoying inline line-height styles added by Webkit
Version: 1.0
Author: Simon Blackbourn @ Lumpy Lemon
Author URI: http://lumpylemon.co.uk
See also: https://core.trac.wordpress.org/ticket/26975
Released under the GPL license:
http://www.opensource.org/licenses/gpl-license.php
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
defined( 'ABSPATH' ) or die();
webkit_lhf::get_instance();
class webkit_lhf {
// used to prevent infinite looping on the save_post hook
var $no_recursion = false;
private static $instance = null;
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
private function __construct() {
add_action( 'save_post', array( $this, 'strip_n_save' ), 10, 2 );
}
function strip_n_save( $post_id, $post ) {
if ( $this->no_recursion )
return;
$content = str_replace( ' style="line-height: 1.5;"', '', $post->post_content );
$content = str_replace( ' style="line-height: 1.5em;"', '', $content );
$content = str_replace( ' style="line-height: 1.55;"', '', $content );
$post_data = array(
'ID' => $post_id,
'post_content' => $content
);
$this->no_recursion = true;
wp_update_post( $post_data );
$this->no_recursion = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment