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,66 @@
|
||||
<?php declare( strict_types=1 );
|
||||
|
||||
namespace KadenceWP\KadenceBlocks\Optimizer\Image\Processors;
|
||||
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Image\Contracts\Processor;
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Response\ImageAnalysis;
|
||||
use WP_HTML_Tag_Processor;
|
||||
|
||||
final class Lazy_Load_Processor implements Processor {
|
||||
|
||||
/**
|
||||
* A queue of URLs that are above the fold.
|
||||
*
|
||||
* @var string[]|null
|
||||
*/
|
||||
private ?array $critical_image_queue = null;
|
||||
|
||||
/**
|
||||
* Add or remove the appropriate lazy loading attributes. It's important to note that WordPress
|
||||
* may have already added a loading=lazy attribute to an image that shouldn't have it.
|
||||
*
|
||||
* @param WP_HTML_Tag_Processor $p The HTML Tag Processor, set on the current image it's processing.
|
||||
* @param string[] $critical_images The list of the above the fold image URLs.
|
||||
* @param array<string, ImageAnalysis> $images The array of all collected images indexed by a unique key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process( WP_HTML_Tag_Processor $p, array $critical_images, array $images ): void {
|
||||
$src = (string) $p->get_attribute( 'src' );
|
||||
|
||||
// Don't lazy load data URLs.
|
||||
if ( str_starts_with( $src, 'data:' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize the queue on first run.
|
||||
if ( ! isset( $this->critical_image_queue ) ) {
|
||||
$this->critical_image_queue = $critical_images;
|
||||
}
|
||||
|
||||
// Check if this image is next in our critical queue.
|
||||
if ( $this->critical_image_queue ) {
|
||||
$queue_index = array_search( $src, $this->critical_image_queue, true );
|
||||
|
||||
if ( $queue_index !== false ) {
|
||||
// Remove lazy loading for critical image.
|
||||
if ( 'lazy' === $p->get_attribute( 'loading' ) ) {
|
||||
$p->remove_attribute( 'loading' );
|
||||
}
|
||||
|
||||
// Remove this occurrence from the queue.
|
||||
unset( $this->critical_image_queue[ $queue_index ] );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Below the fold logic (or after all critical images processed).
|
||||
$p->set_attribute( 'loading', 'lazy' );
|
||||
|
||||
// If WordPress somehow added a high fetch priority, remove it.
|
||||
if ( 'high' === $p->get_attribute( 'fetchpriority' ) ) {
|
||||
$p->remove_attribute( 'fetchpriority' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php declare( strict_types=1 );
|
||||
|
||||
namespace KadenceWP\KadenceBlocks\Optimizer\Image\Processors;
|
||||
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Image\Contracts\Processor;
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Image\Traits\Image_Key_Generator_Trait;
|
||||
use KadenceWP\KadenceBlocks\Optimizer\Response\ImageAnalysis;
|
||||
use WP_HTML_Tag_Processor;
|
||||
|
||||
final class Sizes_Attribute_Processor implements Processor {
|
||||
|
||||
use Image_Key_Generator_Trait;
|
||||
|
||||
/**
|
||||
* Set the optimal sizes attribute for the image.
|
||||
*
|
||||
* @param WP_HTML_Tag_Processor $p The HTML Tag Processor, set on the current image it's processing.
|
||||
* @param string[] $critical_images The array of critical image src's.
|
||||
* @param array<string, ImageAnalysis> $images The array of all collected images indexed by a unique key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process( WP_HTML_Tag_Processor $p, array $critical_images, array $images ): void {
|
||||
// The analyzer doesn't collect images without a srcset.
|
||||
$srcset = $p->get_attribute( 'srcset' );
|
||||
|
||||
if ( ! $srcset ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$src = $p->get_attribute( 'src' );
|
||||
$sizes = $p->get_attribute( 'sizes' );
|
||||
|
||||
$key = $this->generate_image_key( $src, $sizes );
|
||||
|
||||
if ( null === $key ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$image = $images[ $key ] ?? false;
|
||||
|
||||
if ( ! $image instanceof ImageAnalysis ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the sizes attribute with our optimal sizes.
|
||||
if ( $image->optimalSizes ) {
|
||||
$p->set_attribute( 'sizes', $image->optimalSizes );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user