我有一个插件设置,使用wp_editor()
来处理输入,并将作为短代码的一部分进行回显。在管理端,一切都很好,但当我在客户端回显输出时,在短代码中,内容不会以换行符和段落分隔符进行回显,如the_content()
.
是否有回音的现有方法(或功能)wp_editor()
来自其他来源的内容,例如插件设置?或者我需要手动解析和构建段落和换行符吗(我觉得我在这里重新发明轮子!)?
参考代码示例:
add_action(\'admin_init\', \'my_plugin_settings\');
function my_plugin_settings() {
add_settings_section(
\'my_messages_section\',
\'Messages\',
\'Messages\',
\'my_settings\'
);
register_setting(\'my_settings\', \'my_failure_message\');
add_settings_field(
\'my_failure_message\',
\'Failure Message\',
\'my_failure_message_input\',
\'my_settings\',
\'my_messages_section\'
);
}
function my_failure_message_input() {
wp_editor(get_option(\'my_failure_message\'), \'my_failure_message\');
}
function my_plugin_shortcodes() {
add_shortcode(\'my_shortcode\', \'my_messages_shortcode\');
}
add_action(\'init\', \'my_plugin_shortcodes\');
function my_messages_shortcode($atts = [], $content = NULL, $tag = \'\') {
echo get_option(\'my_failure_message\');
}
所需输出:
<p><strong>Failed.</strong></p>
<p>There was an error. Please try again later.</p>
实际输出(折叠成一行):
<strong>Failed.</strong>
There was an error. Please try again later.