From 005dbeb4b1d6d5ac5fb165cd2aaf3fdc9f7d47d3 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Tue, 17 Dec 2024 18:27:40 +0100 Subject: [PATCH] cleanup --- s3-uploads.php | 115 ++++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/s3-uploads.php b/s3-uploads.php index c8f9395..58f0cfb 100644 --- a/s3-uploads.php +++ b/s3-uploads.php @@ -8,32 +8,31 @@ Author URI: http://hmn.md */ -if (defined('WP_CLI') && WP_CLI ) { - include_once dirname(__FILE__) . '/inc/class-s3-uploads-wp-cli-command.php'; +if ( defined( 'WP_CLI' ) && WP_CLI ) { + require_once dirname( __FILE__ ) . '/inc/class-s3-uploads-wp-cli-command.php'; } -add_action('plugins_loaded', 's3_uploads_init'); +add_action( 'plugins_loaded', 's3_uploads_init' ); -function s3_uploads_init() -{ - if (! s3_uploads_check_requirements() ) { - return; - } +function s3_uploads_init() { + if ( ! s3_uploads_check_requirements() ) { + return; + } - if (! defined('S3_UPLOADS_BUCKET') ) { - return; - } + if ( ! defined( 'S3_UPLOADS_BUCKET' ) ) { + return; + } - if (( ! defined('S3_UPLOADS_KEY') || ! defined('S3_UPLOADS_SECRET') ) && ! defined('S3_UPLOADS_USE_INSTANCE_PROFILE') ) { - return; - } + if ( ( ! defined( 'S3_UPLOADS_KEY' ) || ! defined( 'S3_UPLOADS_SECRET' ) ) && ! defined( 'S3_UPLOADS_USE_INSTANCE_PROFILE' ) ) { + return; + } - if (! s3_uploads_enabled() ) { - return; - } + if ( ! s3_uploads_enabled() ) { + return; + } - $instance = S3_Uploads::get_instance(); - $instance->setup(); + $instance = S3_Uploads::get_instance(); + $instance->setup(); } /** @@ -41,17 +40,16 @@ function s3_uploads_init() * * @return bool True if the requirements are met, else false. */ -function s3_uploads_check_requirements() -{ - if (version_compare('5.3.3', PHP_VERSION, '>') ) { - if (is_admin() && ! defined('DOING_AJAX') ) { - add_action('admin_notices', 's3_uploads_outdated_php_version_notice'); - } +function s3_uploads_check_requirements() { + if ( version_compare( '5.3.3', PHP_VERSION, '>' ) ) { + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { + add_action( 'admin_notices', 's3_uploads_outdated_php_version_notice' ); + } - return false; - } + return false; + } - return true; + return true; } /** @@ -59,12 +57,10 @@ function s3_uploads_check_requirements() * * This has to be a named function for compatibility with PHP 5.2. */ -function s3_uploads_outdated_php_version_notice() -{ - printf( - '

The S3 Uploads plugin requires PHP version 5.3.3 or higher. Your server is running PHP version %s.

', - PHP_VERSION - ); +function s3_uploads_outdated_php_version_notice() { + printf( '

The S3 Uploads plugin requires PHP version 5.3.3 or higher. Your server is running PHP version %s.

', + PHP_VERSION + ); } /** @@ -75,36 +71,39 @@ function s3_uploads_outdated_php_version_notice() * * @return bool */ -function s3_uploads_enabled() -{ - // Make sure the plugin is enabled when autoenable is on - $constant_autoenable_off = ( defined('S3_UPLOADS_AUTOENABLE') && false === S3_UPLOADS_AUTOENABLE ); +function s3_uploads_enabled() { + // Make sure the plugin is enabled when autoenable is on + $constant_autoenable_off = ( defined( 'S3_UPLOADS_AUTOENABLE' ) && false === S3_UPLOADS_AUTOENABLE ); - if ($constant_autoenable_off && 'enabled' !== get_option('s3_uploads_enabled') ) { // If the plugin is not enabled, skip - return false; - } + if ( $constant_autoenable_off && 'enabled' !== get_option( 's3_uploads_enabled' ) ) { // If the plugin is not enabled, skip + return false; + } - return true; + return true; } -function s3_uploads_autoload($class) -{ - $mapping = array( - 'S3_Uploads_ChangedFilesIterator' => __DIR__ . '/inc/class-s3-uploads-changed-files-iterator.php', - 'S3_Uploads_Image_Editor_Imagick' => __DIR__ . '/inc/class-s3-uploads-image-editor-imagick.php', - 'S3_Uploads_Local_Stream_Wrapper' => __DIR__ . '/inc/class-s3-uploads-local-stream-wrapper.php', - 'S3_Uploads_Stream_Wrapper' => __DIR__ . '/inc/class-s3-uploads-stream-wrapper.php', - 'S3_Uploads_UploadSyncBuilder' => __DIR__ . '/inc/class-s3-uploads-uploadsyncbuilder.php', - 'S3_Uploads_WP_CLI_Command' => __DIR__ . '/inc/class-s3-uploads-wp-cli-command.php', - 'S3_Uploads' => __DIR__ . '/inc/class-s3-uploads.php', - ); - - if (isset($mapping[$class])) { - include $mapping[$class]; - } +/** + * Autoload callback. + * + * @param $class_name Name of the class to load. + */ +function s3_uploads_autoload($class) { + $mapping = array( + 'S3_Uploads_ChangedFilesIterator' => __DIR__ . '/inc/class-s3-uploads-changed-files-iterator.php', + 'S3_Uploads_Image_Editor_Imagick' => __DIR__ . '/inc/class-s3-uploads-image-editor-imagick.php', + 'S3_Uploads_Local_Stream_Wrapper' => __DIR__ . '/inc/class-s3-uploads-local-stream-wrapper.php', + 'S3_Uploads_Stream_Wrapper' => __DIR__ . '/inc/class-s3-uploads-stream-wrapper.php', + 'S3_Uploads_UploadSyncBuilder' => __DIR__ . '/inc/class-s3-uploads-uploadsyncbuilder.php', + 'S3_Uploads_WP_CLI_Command' => __DIR__ . '/inc/class-s3-uploads-wp-cli-command.php', + 'S3_Uploads' => __DIR__ . '/inc/class-s3-uploads.php', + ); + + if (isset($mapping[$class])) { + require $mapping[$class]; + } } spl_autoload_register('s3_uploads_autoload', true); // Require AWS Autoloader file. -require_once dirname(__FILE__) . '/lib/aws-sdk/aws-autoloader.php'; +require_once dirname( __FILE__ ) . '/lib/aws-sdk/aws-autoloader.php';