Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tmountjr committed Feb 16, 2020
0 parents commit 38015b6
Show file tree
Hide file tree
Showing 2 changed files with 438 additions and 0 deletions.
46 changes: 46 additions & 0 deletions fastly-io.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Plugin Name: Fastly IO
* Description: Set up Fastly Image Optimizer as an image editing library.
* Author: Tom Mount <tom.mount@pantheon.io>
* Author URI: https://pantheon.io
* Text Domain: fastly-io
* Domain Path: /languages
* Version: 1.0.0
*
* @package Fastly_IO
*/

function fastly_io_set_library($editors)
{
// If the class doesn't exist, fall back to normal.
if (! class_exists('Fastly_IO\WP_Image_Editor_Fastly')) {
return $editors;
}

// Otherwise, use this one.
$editors = [ Fastly_IO\WP_Image_Editor_Fastly::class ];
return $editors;
}

spl_autoload_register(
function ($class) {
$class = ltrim($class, '\\');
if (stripos($class, 'Fastly_IO\\') !== 0) {
return;
}

$parts = explode('\\', $class);
array_shift($parts);
$last = array_pop($parts);
$last = "class-${last}.php";
$parts[] = $last;
$file = dirname(__FILE__) . '/src/classes/' . str_replace('_', '-', strtolower(implode('/', $parts)));
if (file_exists($file)) {
require $file;
}
}
);

add_filter('big_image_size_threshold', '__return false;');
add_filter('wp_image_editors', 'fastly_io_set_library');
Loading

0 comments on commit 38015b6

Please sign in to comment.