atarim-visual-collaboration
/
third-party
/
image-optimizer
/
shortpixel
/
class-avcf-shortpixel-detector.php
class-avcf-abilities-shortpixel.php
2 weeks ago
class-avcf-shortpixel-detector.php
2 weeks ago
class-avcf-shortpixel-helpers.php
2 weeks ago
class-avcf-shortpixel-detector.php
50 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ShortPixel Image Optimizer detector. |
| 4 | * |
| 5 | * ShortPixel is a CLOUD/async optimizer: compression runs on ShortPixel's |
| 6 | * servers via a background queue. Our abilities DRIVE the installed plugin |
| 7 | * (enqueue work, read status); they never hold or read its API key and never |
| 8 | * reimplement compression. |
| 9 | * |
| 10 | * Verified against ShortPixel Image Optimizer 6.5.5 (namespaced controllers + |
| 11 | * custom queue). Availability is keyed on the plugin's version constant. |
| 12 | * |
| 13 | * @package atarim-visual-collaboration |
| 14 | */ |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; |
| 18 | } |
| 19 | |
| 20 | class AVCF_ShortPixel_Detector { |
| 21 | |
| 22 | /** Whether ShortPixel Image Optimizer is active on this site. */ |
| 23 | public function avcf_shortpixel_is_available() { |
| 24 | return defined( 'SHORTPIXEL_IMAGE_OPTIMISER_VERSION' ) |
| 25 | && class_exists( '\\ShortPixel\\Controller\\QueueController' ) |
| 26 | && class_exists( '\\ShortPixel\\Controller\\ApiKeyController' ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Whether ShortPixel is configured with a verified API key. Uses the |
| 31 | * plugin's own ApiKeyModel::is_verified() and NEVER reads the key value. |
| 32 | * Returns false if unavailable or unconfigured. |
| 33 | */ |
| 34 | public function avcf_shortpixel_is_configured() { |
| 35 | if ( ! $this->avcf_shortpixel_is_available() ) { |
| 36 | return false; |
| 37 | } |
| 38 | try { |
| 39 | $key_control = \ShortPixel\Controller\ApiKeyController::getInstance(); |
| 40 | if ( ! is_object( $key_control ) || ! method_exists( $key_control, 'getKeyModel' ) ) { |
| 41 | return false; |
| 42 | } |
| 43 | $model = $key_control->getKeyModel(); |
| 44 | return is_object( $model ) && method_exists( $model, 'is_verified' ) && (bool) $model->is_verified(); |
| 45 | } catch ( \Throwable $e ) { |
| 46 | return false; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 |