admin管理员组文章数量:1022997
I have a plugin setting that uses wp_editor()
to handle the input and will get echoed as part of a shortcode. Everything is working great on the admin side but when I echo the output on the client side, in the shortcode, the content does not echo with line breaks and paragraph breaks, like the_content()
.
Is there an existing method (or function) for echoing wp_editor()
content from other sources, e.g. a plugin setting? Or do I need to parse and build paragraphs and line breaks manually (I feel like I'm reinventing the wheel here!)?
Example code for reference:
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');
}
Desired output:
<p><strong>Failed.</strong></p>
<p>There was an error. Please try again later.</p>
Actual output (that folds into one line):
<strong>Failed.</strong>
There was an error. Please try again later.
I have a plugin setting that uses wp_editor()
to handle the input and will get echoed as part of a shortcode. Everything is working great on the admin side but when I echo the output on the client side, in the shortcode, the content does not echo with line breaks and paragraph breaks, like the_content()
.
Is there an existing method (or function) for echoing wp_editor()
content from other sources, e.g. a plugin setting? Or do I need to parse and build paragraphs and line breaks manually (I feel like I'm reinventing the wheel here!)?
Example code for reference:
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');
}
Desired output:
<p><strong>Failed.</strong></p>
<p>There was an error. Please try again later.</p>
Actual output (that folds into one line):
<strong>Failed.</strong>
There was an error. Please try again later.
Share
Improve this question
asked Apr 23, 2019 at 5:56
WarwickWarwick
2732 silver badges6 bronze badges
1 Answer
Reset to default 0the_content
filter can be used to filter the content after it is retrieved from the database and before it is printed to the screen.
The Core filters on the_content
are:
add_filter( 'the_content', 'wptexturize' );
add_filter( 'the_content', 'convert_smilies' );
add_filter( 'the_content', 'convert_chars' );
add_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'shortcode_unautop' );
add_filter( 'the_content', 'prepend_attachment' );
Reference to some of above filters:
http://codex.wordpress/Function_Reference/wptexturize
http://codex.wordpress/Function_Reference/convert_smilies
http://codex.wordpress/Function_Reference/wpautop
In general; this should get your job done.
function my_messages_shortcode($atts = [], $content = NULL, $tag = '') {
return apply_filters('the_content', get_option('my_failure_message') );
}
I have a plugin setting that uses wp_editor()
to handle the input and will get echoed as part of a shortcode. Everything is working great on the admin side but when I echo the output on the client side, in the shortcode, the content does not echo with line breaks and paragraph breaks, like the_content()
.
Is there an existing method (or function) for echoing wp_editor()
content from other sources, e.g. a plugin setting? Or do I need to parse and build paragraphs and line breaks manually (I feel like I'm reinventing the wheel here!)?
Example code for reference:
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');
}
Desired output:
<p><strong>Failed.</strong></p>
<p>There was an error. Please try again later.</p>
Actual output (that folds into one line):
<strong>Failed.</strong>
There was an error. Please try again later.
I have a plugin setting that uses wp_editor()
to handle the input and will get echoed as part of a shortcode. Everything is working great on the admin side but when I echo the output on the client side, in the shortcode, the content does not echo with line breaks and paragraph breaks, like the_content()
.
Is there an existing method (or function) for echoing wp_editor()
content from other sources, e.g. a plugin setting? Or do I need to parse and build paragraphs and line breaks manually (I feel like I'm reinventing the wheel here!)?
Example code for reference:
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');
}
Desired output:
<p><strong>Failed.</strong></p>
<p>There was an error. Please try again later.</p>
Actual output (that folds into one line):
<strong>Failed.</strong>
There was an error. Please try again later.
Share
Improve this question
asked Apr 23, 2019 at 5:56
WarwickWarwick
2732 silver badges6 bronze badges
1 Answer
Reset to default 0the_content
filter can be used to filter the content after it is retrieved from the database and before it is printed to the screen.
The Core filters on the_content
are:
add_filter( 'the_content', 'wptexturize' );
add_filter( 'the_content', 'convert_smilies' );
add_filter( 'the_content', 'convert_chars' );
add_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'shortcode_unautop' );
add_filter( 'the_content', 'prepend_attachment' );
Reference to some of above filters:
http://codex.wordpress/Function_Reference/wptexturize
http://codex.wordpress/Function_Reference/convert_smilies
http://codex.wordpress/Function_Reference/wpautop
In general; this should get your job done.
function my_messages_shortcode($atts = [], $content = NULL, $tag = '') {
return apply_filters('the_content', get_option('my_failure_message') );
}
本文标签: How do I render content from a wpeditor in a plugin setting field
版权声明:本文标题:How do I render content from a wp_editor in a plugin setting field? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745560543a2156136.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论