Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Tinify service available outside wp-admin #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/class-tiny-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Tiny_Settings extends Tiny_WP_Base {
private $tinify_sizes;
private $compressor;
private $notices;

// Make Tinify available from outside wp-admin
private $compressor_init = false;

protected static $offload_s3_plugin = 'amazon-s3-and-cloudfront/wordpress-s3.php';

Expand All @@ -37,6 +40,9 @@ private function init_compressor() {
$this->get_api_key(),
$this->get_method( 'after_compress_callback' )
);

// We assume, we now have a compressor. If not, something else went wrong.
$this->compressor_init = true;
}

public function get_absolute_url() {
Expand Down Expand Up @@ -151,10 +157,25 @@ public function account_status() {
}

public function get_compressor() {
// We check if we should have a compressor available, and if not, we create one.
if ( $this->compressor_init === false ) {
try {
$this->init_compressor();
} catch ( Tiny_Exception $e ) {
// Did not work. Fail silently, like in XMLRPC
}
}

return $this->compressor;
}

public function set_compressor( $compressor ) {
// If $compressor is not null, we use this one. Otherwise we try to init our own when the time comes.
if ( ! is_null( $compressor ) ) {
$this->compressor_init = true;
} else {
$this->compressor_init = false;
}
$this->compressor = $compressor;
}

Expand Down