first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace WPML\TM\Menu\TranslationRoles;
use WPML\FP\Obj;
class RoleValidator {
/**
* Checks if a specific role is valid.
*
* @param string $roleName
* @return bool
*/
public static function isValid( $roleName ) {
$wp_role = get_role( $roleName );
return $wp_role instanceof \WP_Role;
}
/**
* @param string $roleName
*
* @return string|null
*/
public static function getTheHighestPossibleIfNotValid( $roleName ) {
$wp_role = get_role( $roleName );
$user = wp_get_current_user();
if ( \WPML_WP_Roles::get_highest_level( $wp_role->capabilities ) > \WPML_WP_Roles::get_user_max_level( $user ) ) {
$wp_role = current( \WPML_WP_Roles::get_roles_up_to_user_level( $user ) );
if ( ! $wp_role ) {
return null;
}
$roleName = Obj::prop( 'name', $wp_role );
}
return $roleName;
}
}