public static function get_compressor($api_key, $after_compress_callback = null)
 {
     if (Tiny_PHP::is_curl_available()) {
         return new Tiny_Compress_Curl($api_key, $after_compress_callback);
     } elseif (Tiny_PHP::is_fopen_available()) {
         return new Tiny_Compress_Fopen($api_key, $after_compress_callback);
     }
     throw new Tiny_Exception('No HTTP client is available (cURL or fopen)', 'NoHttpClient');
 }
 public static function create($api_key, $after_compress_callback = null)
 {
     if (Tiny_PHP::client_supported()) {
         $class = 'Tiny_Compress_Client';
     } elseif (Tiny_PHP::fopen_available()) {
         $class = 'Tiny_Compress_Fopen';
     } else {
         throw new Tiny_Exception('No HTTP client is available (cURL or fopen)', 'NoHttpClient');
     }
     return new $class($api_key, $after_compress_callback);
 }
 public function admin_init()
 {
     if (current_user_can('manage_options')) {
         if (!$this->get_api_key()) {
             $notice_class = 'error';
             $notice = esc_html__('Please register or provide an API key to start compressing images', 'tiny-compress-images');
         } else {
             if ($this->get_api_key_pending()) {
                 $notice_class = 'notice-warning';
                 $notice = esc_html__('Please activate your account to start compressing images', 'tiny-compress-images');
             }
         }
         if (isset($notice) && $notice) {
             $link = sprintf('<a href="options-media.php#%s">%s</a>', self::NAME, $notice);
             $this->notices->show('setting', $link, $notice_class, false);
         }
         if (!Tiny_PHP::client_supported()) {
             $details = 'PHP ' . PHP_VERSION;
             if (extension_loaded('curl')) {
                 $curlinfo = curl_version();
                 $details .= ' with curl ' . $curlinfo['version'];
             } else {
                 $details .= ' without curl';
             }
             $message = esc_html__('You are using an outdated platform (' . $details . ') – some features are disabled', 'tiny-compress-images');
             $this->notices->show('deprecated', $message, 'notice-warning', false);
         }
     }
     try {
         $this->init_compressor();
     } catch (Tiny_Exception $e) {
         $this->notices->show('compressor_exception', esc_html__($e->getMessage(), 'tiny-compress-images'), 'error', false);
     }
     $section = self::get_prefixed_name('settings');
     add_settings_section($section, esc_html__('JPEG and PNG optimization', 'tiny-compress-images'), $this->get_method('render_section'), 'media');
     $field = self::get_prefixed_name('api_key');
     register_setting('media', $field);
     add_settings_field($field, esc_html__('TinyPNG account', 'tiny-compress-images'), $this->get_method('render_pending_status'), 'media', $section);
     $field = self::get_prefixed_name('api_key_pending');
     register_setting('media', $field);
     $field = self::get_prefixed_name('sizes');
     register_setting('media', $field);
     add_settings_field($field, esc_html__('File compression', 'tiny-compress-images'), $this->get_method('render_sizes'), 'media', $section);
     $field = self::get_prefixed_name('resize_original');
     register_setting('media', $field);
     add_settings_field($field, esc_html__('Original image', 'tiny-compress-images'), $this->get_method('render_resize'), 'media', $section);
     $field = self::get_prefixed_name('preserve_data');
     register_setting('media', $field);
     add_settings_section('section_end', '', $this->get_method('render_section_end'), 'media');
     add_action('wp_ajax_tiny_image_sizes_notice', $this->get_method('image_sizes_notice'));
     add_action('wp_ajax_tiny_account_status', $this->get_method('account_status'));
     add_action('wp_ajax_tiny_settings_create_api_key', $this->get_method('create_api_key'));
     add_action('wp_ajax_tiny_settings_update_api_key', $this->get_method('update_api_key'));
 }
 public static function tear_down_after_class()
 {
     Tiny_PHP::$client_supported = true;
     Tiny_PHP::$fopen_available = true;
 }
 public static function set_up_before_class()
 {
     Tiny_PHP::$client_supported = false;
 }
<?php

/**
 * Plugin Name: Compress JPEG & PNG images
 * Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
 * Version: 2.1.0
 * Author: TinyPNG
 * Author URI: https://tinypng.com
 * Text Domain: tiny-compress-images
 * License: GPLv2 or later
 */
require dirname(__FILE__) . '/src/config/tiny-config.php';
require dirname(__FILE__) . '/src/class-tiny-php.php';
require dirname(__FILE__) . '/src/class-tiny-wp-base.php';
require dirname(__FILE__) . '/src/class-tiny-exception.php';
require dirname(__FILE__) . '/src/class-tiny-compress.php';
require dirname(__FILE__) . '/src/class-tiny-image-size.php';
require dirname(__FILE__) . '/src/class-tiny-image.php';
require dirname(__FILE__) . '/src/class-tiny-settings.php';
require dirname(__FILE__) . '/src/class-tiny-plugin.php';
require dirname(__FILE__) . '/src/class-tiny-notices.php';
if (Tiny_PHP::client_supported()) {
    require dirname(__FILE__) . '/src/class-tiny-compress-client.php';
} else {
    require dirname(__FILE__) . '/src/class-tiny-compress-fopen.php';
}
$tiny_plugin = new Tiny_Plugin();
 public static function set_up_before_class()
 {
     Tiny_PHP::$client_supported = false;
     Tiny_PHP::$fopen_available = false;
 }