$input Ability input. * @param string $message Optional operation-specific message. * @return true|WP_Error */ public static function assert_confirmed( array $input, string $message = '' ) { if ( empty( $input['confirm'] ) ) { return new WP_Error( 'confirmation_required', '' !== $message ? $message : __( 'This operation cannot be undone. Pass confirm: true to proceed.', 'acrossai-abilities-manager' ) ); } return true; } /** * Build the permission_callback for one ability. * * A SINGLE `current_user_can( $floor )`, never OR-ed with a default, so the filter can only ever * raise the requirement (PATTERN-FILTERABLE-CAPABILITY-RAISE-ONLY). * * Unlike Contact Form 7, LiteSpeed defines no granular capabilities of its own — every one of its * admin screens is `manage_options` — so there is nothing to compose with and the floor stands * alone. It is still declared `final` on the base, for the same reason: to stop a future subclass * quietly lowering it. * * @since 0.0.34 * @param string $floor WordPress capability floor. * @return callable */ public static function can( string $floor = 'manage_options' ): callable { return static function () use ( $floor ): bool { if ( ! current_user_can( $floor ) ) { return false; } /** * Filters whether the current user may use a LiteSpeed Cache ability. * * Consulted only for a user who already clears the floor, so it can deny but never * grant (PATTERN-FILTERABLE-CAPABILITY-RAISE-ONLY). Returning the filter's value * directly would let any plugin on the site hand an ability to a subscriber. * * @since 0.0.34 * @param bool $allowed Whether access is granted. Always true at this point. * @param string $floor WordPress capability floor. */ return (bool) apply_filters( self::PERMISSION_FILTER, true, $floor ); }; } /** * Build a success envelope. * * @since 0.0.34 * @param array $payload Ability-specific keys. * @param string $message Human-readable summary. * @return array */ public static function ok( array $payload, string $message ): array { unset( $payload['success'], $payload['message'], $payload['error_code'] ); return array_merge( array( 'success' => true ), $payload, array( 'message' => $message ) ); } /** * Build a failure envelope from a WP_Error. * * @since 0.0.34 * @param WP_Error $error Error to unwrap. * @return array */ public static function fail( WP_Error $error ): array { return self::error( (string) $error->get_error_code(), (string) $error->get_error_message() ); } /** * Build a failure envelope from an explicit code and message. * * @since 0.0.34 * @param string $code Machine-readable error code. * @param string $message Human-readable message. * @return array */ public static function error( string $code, string $message ): array { return array( 'success' => false, 'error_code' => $code, 'message' => $message, ); } }