I am creating a custom settings page for my plugin. I have four textarea fields, Which need to be replaced by wp_editor. My problem is that I am not able to store the data to database. Bellow is my code.

    __( 'SMS templates', 'wordpress' ), 

function nga_textarea_field_1_render_i() { 
    $nga_textarea_field_1_invalid = get_option( 'nga_textarea_field_1' );
    wp_editor( $nga_textarea_field_1_invalid, 'nga_textarea_field_1', array( 'textarea_name' => 'nga_textarea_field_1' )); 
    //update_option('nga_textarea_field_1_invalid', $content);

Might be possible that your wp_editor is broken! According to codex you can not use numeric editor ID

may only contain lowercase letters and underscores...hyphens will cause editor to not display properly

Call wp_editor in this way

wp_editor( $nga_textarea_field_1_invalid, 'nga_textarea_field_one' );

textarea_name is not required because by default it is already wp_editor ID.

I am not sure how you are saving the option but in settings API you need to pass the field name with [] for multiple fields with one option key. e.g.

wp_editor( $nga_textarea_field_1_invalid, 'nga_textarea_field_one', array( 'textarea_name' => 'plugin_option_name["nga_textarea_field_1"]' ));

Where plugin_option_name is name of the option key which you've used in register_setting.

|improve this answer|||||
  • Im experiencing the very same thing. The odd thing is, when i switch from visual to text and save, then it gets saved, and vice versa. It's like the editor JS isn't registering the changes made until you trigger it by switching edit-mode. – Sillo Apr 22 '18 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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