$input Ability input. * @param string $message What the caller is confirming. * @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 : __( 'Pass confirm: true to proceed.', 'acrossai-abilities-manager' ) ); } return true; } /** * Permission callback factory. * * A single `current_user_can( $floor )`, and the filter is consulted only after it passes — so a * filter can tighten access and never widen it (PATTERN-FILTERABLE-CAPABILITY-RAISE-ONLY). * * @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 an UpdraftPlus ability. * * @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 ); }; } /** * @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['error_code'], $payload['message'] ); return array_merge( array( 'success' => true ), $payload, array( 'message' => $message ) ); } /** * @since 0.0.34 * @param WP_Error $error Error. * @return array */ public static function fail( WP_Error $error ): array { return self::error( (string) $error->get_error_code(), (string) $error->get_error_message() ); } /** * @since 0.0.34 * @param string $code Machine-readable 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, ); } }