403 ) ); } $needed = (array) $cap['scopes']; // An empty list is a guest capability: what a signed-out visitor could do. if ( $needed ) { if ( ! $context->signed_in() ) { return new WP_Error( 'sign_in_required', 'this needs a signed-in Session', array( 'status' => 403 ) ); } $missing = array_values( array_filter( $needed, static fn( $s ) => ! $context->has_scope( $s ) ) ); if ( $missing ) { return new WP_Error( 'insufficient_scope', 'this needs more account access', array( 'status' => 403, 'scope' => implode( ' ', $needed ) ) ); } } /** * Refuse a request the checks above allowed (merchant policy). The * filter runs only AFTER the scope checks pass and only a WP_Error * changes the answer, so nothing hooked here can widen access. * * @param true $allowed True. * @param AgentAdapt_Context $context Who is asking. * @param array $cap The capability. */ $verdict = apply_filters( 'agentadapt_gate_restrict', true, $context, $cap ); return is_wp_error( $verdict ) ? $verdict : true; } }