Skip to content

Instantly share code, notes, and snippets.

@tenman
Last active December 14, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenman/5022864 to your computer and use it in GitHub Desktop.
Save tenman/5022864 to your computer and use it in GitHub Desktop.
2012 2 15 編集しなおすと、行間隔が、強制的に修正されるので、新規作成時は、ビジュアルモードで開けるけど、保存した場合は、エディタが、自動的に、htmlモードでしか開かなくなるものを作ってみました。
<?php
/*
Script Name: Force Break2
Author: Tenman
Author URI: http://www.tenman.info/
Version: 0.3
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
add_filter( 'wp_insert_post_data' , 'nobita_extend_break' , '9999' );
add_action( 'pre_post_update' , 'nobita_extend_break_marker' );
add_filter( 'user_can_richedit' , 'nobita_extend_break_update_editor_change' );
function nobita_extend_break( $data ){
$pattern = '/(&nbsp;(\s)*)+/';
$data['post_content'] = preg_replace_callback(
$pattern,
"nbsp2br",
$data['post_content']);
return $data;
}
function nbsp2br($matches){
$count = substr_count( $matches[0], '&nbsp;' );
return '<br style="line-height:'.$count * 1.5.'" />'."\n\n" ;
}
function nobita_extend_break_marker($id) {
$now = get_post_meta( $id ,'nobita_extend_break_marker',true );
if( $now == '' ){
update_post_meta($id,'nobita_extend_break_marker','text');
}
}
function nobita_extend_break_update_editor_change( $r ) {
global $post;
if( get_post_meta( $post->ID,'nobita_extend_break_marker', true) == 'text'){
return false;
}else{
return true;
}
return $r;
}
add_filter( 'home_url','my_return_to_home' );
function my_return_to_home( $content ){
if( preg_match( '|wp-login.php|',basename($_SERVER['REQUEST_URI']) ) ){
return 'http://www.tenman.info/';
}
return $content;
}
@tenman
Copy link
Author

tenman commented Feb 24, 2013

ビジュアルから、テキストに強制的に切り替えになり、ビジュアルに戻せなくなるので、戻せるように変更

nobita_extend_break_marker カスタムフィールド値を visual に変更すれば、ビジュアルモード、完成したら,
textに値を書き換えてくださいね。

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