function __construct($id = '', $output = 'OBJECT')
 {
     $this->id = $id;
     $this->output = $output;
     $this->details = get_post($this->id, $this->output);
     $templates = new CP_Certificate_Templates();
     $fields = $templates->get_template_col_fields();
     foreach ($fields as $field) {
         if (!isset($this->details->{$field['field_name']})) {
             $this->details->{$field['field_name']} = get_post_meta($this->id, $field['field_name'], true);
         }
     }
 }
<?php

global $cp_template_elements;
$templates = new CP_Certificate_Templates();
$template_elements = new CP_Certificate_Template_Elements();
$template_elements_set = array();
$page = $_GET['page'];
if (isset($_POST['add_new_template'])) {
    if (check_admin_referer('save_template')) {
        if (current_user_can('coursepress_create_certificates_cap') || current_user_can('manage_options')) {
            $templates->add_new_template();
            $message = __('Certificate Template data has been successfully saved.', 'cp');
        } else {
            $message = __('You do not have required permissions for this action.', 'cp');
        }
    }
}
if (isset($_GET['action']) && $_GET['action'] == 'edit' && (current_user_can('coursepress_update_certificates_cap') || current_user_can('manage_options'))) {
    $post_id = (int) $_GET['ID'];
    $template = new CP_Certificate_Template($post_id);
    $template_elements = new CP_Certificate_Template_Elements($post_id);
    $template_elements_set = $template_elements->get_all_set_elements();
}
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
    if (!isset($_POST['_wpnonce'])) {
        check_admin_referer('delete_' . $_GET['ID']);
        if (current_user_can('coursepress_delete_certificates_cap') || current_user_can('manage_options')) {
            $template = new CP_Certificate_Template((int) $_GET['ID']);
            $template->delete_template();
            $message = __('Certificate Template has been successfully deleted.', 'cp');
        } else {