/** * Customise the view filter counts * * @since 1.0 * @param arr $views Array of views * @return arr $views Filtered Array of views */ function mdjm_quote_view_filters($views) { // We only run this filter if the user has restrictive caps and the post type is mdjm-event if (!is_post_type_archive('mdjm-quotes') || mdjm_employee_can('list_all_quotes')) { return $views; } global $user_ID; $events = mdjm_get_employee_events($user_ID); $all = 0; if ($events) { foreach ($events as $event) { $quote = mdjm_get_event_quote_id($event->ID); $quote_status = get_post_status($quote); if (!isset($status[$quote_status])) { $status[$quote_status] = 1; } else { $status[$quote_status]++; } $all++; } } // The All filter $views['all'] = preg_replace('/\\(.+\\)/U', '(' . mdjm_count_employee_events() . ')', $views['all']); $event_statuses = mdjm_all_event_status(); foreach ($event_statuses as $status => $label) { $events = mdjm_get_employee_events('', array('post_status' => $status)); if (empty($events)) { if (isset($views[$status])) { unset($views[$status]); } continue; } $views[$status] = preg_replace('/\\(.+\\)/U', '(' . count($events) . ')', $views[$status]); } // Only show the views we want foreach ($views as $status => $link) { if ($status != 'all' && !array_key_exists($status, $event_stati)) { unset($views[$status]); } } return $views; }
/** * Generates a new online quote for the event. * * Uses the quote template defined within settings unless $template_id is provided. * * @since 1.3 * @param int $event_id The event ID. * @param int $template_id The template ID from which to create the quote. * @return int $quote_id The ID of the newly created post or false on fail. */ function mdjm_create_online_quote($event_id, $template_id = '') { $existing_id = mdjm_get_event_quote_id($event_id); $template_id = !empty($template_id) ? $template_id : mdjm_get_option('online_enquiry'); if (empty($template_id)) { return false; } /** * Allow filtering of the quote template. * * @since 1.3 * @param $template_id */ $template_id = apply_filters('mdjm_online_quote_template', $template_id); $template = get_post($template_id); if (!$template) { return false; } /** * Fire the `mdjm_pre_create_online_quote` hook. * * @since 1.3 * @param int $event_id The Event ID * @param int $template_id The quote template ID * @param obj $template The quote template WP_Post object */ do_action('mdjm_pre_create_online_quote', $event_id, $template_id, $template); $client_id = mdjm_get_event_client_id($event_id); $content = $template->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = mdjm_do_content_tags($content, $event_id, $client_id); $args = array('ID' => $existing_id, 'post_date' => current_time('mysql'), 'post_modified' => current_time('mysql'), 'post_title' => sprintf(__('Quote %s', 'mobile-dj-manager'), mdjm_get_event_contract_id($event_id)), 'post_content' => $content, 'post_type' => 'mdjm-quotes', 'post_status' => 'mdjm-quote-generated', 'post_author' => !empty($client_id) ? $client_id : 1, 'post_parent' => $event_id, 'meta_input' => array('_mdjm_quote_viewed_date' => 0, '_mdjm_quote_viewed_count' => 0)); /** * Allow filtering of the quote template args. * * @since 1.3 * @param $args */ $args = apply_filters('mdjm_create_online_quote_args', $args); $quote_id = wp_insert_post($args); if (!$quote_id) { return false; } // Reset view date and count for existing quotes if (!empty($existing_id)) { delete_post_meta($quote_id, '_mdjm_quote_viewed_date'); delete_post_meta($quote_id, '_mdjm_quote_viewed_count'); } /** * Fire the `mdjm_post_create_online_quote` hook. * * @since 1.3 * @param int $quote_id The new quote ID */ do_action('mdjm_pre_create_online_quote', $quote_id); return $quote_id; }