Saving custom wp_editor meta box
-
I’ve managed to add a TinyMCE editor to a custom meta box using a mashup of https://mattgeri.com/2012/02/how-to-add-the-tinymce-editor-to-a-wordpress-meta-box-or-plugin-form/ and https://wpshed.com/create-custom-meta-box-easy-way/
However when I try to save the post I receive the following errors.
Warning: Cannot modify header information - headers already sent by (output started at website.com/html/wp-content/plugins/name-of-plugin-2/name-of-plugin.php:245) in website.com/html/wp-admin/post.php on line 233 Warning: Cannot modify header information - headers already sent by (output started at website.com/html/wp-content/plugins/name-of-plugin-2/name-of-plugin.php:245) in website.com/html/wp-includes/pluggable.php on line 1178
Line 233 is:
add_action( 'add_meta_boxes', 'wpshed_add_custom_meta_box' );
Here’s the full code:
// Little function to return a custom field value function wpshed_get_custom_field( $value ) { global $post; $custom_field = get_post_meta( $post->ID, $value, true ); if ( !empty( $custom_field ) ) return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) ); return false; } // Register the Metabox function wpshed_add_custom_meta_box() { add_meta_box( 'wpshed-meta-box', __( 'Relevant Reading', 'textdomain' ), 'wpshed_meta_box_output', 'article', 'normal', 'high' ); //add_meta_box( 'wpshed-meta-box', __( 'Metabox Example', 'textdomain' ), 'wpshed_meta_box_output', 'page', 'normal', 'high' ); } add_action( 'add_meta_boxes', 'wpshed_add_custom_meta_box' ); // Output the Metabox function wpshed_meta_box_output( $post ) { echo '<label for="relevant_reading">Content</label>'; wp_editor( '', 'relevant_reading', array( 'textarea_name' => 'relevant_reading', 'media_buttons' => false,'quicktags' => false, 'teeny'=>true, 'tinymce' => array( 'theme_advanced_buttons1' => 'bullist,numlist,link,unlink,undo,redo' ) ) ); } ?> <?php // Save the Metabox values function wpshed_meta_box_save( $post_id ) { // Stop the script when doing autosave if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // Verify the nonce. If insn't there, stop the script if( !isset( $_POST['wpshed_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['wpshed_meta_box_nonce'], 'my_wpshed_meta_box_nonce' ) ) return; // Stop the script if the user does not have edit permissions if( !current_user_can( 'edit_post' ) ) return; /** // Save the textfield if( isset( $_POST['wpshed_textfield'] ) ) update_post_meta( $post_id, 'wpshed_textfield', esc_attr( $_POST['wpshed_textfield'] ) ); **/ // Save the textarea if( isset( $_POST['relevant_reading'] ) ) update_post_meta( $post_id, 'relevant_reading', esc_attr( $_POST['relevant_reading'] ) ); } add_action( 'save_post', 'wpshed_meta_box_save' );
- The topic ‘Saving custom wp_editor meta box’ is closed to new replies.