Skip to main content

GravityKit\GravityMigrate\Migration\Permission

The capability rules a migration is subject to, stated once.

Six callers ask the same four questions -- may this user see Gravity Forms forms, may they create them, may another plugin's own read capability stand in for listing that plugin's forms, and may they create a form in the destination plugin. Both AJAX controllers ask, the background batch route and its job driver ask, the exporters' and importers' own inner gates ask, and the CLI asks. A rule each of them states for itself is a rule they can come to disagree about, and the direction that disagreement runs is a surface quietly doing more than the wizard would.

The answers are conditions, never sentences. A refusal comes back as one of the NEEDS_* constants, so the wizard can say "You do not have permission to import forms.", a terminal can say "Run with --user=<a login that can>", and an ability can say something a model can act on -- all from one decision.

Since: %ver%

Source: src/Migration/Permission.php:29

Details

  • Kind: class
  • Namespace: GravityKit\GravityMigrate\Migration

Methods

MethodDescription
holds()Whether the current user holds a capability, an administrator always counting.
can_view_gravity_forms()Whether this user may see Gravity Forms forms, which an export reads.
can_create_gravity_forms()Whether this user may create Gravity Forms forms, which an import produces.
wpforms_may_view_forms()What WPForms' own read capability says about this user, where WPForms is here to say it.
plugin_read_stands_in()Whether the source plugin's own read capability may stand in for listing its forms.
to_read()Whether this user may read the forms a migration in this direction would read.
readable_directions()The directions this user may read, which is what a listing of the form plugins may show.
to_write()Whether this user may create the forms a migration in this direction would create.

Method Reference

holds()

public static function holds( string $capability ): bool

Whether the current user holds a capability, an administrator always counting.

The || manage_options half is the part that gets forgotten, and forgetting it locks an administrator out of a screen every role below them can reach.

Parameters

NameTypeDefaultDescription
$capabilitystringThe capability.

Returns

  • bool

Since: %ver%

Source: src/Migration/Permission.php:96

can_view_gravity_forms()

public static function can_view_gravity_forms(): bool

Whether this user may see Gravity Forms forms, which an export reads.

Returns

  • bool

Since: %ver%

Source: src/Migration/Permission.php:107

can_create_gravity_forms()

public static function can_create_gravity_forms(): bool

Whether this user may create Gravity Forms forms, which an import produces.

Returns

  • bool

Since: %ver%

Source: src/Migration/Permission.php:118

wpforms_may_view_forms()

public static function wpforms_may_view_forms()

What WPForms' own read capability says about this user, where WPForms is here to say it.

Its own function rather than current_user_can( 'wpforms_view_forms' ) because WPForms resolves capabilities from its own settings, so a site that has narrowed them is only honoured by asking the plugin.

Three-valued on purpose. "WPForms is not installed" and "WPForms says no" are different answers and two callers need to tell them apart: the read carve-out below treats a missing plugin as no, and the background batch route treats it as nothing to verify.

Returns

  • bool | null — Null when WPForms is not here to be asked.

Since: %ver%

Source: src/Migration/Permission.php:137

plugin_read_stands_in()

public static function plugin_read_stands_in( string $provider ): bool

Whether the source plugin's own read capability may stand in for listing its forms.

WPForms' view_forms is read-only and grantable to low privilege roles, so it may open a listing or an analysis of that plugin's forms -- and nothing else. Importing creates Gravity Forms forms, and no third-party read capability speaks for that.

It speaks for its own plugin only: a WPForms capability says nothing about reading Ninja Forms.

Parameters

NameTypeDefaultDescription
$providerstringSource provider slug.

Returns

  • bool

Since: %ver%

Source: src/Migration/Permission.php:161

to_read()

public static function to_read( string $direction='', string $provider='' ): string

Whether this user may read the forms a migration in this direction would read.

The two directions are gated differently because the wizard gates them differently. Reading for an export asks only to see Gravity Forms forms. Reading for an import is the first step of creating them, so Importers\Controller::validate_request() asks for gravityforms_create_form even on a read, with one exception it makes deliberately (\self::plugin_read_stands_in()).

Parameters

NameTypeDefaultDescription
$directionstring''\ExternalMigration::DIRECTION_TO() or DIRECTION_FROM. An empty direction is answered as the export one, which asks only to see Gravity Forms forms. It is NOT an answer for a surface that shows both directions -- \self::readable_directions() is.
$providerstring''Provider slug, for the source-plugin carve-out.

Returns

  • string — {@see self::ALLOWED}, or one of {@see self::REASONS}.

Since: %ver%

Source: src/Migration/Permission.php:188

readable_directions()

public static function readable_directions(): array

The directions this user may read, which is what a listing of the form plugins may show.

Asked because the two list routes are gated differently and a surface that shows both halves under one gate hands a user the half the wizard refuses them. Exporters\Controller::list_exporters() asks for gravityforms_view_forms; Importers\Controller::list_importers() asks for gravityforms_create_form, and the list route carries no provider, so the WPForms carve-out (\self::plugin_read_stands_in()) cannot open it. wp gk migrate plugins gated on the export rule alone printed the import half -- availability and the names of the classes it is missing -- to a view-only user who is refused the same list on screen.

Returns

  • string[] — Any of {@see ExternalMigration::DIRECTION_TO} and DIRECTION_FROM, in that order. Empty when this user may read neither.

Since: %ver%

Source: src/Migration/Permission.php:217

to_write()

public static function to_write( string $direction, string $provider ): string

Whether this user may create the forms a migration in this direction would create.

Reading forms and creating them are different privileges, and each destination is asked in its own vocabulary: exporting creates a form in the destination plugin (\TargetCapability::can_write()), importing creates a Gravity Forms form.

Parameters

NameTypeDefaultDescription
$directionstring\ExternalMigration::DIRECTION_TO() or DIRECTION_FROM.
$providerstringProvider slug.

Returns

  • string — {@see self::ALLOWED}, or one of {@see self::REASONS}.

Since: %ver%

Source: src/Migration/Permission.php:243