我有一个php函数,它在WP内容编辑器(见下文)中的add\\u meta\\u box()内执行,我想将其转换为javascript,以便它在点击按钮时执行(按需与自动加载),以实时转换帖子内容(无需发布到服务器)。
javascript中是否设置了等效的方法?
add_meta_box(\'mycontentfilter\', __(\'My Content Filter\'), \'my_content_filter\', \'post\', \'side\', \'high\');
function my_content_filter()
{
global $post;
$mykeyword = \'find this phrase\';
$post->post_content = preg_replace_callback("/\\b($mykeyword)\\b/","doReplace", $post->post_content);
}
// the callback function
function doReplace($matches)
{
static $count = 0;
switch($count++)
{
case 0: return \'<b>\'.$matches[1].\'</b>\'; // 1st instance, wrap in bold
case 1: return \'<em>\'.$matches[1].\'</em>\'; // 2nd instance, wrap in italics
case 2: return \'<u>\'.$matches[1].\'</u>\'; // 3rd instance, wrap in underline
default: return $matches[1]; // don\'t change others.
}
}