/** * Add default KBS email template tags * * @since 0.1 */ function kbs_setup_email_tags() { // Setup default tags array $email_tags = array(array('tag' => 'ticket_details', 'description' => __('Details of the ticket', 'kb-support'), 'function' => 'text/html' == KBS()->emails->get_content_type() ? 'kbs_email_tag_ticket_details' : 'kbs_email_tag_ticket_details_plain'), array('tag' => 'name', 'description' => __('The customers first name', 'kb-support'), 'function' => 'kbs_email_tag_first_name'), array('tag' => 'fullname', 'description' => __('The customers full name, first and last', 'kb-support'), 'function' => 'kbs_email_tag_fullname'), array('tag' => 'username', 'description' => __('The customers user name on the site, if they registered an account', 'kb-support'), 'function' => 'kbs_email_tag_username'), array('tag' => 'user_email', 'description' => __('The customers email address', 'kb-support'), 'function' => 'kbs_email_tag_user_email'), array('tag' => 'date', 'description' => __('The date of the ticket', 'kb-support'), 'function' => 'kbs_email_tag_date'), array('tag' => 'ticket_id', 'description' => __('The unique ID number for this ticket', 'kb-support'), 'function' => 'kbs_email_tag_ticket_id'), array('tag' => 'sitename', 'description' => __('Your site name', 'kb-support'), 'function' => 'kbs_email_tag_sitename'), array('tag' => 'ticket_link', 'description' => __('Adds a link so users can view their ticket directly on your website if they are unable to view it in the browser correctly.', 'kb-support'), 'function' => 'kbs_email_tag_ticket_link'), array('tag' => 'ip_address', 'description' => __('The customers IP Address', 'kb-support'), 'function' => 'kbs_email_tag_ip_address')); // Apply kbs_email_tags filter $email_tags = apply_filters('kbs_email_tags', $email_tags); // Add email tags foreach ($email_tags as $email_tag) { kbs_add_email_tag($email_tag['tag'], $email_tag['description'], $email_tag['function']); } }
* @version 0.1 */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly // For gmail compatibility, including CSS styles in head/body are stripped out therefore styles need to be inline. These variables contain rules which are added to the template inline. !important; is a gmail hack to prevent styles being stripped if it doesn't like something. $body = "\n\tbackground-color: #f6f6f6;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n"; $wrapper = "\n\twidth:100%;\n\t-webkit-text-size-adjust:none !important;\n\tmargin:0;\n\tpadding: 70px 0 70px 0;\n"; $template_container = "\n\tbox-shadow:0 0 0 1px #f3f3f3 !important;\n\tborder-radius:3px !important;\n\tbackground-color: #ffffff;\n\tborder: 1px solid #e9e9e9;\n\tborder-radius:3px !important;\n\tpadding: 20px;\n"; $template_header = "\n\tcolor: #00000;\n\tborder-top-left-radius:3px !important;\n\tborder-top-right-radius:3px !important;\n\tborder-bottom: 0;\n\tfont-weight:bold;\n\tline-height:100%;\n\ttext-align: center;\n\tvertical-align:middle;\n"; $body_content = "\n\tborder-radius:3px !important;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n"; $body_content_inner = "\n\tcolor: #000000;\n\tfont-size:14px;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n\tline-height:150%;\n\ttext-align:left;\n"; $header_content_h1 = "\n\tcolor: #000000;\n\tmargin:0;\n\tpadding: 28px 24px;\n\tdisplay:block;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n\tfont-size:32px;\n\tfont-weight: 500;\n\tline-height: 1.2;\n"; $header_img = kbs_get_option('email_logo', ''); $heading = KBS()->emails->get_heading(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo get_bloginfo('name'); ?> </title> </head> <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="<?php echo $body; ?> "> <div style="<?php
/** * Retrieves a single customer from the database * * @access public * @since 1.0 * @param str $column id or email * @param mixed $value The Customer ID or email to search * @return mixed Upon success, an object of the customer. Upon failure, NULL */ public function get_customer_by($field = 'id', $value = 0) { global $wpdb; if (empty($field) || empty($value)) { return NULL; } if ('id' == $field || 'user_id' == $field) { // Make sure the value is numeric to avoid casting objects, for example, // to int 1. if (!is_numeric($value)) { return false; } $value = intval($value); if ($value < 1) { return false; } } elseif ('email' === $field) { if (!is_email($value)) { return false; } $value = trim($value); } if (!$value) { return false; } switch ($field) { case 'id': $db_field = 'id'; break; case 'email': $value = sanitize_text_field($value); $db_field = 'email'; break; case 'user_id': $db_field = 'user_id'; break; default: return false; } if (!($customer = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->table_name} WHERE {$db_field} = %s LIMIT 1", $value)))) { // Look for customer from an additional email if ('email' === $field) { $meta_table = KBS()->customer_meta->table_name; $customer_id = $wpdb->get_var($wpdb->prepare("SELECT customer_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = '%s' LIMIT 1", $value)); if (!empty($customer_id)) { return $this->get($customer_id); } } return false; } return $customer; }
/** * Sends the Admin Ticket Notification Email * * @since 1.0 * @param int $ticket_id Ticket ID (default: 0) * @param arr $ticket_data Ticket Meta and Data * @return void */ function kbs_admin_email_notice($ticket_id = 0, $ticket_data = array()) { $ticket_id = absint($ticket_id); if (empty($ticket_id)) { return; } /*if( ! kbs_get_payment_by( 'id', $ticket_id ) ) { return; }*/ $from_name = kbs_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); $from_name = apply_filters('kbs_ticket_from_name', $from_name, $ticket_id, $ticket_data); $from_email = kbs_get_option('from_email', get_bloginfo('admin_email')); $from_email = apply_filters('kbs_admin_ticket_from_address', $from_email, $ticket_id, $ticket_data); $subject = kbs_get_option('ticket_notification_subject', sprintf(__('New %1Ss logged - Case #%1$s', 'kb-support'), kbs_get_ticket_label_singular(), $ticket_id)); $subject = apply_filters('kbs_admin_ticket_notification_subject', wp_strip_all_tags($subject), $ticket_id); $subject = kbs_do_email_tags($subject, $ticket_id); $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n"; $headers .= "Reply-To: " . $from_email . "\r\n"; //$headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=utf-8\r\n"; $headers = apply_filters('kbs_admin_ticket_notification_headers', $headers, $ticket_id, $ticket_data); $attachments = apply_filters('kbs_admin_ticket_notification_attachments', array(), $ticket_id, $ticket_data); $message = kbs_get_ticket_notification_body_content($ticket_id, $ticket_data); $emails = KBS()->emails; $emails->__set('from_name', $from_name); $emails->__set('from_email', $from_email); $emails->__set('headers', $headers); $emails->__set('heading', __('New Sale!', 'kb-support')); $emails->send(kbs_get_admin_notice_emails(), $subject, $message, $attachments); }
/** * Display the ticket add note row. * * @since 1.0 * @global obj $kbs_ticket KBS_Ticket class object * @global bool $kbs_ticket_update True if this ticket is being updated, false if new. * @param int $ticket_id The ticket post ID. * @return str */ function kbs_ticket_metabox_add_note_row($ticket_id) { global $kbs_ticket, $kbs_ticket_update; ?> <div id="kbs-ticket-add-note-container"> <p><label for="kbs_new_note"><strong><?php _e('Add a New Note', 'kb-support'); ?> </strong></label><br /> <?php echo KBS()->html->textarea(array('name' => 'kbs_new_note', 'id' => 'kbs_new_note', 'desc' => __('Notes are only visible to support workers', 'kb-support'), 'class' => 'large-text', 'rows' => 5)); ?> </p> <?php /* * Fires immediately before the add note button is output. * @since 1.0 * @param int $post_id The Ticket post ID */ do_action('kbs_ticket_before_add_note_button', $ticket_id); ?> <div class="kbs-add-note"><a id="kbs-add-note" class="button button-secondary"><?php _e('Add Note', 'kb-support'); ?> </a></div> <div id="kbs-new-note-loader"></div> </div> <?php }
/** * Renders an HTML Dropdown of customers * * @access public * @since 1.0 * @param arr $args * @return str Customer dropdown */ public function customer_dropdown($args = array()) { $defaults = array('name' => 'customers', 'id' => '', 'class' => '', 'multiple' => false, 'selected' => 0, 'chosen' => true, 'placeholder' => __('Select a Customer', 'kb-support'), 'number' => 30, 'data' => array('search-type' => 'customer')); $args = wp_parse_args($args, $defaults); $customers = KBS()->customers->get_customers(array('number' => $args['number'])); $options = array(); if ($customers) { $options[0] = __('No customer attached', 'kb-support'); foreach ($customers as $customer) { $options[absint($customer->id)] = esc_html($customer->name . ' (' . $customer->email . ')'); } } else { $options[0] = __('No customers found', 'kb-support'); } if (!empty($args['selected'])) { // If a selected customer has been specified, we need to ensure it's in the initial list of customers displayed if (!array_key_exists($args['selected'], $options)) { $customer = new KBS_Customer($args['selected']); if ($customer) { $options[absint($args['selected'])] = esc_html($customer->name . ' (' . $customer->email . ')'); } } } $output = $this->select(array('name' => $args['name'], 'selected' => $args['selected'], 'id' => $args['id'], 'class' => $args['class'] . ' kbs-customer-select', 'options' => $options, 'multiple' => $args['multiple'], 'chosen' => $args['chosen'], 'show_option_all' => false, 'show_option_none' => false, 'data' => $args['data'])); return $output; }
/** * Remove metadata matching criteria from a customer. * * @param str $meta_key Metadata name. * @param mixed $meta_value Optional. Metadata value. * @return bool False for failure. True for success. * * @access public * @since 1.0 */ public function delete_meta($meta_key = '', $meta_value = '') { return KBS()->customer_meta->delete_meta($this->id, $meta_key, $meta_value); }
/** * Render the rows for setting field options. * * @since 0.1 * @param int $post_id The form post ID. * @param arr $args Function arguments * @return str */ function kbs_render_field_options_rows($post_id) { global $kbs_edit_field; ?> <div id="kbs_meta_field_select_options_wrap"> <p><strong><?php _e('Options', 'kb-support'); ?> </strong><br /> <label for="kbs_field_select_options"> <?php echo KBS()->html->textarea(array('name' => 'kbs_field_select_options', 'value' => !empty($kbs_edit_field->settings['select_options']) ? implode("\n", $kbs_edit_field->settings['select_options']) : null, 'placeholder' => __('One entry per line', 'kb-support'), 'class' => 'kbs_input')); ?> </label></p> </div> <div id="kbs_meta_field_select_multiple_wrap"> <p><label for="kbs_field_select_multiple"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_select_multiple', 'current' => !empty($kbs_edit_field->settings['select_multiple']) ? $kbs_edit_field->settings['select_multiple'] : null)); ?> <strong><?php _e('Multiple Select?', 'kb-support'); ?> </strong></label> </p> </div> <div id="kbs_meta_field_option_selected_wrap"> <p><label for="kbs_field_option_selected"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_option_selected', 'current' => !empty($kbs_edit_field->settings['selected']) ? $kbs_edit_field->settings['selected'] : null)); ?> <strong><?php _e('Initially Selected?', 'kb-support'); ?> </strong></label> </p> </div> <div id="kbs_meta_field_select_searchable_wrap"> <p><label for="kbs_field_select_chosen"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_select_chosen', 'current' => !empty($kbs_edit_field->settings['chosen']) ? $kbs_edit_field->settings['chosen'] : null)); ?> <strong><?php _e('Searchable?', 'kb-support'); ?> </strong></label> </p> </div> <div id="kbs_meta_field_maxfiles_wrap"> <p><strong><?php _e('Maximum Files', 'kb-support'); ?> </strong><br /> <label for="kbs_field_maxfiles"> <?php echo KBS()->html->number(array('name' => 'kbs_field_maxfiles', 'value' => !empty($kbs_edit_field->settings['maxfiles']) ? $kbs_edit_field->settings['maxfiles'] : null, 'class' => 'small-text kbs_input', 'min' => 1, 'max' => kbs_get_option('file_uploads'))); ?> </label></p> </div> <div id="kbs_meta_field_placeholder_wrap"> <p><strong><?php _e('Placeholder', 'kb-support'); ?> </strong><br /> <label for="kbs_field_placeholder"> <?php echo KBS()->html->text(array('name' => 'kbs_field_placeholder', 'value' => !empty($kbs_edit_field->settings['placeholder']) ? $kbs_edit_field->settings['placeholder'] : null, 'class' => 'kbs_input')); ?> </label></p> </div> <div id="kbs_meta_field_hide_label_wrap"> <p><label for="kbs_field_hide_label"> <?php echo KBS()->html->checkbox(array('name' => 'kbs_field_hide_label', 'current' => !empty($kbs_edit_field->settings['hide_label']) ? $kbs_edit_field->settings['hide_label'] : null)); ?> <strong><?php _e('Hide Label?', 'kb-support'); ?> </strong></label> </p> </div> <?php }
/** * Email Template Body * * @since 0.1 * @param int $ticket_id Payment ID * @param arr $ticket_data Payment Data * @return str $email_body Body of the email */ function kbs_get_email_body_content($ticket_id = 0, $ticket_data = array()) { $default_email_body = __("Dear", "kb-support") . " {name},\n\n"; $default_email_body .= sprintf(__("Thank you for logging your %s.", "kb-support"), kbs_get_ticket_label_singular(true)) . "\n\n"; $default_email_body .= "{ticket_detailst}\n\n"; $default_email_body .= "{sitename}"; $email = kbs_get_option('ticket_received', false); $email = $email ? stripslashes($email) : $default_email_body; $email_body = apply_filters('kbs_email_template_wpautop', true) ? wpautop($email) : $email; $email_body = apply_filters('kbs_ticket_received_' . KBS()->emails->get_template(), $email_body, $ticket_id, $ticket_data); return apply_filters('kbs_ticket_received', $email_body, $ticket_id, $ticket_data); }
* @return void */ public function load_textdomain() { load_plugin_textdomain('kb-support', false, dirname(plugin_basename(__FILE__)) . '/languages/'); } } // class KB_Support } /** * The main function for that returns KB_Support * * The main function responsible for returning the one true KB_Support * Instance to functions everywhere. * * Use this function like you would a global variable, except without needing * to declare the global. * * Example: <?php $kbs = KBS(); ?> * * @since 1.0 * @return obj KB_Support The one true KB_Support Instance. */ function KBS() { return KB_Support::instance(); } // KBS // Get KBS Running KBS();
/** * Setup the email address for the ticket * * @since 1.0 * @return str The email address for the ticket */ private function setup_email() { $email = $this->get_meta('_kbs_ticket_user_email', true); if (empty($email)) { $email = KBS()->customers->get_column('email', $this->customer_id); } return $email; }
/** * Run the KBS Install process * * @since 1.0 * @return void */ function kbs_run_install() { global $wpdb, $kbs_options, $wp_version; // Setup the Custom Post Types kbs_setup_kbs_post_types(); // Setup the Custom Taxonomies kbs_setup_custom_taxonomies(); // Clear the permalinks flush_rewrite_rules(false); // Add Upgraded From Option $current_version = get_option('kbs_version'); if ($current_version) { update_option('kbs_version_upgraded_from', $current_version); } // Setup some default options $options = array(); // Pull options from WP, not KBS' global $current_options = get_option('kbs_settings', array()); // Populate some default values foreach (kbs_get_registered_settings() as $tab => $sections) { foreach ($sections as $section => $settings) { // Check for backwards compatibility $tab_sections = kbs_get_settings_tab_sections($tab); if (!is_array($tab_sections) || !array_key_exists($section, $tab_sections)) { $section = 'main'; $settings = $sections; } foreach ($settings as $option) { if (!empty($option['std'])) { if ('checkbox' == $option['type']) { $options[$option['id']] = '1'; } else { $options[$option['id']] = $option['std']; } } } } } $merged_options = array_merge($kbs_options, $options); $kbs_options = $merged_options; update_option('kbs_settings', $merged_options); update_option('kbs_version', KBS_VERSION); // Create KBS support roles $roles = new KBS_Roles(); $roles->add_roles(); $roles->add_caps(); // Create the customer databases @KBS()->customers->create_table(); @KBS()->customer_meta->create_table(); // Add a temporary option to note that KBS pages have been created set_transient('_kbs_installed', $merged_options, 30); /*if ( ! $current_version ) { require_once KBS_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; // When new upgrade routines are added, mark them as complete on fresh install $upgrade_routines = array(); foreach ( $upgrade_routines as $upgrade ) { kbs_set_upgrade_complete( $upgrade ); } }*/ // Bail if activating from network, or bulk if (is_network_admin() || isset($_GET['activate-multi'])) { return; } // Add the transient to redirect set_transient('_kbs_activation_redirect', true, 30); }