| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WP-Stateless |
| 4 |
* Plugin URI: https://www.usabilitydynamics.com |
| 5 |
* Description: Upload and serve your WordPress media files from Google Cloud Storage. |
| 6 |
* Author: Usability Dynamics, Inc. |
| 7 |
* Version: 2.2.2 |
| 8 |
* Text Domain: stateless-media |
| 9 |
* Author URI: https://www.usabilitydynamics.com |
| 10 |
* |
| 11 |
* Copyright 2012 - 2018 Usability Dynamics, Inc. ( email : info@usabilitydynamics.com ) |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
if( !function_exists( 'ud_get_stateless_media' ) ) { |
| 16 |
|
| 17 |
/** |
| 18 |
* Returns Stateless Media Instance |
| 19 |
* |
| 20 |
* @author Usability Dynamics, Inc. |
| 21 |
* @since 0.2.0 |
| 22 |
* @param bool $key |
| 23 |
* @param null $default |
| 24 |
* @return |
| 25 |
*/ |
| 26 |
function ud_get_stateless_media( $key = false, $default = null ) { |
| 27 |
$instance = \wpCloud\StatelessMedia\Bootstrap::get_instance(); |
| 28 |
return $key ? $instance->get( $key, $default ) : $instance; |
| 29 |
} |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
if( !function_exists( 'ud_check_stateless_media' ) ) { |
| 34 |
/** |
| 35 |
* Determines if plugin can be initialized. |
| 36 |
* |
| 37 |
* @author Usability Dynamics, Inc. |
| 38 |
* @since 0.2.0 |
| 39 |
*/ |
| 40 |
function ud_check_stateless_media() { |
| 41 |
global $_ud_stateless_media_error; |
| 42 |
try { |
| 43 |
//** Be sure composer.json exists */ |
| 44 |
$file = dirname( __FILE__ ) . '/composer.json'; |
| 45 |
if( !file_exists( $file ) ) { |
| 46 |
throw new Exception( __( 'Distributive is broken. composer.json is missed. Try to remove and upload plugin again.', 'stateless-media' ) ); |
| 47 |
} |
| 48 |
$data = json_decode( file_get_contents( $file ), true ); |
| 49 |
//** Be sure PHP version is correct. */ |
| 50 |
if( !empty( $data[ 'require' ][ 'php' ] ) ) { |
| 51 |
preg_match( '/^([><=]*)([0-9\.]*)$/', $data[ 'require' ][ 'php' ], $matches ); |
| 52 |
if( !empty( $matches[1] ) && !empty( $matches[2] ) ) { |
| 53 |
if( !version_compare( PHP_VERSION, $matches[2], $matches[1] ) ) { |
| 54 |
throw new Exception( sprintf( __( 'Plugin requires PHP %s or higher. Your current PHP version is %s', 'stateless-media' ), $matches[2], PHP_VERSION ) ); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
//** Be sure vendor autoloader exists */ |
| 59 |
if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) { |
| 60 |
require_once ( dirname( __FILE__ ) . '/vendor/autoload.php' ); |
| 61 |
} else { |
| 62 |
throw new Exception( sprintf( __( 'Distributive is broken. %s file is missed. Try to remove and upload plugin again.', 'stateless-media' ), dirname( __FILE__ ) . '/vendor/autoload.php' ) ); |
| 63 |
} |
| 64 |
//** Be sure our Bootstrap class exists */ |
| 65 |
if( !class_exists( '\wpCloud\StatelessMedia\Bootstrap' ) ) { |
| 66 |
throw new Exception( __( 'Distributive is broken. Plugin loader is not available. Try to remove and upload plugin again.', 'stateless-media' ) ); |
| 67 |
} |
| 68 |
} catch( Exception $e ) { |
| 69 |
$_ud_stateless_media_error = $e->getMessage(); |
| 70 |
return false; |
| 71 |
} |
| 72 |
return true; |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
if( !function_exists( 'ud_stateless_media_message' ) ) { |
| 78 |
/** |
| 79 |
* Renders admin notes in case there are errors on plugin init |
| 80 |
* |
| 81 |
* @author Usability Dynamics, Inc. |
| 82 |
* @since 1.0.0 |
| 83 |
*/ |
| 84 |
function ud_stateless_media_message() { |
| 85 |
global $_ud_stateless_media_error; |
| 86 |
if( !empty( $_ud_stateless_media_error ) ) { |
| 87 |
$message = sprintf( __( '<p><b>%s</b> can not be initialized. %s</p>', 'stateless-media' ), 'Stateless Media', $_ud_stateless_media_error ); |
| 88 |
echo '<div class="error fade" style="padding:11px;">' . $message . '</div>'; |
| 89 |
} |
| 90 |
} |
| 91 |
add_action( 'admin_notices', 'ud_stateless_media_message' ); |
| 92 |
} |
| 93 |
|
| 94 |
if( ud_check_stateless_media() ) { |
| 95 |
//** Initialize. */ |
| 96 |
ud_get_stateless_media(); |
| 97 |
} |
| 98 |
|