hooks(); } // __construct() public function hooks() { add_action( 'add_meta_boxes', array( $this, 'ams_add_metabox_action' ) ); add_action( 'save_post', array( $this, 'ams_save_post_action' ) ); add_action( 'delete_post', array( $this, 'ams_delete_post_action' ) ); if( ! is_admin() ) { add_filter( 'the_title', array($this, 'ams_the_title') ); } } // hooks() public function ams_add_metabox_action(){ $posttypes = array( 'post', 'page' ); foreach ( $posttypes as $posttype ){ add_meta_box( $this->ams_term, 'Hide Title', array( $this, 'ams_create_metabox' ), $posttype, 'side', 'high' ); } } // ams_add_metabox() public function ams_create_metabox( $post ){ $value = get_post_meta( $post->ID, $this->ams_term, true ); $checked = ''; if( (bool) $value ){ $checked = ' checked="checked"'; } wp_nonce_field( 'msv_ams_hpapt_action', 'msv_ams_hpapt_hide_field' ); ?> ams_term, true ); $new_value = isset($_POST[ $this->ams_term ]) ? $_POST[ $this->ams_term ] : 'off' ; if( $old_value ){ if ( is_null( $new_value ) ){ delete_post_meta( $postID, $this->ams_term ); } else { update_post_meta( $postID, $this->ams_term, $new_value, $old_value ); } } elseif ( !is_null( $new_value ) ){ add_post_meta( $postID, $this->ams_term, $new_value, true ); } return $postID; } // on_save() public function ams_delete_post_action( $postID ){ delete_post_meta( $postID, $this->ams_term ); return $postID; } // on_delete() function ams_the_title( $title ) { global $post; $value = get_post_meta( $post->ID, $this->ams_term, true ); if ( 'on' == $value ) return $title = ''; return $title; } } ?>