Beispiel #1
0
 function get_usergroups_clause($table_alias, $args = array())
 {
     $table_alias = $table_alias ? "{$table_alias}." : '';
     $arr = array();
     $arr[] = "{$table_alias}agent_type = 'user' AND {$table_alias}agent_id = '{$this->ID}'";
     foreach (pp_get_group_types(array(), 'names') as $agent_type) {
         $apply_groups = $this->groups[$agent_type];
         if ('pp_group' == $agent_type && pp_get_option('netwide_groups')) {
             foreach (array_keys($apply_groups) as $k) {
                 if (empty($apply_groups[$k]->metagroup_type)) {
                     unset($apply_groups[$k]);
                 }
             }
         }
         if (!empty($apply_groups)) {
             $arr[] = "{$table_alias}agent_type = '{$agent_type}' AND {$table_alias}agent_id IN ('" . implode("', '", array_keys($apply_groups)) . "')";
         }
     }
     if (!empty($args['user_clause'])) {
         $arr[] = "{$table_alias}agent_type = 'user' AND {$table_alias}agent_id = '{$this->ID}'";
     }
     $clause = pp_implode(' OR ', $arr);
     if (count($arr) > 1) {
         $clause = "( {$clause} )";
     }
     if ($clause) {
         return " AND {$clause}";
     } else {
         return ' AND 1=2';
     }
 }
 public static function get_exceptions($args = array())
 {
     $defaults = array('operations' => array(), 'inherited_from' => '', 'for_item_source' => false, 'via_item_source' => false, 'assign_for' => 'item', 'for_item_status' => false, 'post_types' => true, 'taxonomies' => true, 'item_id' => false, 'agent_type' => '', 'agent_id' => 0, 'query_agent_ids' => array(), 'ug_clause' => '', 'return_raw_results' => false, 'extra_cols' => array(), 'cols' => array());
     $args = array_merge($defaults, $args);
     extract($args, EXTR_SKIP);
     global $wpdb;
     $except = array();
     $operations = (array) $operations;
     if ($operations) {
         $operations = array_intersect($operations, pp_get_operations());
     } else {
         $operations = pp_get_operations();
     }
     if (!is_array($post_types)) {
         $post_types = pp_get_enabled_post_types();
     }
     if (!is_array($taxonomies)) {
         $taxonomies = pp_get_enabled_taxonomies();
     }
     $default_arr = array('include', 'exclude');
     if (!defined('PP_NO_ADDITIONAL_ACCESS')) {
         $default_arr[] = 'additional';
     }
     $valid_src_types = array('post' => array('post' => array('' => array_fill_keys($default_arr, array_fill_keys($post_types, array()))), 'term' => array()), 'term' => array('term' => array()), 'pp_group' => array('pp_group' => array()));
     if ($add_source_types = apply_filters('pp_add_exception_source_types', array())) {
         // valid return array is arr[for_item_source] = arr[via_item_src][via_item_type] = array('include', 'exclude' )
         $valid_src_types = array_merge($valid_src_types, $add_source_types);
     }
     if ($for_item_source) {
         $for_item_source = array_flip((array) $for_item_source);
         if (!($for_item_sources = array_intersect_key($for_item_source, $valid_src_types))) {
             return array();
         }
     } else {
         $for_item_sources = $valid_src_types;
     }
     $for_item_clauses = array();
     foreach (array_keys($for_item_sources) as $for_src_name) {
         if (isset($valid_src_types[$for_src_name])) {
             foreach ($operations as $op) {
                 $except["{$op}_{$for_src_name}"] = $valid_src_types[$for_src_name];
             }
             $for_types = array();
             foreach (array_keys($valid_src_types[$for_src_name]) as $via_src_name) {
                 if ('post' == $via_src_name) {
                     foreach (array_keys($valid_src_types[$for_src_name][$via_src_name]) as $via_type) {
                         foreach (array_keys($valid_src_types[$for_src_name][$via_src_name][$via_type]) as $mod_type) {
                             $for_types = array_merge($for_types, array_keys($valid_src_types[$for_src_name][$via_src_name][$via_type][$mod_type]));
                         }
                     }
                 } elseif ('term' == $via_src_name) {
                     if ('term' == $for_src_name) {
                         $for_types = $taxonomies;
                     } else {
                         $for_types = $post_types;
                     }
                 } else {
                     $for_types = false;
                 }
             }
             if (false === $for_types) {
                 $for_item_clauses[] = "e.for_item_source = '{$for_src_name}'";
             } else {
                 $for_item_clauses[] = "e.for_item_source = '{$for_src_name}' AND e.for_item_type IN ('', '" . implode("','", array_unique($for_types)) . "')";
             }
         }
     }
     if ($type_clause = pp_implode('OR', $for_item_clauses)) {
         $type_clause = "AND ( {$type_clause} )";
     }
     if ($via_item_source) {
         $type_clause .= $wpdb->prepare("AND e.via_item_source = '{$via_item_source}'", $via_item_source);
     }
     if ($agent_type && !$ug_clause) {
         $ug_clause = $wpdb->prepare(" AND e.agent_type = %s AND e.agent_id IN ('" . implode("','", array_map('intval', (array) $agent_id)) . "')", $agent_type);
     }
     $operation_clause = "AND e.operation IN ('" . implode("','", $operations) . "')";
     $mod_clause = defined('PP_NO_ADDITIONAL_ACCESS') ? "AND e.mod_type != 'additional'" : '';
     $assign_for_clause = $assign_for ? $wpdb->prepare("AND i.assign_for = %s", $assign_for) : '';
     $inherited_from_clause = $inherited_from !== '' ? $wpdb->prepare("AND i.inherited_from = %d", $inherited_from) : '';
     $status_clause = false !== $for_item_status ? $wpdb->prepare("AND e.for_item_status = %s", $for_item_status) : '';
     if (!$status_clause && !defined('PPS_VERSION')) {
         $status_clause = "AND e.for_item_status IN ('','post_status:private','post_status:draft')";
     }
     // exceptions for other statuses will not be applied correctly without custom statuses extension
     if (!$cols) {
         $cols = "e.operation, e.for_item_source, e.for_item_type, e.mod_type, e.via_item_source, e.via_item_type, e.for_item_status, i.item_id, i.assign_for";
     }
     $extra_cols_clause = $extra_cols ? ', ' . implode(",", $extra_cols) : '';
     $id_clause = false !== $item_id ? $wpdb->prepare("AND i.item_id = %d", $item_id) : '';
     $results = $wpdb->get_results("SELECT {$cols}{$extra_cols_clause} FROM {$wpdb->ppc_exceptions} AS e INNER JOIN {$wpdb->ppc_exception_items} AS i ON e.exception_id = i.exception_id WHERE ( 1=1 {$operation_clause} {$assign_for_clause} {$inherited_from_clause} {$mod_clause} {$type_clause} {$status_clause} {$id_clause} ) {$ug_clause}");
     if ($return_raw_results) {
         return $results;
     }
     foreach ($results as $row) {
         // note: currently only additional access can be status-specific
         $except["{$row->operation}_{$row->for_item_source}"][$row->via_item_source][$row->via_item_type][$row->mod_type][$row->for_item_type][$row->for_item_status][] = $row->item_id;
     }
     return $except;
 }
 function load_exceptions($via_item_source, $for_item_source, $via_item_type, $item_id, $args = array())
 {
     global $wpdb, $wp_roles;
     $this->loaded_item_id = $item_id;
     if (!isset($this->current_exceptions)) {
         $this->current_exceptions = array();
         $this->agent_info = array();
     }
     $args = array_merge(compact('for_item_source', 'item_id'), array('for_item_type' => '', 'for_item_status' => ''), $args, array('cols' => 'e.agent_type, e.agent_id, e.operation, e.mod_type, i.eitem_id, i.assign_for', 'return_raw_results' => true, 'inherited_from' => '', 'assign_for' => '', 'hierarchical' => false));
     $for_item_type = isset($args['for_item_type']) ? $args['for_item_type'] : $via_item_type;
     extract($args, EXTR_SKIP);
     if ('term' == $via_item_source && !$for_item_type) {
         unset($args['for_item_source']);
         $args['post_types'] = array('');
     }
     //if ( 'term' == $for_item_source )
     $args['cols'] .= ', e.for_item_type';
     if (!empty($agent_type)) {
         $agents_by_type = array($agent_type => array());
     } else {
         $agents_by_type = array();
     }
     $exc = ppc_get_exceptions($args);
     foreach ($exc as $row) {
         pp_set_array_elem($this->current_exceptions, array($row->for_item_type, $row->operation, $row->agent_type, $row->agent_id, $row->assign_for, $row->mod_type));
         $this->current_exceptions[$row->for_item_type][$row->operation][$row->agent_type][$row->agent_id][$row->assign_for][$row->mod_type] = $row->eitem_id;
         if (!isset($agents_by_type[$row->agent_type])) {
             $agents_by_type[$row->agent_type] = array();
         }
         $agents_by_type[$row->agent_type][] = $row->agent_id;
     }
     foreach (array_keys($agents_by_type) as $agent_type) {
         $agents_by_type[$agent_type] = array_unique($agents_by_type[$agent_type]);
         $ids = $agents_by_type[$agent_type];
         if (!empty($agent_id)) {
             $ids = array_merge($ids, (array) $agent_id);
         }
         // ajax passes in specific id(s)
         if ('user' == $agent_type) {
             $this->agent_info['user'] = $wpdb->get_results("SELECT ID, user_login as name, display_name FROM {$wpdb->users} WHERE ID IN ('" . implode("','", array_map('intval', $ids)) . "') ORDER BY user_login", OBJECT_K);
         } elseif ('pp_group' != $agent_type) {
             $_args = array('ids' => $ids);
             $this->agent_info[$agent_type] = pp_get_groups($agent_type, $_args);
         }
     }
     // retrieve info for all WP roles regardless of exception storage
     $_args = array('cols' => "ID, group_name AS name, metagroup_type, metagroup_id");
     if (!empty($agent_id)) {
         // ajax usage
         $_args['ids'] = (array) $agent_id;
     } else {
         $_where = isset($agents_by_type['pp_group']) ? "ID IN ('" . implode("','", $agents_by_type['pp_group']) . "')" : "  metagroup_type != 'wp_role'";
         if (!($pp_only_roles = pp_get_option('supplemental_role_defs'))) {
             $pp_only_roles = array();
         }
         $_args['where'] = " AND ( {$_where} OR ( metagroup_type = 'wp_role' AND metagroup_id NOT IN ('" . implode("','", $pp_only_roles) . "') ) )";
     }
     $this->agent_info['pp_group'] = pp_get_groups('pp_group', $_args);
     $this->agent_info['wp_role'] = array();
     // rekey WP role exceptions
     foreach ($this->agent_info['pp_group'] as $agent_id => $group) {
         if ('wp_role' == $group->metagroup_type) {
             /*
             if ( 'wp_anon' == $group->metagroup_id ) {
             	unset( $this->agent_info['pp_group'][$agent_id] );
             	continue;
             }
             */
             $this->agent_info['wp_role'][$agent_id] = (object) $this->agent_info['pp_group'][$agent_id];
             if ($role_exists = isset($wp_roles->role_names[$group->metagroup_id])) {
                 $this->agent_info['wp_role'][$agent_id]->name = $wp_roles->role_names[$group->metagroup_id];
             }
             unset($this->agent_info['pp_group'][$agent_id]);
             if ($role_exists || in_array($group->metagroup_id, array('wp_anon', 'wp_all', 'wp_auth'))) {
                 foreach (array_keys($this->current_exceptions) as $for_item_type) {
                     foreach (array_keys($this->current_exceptions[$for_item_type]) as $op) {
                         if (isset($this->current_exceptions[$for_item_type][$op]['pp_group'][$agent_id])) {
                             $this->current_exceptions[$for_item_type][$op]['wp_role'][$agent_id] = (array) $this->current_exceptions[$for_item_type][$op]['pp_group'][$agent_id];
                             unset($this->current_exceptions[$for_item_type][$op]['pp_group'][$agent_id]);
                         }
                     }
                 }
             }
         }
     }
     // don't include orphaned assignments in metabox tab count
     foreach (array_keys($this->current_exceptions) as $for_item_type) {
         foreach (array_keys($this->current_exceptions[$for_item_type]) as $op) {
             foreach (array_keys($this->current_exceptions[$for_item_type][$op]) as $agent_type) {
                 $this->current_exceptions[$for_item_type][$op][$agent_type] = array_intersect_key($this->current_exceptions[$for_item_type][$op][$agent_type], $this->agent_info[$agent_type]);
             }
         }
     }
     // determine if inclusions are set for any agents
     $where = 'term' == $via_item_source ? "AND e.via_item_type = '{$via_item_type}'" : '';
     $where .= 'term' == $via_item_source ? '' : " AND e.for_item_source = '{$for_item_source}'";
     $query_users = isset($this->agent_info['user']) ? array_keys($this->agent_info['user']) : array();
     if (!empty($args['agent_type']) && 'user' == $args['agent_type'] && !empty($args['agent_id'])) {
         $query_users = array_merge($query_users, (array) $args['agent_id']);
     }
     $agents_clause = array();
     if (!empty($args['agent_type']) && 'user' != $args['agent_type']) {
         $agents_clause[] = "( e.agent_type = '" . $args['agent_type'] . "' )";
     }
     if ($query_users) {
         $agents_clause[] = "( e.agent_type = 'user' AND e.agent_id IN ('" . implode("','", $query_users) . "') )";
     }
     $agents_clause = $agents_clause ? pp_implode(' OR ', $agents_clause) : '1=1';
     $_assignment_modes = $hierarchical ? array('item', 'children') : array('item');
     // Populate only for wp roles, groups and users with stored exceptions.  Will query for additional individual users as needed.
     foreach ($_assignment_modes as $_assign_for) {
         $results = $wpdb->get_results("SELECT DISTINCT e.agent_type, e.agent_id, e.operation, e.for_item_type FROM {$wpdb->ppc_exceptions} AS e INNER JOIN {$wpdb->ppc_exception_items} AS i ON e.exception_id = i.exception_id WHERE {$agents_clause} AND i.assign_for = '{$_assign_for}' AND e.mod_type = 'include' {$where}");
         foreach ($results as $row) {
             //$_agent_type = ( 'pp_group' == $row->agent_type ) ? 'wp_role' : $row->agent_type;
             if ('pp_group' == $row->agent_type && in_array($row->agent_id, array_keys($this->agent_info['wp_role']))) {
                 $_agent_type = 'wp_role';
             } else {
                 $_agent_type = $row->agent_type;
             }
             pp_set_array_elem($this->inclusions_active, array($row->for_item_type, $row->operation, $_agent_type, $row->agent_id, $_assign_for));
             $this->inclusions_active[$row->for_item_type][$row->operation][$_agent_type][$row->agent_id][$_assign_for] = true;
         }
     }
 }
 public static function add_exception_clauses($where, $required_operation, $post_type, $args = array())
 {
     $defaults = array('source_alias' => '', 'apply_term_restrictions' => true, 'append_post_type_clause' => true, 'additions_only' => false);
     extract(array_merge($defaults, $args), EXTR_SKIP);
     global $wpdb, $pp_current_user;
     $src_table = $source_alias ? $source_alias : $wpdb->posts;
     $exc_post_type = apply_filters('pp_exception_post_type', $post_type, $required_operation, $args);
     if (!$additions_only) {
         if ($where) {
             // where clause already indicates sitewide caps for one or more statuses (or just want the exceptions clause generated)
             if ($append_clause = apply_filters('pp_append_query_clause', '', $post_type, $required_operation, $args)) {
                 $where .= $append_clause;
             }
             $post_blockage_priority = pp_get_option('post_blockage_priority');
             $post_blockage_clause = '';
             foreach (array('include' => 'IN', 'exclude' => 'NOT IN') as $mod => $logic) {
                 if ($ids = $pp_current_user->get_exception_posts($required_operation, $mod, $exc_post_type)) {
                     $_args = array_merge($args, compact('mod', 'ids', 'src_table', 'logic'));
                     $clause_var = $post_blockage_priority ? 'post_blockage_clause' : 'where';
                     ${$clause_var} .= " AND " . apply_filters('pp_exception_clause', "{$src_table}.ID {$logic} ('" . implode("','", $ids) . "')", $required_operation, $post_type, $_args);
                     break;
                     // don't use both include and exclude clauses
                 }
             }
             // term restrictions which apply only to this post type
             if ($apply_term_restrictions) {
                 $where .= self::add_term_restrictions_clause($required_operation, $post_type, $src_table);
             }
         } else {
             $where = '1=2';
         }
     }
     $additions = array();
     $additional_ids = $pp_current_user->get_exception_posts($required_operation, 'additional', $exc_post_type, array('status' => true));
     foreach ($additional_ids as $_status => $_ids) {
         if ($_status) {
             // db storage is with "post_status:" prefix to allow for implementation of other attributes
             if (0 === strpos($_status, 'post_status:')) {
                 $_status = str_replace('post_status:', '', $_status);
             } else {
                 continue;
             }
         }
         if (!isset($additions[$_status])) {
             $additions[$_status] = array();
         }
         // facilitates user-add on post edit form without dealing with status caps
         $in_clause = "IN ('" . implode("','", $_ids) . "')";
         $additions[$_status][] = apply_filters('pp_additions_clause', "{$src_table}.ID {$in_clause}", $required_operation, $post_type, array('via_item_source' => 'post', 'status' => $_status, 'in_clause' => $in_clause, 'src_table' => $src_table));
     }
     $additional_ttids = array();
     foreach (pp_get_enabled_taxonomies(array('object_type' => $post_type)) as $taxonomy) {
         $tt_ids = $pp_current_user->get_exception_terms($required_operation, 'additional', $post_type, $taxonomy, array('status' => true, 'merge_universals' => true));
         // merge this taxonomy exceptions with other taxonomies
         foreach (array_keys($tt_ids) as $_status) {
             if (!isset($additional_ttids[$_status])) {
                 $additional_ttids[$_status] = array();
             }
             $additional_ttids[$_status] = array_merge($additional_ttids[$_status], $tt_ids[$_status]);
         }
     }
     if ($additional_ttids) {
         foreach ($additional_ttids as $_status => $_ttids) {
             if ($_status) {
                 if (0 === strpos($_status, 'post_status:')) {
                     $_status = str_replace('post_status:', '', $_status);
                 } else {
                     continue;
                 }
             }
             if (!isset($additions[$_status])) {
                 $additions[$_status] = array();
             }
             $in_clause = "IN ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ('" . implode("','", $_ttids) . "') )";
             $additions[$_status][] = apply_filters('pp_additions_clause', "{$src_table}.ID {$in_clause}", $required_operation, $post_type, array('via_item_source' => 'term', 'status' => $_status, 'in_clause' => $in_clause, 'src_table' => $src_table));
         }
     }
     foreach (array_keys($additions) as $_status) {
         switch ($_status) {
             case '':
                 $_status_clause = '';
                 break;
             case '{unpublished}':
                 if ('read' != $required_operation) {
                     // sanity check
                     $_stati = array_merge(pp_get_post_stati(array('public' => true, 'post_type' => $post_type)), pp_get_post_stati(array('private' => true, 'post_type' => $post_type)));
                     $_status_clause = "{$src_table}.post_status NOT IN ('" . implode("','", $_stati) . "') AND ";
                     break;
                 }
             default:
                 $_status_clause = "{$src_table}.post_status = '{$_status}' AND ";
                 break;
         }
         $additions[$_status] = $_status_clause . pp_implode(' OR ', $additions[$_status]);
     }
     if ($additions = apply_filters('pp_apply_additions', $additions, $where, $required_operation, $post_type, $args)) {
         $where = "( {$where} ) OR ( " . pp_implode(' OR ', $additions) . " )";
         if ($post_blockage_clause) {
             $post_blockage_clause = "AND ( ( 1=1 {$post_blockage_clause} ) OR ( " . pp_implode(' OR ', $additions) . " ) )";
         }
         /*
         $additions = pp_implode( ' OR ', $additions );
         
         if ( $append_post_type_clause )
         	$where = "$src_table.post_type = '$post_type' AND ( ( $where ) OR ( $additions ) )";
         else
         	$where = "( $where ) OR ( $additions )";
         		
         		} elseif ( $append_post_type_clause ) {
         $where = "$src_table.post_type = '$post_type' AND $where";
         */
     }
     if ($post_blockage_priority) {
         $where = "( {$where} ) {$post_blockage_clause}";
     }
     if ($append_post_type_clause) {
         $where = "{$src_table}.post_type = '{$post_type}' AND ( {$where} )";
     }
     return $where;
 }
 function get_posts_where($args)
 {
     $defaults = array('post_types' => array(), 'source_alias' => false, 'src_table' => '', 'apply_term_restrictions' => true, 'include_trash' => 0, 'required_operation' => '', 'limit_statuses' => false, 'skip_teaser' => false, 'query_contexts' => array(), 'force_types' => false);
     $args = array_merge($defaults, (array) $args);
     extract($args, EXTR_SKIP);
     //d_echo ("<br /><strong>get_posts_where:</strong> <br />");
     global $wpdb;
     if (!$src_table) {
         $src_table = $source_alias ? $source_alias : $wpdb->posts;
         $args['src_table'] = $src_table;
     }
     if (!$force_types) {
         $post_types = array_intersect((array) $post_types, pp_get_enabled_post_types());
     }
     $tease_otypes = array_intersect($post_types, $this->_get_teaser_post_types($post_types, $args));
     if (!$required_operation) {
         $required_operation = pp_is_front() && !is_preview() ? 'read' : 'edit';
         $args['required_operation'] = $required_operation;
     }
     if ($query_contexts) {
         $query_contexts = (array) $query_contexts;
     }
     $meta_cap = "{$required_operation}_post";
     if ('read' == $required_operation) {
         $use_statuses = array_merge(pp_get_post_stati(array('public' => true, 'post_type' => $post_types), 'object'), pp_get_post_stati(array('private' => true, 'post_type' => $post_types), 'object'));
         foreach ($use_statuses as $key => $obj) {
             if (!empty($obj->exclude_from_search)) {
                 // example usage is bbPress hidden status
                 unset($use_statuses[$key]);
             }
         }
     } else {
         $use_statuses = pp_get_post_stati(array('internal' => false, 'post_type' => $post_types), 'object');
     }
     if (in_array('attachment', $post_types)) {
         $use_statuses['inherit'] = (object) array();
     }
     if (is_array($limit_statuses)) {
         $use_statuses = array_intersect_key($use_statuses, $limit_statuses);
     }
     if (empty($skip_teaser) && !array_diff($post_types, $tease_otypes)) {
         // All object types potentially returned by this query will have a teaser filter applied to results, so we don't need to use further query filtering
         $status_clause = "AND {$src_table}.post_status IN ('" . implode("','", array_keys($use_statuses)) . "')";
         return $status_clause;
     }
     if (!is_bool($include_trash)) {
         if (!empty($_REQUEST['post_status']) && 'trash' == $_REQUEST['post_status']) {
             $include_trash = true;
         }
     }
     $where_arr = array();
     global $pp_current_user;
     global $pp_meta_caps;
     $flag_meta_caps = !empty($pp_meta_caps);
     foreach ($post_types as $post_type) {
         if (in_array($post_type, $tease_otypes) && empty($skip_teaser)) {
             $where_arr[$post_type] = "{$src_table}.post_type = '{$post_type}' AND 1=1";
         } else {
             $have_site_caps = array();
             $type_obj = get_post_type_object($post_type);
             foreach (array_keys($use_statuses) as $status) {
                 if ('private' == $status) {
                     $cap_property = "{$required_operation}_private_posts";
                     if (empty($type_obj->cap->{$cap_property})) {
                         continue;
                     }
                 }
                 if ($flag_meta_caps) {
                     $pp_meta_caps->do_status_cap_map = true;
                 }
                 $reqd_caps = pp_map_meta_cap($meta_cap, $pp_current_user->ID, 0, compact('post_type', 'status', 'query_contexts'));
                 if ($flag_meta_caps) {
                     $pp_meta_caps->do_status_cap_map = false;
                 }
                 if ($reqd_caps) {
                     // note: this function is called only for listing query filters (not for user_has_cap filter)
                     if ($missing_caps = apply_filters('pp_query_missing_caps', array_diff($reqd_caps, array_keys($pp_current_user->allcaps)), $reqd_caps, $post_type, $meta_cap)) {
                         $owner_reqd_caps = $this->get_base_caps($reqd_caps, $post_type);
                         // remove "others" and "private" cap requirements for post author
                         if ($owner_reqd_caps != $reqd_caps && $pp_current_user->ID) {
                             // && ! $omit_owner_clause
                             if (!array_diff($owner_reqd_caps, array_keys($pp_current_user->allcaps))) {
                                 $have_site_caps['owner'][] = $status;
                             }
                         }
                     } else {
                         $have_site_caps['user'][] = $status;
                     }
                 }
             }
             $have_site_caps = apply_filters('pp_have_site_caps', $have_site_caps, $post_type, $args);
             if ($include_trash) {
                 if ($type_obj = get_post_type_object($post_type)) {
                     if ('edit_post' == $meta_cap && !empty($pp_current_user->allcaps[$type_obj->cap->edit_posts]) || 'delete_post' == $meta_cap && !empty($pp_current_user->allcaps[$type_obj->cap->delete_posts])) {
                         if (!isset($type_obj->cap->delete_others_posts) || !empty($pp_current_user->allcaps[$type_obj->cap->delete_others_posts])) {
                             $have_site_caps['user'][] = 'trash';
                         } else {
                             $have_site_caps['owner'][] = 'trash';
                         }
                     }
                 }
             }
             $where_arr[$post_type] = array();
             if (!empty($have_site_caps['user'])) {
                 $where_arr[$post_type]['user'] = "******" . implode("','", array_unique($have_site_caps['user'])) . "')";
             }
             //dump($have_site_caps);
             if (!empty($have_site_caps['owner'])) {
                 $parent_clause = '';
                 // PPCE may be set to "ID IN (...) OR " to enable post revisors to edit their own pending revisions
                 $args['post_type'] = $post_type;
                 $_vars = apply_filters('pp_generate_where_clause_force_vars', null, 'post', $args);
                 if (is_array($_vars)) {
                     extract($_vars);
                     // possible @todo: intersect keys as with pp_has_cap_force_vars
                 }
                 if (!empty($args['skip_stati_usage_clause']) && !$limit_statuses && !array_diff_key($use_statuses, array_flip($have_site_caps['owner']))) {
                     $where_arr[$post_type]['owner'] = "{$parent_clause} ( {$src_table}.post_author = {$pp_current_user->ID} )";
                 } else {
                     $where_arr[$post_type]['owner'] = "{$parent_clause} ( {$src_table}.post_author = {$pp_current_user->ID} ) AND {$src_table}.post_status IN ('" . implode("','", array_unique($have_site_caps['owner'])) . "')";
                 }
             }
             if (is_array($where_arr[$post_type])) {
                 if ($where_arr[$post_type]) {
                     $where_arr[$post_type] = pp_implode('OR', $where_arr[$post_type]);
                     $where_arr[$post_type] = "1=1 AND ( " . $where_arr[$post_type] . " )";
                 } else {
                     $where_arr[$post_type] = '1=2';
                 }
             }
             if ($modified = apply_filters('pp_adjust_posts_where_clause', false, $where_arr[$post_type], $post_type, $args)) {
                 $where_arr[$post_type] = $modified;
             }
             if ('attachment' == $post_type) {
                 if ('read' == $required_operation || apply_filters('pp_force_attachment_parent_clause', false, $args)) {
                     //if ( ( 'read' == $required_operation ) || ( defined('DOING_AJAX') && DOING_AJAX && ( false != strpos( $_SERVER['REQUEST_URI'], 'async-upload.php' ) ) ) || apply_filters( 'pp_force_attachment_parent_clause', false, $args ) ) {
                     $where_arr[$post_type] = "( " . $this->append_attachment_clause("{$src_table}.post_type = 'attachment'", array(), $args) . " )";
                 }
             }
             if ('delete' == $required_operation) {
                 $const = "PP_EDIT_EXCEPTIONS_ALLOW_" . strtoupper($post_type) . "_DELETION";
                 if (defined('PP_EDIT_EXCEPTIONS_ALLOW_DELETION') || defined($const)) {
                     $required_operation = 'edit';
                 }
             }
             $where_arr[$post_type] = PP_Exceptions::add_exception_clauses($where_arr[$post_type], $required_operation, $post_type, $args);
         }
     }
     // end foreach post_type
     if (!($pp_where = pp_implode('OR', $where_arr))) {
         $pp_where = '1=1';
     }
     // term restrictions which apply to any post type
     if ($apply_term_restrictions) {
         if ($term_exc_where = PP_Exceptions::add_term_restrictions_clause($required_operation, '', $src_table, array('merge_universals' => true, 'merge_additions' => true, 'exempt_post_types' => $tease_otypes))) {
             $pp_where = "( {$pp_where} ) {$term_exc_where}";
         }
     }
     if ($pp_where) {
         $pp_where = " AND ( {$pp_where} )";
     }
     return $pp_where;
 }