add_filter('content_pagination',function($pages, $post){
if(!is_single()){return $pages;}
$pages = explodePost($pages,$post);
return $pages;
},10,2);
function explodePost($pages, $post){
if(get_post_meta($post->ID,'mp_switch',true)){return $pages;}
$content = $post->post_content;
if(strpos($content,'//act.ballooon.jp/imp/imp')){ // for ballooon counter
return $pages;
}
$len = mb_strlen($content,'utf-8');
$insert = "<!--nextpage-->";
$width = 3000;
if($len/$width<2){
return $pages;
}
$content = preg_replace("/\r\n|\r|\n/", "\n", $content);
$st = $width;
foreach(range(1,(int)($len/$width)) as $i){
if($st > $len){ break; }
$content = preg_replace("/^.{0,$st}.+\?\n\n\K/us", $insert, $content);
$st = mb_strrpos($content,$insert,0,'utf-8')+$width;
}
// pattern blockquate
$pat = sprintf("/(<blockquote[^>]*>.*)%s(.*<\/blockquote>)/isu",preg_quote($insert,'/'));
$content = preg_replace($pat,'${1}${2}',$content);
$pat = sprintf("/%s(.{0,%d})$/isu",preg_quote($insert,'/'),$width/2);
$content = preg_replace($pat,'${1}${2}',$content);
$return = explode($insert,$content);
$return = array_filter($return,'strlen');
$return = array_values($return);
if(!$return[0]){ return $pages; }
return $return;
}