我有一个屏幕截图,可以准确地解释发生了什么,我也会发布我的代码片段。
我正在制作一个wordpress插件,添加在我的自定义设置页面上调用的WYSIWYG编辑器中编辑的文本。我已经将它保存的输入发布到我希望它去的地方(虽然编辑主题模板文件,不是我真正想要的,但它正在工作)但它输出保存的文本没有选择的格式通过我的插件页面在WYSIWYG中。
我一直在做一些阅读,我想也许可能与esc_html
有关?我真的不太确定。
这个代码片段是我的实际的WordPress插件:
<?php
/*/
Plugin Name: Custom Text Adder
Plugin URI: N/A
Description: Demonstrates how rubbish I am at pretty much everything I want to do
Version: 101
Author: JD
Author URI: N/A
/*/
// create custom plugin settings menu
add_action('admin_menu', 'custom_create_menu');
// Add Font-Size to WYSIWYG Editor
function wp_editor_fontsize_filter( $options ) {
array_shift( $options );
array_unshift( $options, 'fontsizeselect');
array_unshift( $options, 'formatselect');
return $options;
}
add_filter('mce_buttons_2', 'wp_editor_fontsize_filter');
function custom_create_menu() {
//create new top-level menu
add_menu_page('Custom Plugin Settings', 'Custom Settings', 'administrator', __FILE__, 'custom_settings_page',plugins_url('/img/icon.png', __FILE__));
//call register settings function
add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
//register our settings
register_setting( 'custom-settings-group', 'new_option_name' );
register_setting( 'custom-settings-group', 'some_other_option' );
register_setting( 'custom-settings-group', 'option_etc' );
register_setting( 'custom-settings-group', 'font_size' );
register_setting( 'custom-settings-group', 'post_text' );
}
function custom_settings_page() {
?>
<div class="wrap">
<h2>Custom Text</h2>
<?php?>
<form method="post" action="options.php">
<?php settings_fields( 'custom-settings-group' ); ?>
<table class="form-table">
<?php /* Bring the editor onto the page */
wp_editor( '', 'post_text', $settings = array() );
/**
* 4.
* Custom buttons for the editor.
* This is a list separated with a comma after each feature
* eg. link, unlink, bold, ...
*/
$settings = array(
'textarea_name' => 'post_text',
'media_buttons' => true,
'tinymce' => array(
'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
'bullist,blockquote,|,justifyleft,justifycenter' .
',justifyright,justifyfull,|,link,unlink,|' .
',spellchecker,wp_fullscreen,wp_adv'
)
);
submit_button( 'Save everything', 'primary', 'submit' ); ?>
</form>
</div>
这一个是主题 home.php模板文件中发布文本的地方:
<?php if ( get_option('chameleon_quote') == 'on' ) { ?>
<div id="category-name">
<div id="category-inner">
<div><?php print esc_html(get_option('post_text')); ?></div>
<?php if ( get_option('post_text') <> '' ) { ?>
<h3><?php echo esc_html(get_option('post_text')); ?></h3>
<?php } ?>
<?php if ( get_option('chameleon_quote_two') <> '' ) { ?>
<p><?php echo esc_html(get_option('chameleon_quote_two')); ?></p>
<?php } ?>
</div>
</div> <!-- end .category-name -->
<?php } ?>
我正在做('post_text')
部分。如你所见,我基本上复制了底部函数。
答案 0 :(得分:2)
尽量不要使用esc_html
<?php if ( get_option('chameleon_quote') == 'on' ) { ?>
<div id="category-name">
<div id="category-inner">
<div><?php print get_option('post_text'); ?></div>
<?php if ( get_option('post_text') <> '' ) { ?>
<h3><?php echo get_option('post_text'); ?></h3>
<?php } ?>
<?php if ( get_option('chameleon_quote_two') <> '' ) { ?>
<p><?php echo get_option('chameleon_quote_two'); ?></p>
<?php } ?>
</div>
</div> <!-- end .category-name -->
<?php } ?>