feat: initial ACRIB WordPress deployment
- WordPress 6.9.4 (es_ES) with Kadence theme - Homepage: Hero, La Asociación, Pilares, Beneficios, Eventos, Miembros, Hazte Miembro, Contacto - Brand identity: #13294b navy, #a12932 burgundy, #c69c48 gold - Fonts: Raleway (headings) + Source Sans 3 (body) + Lato (UI) - Plugins: Kadence Blocks, Polylang, Contact Form 7 - Custom CSS with full brand styling and responsive layout - HTTPS enforced via wp-config.php proxy detection
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
namespace WP_Syntex\Polylang\Capabilities\Create;
|
||||
|
||||
use PLL_Model;
|
||||
use PLL_Language;
|
||||
use WP_Syntex\Polylang\REST\Request;
|
||||
|
||||
/**
|
||||
* Class to manage the language context for posts creation or update.
|
||||
*
|
||||
* @since 3.8
|
||||
*/
|
||||
abstract class Abstract_Object {
|
||||
/**
|
||||
* @var PLL_Model
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @var PLL_Language|null
|
||||
*/
|
||||
protected $pref_lang;
|
||||
|
||||
/**
|
||||
* @var PLL_Language|null
|
||||
*/
|
||||
protected $curlang;
|
||||
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param PLL_Model $model The model instance.
|
||||
* @param Request $request The request instance.
|
||||
* @param PLL_Language|null $pref_lang The preferred language.
|
||||
* @param PLL_Language|null $curlang The current language.
|
||||
*/
|
||||
public function __construct( PLL_Model $model, Request $request, ?PLL_Language $pref_lang, ?PLL_Language $curlang ) {
|
||||
$this->model = $model;
|
||||
$this->request = $request;
|
||||
$this->pref_lang = $pref_lang;
|
||||
$this->curlang = $curlang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the language to set for an object creation or update based on the global context.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param int $id The object ID.
|
||||
* @return PLL_Language The language defined from the global context.
|
||||
*/
|
||||
abstract public function get_language( int $id = 0 ): PLL_Language;
|
||||
}
|
||||
70
wp-content/plugins/polylang/src/Capabilities/Create/Post.php
Normal file
70
wp-content/plugins/polylang/src/Capabilities/Create/Post.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
namespace WP_Syntex\Polylang\Capabilities\Create;
|
||||
|
||||
use PLL_Language;
|
||||
use WP_Syntex\Polylang\Capabilities\Capabilities;
|
||||
|
||||
/**
|
||||
* Class to manage the language context for posts creation or update.
|
||||
*
|
||||
* @since 3.8
|
||||
*/
|
||||
class Post extends Abstract_Object {
|
||||
/**
|
||||
* Returns the language to set for a post creation or update.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param int $id The post ID for which to set the language. Default `0`.
|
||||
* @return PLL_Language The language context.
|
||||
*/
|
||||
public function get_language( int $id = 0 ): PLL_Language {
|
||||
/** @var PLL_Language $default_language The default language is always defined. */
|
||||
$default_language = $this->model->get_default_language();
|
||||
$user = Capabilities::get_user();
|
||||
|
||||
if ( ! empty( $_GET['new_lang'] ) && $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
// Defined only on admin.
|
||||
return $lang;
|
||||
}
|
||||
if ( ! isset( $this->pref_lang ) && ! empty( $_REQUEST['lang'] ) && $lang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
// Testing $this->pref_lang makes this test pass only on frontend.
|
||||
return $lang;
|
||||
}
|
||||
if ( $this->request && $lang = $this->request->get_language() ) {
|
||||
// REST request.
|
||||
return $lang;
|
||||
}
|
||||
if ( ( $parent_id = wp_get_post_parent_id( $id ) ) && $parent_lang = $this->model->post->get_language( $parent_id ) ) {
|
||||
// Use parent if exists.
|
||||
return $parent_lang;
|
||||
}
|
||||
if ( isset( $this->pref_lang ) && $user->can_translate( $this->pref_lang ) ) {
|
||||
// Always defined on admin, never defined on frontend.
|
||||
return $this->pref_lang;
|
||||
}
|
||||
if ( ! empty( $this->curlang ) ) {
|
||||
// Only on frontend due to the previous test always true on admin.
|
||||
return $this->curlang;
|
||||
}
|
||||
if ( $user->is_translator() ) {
|
||||
// Use default language if user can translate into it...
|
||||
if ( $user->can_translate( $default_language ) ) {
|
||||
return $default_language;
|
||||
}
|
||||
|
||||
// ... or its preferred one.
|
||||
$preferred_language = $this->model->get_language( $user->get_preferred_language_slug() );
|
||||
if ( $preferred_language ) {
|
||||
return $preferred_language;
|
||||
}
|
||||
}
|
||||
|
||||
// In all other cases use default language because we must have a language to set.
|
||||
return $default_language;
|
||||
}
|
||||
}
|
||||
77
wp-content/plugins/polylang/src/Capabilities/Create/Term.php
Normal file
77
wp-content/plugins/polylang/src/Capabilities/Create/Term.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
namespace WP_Syntex\Polylang\Capabilities\Create;
|
||||
|
||||
use PLL_Language;
|
||||
use WP_Syntex\Polylang\Capabilities\Capabilities;
|
||||
|
||||
/**
|
||||
* Class to manage the language context for terms creation or update.
|
||||
*
|
||||
* @since 3.8
|
||||
*/
|
||||
class Term extends Abstract_Object {
|
||||
/**
|
||||
* Returns the language to set for a post creation.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param int $id The term ID for which to set the language. Default `0`.
|
||||
* @param string $taxonomy The taxonomy for which to set the language. Default `''`.
|
||||
* @return PLL_Language The language context.
|
||||
*/
|
||||
public function get_language( int $id = 0, string $taxonomy = '' ): PLL_Language {
|
||||
/** @var PLL_Language $default_language The default language is always defined. */
|
||||
$default_language = $this->model->get_default_language();
|
||||
$user = Capabilities::get_user();
|
||||
|
||||
if ( ! empty( $_GET['new_lang'] ) && $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
// Defined only on admin.
|
||||
return $lang;
|
||||
}
|
||||
if ( ! empty( $_POST['term_lang_choice'] ) && is_string( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
return $lang;
|
||||
}
|
||||
if ( ! empty( $_POST['inline_lang_choice'] ) && is_string( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
return $lang;
|
||||
}
|
||||
if ( ! isset( $this->pref_lang ) && ! empty( $_REQUEST['lang'] ) && $lang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
// Testing $this->pref_lang makes this test pass only on frontend.
|
||||
return $lang;
|
||||
}
|
||||
if ( $this->request && $lang = $this->request->get_language() ) {
|
||||
// REST request.
|
||||
return $lang;
|
||||
}
|
||||
if ( ( $term = get_term( $id, $taxonomy ) ) && ! empty( $term->parent ) && $parent_lang = $this->model->term->get_language( $term->parent ) ) {
|
||||
// Sets language from term parent if exists thanks to Scott Kingsley Clark.
|
||||
return $parent_lang;
|
||||
}
|
||||
if ( isset( $this->pref_lang ) && $user->can_translate( $this->pref_lang ) ) {
|
||||
// Always defined on admin, never defined on frontend.
|
||||
return $this->pref_lang;
|
||||
}
|
||||
if ( ! empty( $this->curlang ) ) {
|
||||
// Only on frontend due to the previous test always true on admin.
|
||||
return $this->curlang;
|
||||
}
|
||||
if ( $user->is_translator() ) {
|
||||
// Use default language if user can translate into it...
|
||||
if ( $user->can_translate( $default_language ) ) {
|
||||
return $default_language;
|
||||
}
|
||||
|
||||
// ... or its preferred one.
|
||||
$preferred_language = $this->model->get_language( $user->get_preferred_language_slug() );
|
||||
if ( $preferred_language ) {
|
||||
return $preferred_language;
|
||||
}
|
||||
}
|
||||
|
||||
// In all other cases use default language because we must have a language to set.
|
||||
return $default_language;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
namespace WP_Syntex\Polylang\Capabilities\User;
|
||||
|
||||
use WP_User;
|
||||
|
||||
/**
|
||||
* A class to create a decorated user.
|
||||
* Always returns a `NOOP` instance so capabilities features are disabled by default.
|
||||
*
|
||||
* @since 3.8
|
||||
*/
|
||||
class Creator implements Creator_Interface {
|
||||
/**
|
||||
* The user instance to be used for capability checks.
|
||||
*
|
||||
* @var NOOP
|
||||
*/
|
||||
private ?NOOP $instance = null;
|
||||
|
||||
/**
|
||||
* Creates and returns the user.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param WP_User $user The user to decorate.
|
||||
* @return User_Interface Instance of `NOOP`.
|
||||
*/
|
||||
public function get( WP_User $user ): User_Interface {
|
||||
if ( $this->instance && $user->ID === $this->instance->get_id() ) {
|
||||
return $this->instance;
|
||||
}
|
||||
|
||||
$this->instance = new NOOP( $user );
|
||||
|
||||
return $this->instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
namespace WP_Syntex\Polylang\Capabilities\User;
|
||||
|
||||
use WP_User;
|
||||
|
||||
/**
|
||||
* An interface for user creators.
|
||||
* Allows to change the user decoration behavior at runtime.
|
||||
*
|
||||
* @since 3.8
|
||||
*/
|
||||
interface Creator_Interface {
|
||||
/**
|
||||
* Returns the user instance to be used for capability checks.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param WP_User $user The user to decorate.
|
||||
* @return User_Interface The user instance.
|
||||
*/
|
||||
public function get( WP_User $user ): User_Interface;
|
||||
}
|
||||
125
wp-content/plugins/polylang/src/Capabilities/User/NOOP.php
Normal file
125
wp-content/plugins/polylang/src/Capabilities/User/NOOP.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
namespace WP_Syntex\Polylang\Capabilities\User;
|
||||
|
||||
use WP_User;
|
||||
use PLL_Language;
|
||||
|
||||
/**
|
||||
* A NOOP user class that decorates `WP_User` and deactivates language-related methods.
|
||||
* This class allows all translations but doesn't consider the user as a translator.
|
||||
*
|
||||
* @since 3.8
|
||||
*/
|
||||
class NOOP implements User_Interface {
|
||||
/**
|
||||
* User instance to decorate.
|
||||
*
|
||||
* @var WP_User
|
||||
*/
|
||||
private WP_User $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param WP_User $user An instance of `WP_User`.
|
||||
*/
|
||||
public function __construct( WP_User $user ) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user ID.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id(): int {
|
||||
return $this->user->ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the user is a translator (has a translator capability).
|
||||
* Always returns false for NOOP user.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_translator(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the user can translate to the given language.
|
||||
* Always returns true for NOOP user.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param PLL_Language $language A language object.
|
||||
* @return bool
|
||||
*/
|
||||
public function can_translate( PLL_Language $language ): bool { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the user can translate to all the given languages.
|
||||
* Always returns true for NOOP user.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param array $languages List of language slugs.
|
||||
* @return bool
|
||||
*
|
||||
* @phpstan-param array<non-empty-string> $languages
|
||||
*/
|
||||
public function can_translate_all( array $languages ): bool { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the user has the specified capability.
|
||||
* Delegates to WP_User.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param string $capability Capability name.
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool
|
||||
*/
|
||||
public function has_cap( $capability, ...$args ): bool {
|
||||
return $this->user->has_cap( $capability, ...$args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preferred language of the user.
|
||||
* Always returns an empty string for NOOP user.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @return string The preferred language slug, empty string if no preferred language is found.
|
||||
*/
|
||||
public function get_preferred_language_slug(): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user has the rights to assign a language to an object and dies if not.
|
||||
* Does nothing for NOOP user (always allows).
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param PLL_Language $language The language to assign.
|
||||
* @return void|never Dies if the user does not have the rights, does nothing otherwise.
|
||||
*/
|
||||
public function can_translate_or_die( PLL_Language $language ): void { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
// Never say die!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
|
||||
namespace WP_Syntex\Polylang\Capabilities\User;
|
||||
|
||||
use WP_User;
|
||||
use PLL_Language;
|
||||
|
||||
/**
|
||||
* An interface for user with translation management feature.
|
||||
* Implements decorator pattern for `WP_User`.
|
||||
*
|
||||
* @since 3.8
|
||||
*/
|
||||
interface User_Interface {
|
||||
/**
|
||||
* Returns the user ID.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id(): int;
|
||||
|
||||
/**
|
||||
* Tells if the user is a translator (has a translator capability).
|
||||
* Note: returns `true` if the user has a capability for a language that doesn't exist anymore. This is intentional,
|
||||
* to prevent the user to suddenly have the rights to translate in all languages while it wasn't allowed until then.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_translator(): bool;
|
||||
|
||||
/**
|
||||
* Tells if the user can translate to the given language.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param PLL_Language $language A language object.
|
||||
* @return bool
|
||||
*/
|
||||
public function can_translate( PLL_Language $language ): bool;
|
||||
|
||||
/**
|
||||
* Tells if the user can translate to all the given languages.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param array $languages List of language slugs.
|
||||
* @return bool
|
||||
*
|
||||
* @phpstan-param array<non-empty-string> $languages
|
||||
*/
|
||||
public function can_translate_all( array $languages ): bool;
|
||||
|
||||
/**
|
||||
* Tells if the user has the specified capability.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param string $capability Capability name.
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool
|
||||
*/
|
||||
public function has_cap( $capability, ...$args ): bool;
|
||||
|
||||
/**
|
||||
* Returns the preferred language of the user.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @return string The preferred language slug, empty string if no preferred language is found.
|
||||
*/
|
||||
public function get_preferred_language_slug(): string;
|
||||
|
||||
/**
|
||||
* Checks if the current user has the rights to assign a language to an object and dies if not.
|
||||
*
|
||||
* @since 3.8
|
||||
*
|
||||
* @param PLL_Language $language The language to assign.
|
||||
* @return void|never Dies if the user does not have the rights, does nothing otherwise.
|
||||
*/
|
||||
public function can_translate_or_die( PLL_Language $language ): void;
|
||||
}
|
||||
Reference in New Issue
Block a user