This is an old revision of the document!
Um eine einfache Metabox bei der Beitragsbearbeitenseiten (Post Edit Screen) einzufügen, kann folgender Code genutzt werden.
<?php /* Metabox init */ new MetaboxPost(); /** * METABOX KLASSE */ class MetaboxPost { function __construct( ) { add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] ); add_action( 'save_post', [ $this, 'save' ] ); } public function add_metabox() { $mb_id = 'plugin_metbox_name'; $mb_title = 'Meine Metabox'; $mb_callback = [ $this, 'render_metabox' ]; $mb_screens = ['post','event']; $mb_position = 'side'; $mb_priority = 'low'; $mb_callback_args = null; add_meta_box( $mb_id, $mb_title, $mb_callback, $mb_screens, $mb_position, $mb_priority, $mb_callback_args ); } public function render_metabox() { echo "<p>HTML Ausgabe der Metabox</p>"; } public function save() { // Nichts machen bei Auto-Save if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } // Sanitizen von Eingaben //$mydata = sanitize_text_field( $_POST['myplugin_new_field'] ); // Update von einem Metafeld //update_post_meta( $post_id, '_my_meta_value_key', $mydata ); } }