| Server IP : 85.112.90.236 / Your IP : 192.168.1.26 Web Server : Apache System : Linux 85-112-90-236.cprapid.com 6.12.0-211.7.3.el10_2.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 12:46:58 EDT 2026 x86_64 User : ftechme ( 1002) PHP Version : 8.2.32 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/ftechme/public_html/wp-content/plugins/polylang/src/Capabilities/ |
Upload File : |
<?php
/**
* @package Polylang
*/
namespace WP_Syntex\Polylang\Capabilities;
use WP_User;
use WP_Syntex\Polylang\Capabilities\User\Creator;
use WP_Syntex\Polylang\Capabilities\User\User_Interface;
use WP_Syntex\Polylang\Capabilities\User\Creator_Interface;
/**
* A class allowing to map Polylang's custom user capabilities to WP's native ones.
*
* @since 3.8
*/
class Capabilities {
public const LANGUAGES = 'manage_languages';
public const TRANSLATIONS = 'manage_translations';
/**
* The user creator to be used for capability checks.
*
* @var Creator_Interface|null
*/
private static ?Creator_Interface $creator = null;
/**
* Constructor.
*
* @since 3.8
*/
public function __construct() {
add_filter( 'map_meta_cap', array( $this, 'map_custom_caps' ), 1, 2 );
}
/**
* Filters user capabilities to handle PLL's custom capabilities.
*
* @since 3.8
*
* @param string[] $caps Primitive capabilities required by the user.
* @param string $cap Capability being checked.
* @return string[]
*/
public function map_custom_caps( $caps, $cap ) {
if ( in_array( $cap, array( self::TRANSLATIONS, self::LANGUAGES ), true ) ) {
$caps = array_diff( $caps, array( $cap ) );
$caps[] = 'manage_options';
}
return $caps;
}
/**
* Returns the user instance to be used for capability checks.
*
* @since 3.8
*
* @param WP_User|null $user The user to decorate. If null, the current user is used.
* @return User_Interface The user instance.
*/
public static function get_user( ?WP_User $user = null ): User_Interface {
if ( ! self::$creator ) {
self::$creator = new Creator();
}
return self::$creator->get( $user ?? wp_get_current_user() );
}
/**
* Sets the user creator to be used for capability checks.
*
* Having a separate class to create the decorated user allows for better decoupling.
* This allows to set a creator object without dependence to a `WP_User`.
*
* @since 3.8
*
* @param Creator_Interface $creator The user creator to be used for capability checks.
* @return void
*/
public static function set_user_creator( Creator_Interface $creator ): void {
self::$creator = $creator;
}
}