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;
}
}

View File

@@ -0,0 +1,14 @@
<?php
use WPML\TM\Menu\TranslationServices\SectionFactory;
class WPML_TM_Translation_Roles_Section_Factory implements IWPML_TM_Admin_Section_Factory {
/**
* @return \WPML_TM_Admin_Section|\WPML_TM_Translation_Roles_Section
*/
public function create() {
return new WPML_TM_Translation_Roles_Section( ( new SectionFactory() )->create() );
}
}

View File

@@ -0,0 +1,97 @@
<?php
use WPML\TranslationRoles\UI\Initializer;
use WPML\TM\Menu\TranslationServices\Section;
use WPML\TM\Menu\TranslationMethod\TranslationMethodSettings;
use WPML\FP\Relation;
class WPML_TM_Translation_Roles_Section implements IWPML_TM_Admin_Section {
const SLUG = 'translators';
/**
* @var Section
*/
private $translation_services_section;
public function __construct( Section $translation_services_section ) {
$this->translation_services_section = $translation_services_section;
TranslationMethodSettings::addHooks();
}
/**
* Returns a value which will be used for sorting the sections.
*
* @return int
*/
public function get_order() {
return 300;
}
/**
* Returns the unique slug of the sections which is used to build the URL for opening this section.
*
* @return string
*/
public function get_slug() {
return self::SLUG;
}
/**
* Returns one or more capabilities required to display this section.
*
* @return string|array
*/
public function get_capabilities() {
return [ WPML_Manage_Translations_Role::CAPABILITY, 'manage_options' ];
}
/**
* Returns the caption to display in the section.
*
* @return string
*/
public function get_caption() {
return __( 'Translators', 'wpml-translation-management' );
}
/**
* Returns the callback responsible for rendering the content of the section.
*
* @return callable
*/
public function get_callback() {
return [ $this, 'render' ];
}
/**
* This method is hooked to the `admin_enqueue_scripts` action.
*
* @param string $hook The current page.
*/
public function admin_enqueue_scripts( $hook ) {
if ( Relation::propEq( 'sm', 'translators', $_GET ) ) {
Initializer::loadJS();
}
}
/**
* Used to extend the logic for displaying/hiding the section.
*
* @return bool
*/
public function is_visible() {
return true;
}
/**
* Outputs the content of the section.
*/
public function render() {
?>
<div id="wpml-translation-roles-ui-container"></div>
<?php
$this->translation_services_section->render();
}
}