| Server IP : 146.190.157.162 / Your IP : 216.73.217.6 Web Server : Apache System : Linux ubuntu-s-2vcpu-4gb-amd-sfo3-01-KIT-DIGITAL 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:10:09 UTC 2024 x86_64 User : businessweek ( 639) PHP Version : 8.2.10-2ubuntu2.2 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_signal,pcntl_signal_dispatch,pcntl_getpriority,pcntl_setpriority,dl,putenv,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/ballesteros/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;
}
}