Permissions & Roles

PerfLocale provides a comprehensive permissions system with a custom Translator role and granular capabilities that integrate with WordPress's built-in role system.

Custom Role: Translator

Slug: perflocale_translator

The Translator role is designed for team members who only need to translate content. They can edit posts and pages (to translate them) but cannot publish, delete, or manage site settings.

WordPress capabilities included:

CapabilityGranted
readYes
edit_postsYes
edit_others_postsYes
edit_published_postsYes
edit_pagesYes
edit_others_pagesYes
edit_published_pagesYes
upload_filesYes
publish_postsNo
delete_postsNo
manage_optionsNo

Custom Capabilities

PerfLocale adds 9 custom capabilities that control access to specific plugin features.

Capability Matrix

CapabilityTranslatorEditorAdministratorDescription
perflocale_translateYesYesYesCreate and edit translations
perflocale_manage_translationsNoYesYesManage translation settings, assign workflow
perflocale_manage_languagesNoNoYesAdd, edit, delete languages
perflocale_manage_glossaryNoYesYesAdd, edit, delete glossary terms
perflocale_manage_addonsNoNoYesManage plugin addons
perflocale_use_mtYesYesYesUse machine translation
perflocale_bulk_translateNoYesYesRun bulk translation jobs
perflocale_import_exportNoNoYesImport/export translations (XLIFF, PO/MO)
perflocale_view_analyticsYesYesYesView translation analytics dashboard

Capability Details

perflocale_translate

The core translation capability. Users with this cap can:

  • Create translation versions of posts, pages, and terms
  • Edit existing translations
  • See the Translations panel in the block/classic editor

perflocale_manage_translations

Management-level access:

  • Assign translations to other users via the workflow system
  • Change workflow statuses (assigned, in review, approved)
  • Manage translation priorities and deadlines

perflocale_manage_languages

Administrative control over languages:

  • Add new languages
  • Edit language settings (name, locale, flag, direction)
  • Delete languages
  • Set the default language
  • Reorder languages

perflocale_manage_glossary

Glossary management:

  • Add glossary terms
  • Edit existing terms
  • Delete terms
  • These terms are enforced during machine translation

perflocale_manage_addons

Addon lifecycle management:

  • View the Addons page
  • (Reserved for future manual addon install/uninstall)
  • Currently addons auto-activate based on compatible plugins

perflocale_use_mt

Machine translation access:

  • Trigger machine translation for individual posts
  • Access the "MT" button in the editor sidebar
  • Uses configured MT provider (DeepL, Google, Microsoft, LibreTranslate)

perflocale_bulk_translate

Batch operations:

  • Start bulk translation jobs for entire post types
  • Monitor bulk translation progress
  • Cancel running bulk jobs

perflocale_import_export

Data portability:

  • Export translations to XLIFF 2.0 format
  • Import XLIFF files
  • Export string translations to PO/MO files
  • Migrate from WPML or Polylang

perflocale_view_analytics

Read-only analytics access:

  • View the Analytics dashboard
  • See translation progress by language
  • View workflow summaries and system stats

Admin Menu Visibility

Menu ItemRequired Capability
Dashboardperflocale_translate
Languagesperflocale_manage_languages
Stringsperflocale_manage_translations
Glossaryperflocale_manage_glossary
Addonsperflocale_manage_addons
Analyticsperflocale_view_analytics
Settingsmanage_options (WP core)

REST API Permissions

EndpointRequired Check
GET /languagesPublic by default (no auth required) - gateable via perflocale/api/languages_public filter
POST /languagesperflocale_manage_languages
PUT/DELETE /languages/{slug}perflocale_manage_languages
GET /translations/{type}/{id}perflocale_translate + edit_post
POST /translations/{type}/{id}perflocale_translate + edit_post
PUT /translations/{type}/{id}/{lang}perflocale_translate + edit_post
DELETE /translations/{type}/{id}/{lang}perflocale_translate + delete_post
GET /stringsperflocale_translate
POST /strings/scanmanage_options
POST /machine-translateperflocale_use_mt + edit_post
POST /import/*perflocale_import_export
POST /xliff/*perflocale_import_export
PUT /workflow/{id}/{lang_id}perflocale_translate + edit_post
POST /webhooksmanage_options

Workflow States

Translations move through a workflow tracked in the wp_perflocale_workflow table:

Unassigned → Assigned → In Progress → In Review → Approved → Published
StateWho can set itDescription
unassignedSystemDefault state for new translations
assignedEditor, AdminTranslation assigned to a translator
in_progressTranslatorTranslator has started working
reviewTranslatorSubmitted for review
approvedEditor, AdminTranslation approved
publishedEditor, AdminTranslation published on the site

Programmatic Usage

Check capabilities in PHP

use PerfLocale\Admin\TranslatorRole;

// Check a specific capability.
if ( TranslatorRole::current_user_can( 'perflocale_translate' ) ) {
	// User can translate.
}

// Or use WordPress core function.
if ( current_user_can( 'perflocale_manage_languages' ) ) {
	// User can manage languages.
}

Grant a capability to a custom role

$role = get_role( 'my_custom_role' );

if ( $role ) {
	$role->add_cap( 'perflocale_translate' );
	$role->add_cap( 'perflocale_use_mt' );
}

Remove all PerfLocale capabilities

On plugin deactivation, call:

PerfLocale\Admin\TranslatorRole::remove_roles();

This removes the Translator role and all custom capabilities from all roles.

Hooks

perflocale/roles/editor_caps

Filters the capabilities granted to the Editor role when the plugin activates. Return an empty array to prevent Editors from receiving any PerfLocale capabilities. Return a subset to restrict them to specific ones. The Administrator role is unaffected by this filter.

// Remove ALL PerfLocale capabilities from the Editor role.
add_filter( 'perflocale/roles/editor_caps', '__return_empty_array' );

// Grant only translation access to Editors (no bulk-translate, no glossary management).
add_filter( 'perflocale/roles/editor_caps', function ( array $caps ): array {
	return [
		'perflocale_translate'      => true,
		'perflocale_use_mt'         => true,
		'perflocale_view_analytics' => true,
	];
} );

Note: Capability grants are written to the database the first time the plugin activates (version-gated). If you add this filter to an existing install, reset the grant by running delete_option('perflocale_caps_version') in a one-time hook, then let WordPress reload - the filter will apply on the next admin_init.

perflocale/roles/cap_roles

Filters which WordPress roles have PerfLocale capabilities removed on plugin deactivation or uninstall. This filter fires in three places - TranslatorRole::remove_roles() (deactivation), and both the full-wipe and preserve-data branches of uninstall.php.

// Do NOT strip caps from the Editor role on deactivation / uninstall.
// Useful if you manage editor access separately and don't want it wiped.
add_filter( 'perflocale/roles/cap_roles', function ( array $roles ): array {
	return array_diff( $roles, [ 'editor' ] ); // keeps ['administrator']
} );

// Extend cleanup to a custom role that was granted caps programmatically.
add_filter( 'perflocale/roles/cap_roles', function ( array $roles ): array {
	$roles[] = 'shop_manager';
	return $roles;
} );

Workflow hooks

// Filter workflow assignment.
add_action( 'perflocale/workflow/assigned', function( $object_id, $type, $lang_id, $user_id ) {
	// Send notification email to the assigned translator.
}, 10, 4 );

// Filter workflow status changes.
add_action( 'perflocale/workflow/status_changed', function( $object_id, $type, $lang_id, $status ) {
	// Log status change or trigger automation.
}, 10, 4 );