我正在研究 Wordpress 主题,该主题通过update_post_meta()hook 作为 post将自定义 Javascript 存储到数据库中metadata。但问题是,PHP file_get_contents()异常删除反斜杠。
我在Wordpress 中PHP使用的功能functions.php
function add_template($post_id){
$custom_javascript = get_post_meta( $post->ID, 'custom_javascript', true );
$template_js = file_get_contents(get_template_directory_uri(). '/template/prism.js');
update_post_meta( $post_id, 'custom_javascript', $template_js );
}
add_action( 'save_post', 'add_template' );
一个错误:
原始的Javascript:(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)
修改后的Javascript:(^|[^\])/*[sS]*?(?:*/|$)
如何摆脱这个问题?任何帮助/建议将不胜感激。
人到中年有点甜