Skip to content

Commit

Permalink
3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jono committed Dec 21, 2022
1 parent e3e61d1 commit ac8989a
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 58 deletions.
13 changes: 10 additions & 3 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images
*/

namespace Edge_Images;

// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
// Avoid direct calls to this file.
if ( ! defined( 'EDGE_IMAGES_VERSION' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions classes/class-admin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images
*/

namespace Edge_Images;

Expand Down
5 changes: 5 additions & 0 deletions classes/class-assets.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images
*/

namespace Edge_Images;

Expand Down
5 changes: 5 additions & 0 deletions classes/class-edge-provider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images
*/

namespace Edge_Images;

Expand Down
8 changes: 6 additions & 2 deletions classes/class-handler.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images
*/

namespace Edge_Images;

use Edge_Images\Helpers;
use Edge_Images\Image;
use Edge_Images\{Helpers, Image};

/**
* Filters wp_get_attachment_image and related functions to use the edge.
Expand Down
5 changes: 5 additions & 0 deletions classes/class-helpers.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images
*/

namespace Edge_Images;

Expand Down
5 changes: 5 additions & 0 deletions classes/class-image.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images
*/

namespace Edge_Images;

Expand Down
5 changes: 5 additions & 0 deletions classes/edge-providers/class-accelerated-domains.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images\Edge_Providers
*/

namespace Edge_Images\Edge_Providers;

Expand Down
5 changes: 5 additions & 0 deletions classes/edge-providers/class-cloudflare.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images\Edge_Providers
*/

namespace Edge_Images\Edge_Providers;

Expand Down
2 changes: 2 additions & 0 deletions classes/edge-providers/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
14 changes: 11 additions & 3 deletions classes/features/class-preloads.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images\Features
*/

namespace Edge_Images\Features;

Expand All @@ -25,7 +30,7 @@ public static function register() : void {
* @return void
*/
public function preload_filtered_images() : void {
$images = apply_filters( 'Edge_Images\preloads', array() );
$images = apply_filters( 'edge_images_preloads', array() );

// Bail if $images isn't an array.
if ( ! is_array( $images ) || empty( $images ) ) {
Expand Down Expand Up @@ -69,8 +74,11 @@ private function preload_image( int $id, $size ) : void {

echo sprintf(
'<link rel="preload" as="image" imagesrcset="%s" imagesizes="%s" fetchpriority="high">',
implode( ', ', $image->attrs['srcset'] ),
$image->attrs['sizes'],
implode(
', ',
esc_url_raw( $image->attrs['srcset'] ),
esc_attr( $image->attrs['sizes'] ),
)
) . PHP_EOL;

}
Expand Down
2 changes: 2 additions & 0 deletions classes/features/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
2 changes: 2 additions & 0 deletions classes/integrations/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
5 changes: 5 additions & 0 deletions classes/integrations/yoast-seo/class-schema-images.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images\Integrations
*/

namespace Edge_Images\Integrations\Yoast_SEO;

Expand Down
5 changes: 5 additions & 0 deletions classes/integrations/yoast-seo/class-social-images.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images\Integrations
*/

namespace Edge_Images\Integrations\Yoast_SEO;

Expand Down
5 changes: 5 additions & 0 deletions classes/integrations/yoast-seo/class-xml-sitemaps.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Edge Images plugin file.
*
* @package Edge_Images\Integrations
*/

namespace Edge_Images\Integrations\Yoast_SEO;

Expand Down
2 changes: 2 additions & 0 deletions classes/integrations/yoast-seo/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
74 changes: 42 additions & 32 deletions classes/views/admin.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
<?php
// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
exit;
/**
* Edge Images plugin file.
*
* @package Edge_Images\Views
*/

namespace Edge_Images\Views;

// Avoid direct calls to this file.
if ( ! defined( 'EDGE_IMAGES_VERSION' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
?>

<div class="wrap">

<h1>Edge Images</h1>

<form method="post" action="options.php">
<input type="hidden" name="option_page" value="edge_images">
<input type="hidden" name="action" value="update">

<input type="hidden" id="_wpnonce" name="_wpnonce" value="XXXXXX">
<input type="hidden" name="_wp_http_referer" value="XXXX">

<table class="form-table" role="presentation">
<tbody>
<tr>
<th scope="row"><label for="edge_provider">Edge Provider</label></th>
<td>
<select id="edge_provider" name="edge_provider">
<option>- None -</option>
<option>Cloudflare</option>
<option>Accelerated Domains</option>
</select>
</td>
</tr>
</tbody>
</table>

<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
</p>

</form>
<h1>Edge Images</h1>

<form method="post" action="options.php">

<input type="hidden" name="option_page" value="edge_images">
<input type="hidden" name="action" value="update">

<input type="hidden" id="_wpnonce" name="_wpnonce" value="XXXXXX">
<input type="hidden" name="_wp_http_referer" value="XXXX">

<table class="form-table" role="presentation">
<tbody>
<tr>
<th scope="row"><label for="edge_provider">Edge Provider</label></th>
<td>
<select id="edge_provider" name="edge_provider">
<option>Cloudflare</option>
<option>Accelerated Domains</option>
</select>
</td>
</tr>
</tbody>
</table>

<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
</p>

</form>

</div>
2 changes: 2 additions & 0 deletions classes/views/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
45 changes: 38 additions & 7 deletions edge-images.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
<?php

namespace Edge_Images;

/**
* Edge Images
*
* @package Edge_Images
* @copyright Copyright (C) 2008-2022, Yoast BV - [email protected]
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3 or higher
*
* @wordpress-plugin
* Plugin Name: Edge Images
* Version: 3.1
* Description: Provides support for Cloudflare's images transformation service.
* Description: Provides support for transforming images on the edge, via Cloudflare or Accelerated Domains.
*
* Author: Jono Alderson
* Author URI: https://www.jonoalderson.com
* Plugin URI: https://www.jonoalderson.com/plugins/edge-images/
* Donate link: https://www.jonoalderson.com
* Contributors: jonoaldersonwp
*
* Version: 3.2
* Requires at least: 6.0
* Tested up to: 6.1.1
* Stable tag: 3.1
* Requires PHP: 7.4
*
* Text Domain: edge-images
* Tags: images, cloudflare, accelerated domains, performance
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Edge_Images;

// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Set our constants.
if ( ! defined( 'EDGE_IMAGES_VERSION' ) ) {
define( 'EDGE_IMAGES_VERSION', '3.1' );
define( 'EDGE_IMAGES_VERSION', '3.2' );
}

if ( ! defined( 'EDGE_IMAGES_PLUGIN_DIR' ) ) {
Expand Down Expand Up @@ -113,8 +144,8 @@ function get_edge_image( int $id, array $atts = array(), $size = 'large', bool $
// Construct the <img>, and wrap it in a <picture>.
$html = $image->construct_img_el( true );

// Echo the image.
if ( $echo ) {
// Echo the image.
echo Helpers::sanitize_image_html( $html );
return;
}
Expand Down
21 changes: 10 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Edge Images
=== Edge Images ===
Contributors: jonoaldersonwp
Donate link: https://www.jonoalderson.com
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html
Tags: images, cloudflare, accelerated domains, performance
Tested up to: 6.1.1
Stable tag: 3.2
Requires PHP: 7.4

A WordPress plugin which automatically uses an edge transformation service (e.g., [Cloudflare](https://www.cloudflare.com/) or [Accelerated Domains](https://accelerateddomains.com/)) to apply performance optimizations to `<img>` markup.

- [About](#about)
- [Requirements](#requirements)
- [Customization](#customization)
- [Examples](#examples)
- [Integrations](#integrations)
- [Roadmap](#roadmap--known-issues)
- [Changelog](#changelog)
== Description ==

## About

### What does it do?
Edge Images intercepts various flavors of WordPress' native `wp_get_attachment_image()`, `get_the_post_thumbnail()` and similar, and:
- Uses an associative array of named (or h/w array value) sizes as lookups for user-defined layout, presentation and optimization rules.
- Generates comprehensive `srcset` values, optimal `sizes` attributes, and applies general image optimizations.
Expand Down

0 comments on commit ac8989a

Please sign in to comment.