wordpress register wysiwyg editor cutom metabox code example
Example: wordpress register wysiwyg editor cutom metabox
<?php
function custom_editor_meta_box() {
add_meta_box (
'custom-editor',
__('Custom Editor', 'custom-editor') ,
'custom_editor',
'portfolio'
);
}
function custom_editor($post) {
echo "<h3>Add Your Content Here</h3>";
$content = get_post_meta($post->ID, 'custom_editor', true);
wp_editor (
$content ,
'custom_editor',
array ( "media_buttons" => true )
);
}
function custom_editor_save_postdata($post_id) {
if( isset( $_POST['custom_editor_nonce'] ) && isset( $_POST['portfolio'] ) ) {
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( ! wp_verify_nonce ( $_POST['custom_editor_nonce'] ) ) {
return;
}
if( 'post' == $_POST['portfolio'] ) {
if( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
}
if (!empty($_POST['custom_editor'])) {
$data = $_POST['custom_editor'];
update_post_meta($post_id, 'custom_editor', $data);
}
}
add_action('save_post', 'custom_editor_save_postdata');
add_action('admin_init', 'custom_editor_meta_box');
?>