Last active
May 24, 2016 07:52
-
-
Save soderlind/6b9fab92d15e6e75c6498a69ece99275 to your computer and use it in GitHub Desktop.
On save/update, convert nbsp (\xc2\xa0 and \xa0) to space
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: On save/update, convert nbsp to space | |
* | |
* From http://wordpress.stackexchange.com/a/168358, modified by me | |
* | |
* @package 'dss_convert_nbsp_wp_insert_post_data' | |
*/ | |
add_filter( 'wp_insert_post_data', 'dss_convert_nbsp_wp_insert_post_data', '99', 2 ); | |
/** | |
* Converts nbsp to space | |
* | |
* @author soderlind | |
* @version 1.0.0 | |
* @param array $data Sanitized post data. | |
* @param array $postarr Raw post data. | |
* @return array Sanitized post data. | |
*/ | |
function dss_convert_nbsp_wp_insert_post_data( $data, $postarr ) { | |
$data = str_replace( "\xc2\xa0", ' ', $data ); // UTF-8 nbsp -> space | |
$data = str_replace( "\xa0", ' ', $data ); // ISO-8859-1 nbsp -> space, why: http://stackoverflow.com/a/1462039. | |
$data = str_replace( ' ', "\xc2\xa0", $data ); | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment