public static function item_update_process_exceptions($via_item_source, $for_item_source, $item_id, $args = array()) { $defaults = array_fill_keys(array('is_new', 'set_parent', 'last_parent', 'disallow_manual_entry', 'force_for_item_type'), false); $args = apply_filters('pp_item_update_process_roles_args', array_merge($defaults, array('via_item_type' => '', 'for_item_status' => ''), (array) $args, compact('via_item_source', 'for_item_source', 'item_id')), $via_item_source, $for_item_source, $item_id); if (!defined('PP_EXTRA_ITEM_UPDATE_ARGS')) { $args['for_item_status'] = ''; } extract($args, EXTR_SKIP); if ($can_assign_roles = current_user_can('pp_assign_roles')) { if (apply_filters('pp_disable_exception_edit', false, $via_item_source, $item_id)) { $can_assign_roles = false; } } if (!$disallow_manual_entry) { $disallow_manual_entry = defined('XMLRPC_REQUEST'); } $posted_exceptions = isset($_POST['pp_exceptions']) ? $_POST['pp_exceptions'] : array(); if ($posted_exceptions && !$disallow_manual_entry && $can_assign_roles) { foreach (array_keys($posted_exceptions) as $for_item_type) { $_for_type = '(all)' == $for_item_type ? '' : $for_item_type; if ($_for_type && 'post' == $for_item_source && !post_type_exists($_for_type)) { continue; } if ('term' == $for_item_source && !taxonomy_exists($_for_type)) { continue; } foreach (array_keys($posted_exceptions[$for_item_type]) as $op) { if (!_pp_can_set_exceptions($op, $for_item_type, compact('via_item_source', 'via_item_type', 'item_id', 'for_item_source'))) { continue; } foreach (array_keys($posted_exceptions[$for_item_type][$op]) as $agent_type) { $args['for_item_type'] = $_for_type; $args['operation'] = $op; $args['agent_type'] = $agent_type; if (ppc_assign_exceptions($posted_exceptions[$for_item_type][$op][$agent_type], $agent_type, $args)) { // assignments[assign_for][agent_id] = has_access $roles_customized = true; // may be true already based on a prior role edit } } // end foreach group type } } } if ('post' == $via_item_source && 'post' == $for_item_source) { if ($post = get_post($item_id)) { if ('attachment' == $post->post_type) { // don't propagate page exceptions to attachments return; } } } self::inherit_parent_exceptions($item_id, compact('via_item_source', 'via_item_type', 'set_parent', 'last_parent', 'is_new')); }
} else { $agent_clause = ''; } if ($row = $wpdb->get_row("SELECT * FROM {$wpdb->ppc_exception_items} AS i INNER JOIN {$wpdb->ppc_exceptions} AS e ON i.exception_id = e.exception_id WHERE {$agent_clause} eitem_id IN ('" . implode("','", $eitem_ids) . "') LIMIT 1")) { $args = (array) $row; if ('exceptions_propagate' == $action) { $agents = array('children' => array($agent_id => true)); ppc_assign_exceptions($agents, $agent_type, $args); } elseif ('exceptions_unpropagate' == $action) { $agents = array('item' => array($agent_id => true)); ppc_assign_exceptions($agents, $agent_type, $args); $wpdb->delete($wpdb->ppc_exception_items, array('assign_for' => 'children', 'exception_id' => $row->exception_id, 'item_id' => $row->item_id)); $wpdb->delete($wpdb->ppc_exception_items, array('inherited_from' => $row->eitem_id)); } elseif ('exceptions_children_only' == $action) { $agents = array('children' => array($agent_id => true)); ppc_assign_exceptions($agents, $agent_type, $args); $wpdb->delete($wpdb->ppc_exception_items, array('assign_for' => 'item', 'exception_id' => $row->exception_id, 'item_id' => $row->item_id)); } $edited_input_ids[] = $id_csv; } } echo '<!--ppResponse-->' . $_GET['pp_ajax_submission'] . '~' . implode('|', $edited_input_ids) . '<--ppResponse-->'; break; } // end switch function _pp_editable_assignment_ids($ass_ids) { if (pp_is_user_administrator()) { return $ass_ids; } global $wpdb, $pp_admin;
function _pp_edit_agent_exceptions($agent_id, $agent_type) { if (!current_user_can('pp_assign_roles') || !pp_bulk_roles_enabled()) { return; } $type_objs = array(); if (isset($_POST['pp_add_exception'])) { // note: group editing capability already verified at this point foreach ($_POST['pp_add_exception'] as $exception) { $exception = apply_filters('pp_add_exception', $exception); extract($exception); $args = compact('mod_type', 'item_id', 'operation'); $args['for_item_status'] = $attrib_cond; if (taxonomy_exists($via_type)) { $args['via_item_source'] = 'term'; $args['via_item_type'] = $via_type; $args['item_id'] = pp_termid_to_ttid($item_id, $via_type); } elseif (!$via_type || post_type_exists($via_type)) { $args['via_item_source'] = 'post'; $args['via_item_type'] = ''; } else { $args['via_item_source'] = $via_type; $args['via_item_type'] = ''; } if (taxonomy_exists($for_type)) { $args['for_item_source'] = 'term'; } elseif (!$for_type || post_type_exists($for_type) || '(all)' == $for_type) { $args['for_item_source'] = 'post'; } else { $args['for_item_source'] = $for_type; } $args['for_item_type'] = '(all)' == $for_type ? '' : $for_type; $agents = array(); // also support bulk-assignment of user exceptions $agent_ids = 'user' == $agent_type && !$agent_id && isset($_REQUEST['member_csv']) ? explode(',', $_REQUEST['member_csv']) : array($agent_id); foreach ($agent_ids as $_agent_id) { if ($_agent_id) { foreach (array('item' => $for_item, 'children' => $for_children) as $assign_for => $is_assigned) { if ($is_assigned) { $agents[$assign_for][$_agent_id] = true; } } } } ppc_assign_exceptions($agents, $agent_type, $args); } } }