/** * Hook into pre_get_posts and limit employees quotes to their own events * if their permissions are not full. * * @since 1.0 * @param arr $query The WP_Query * @return void */ function mdjm_limit_results_to_employee_quotes($query) { if (!is_admin() || 'mdjm-quotes' != $query->get('post_type') || mdjm_employee_can('list_all_quotes')) { return; } global $user_ID; $events = mdjm_get_employee_events($user_ID); foreach ($events as $event) { $quote = mdjm_get_event_quote_id($event->ID); if (!empty($quote)) { $quotes[] = $quote; } } if (!empty($quotes)) { $query->set('post__in', $quotes); } }
/** * Hook into pre_get_posts and limit employees addons if their permissions are not full. * * @since 1.4 * @param arr $query The WP_Query * @return void */ function mdjm_limit_results_to_employee_addons($query) { if (!is_admin() || 'mdjm-addon' != $query->get('post_type') || mdjm_employee_can('mdjm_package_edit')) { return; } global $user_ID; $query->set('meta_query', array(array('key' => '_addon_employees', 'value' => sprintf(':"%s";', $user_ID), 'compare' => 'LIKE'))); }
/** * Adjust the query when the transactions are filtered. * * @since 1.3 * @param arr $query The WP_Query * @return void */ function mdjm_transaction_post_filtered($query) { global $pagenow; $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : ''; if ('edit.php' != $pagenow || 'mdjm-transaction' != $post_type || !is_admin()) { return; } // Filter by transaction type if (!empty($_GET['mdjm_filter_type'])) { $type = isset($_GET['mdjm_filter_type']) ? $_GET['mdjm_filter_type'] : 0; if ($type != 0) { $query->set('tax_query', array(array('taxonomy' => 'transaction-types', 'field' => 'term_id', 'terms' => $type))); } } }
/** * Customise the event post query during a search so that clients and employees are included in results. * * @since 1.0 * @param arr $query The WP_Query * @return void */ function mdjm_event_post_search($query) { global $pagenow; if (!is_admin() || 'mdjm-event' != $query->get('post_type') || !$query->is_search() || 'edit.php' != $pagenow) { return; } // If searching it's only useful if we include clients and employees $users = new WP_User_Query(array('search' => $_GET['s'], 'search_columns' => array('user_login', 'user_email', 'user_nicename', 'display_name'))); // WP_User_Query $user_results = $users->get_results(); // Loop through WP_User_Query search looking for events where user is client or employee if (!empty($user_results)) { foreach ($user_results as $user) { $results = get_posts(array('post_type' => 'mdjm-event', 'post_status' => 'any', 'posts_per_page' => -1, 'meta_query' => array('relation' => 'OR', array('key' => '_mdjm_event_dj', 'value' => $user->ID, 'type' => 'NUMERIC'), array('key' => '_mdjm_event_client', 'value' => $user->ID, 'type' => 'NUMERIC'), array('key' => '_mdjm_event_employees', 'value' => sprintf(':"%s";', $user->ID), 'compare' => 'LIKE')))); // get_posts if (!empty($results)) { foreach ($results as $result) { $events[] = $result->ID; } } } // foreach( $users as $user ) if (!empty($events)) { $query->set('post__in', $events); $query->set('post_status', array('mdjm-unattended', 'mdjm-enquiry', 'mdjm-contract', 'mdjm-approved', 'mdjm-failed', 'mdjm-rejected', 'mdjm-completed')); } } // if( !empty( $users ) ) }