Meta Second Editor 1
class sqpp_metabox_second_editor {
public function __construct() {
if ( is_admin() ) {
add_action( 'load-post.php', array( $this, 'init_metabox' ) );
add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
}
}
public function init_metabox() {
add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );
add_action( 'save_post', array( $this, 'save_metabox' ), 10, 2 );
}
public function add_metabox() {
add_meta_box(
'sqpp-mb-second-editor',
__( 'Additional Editor', 'sqppcptmeta' ),
array( $this, 'render_sqpp_metabox_second_editor' ),
'page',
'normal',
'default'
);
}
public function render_sqpp_metabox_second_editor( $post ) {
// Add nonce for security and authentication.
wp_nonce_field( 'sqpp_nonce_action', 'sqpp_nonce' );
// Retrieve an existing value from the database.
$sqpp_sqpp_mb_second_editor_wysiwyg = get_post_meta( $post->ID, 'sqpp_sqpp_mb_second_editor_wysiwyg', true );
// Set default values.
if( empty( $sqpp_sqpp_mb_second_editor_wysiwyg ) ) $sqpp_sqpp_mb_second_editor_wysiwyg = '';
// Form fields.
echo '<table class="form-table">';
echo ' <tr>';
echo ' <th><label for="sqpp_sqpp_mb_second_editor_wysiwyg" class="sqpp_sqpp_mb_second_editor_wysiwyg_label">' . __( '', 'sqppcptmeta' ) . '</label></th>';
echo ' <td>';
wp_editor( $sqpp_sqpp_mb_second_editor_wysiwyg, 'sqpp_sqpp_mb_second_editor_wysiwyg', array( 'media_buttons' => true ) );
echo ' </td>';
echo ' </tr>';
echo '</table>';
}
public function save_metabox( $post_id, $post ) {
// Add nonce for security and authentication.
$nonce_name = isset( $_POST['sqpp_nonce'] ) ? $_POST['sqpp_nonce'] : '';
$nonce_action = 'sqpp_nonce_action';
// Check if a nonce is set.
if ( ! isset( $nonce_name ) )
return;
// Check if a nonce is valid.
if ( ! wp_verify_nonce( $nonce_name, $nonce_action ) )
return;
// Check if the user has permissions to save data.
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
// Check if it's not an autosave.
if ( wp_is_post_autosave( $post_id ) )
return;
// Check if it's not a revision.
if ( wp_is_post_revision( $post_id ) )
return;
// Sanitize user input.
$sqpp_new_sqpp_mb_second_editor_wysiwyg = isset( $_POST[ 'sqpp_sqpp_mb_second_editor_wysiwyg' ] ) ? wp_kses_post( $_POST[ 'sqpp_sqpp_mb_second_editor_wysiwyg' ] ) : '';
// Update the meta field in the database.
update_post_meta( $post_id, 'sqpp_sqpp_mb_second_editor_wysiwyg', $sqpp_new_sqpp_mb_second_editor_wysiwyg );
}
}
new sqpp_metabox_second_editor;