Enable the magic method __construct
You have to change the following line
$MySubBoxClass = new MySubBoxClass;
Into
$MySubBoxClass = new MySubBoxClass();
This way the __construct()
magic method will be used.
The add_action
methods aren’t called now.
Error in html_form_func( $object )
Change
public function html_form_func( $object ) //Creates the HTML form and outputs its value if it has one
{
wp_nonce_field( basename( __FILE__ ), 'meta_box_nonce' );
<label><input type="text" name="subheading" id="meta-box-input" size="144" value="<?php echo get_post_meta( $object->ID, 'subheading', true ); ?>" /></label>
}
Into
public function html_form_func( $object ) //Creates the HTML form and outputs its value if it has one
{
wp_nonce_field( basename( __FILE__ ), 'meta_box_nonce' );
?>
<label><input type="text" name="subheading" id="meta-box-input" size="144" value="<?php echo get_post_meta( $object->ID, 'subheading', true ); ?>" /></label>
<?php
}
Object methods by reference
Change
function __construct()
{
add_action( 'add_meta_boxes', array( $this, 'meta_box_add' ) ); //Hooks meta_box_add() onto the add_meta_boxes hook
add_action( 'save_post', array( $this, 'save_meta_box', 10, 2 ) ); //Hooks save_meta_box() onto the save_post hook
add_action('admin_init', array( $this, 'remove_custom_meta_boxes') );//Hooks remove_custom_meta_boxes() onto admin_init
}
Into
function __construct()
{
add_action( 'add_meta_boxes', array( &$this, 'meta_box_add' ) ); //Hooks meta_box_add() onto the add_meta_boxes hook
add_action( 'save_post', array( &$this, 'save_meta_box', 10, 2 ) ); //Hooks save_meta_box() onto the save_post hook
add_action( 'admin_init', array( &$this, 'remove_custom_meta_boxes' ) );//Hooks remove_custom_meta_boxes() onto admin_init
}
If you use object methods in add_action
you have to use &$this
to use $this
in reference.