Last active
August 29, 2015 13:55
-
-
Save lumpysimon/8782859 to your computer and use it in GitHub Desktop.
Quick n dirty fix to strip out the line height styles inserted by Webkit browsers when saving posts in WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Webkit Line Height Fixer | |
Plugin URI: https://twitter.com/lumpysimon | |
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 | |
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 ); | |
$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