function __construct($id = '', $output = 'OBJECT') { $this->id = $id; $this->output = $output; $this->details = get_post($this->id, $this->output); $api_keys = new TC_API_Keys(); $fields = $api_keys->get_api_keys_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 $tc; $api_keys = new TC_API_Keys(); $page = $_GET['page']; $tab = $_GET['tab']; if (isset($_POST['add_new_api_key'])) { if (check_admin_referer('save_api_key')) { if (current_user_can('manage_options') || current_user_can('add_api_key_cap')) { $api_keys->add_new_api_key(); $message = __('API Key data has been successfully saved.', 'tc'); } else { $message = __('You do not have required permissions for this action.', 'tc'); } } } if (isset($_GET['action']) && $_GET['action'] == 'edit') { $api_key = new TC_API_Key((int) $_GET['ID']); $post_id = (int) $_GET['ID']; } if (isset($_GET['action']) && $_GET['action'] == 'delete') { if (!isset($_POST['_wpnonce'])) { check_admin_referer('delete_' . $_GET['ID']); if (current_user_can('manage_options') || current_user_can('delete_api_key_cap')) { $api_key = new TC_API_Key((int) $_GET['ID']); $api_key->delete_api_key(); $message = __('API Key has been successfully deleted.', 'tc'); } else { $message = __('You do not have required permissions for this action.', 'tc'); } }
function add_default_posts_and_metas() { global $wpdb; $template_count = (int) $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = 'tc_templates' AND post_status = 'publish'"); /* Add Default Ticket Template */ if ($template_count == 0) { $post = array('post_content' => '', 'post_status' => 'publish', 'post_title' => __('Default', 'tc'), 'post_type' => 'tc_templates'); $post = apply_filters('tc_template_post', $post); $post_id = wp_insert_post($post); /* Add post metas for the template */ if ($post_id != 0) { update_post_meta($post_id, 'tc_event_logo_element_cell_alignment', 'left'); update_post_meta($post_id, 'tc_event_logo_element_top_padding', '0'); update_post_meta($post_id, 'tc_event_logo_element_bottom_padding', '3'); update_post_meta($post_id, 'tc_event_terms_element_font_size', '12'); update_post_meta($post_id, 'tc_event_terms_element_font_style', ''); update_post_meta($post_id, 'tc_event_terms_element_font_color', '#7a7a7a'); update_post_meta($post_id, 'tc_event_terms_element_cell_alignment', 'left'); update_post_meta($post_id, 'tc_event_terms_element_top_padding', '1'); update_post_meta($post_id, 'tc_event_terms_element_bottom_padding', '1'); update_post_meta($post_id, 'tc_ticket_qr_code_element_qr_code_size', '50'); update_post_meta($post_id, 'tc_ticket_qr_code_element_cell_alignment', 'center'); update_post_meta($post_id, 'tc_ticket_qr_code_element_top_padding', '1'); update_post_meta($post_id, 'tc_ticket_qr_code_element_bottom_padding', '1'); update_post_meta($post_id, 'tc_event_location_element_font_size', '16'); update_post_meta($post_id, 'tc_event_location_element_font_style', ''); update_post_meta($post_id, 'tc_event_location_element_font_color', '#000000'); update_post_meta($post_id, 'tc_event_location_element_cell_alignment', 'center'); update_post_meta($post_id, 'tc_event_location_element_top_padding', '0'); update_post_meta($post_id, 'tc_event_location_element_bottom_padd', '0'); update_post_meta($post_id, 'tc_ticket_type_element_font_size', '18'); update_post_meta($post_id, 'tc_ticket_type_element_font_style', 'B'); update_post_meta($post_id, 'tc_ticket_type_element_font_color', '#e54c2d'); update_post_meta($post_id, 'tc_ticket_type_element_cell_alignment', 'right'); update_post_meta($post_id, 'tc_ticket_type_element_top_padding', '1'); update_post_meta($post_id, 'tc_ticket_type_element_bottom_padding', '3'); update_post_meta($post_id, 'rows_1', 'tc_event_logo_element,tc_ticket_type_element'); update_post_meta($post_id, 'tc_event_date_time_element_font_size', '16'); update_post_meta($post_id, 'tc_event_date_time_element_font_style', ''); update_post_meta($post_id, 'tc_event_date_time_element_font_color', '#000000'); update_post_meta($post_id, 'tc_event_date_time_element_cell_alignment', 'center'); update_post_meta($post_id, 'tc_event_date_time_element_top_padding', '2'); update_post_meta($post_id, 'tc_event_date_time_element_bottom_padding', '0'); update_post_meta($post_id, 'rows_2', 'tc_event_name_element'); update_post_meta($post_id, 'tc_event_name_element_font_size', '60'); update_post_meta($post_id, 'tc_event_name_element_font_style', ''); update_post_meta($post_id, 'tc_event_name_element_font_color', '#000000'); update_post_meta($post_id, 'tc_event_name_element_cell_alignment', 'center'); update_post_meta($post_id, 'tc_event_name_element_top_padding', '0'); update_post_meta($post_id, 'tc_event_name_element_bottom_padding', '0'); update_post_meta($post_id, 'rows_3', 'tc_event_date_time_element'); update_post_meta($post_id, 'tc_ticket_owner_name_element_font_size', '20'); update_post_meta($post_id, 'tc_ticket_owner_name_element_font_color', '#e54c2d'); update_post_meta($post_id, 'tc_ticket_owner_name_element_cell_alignment', 'center'); update_post_meta($post_id, 'tc_ticket_owner_name_element_top_padding', '3'); update_post_meta($post_id, 'tc_ticket_owner_name_element_bottom_padding', '3'); update_post_meta($post_id, 'rows_4', 'tc_event_location_element'); update_post_meta($post_id, 'rows_5', 'tc_ticket_owner_name_element'); update_post_meta($post_id, 'rows_6', 'tc_ticket_description_element'); update_post_meta($post_id, 'rows_7', 'tc_ticket_qr_code_element'); update_post_meta($post_id, 'rows_8', 'tc_event_terms_element'); update_post_meta($post_id, 'rows_9', ''); update_post_meta($post_id, 'rows_10', ''); update_post_meta($post_id, 'rows_number', '10'); update_post_meta($post_id, 'document_font', 'helvetica'); update_post_meta($post_id, 'document_ticket_size', 'A4'); update_post_meta($post_id, 'document_ticket_orientation', 'P'); update_post_meta($post_id, 'document_ticket_top_margin', '10'); update_post_meta($post_id, 'document_ticket_right_margin', '10'); update_post_meta($post_id, 'document_ticket_left_margin', '10'); update_post_meta($post_id, 'document_ticket_background_image', ''); update_post_meta($post_id, 'tc_ticket_barcode_element_barcode_type', 'C128'); update_post_meta($post_id, 'tc_ticket_barcode_element_barcode_text_visibility', 'visible'); update_post_meta($post_id, 'tc_ticket_barcode_element_1d_barcode_size', '50'); update_post_meta($post_id, 'tc_ticket_barcode_element_font_size', '8'); update_post_meta($post_id, 'tc_ticket_barcode_element_cell_alignment', 'left'); update_post_meta($post_id, 'tc_ticket_barcode_element_top_padding', '0'); update_post_meta($post_id, 'tc_ticket_barcode_element_bottom_padding', '0'); update_post_meta($post_id, 'tc_ticket_description_element_font_size', '12'); update_post_meta($post_id, 'tc_ticket_description_element_font_style', ''); update_post_meta($post_id, 'tc_ticket_description_element_font_color', '#0a0a0a'); update_post_meta($post_id, 'tc_ticket_description_element_cell_alignment', 'left'); update_post_meta($post_id, 'tc_ticket_description_element_top_padding', '0'); update_post_meta($post_id, 'tc_ticket_description_element_bottom_padding', '2'); update_post_meta($post_id, 'tc_event_location_element_bottom_padding', '0'); update_post_meta($post_id, 'tc_ticket_owner_name_element_font_style', ''); } } /* Add random default API Key */ $api_key_count = (int) $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = 'tc_api_keys' AND post_status = 'publish'"); if ($api_key_count == 0) { $post = array('post_content' => '', 'post_status' => 'publish', 'post_title' => __('Default', 'tc'), 'post_type' => 'tc_api_keys'); $post = apply_filters('tc_api_key_default_post', $post); $post_id = wp_insert_post($post); /* Add post metas for the API Key */ $api_keys = new TC_API_Keys(); if ($post_id != 0) { update_post_meta($post_id, 'event_name', 'all'); update_post_meta($post_id, 'api_key_name', 'Default - All Events'); update_post_meta($post_id, 'api_key', $api_keys->get_rand_api_key()); update_post_meta($post_id, 'api_username', ''); } } }
function save_metabox_values($post_id) { if (get_post_type($post_id) == 'tc_events') { $metas = array(); $metas['event_presentation_page'] = $post_id; //Event calendar support URL for better events interface if (isset($_POST['show_tickets_automatically'])) { update_post_meta($post_id, 'show_tickets_automatically', true); } else { update_post_meta($post_id, 'show_tickets_automatically', false); } foreach ($_POST as $field_name => $field_value) { if (preg_match('/_post_meta/', $field_name)) { $metas[str_replace('_post_meta', '', $field_name)] = $field_value; } $metas = apply_filters('events_metas', $metas); if (isset($metas)) { foreach ($metas as $key => $value) { update_post_meta($post_id, $key, $value); } } } //Create default API Key for this event if doesn't exists if (apply_filters('tc_create_event_api_key_automatically', true) == true) { if (!empty($_POST['post_title'])) { $wp_api_keys_search = new TC_API_Keys_Search('', '', $post_id); if (count($wp_api_keys_search->get_results()) == 0) { $api_key_post = array('post_content' => '', 'post_status' => 'publish', 'post_title' => __('', 'tc'), 'post_type' => 'tc_api_keys'); $api_key_post = apply_filters('tc_event_api_key_post', $api_key_post); $api_key_post_id = wp_insert_post($api_key_post); /* Add post metas for the API Key */ $api_keys = new TC_API_Keys(); if ($api_key_post_id != 0) { update_post_meta($api_key_post_id, 'event_name', $post_id); update_post_meta($api_key_post_id, 'api_key_name', $_POST['post_title']); update_post_meta($api_key_post_id, 'api_key', $api_keys->get_rand_api_key()); update_post_meta($api_key_post_id, 'api_username', ''); } } } } } }