Wordpress wp_editor() not working

2019-08-10 07:32发布

问题:

i used wordpress 3.8 and i create plugin and i displayed the wp_editor.

but it look like this.

this is my code.

$content = "";
$edit_id = "slider_text_editor";
wp_editor( $content, $edit_id );

回答1:

try with below code:

wp_tiny_mce( false, $mce_config );

Where $mce_config should be an array of key=>value pairs that represent the configuation settings for the editor(tinymce) instance.

Config settings can be found here.

http://wiki.moxiecode.com/index.php/TinyMCE:Configuration

Or if you prefer, a brief write-up covering the key points can also be found here.

http://www.keighl.com/2010/01/tinymce-in-wordpress-plugins/

If you have problems implementing the code, let me know, i've used it in plugins page myself without a hitch.. ;)

for more information visit : How to use Wordpress Text Editor in a custom plugin

thanks



回答2:

to properly use the wp_editor use it like this:

// add the admin settings and such
add_action('admin_init', 'wp_your_plugin_admin_init');
function wp_your_plugin_admin_init(){
register_setting( 'wp_your_plugin_settings', 'wp_your_plugin_settings', 'wp_your_plugin_settings_validate');
add_settings_field('wp_your_plugin_user_custom_text', __('Enter your message','wp_your_plugin'), 'wp_your_plugin_user_custom_text', 'wp_your_plugin', 'wp_your_plugin_main');

function wp_your_plugin_user_custom_text() {
$options = get_option('wp_your_plugin_settings');
$settings  = array('media_buttons' => true,'textarea_rows' => 5,'textarea_name' => 'user_custom_text');
wp_editor( $options['user_custom_text'],'user_custom_text', $settings  );}  

// validate  
function wp_your_plugin_settings_validate() {
$options = get_option('wp_your_plugin_settings');


if ( empty($_POST['user_custom_text']) ){
    $options['user_custom_text'] =  __('Enter your own content, it will be below the original message','wp_your_plugin');// as set when the plugin activated
}else{
    $options['user_custom_text'] =  wp_kses_post($_POST['user_custom_text']) ;}// u need to Sanitize to be able to get the media to work


标签: php wordpress