Created
October 2, 2017 11:21
-
-
Save bahiirwa/5598115d1ba4a3eab62f056e6696e073 to your computer and use it in GitHub Desktop.
Custom Metaboxes OOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//class custom_metabox | |
// { | |
// | |
// private $cm_name_id; | |
// private $cm_name; | |
// private $cpt_name; | |
// | |
// function __construct( $cm_name_id, $cm_name, $cpt_name ) { | |
// $this->cm_name = $cm_name_id; | |
// $this->cm_name = $cm_name; | |
// $this->cpt_name = $cpt_name; | |
// add_action( 'add_meta_boxes', array( $this, 'client_add_metabox_box' ) ); | |
// add_action( 'save_post', array( $this, 'client_box_save_postdata' ) ); | |
// } | |
// | |
// | |
// /* Add metabox */ | |
// function client_add_metabox_box() { | |
// add_meta_box( | |
// $cm_name_id . '_box_id', //ID for box | |
// $cm_name, //Name for the box | |
// $cm_name_id . '_box', //function for input | |
// $cpt_name, //id for CPT | |
// 'normal', //location of input | |
// 'high' //priority | |
// ); | |
// } | |
// | |
// /* Prints the box content */ | |
// function client_box( $post ) { ?> | |
// <input class="widefat" | |
// placeholder="text goes here" | |
// name="<?php echo $cm_name_id; ?>_box_field" | |
// id="<?php echo $cm_name_id; ?>_box_field" | |
// value="<?php echo esc_html( get_post_meta( $post->ID, $cm_name_id . '_box_meta_value_key', true ) ); ?>" /> | |
// <?php } | |
// | |
// /* Saves the value for the box content */ | |
// function client_box_save_postdata( $post_id ) { | |
// if ( array_key_exists('client_box_field', $_POST ) ) { | |
// update_post_meta( $post_id, 'client_box_meta_value_key', $_POST['client_box_field'] ); | |
// } | |
// } | |
// | |
// } */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment