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,98 @@
|
||||
<?php declare( strict_types=1 );
|
||||
|
||||
namespace KadenceWP\KadenceBlocks\Optimizer\Status;
|
||||
|
||||
use KadenceWP\KadenceBlocks\Asset\Asset;
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Path\Path;
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Store\Contracts\Store;
|
||||
use KadenceWP\KadenceBlocks\Traits\Permalink_Trait;
|
||||
|
||||
/**
|
||||
* Post Meta to control excluding posts from being optimized set
|
||||
* via a Gutenberg plugin.
|
||||
*
|
||||
* @see kadence-control-plugin.js
|
||||
*/
|
||||
final class Meta {
|
||||
|
||||
use Permalink_Trait;
|
||||
|
||||
public const KEY = '_kb_optimizer_status';
|
||||
|
||||
private Asset $asset;
|
||||
private Status $status;
|
||||
private Store $store;
|
||||
|
||||
public function __construct(
|
||||
Asset $asset,
|
||||
Status $status,
|
||||
Store $store
|
||||
) {
|
||||
$this->asset = $asset;
|
||||
$this->status = $status;
|
||||
$this->store = $store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register post meta for the Gutenberg sidebar toggle to exclude a post from optimization.
|
||||
*
|
||||
* @action init
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_meta(): void {
|
||||
register_post_meta(
|
||||
'',
|
||||
self::KEY,
|
||||
[
|
||||
'single' => true,
|
||||
'type' => 'integer',
|
||||
// Excluded is stored a -1.
|
||||
'sanitize_callback' => function ( $value ): int {
|
||||
$value = (int) $value;
|
||||
|
||||
return $this->status->is_valid( $value ) ? $value : 0;
|
||||
},
|
||||
'auth_callback' => static fn(): bool => current_user_can( 'edit_posts' ),
|
||||
'show_in_rest' => [
|
||||
'schema' => [
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Exclude this post from optimization.', 'kadence-blocks' ),
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the optimizer data if this post is excluded.
|
||||
*
|
||||
* @action updated_post_meta
|
||||
*
|
||||
* @param int $post_id The post ID this meta is for.
|
||||
* @param string $meta_key The current meta key.
|
||||
* @param mixed $value The meta value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_clear_optimizer_data( int $post_id, string $meta_key, $value ): void {
|
||||
if ( $meta_key !== self::KEY || $value !== Status::EXCLUDED ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_path = $this->get_post_path( $post_id );
|
||||
|
||||
if ( ! $post_path ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Include post_id for reliable status synchronization.
|
||||
$path = new Path( $post_path, $post_id );
|
||||
|
||||
$this->store->delete( $path );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php declare( strict_types=1 );
|
||||
|
||||
namespace KadenceWP\KadenceBlocks\Optimizer\Status;
|
||||
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Status\Meta;
|
||||
use KadenceWP\KadenceBlocks\StellarWP\ProphecyMonorepo\Container\Contracts\Provider as Provider_Contract;
|
||||
|
||||
final class Provider extends Provider_Contract {
|
||||
|
||||
public function register(): void {
|
||||
$this->container->singleton( Meta::class, Meta::class );
|
||||
|
||||
add_action(
|
||||
'init',
|
||||
$this->container->callback( Meta::class, 'register_meta' )
|
||||
);
|
||||
|
||||
add_action(
|
||||
'updated_post_meta',
|
||||
function ( $meta_id, $post_id, $meta_key, $value ) {
|
||||
$this->container->get( Meta::class )->maybe_clear_optimizer_data( (int) $post_id, $meta_key, $value );
|
||||
},
|
||||
10,
|
||||
4
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php declare( strict_types=1 );
|
||||
|
||||
namespace KadenceWP\KadenceBlocks\Optimizer\Status;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Response\WebsiteAnalysis;
|
||||
|
||||
/**
|
||||
* Store the status for a post, used mostly to sort the Post List Table.
|
||||
*
|
||||
* @note The excluded status is actually the source of truth for this.
|
||||
*/
|
||||
final class Status {
|
||||
|
||||
/**
|
||||
* Optimization status values.
|
||||
*
|
||||
* Values are chosen to sort naturally:
|
||||
* - ASC: Excluded (-1) > Not Optimized (0) > Optimized (1) > Stale (2)
|
||||
* - DESC: Stale (2) > Optimized (1) > Not Optimized (0) > Excluded (-1)
|
||||
*/
|
||||
public const EXCLUDED = -1;
|
||||
|
||||
public const NOT_OPTIMIZED = 0;
|
||||
|
||||
public const OPTIMIZED = 1;
|
||||
|
||||
public const STALE = 2;
|
||||
|
||||
private const STATUSES = [
|
||||
self::EXCLUDED => true,
|
||||
self::NOT_OPTIMIZED => true,
|
||||
self::OPTIMIZED => true,
|
||||
self::STALE => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* Check if a status is valid.
|
||||
*
|
||||
* @param int $status The status to check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid( int $status ): bool {
|
||||
return isset( self::STATUSES[ $status ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optimization status for a post.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
*
|
||||
* @return int One of the STATUS_* constants.
|
||||
*/
|
||||
public function get( int $post_id ): int {
|
||||
return (int) get_post_meta( $post_id, Meta::KEY, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the optimization status for a post.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
* @param int $status One of the STATUS_* constants.
|
||||
*
|
||||
* @throws InvalidArgumentException If the wrong status is passed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function set( int $post_id, int $status = self::OPTIMIZED ): bool {
|
||||
if ( ! isset( self::STATUSES[ $status ] ) ) {
|
||||
throw new InvalidArgumentException( 'Invalid status: ' . $status );
|
||||
}
|
||||
|
||||
return (bool) update_post_meta( $post_id, Meta::KEY, $status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the post to optimized.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function set_optimized( int $post_id ): bool {
|
||||
return $this->set( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the post to excluded.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function set_excluded( int $post_id ): bool {
|
||||
return $this->set( $post_id, self::EXCLUDED );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a post is excluded from optimization.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_excluded( int $post_id ): bool {
|
||||
return $this->get( $post_id ) === self::EXCLUDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the status meta.
|
||||
*
|
||||
* IMPORTANT: Preserves EXCLUDED status since it's user-controlled.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete( int $post_id ): bool {
|
||||
if ( $this->is_excluded( $post_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return delete_post_meta( $post_id, Meta::KEY );
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive status from WebsiteAnalysis.
|
||||
*
|
||||
* Helper method to determine what status should be based on analysis state.
|
||||
*
|
||||
* @param WebsiteAnalysis|null $analysis The analysis data.
|
||||
*
|
||||
* @return int One of the STATUS_* constants.
|
||||
*/
|
||||
public function from_analysis( ?WebsiteAnalysis $analysis ): int {
|
||||
if ( ! $analysis ) {
|
||||
return self::NOT_OPTIMIZED;
|
||||
}
|
||||
|
||||
return $analysis->isStale ? self::STALE : self::OPTIMIZED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync status from analysis data.
|
||||
*
|
||||
* Automatically sets the correct status based on the analysis state.
|
||||
* This is the single source of truth for deriving status from analysis.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
* @param WebsiteAnalysis|null $analysis The analysis data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sync_from_analysis( int $post_id, ?WebsiteAnalysis $analysis ): bool {
|
||||
$status = $this->from_analysis( $analysis );
|
||||
|
||||
return $this->set( $post_id, $status );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user