4

I'm creating a custom options page and I have a textarea that I've turned into a TinyMCE editor using wp_editor.

TinyMCE displays correctly, however it breaks when I include square brackets in the $id. Here's the code I'm using for the add_settings_field function callback:

function px_wp_editor($args){
        $options    = get_option('theme_options');  
        $value      = $options['px_wp_editor'];
        $id         = 'theme_options[px_wp_editor]';

         extract( $args );
         $class = (!empty($class))?$class:'';

         $settings = array(
            'textarea_rows'     => 12,
            'textarea_name'     => $id, 
            'editor_class'      => $class,
            'media_buttons'     => true,
            'tinymce'           => true
         );
         wp_editor($value, $id, $settings );            
    }

If I removed the square brackets from the $id value then it displays fine. However, because of the way I'm retrieving the values using get_option, I need to call "textarea_name" as it currently is, with square brackets.

The first pic below is how it looks when using square brackets for the name (full icons don't display correctly and there are no Visual/Text buttons.

The second pic is how it should display.

Here's a screenshot of how it looks when using square brackets for the name Here's how it should look

2 Answers 2

2

You cannot put square brackets as editor id. but you can change textarea name by.

wp_editor('','px_wp_editor',array('textarea_name' => 'theme_options[px_wp_editor]'));

the important part is, "id" and "textarea_name" are different.

3
  • Please explain why this answer is helpful.
    – kaiser
    Mar 11, 2015 at 13:49
  • 2
    the important part is "id" and "textarea_name" are different. thats all. thats all. Mar 16, 2015 at 11:56
  • Then please, tell that in your answer, and not in the comments.
    – kaiser
    Mar 16, 2015 at 13:37
0

I'm not able to test this right now, but try this:

$id = htmlentities('theme_options[px_wp_editor]');
2
  • Doesn't work :(
    – pixelkicks
    Jul 30, 2014 at 16:01
  • 1
    Sad Christmas. :( I'll try to test this myself and work out why this doesn't work when I get a moment.
    – Jack Lenox
    Jul 30, 2014 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.