| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Infinite Uploads |
| 4 |
* Description: Infinitely scalable cloud storage and delivery for your videos and uploads made easy! Upload directly to cloud storage and manage your files right from the WordPress Media Library. |
| 5 |
* Version: 3.2.4 |
| 6 |
* Author: Infinite Uploads |
| 7 |
* Author URI: https://infiniteuploads.com/?utm_source=iup_plugin&utm_medium=plugin&utm_campaign=iup_plugin&utm_content=meta |
| 8 |
* Text Domain: infinite-uploads |
| 9 |
* Requires at least: 6.0 |
| 10 |
* Tested up to: 7.0 |
| 11 |
* Requires PHP: 8.0 |
| 12 |
* License: GPLv2 |
| 13 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 14 |
* Network: true |
| 15 |
* |
| 16 |
* Inspired by AWS PHP SDK stream wrapper code from the S3 Uploads plugin by Human Made https://github.com/humanmade/S3-Uploads. |
| 17 |
* |
| 18 |
* Copyright 2021-2025 ClikIT, LLC |
| 19 |
*/ |
| 20 |
|
| 21 |
define( 'INFINITE_UPLOADS_VERSION', '3.2.4' ); |
| 22 |
|
| 23 |
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 24 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 25 |
} |
| 26 |
|
| 27 |
// Load action scheduler. |
| 28 |
require_once dirname( __FILE__ ) . '/libs/action-scheduler/action-scheduler.php'; |
| 29 |
|
| 30 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 31 |
\WP_CLI::add_command( 'infinite-uploads', '\ClikIT\InfiniteUploads\InfiniteUploadsWPCLICommand' ); |
| 32 |
} |
| 33 |
|
| 34 |
//require_once 'inc/class-infinite-uploads-wp-mail.php'; |
| 35 |
register_activation_hook( __FILE__, 'infinite_uploads_install' ); |
| 36 |
|
| 37 |
add_action( 'plugins_loaded', 'infinite_uploads_init' ); |
| 38 |
|
| 39 |
function infinite_uploads_init() { |
| 40 |
//how much to try uploading/downloading per ajax loop (we want as much as possible without exceeding (php timeout - ajax_timeout) to avoid 504s |
| 41 |
if ( ! defined( 'INFINITE_UPLOADS_SYNC_MAX_BYTES' ) ) { |
| 42 |
define( 'INFINITE_UPLOADS_SYNC_MAX_BYTES', MB_IN_BYTES * 12 ); |
| 43 |
} |
| 44 |
//This is the maximum to transfer in parallel within the INFINITE_UPLOADS_SYNC_MAX_BYTES size. |
| 45 |
if ( ! defined( 'INFINITE_UPLOADS_SYNC_CONCURRENCY' ) ) { |
| 46 |
define( 'INFINITE_UPLOADS_SYNC_CONCURRENCY', 15 ); |
| 47 |
} |
| 48 |
if ( ! defined( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY' ) ) { |
| 49 |
define( 'INFINITE_UPLOADS_SYNC_MULTIPART_CONCURRENCY', 5 ); |
| 50 |
} |
| 51 |
if ( ! defined( 'INFINITE_UPLOADS_SYNC_PER_LOOP' ) ) { |
| 52 |
define( 'INFINITE_UPLOADS_SYNC_PER_LOOP', 1000 ); |
| 53 |
} |
| 54 |
if ( ! defined( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL' ) ) { |
| 55 |
define( 'INFINITE_UPLOADS_HTTP_CACHE_CONTROL', YEAR_IN_SECONDS ); |
| 56 |
} |
| 57 |
//we cache the last object uploaded to cloud in memory so it can be processed without downloading again. |
| 58 |
if ( ! defined( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES' ) ) { |
| 59 |
define( 'INFINITE_UPLOADS_STREAM_CACHE_MAX_BYTES', MB_IN_BYTES * 32 ); |
| 60 |
} |
| 61 |
|
| 62 |
// Require Our custom AWS Autoloader file. |
| 63 |
|
| 64 |
require_once dirname( __FILE__ ) . '/vendor/Aws3/aws-autoloader.php'; |
| 65 |
|
| 66 |
if ( ! infinite_uploads_check_requirements() ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
infinite_uploads_upgrade(); |
| 71 |
|
| 72 |
$instance = \ClikIT\InfiniteUploads\InfiniteUploads::get_instance(); |
| 73 |
|
| 74 |
require_once dirname( __FILE__ ) . '/functions.php'; |
| 75 |
|
| 76 |
$instance->setup(); |
| 77 |
} |
| 78 |
|
| 79 |
function infinite_uploads_upgrade() { |
| 80 |
|
| 81 |
// Network-wide table (infinite_uploads_files) — one option gates the whole network. |
| 82 |
$installed = get_site_option( 'iup_installed' ); |
| 83 |
if ( INFINITE_UPLOADS_VERSION != $installed ) { |
| 84 |
infinite_uploads_install(); |
| 85 |
} |
| 86 |
|
| 87 |
// Per-site folder tables — each subsite tracks its own version independently. |
| 88 |
$folders_installed = get_option( 'iup_folders_installed' ); |
| 89 |
if ( INFINITE_UPLOADS_VERSION != $folders_installed ) { |
| 90 |
infinite_uploads_install_folders(); |
| 91 |
} |
| 92 |
|
| 93 |
// One-time backfill: prior versions excluded /bb-plugin/cache/ entirely, so any |
| 94 |
// images BB had already cropped before this release were never added to |
| 95 |
// infinite_uploads_files. Schedule an async walk + queue so the existing |
| 96 |
// iu_bb_cache_push handler can offload them. Idempotent — flag is set when done. |
| 97 |
// |
| 98 |
// is_main_site() guard: the flag is network-wide (get_site_option), but |
| 99 |
// `infinite_uploads_upgrade()` runs on every plugins_loaded across every |
| 100 |
// subsite. Without this guard, multiple subsite requests can each pass the |
| 101 |
// `wp_next_scheduled` check before any of them actually schedule, racing to |
| 102 |
// queue duplicate iu_bb_carveout_backfill events. Restricting to the main |
| 103 |
// site collapses the race to a single scheduler. |
| 104 |
if ( is_main_site() && ! get_site_option( 'iup_bb_carveout_backfilled' ) && ! wp_next_scheduled( 'iu_bb_carveout_backfill' ) ) { |
| 105 |
wp_schedule_single_event( time() + 60, 'iu_bb_carveout_backfill' ); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
function infinite_uploads_install() { |
| 110 |
global $wpdb; |
| 111 |
|
| 112 |
//prevent race condition during upgrade by setting option before running potentially long query |
| 113 |
if ( is_multisite() ) { |
| 114 |
update_site_option( 'iup_installed', INFINITE_UPLOADS_VERSION ); |
| 115 |
} else { |
| 116 |
update_option( 'iup_installed', INFINITE_UPLOADS_VERSION, true ); |
| 117 |
} |
| 118 |
|
| 119 |
$charset_collate = $wpdb->get_charset_collate(); |
| 120 |
|
| 121 |
//191 is the maximum innodb default key length on utf8mb4 |
| 122 |
$sql = "CREATE TABLE {$wpdb->base_prefix}infinite_uploads_files ( |
| 123 |
`file` VARCHAR(255) NOT NULL, |
| 124 |
`size` BIGINT UNSIGNED NOT NULL DEFAULT '0', |
| 125 |
`modified` INT UNSIGNED NOT NULL, |
| 126 |
`type` VARCHAR(20) NOT NULL, |
| 127 |
`transferred` BIGINT UNSIGNED NOT NULL DEFAULT '0', |
| 128 |
`synced` BOOLEAN NOT NULL DEFAULT '0', |
| 129 |
`deleted` BOOLEAN NOT NULL DEFAULT '0', |
| 130 |
`errors` INT UNSIGNED NOT NULL DEFAULT '0', |
| 131 |
`transfer_status` TEXT NULL DEFAULT NULL, |
| 132 |
PRIMARY KEY (`file`(191)), |
| 133 |
KEY `type` (`type`), |
| 134 |
KEY `synced` (`synced`), |
| 135 |
KEY `deleted` (`deleted`) |
| 136 |
) {$charset_collate};"; |
| 137 |
|
| 138 |
if ( ! function_exists( 'dbDelta' ) ) { |
| 139 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 140 |
} |
| 141 |
|
| 142 |
dbDelta( $sql ); |
| 143 |
|
| 144 |
// Create per-site folder tables for the current site. |
| 145 |
infinite_uploads_install_folders(); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Create (or upgrade) the per-site media-folder tables for the current subsite. |
| 150 |
* |
| 151 |
* Uses $wpdb->prefix so each subsite gets its own tables, keeping folder |
| 152 |
* assignments isolated to the site that owns the attachment posts. |
| 153 |
* Gated by a per-site option so it runs independently on every subsite. |
| 154 |
*/ |
| 155 |
function infinite_uploads_install_folders() { |
| 156 |
global $wpdb; |
| 157 |
|
| 158 |
// Prevent race conditions by marking done before the potentially slow dbDelta. |
| 159 |
update_option( 'iup_folders_installed', INFINITE_UPLOADS_VERSION, true ); |
| 160 |
|
| 161 |
$charset_collate = $wpdb->get_charset_collate(); |
| 162 |
|
| 163 |
// Media folders table. |
| 164 |
$sql = "CREATE TABLE {$wpdb->prefix}infinite_uploads_media_folders ( |
| 165 |
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 166 |
name VARCHAR(255) NOT NULL, |
| 167 |
parent_id BIGINT UNSIGNED NOT NULL DEFAULT 0, |
| 168 |
sort_order INT UNSIGNED NOT NULL DEFAULT 0, |
| 169 |
created_by BIGINT UNSIGNED NOT NULL DEFAULT 0, |
| 170 |
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 171 |
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 172 |
color VARCHAR(20) NOT NULL DEFAULT '', |
| 173 |
PRIMARY KEY (id), |
| 174 |
KEY parent_id (parent_id), |
| 175 |
KEY sort_order (sort_order) |
| 176 |
) {$charset_collate};"; |
| 177 |
|
| 178 |
// Media-to-folder relationship table. |
| 179 |
$sql .= "\nCREATE TABLE {$wpdb->prefix}infinite_uploads_media_folder_relationships ( |
| 180 |
folder_id BIGINT UNSIGNED NOT NULL, |
| 181 |
attachment_id BIGINT UNSIGNED NOT NULL, |
| 182 |
PRIMARY KEY (folder_id, attachment_id), |
| 183 |
KEY attachment_id (attachment_id) |
| 184 |
) {$charset_collate};"; |
| 185 |
|
| 186 |
if ( ! function_exists( 'dbDelta' ) ) { |
| 187 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 188 |
} |
| 189 |
|
| 190 |
dbDelta( $sql ); |
| 191 |
} |
| 192 |
|
| 193 |
// Create folder tables for each new subsite when it is provisioned. |
| 194 |
add_action( 'wp_initialize_site', function ( $new_site ) { |
| 195 |
switch_to_blog( $new_site->blog_id ); |
| 196 |
infinite_uploads_install_folders(); |
| 197 |
restore_current_blog(); |
| 198 |
} ); |
| 199 |
|
| 200 |
/** |
| 201 |
* Check whether the environment meets the plugin's requirements, like the minimum PHP version. |
| 202 |
* |
| 203 |
* @return bool True if the requirements are met, else false. |
| 204 |
*/ |
| 205 |
function infinite_uploads_check_requirements() { |
| 206 |
global $wp_version; |
| 207 |
$hook = is_multisite() ? 'network_admin_notices' : 'admin_notices'; |
| 208 |
|
| 209 |
if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) { |
| 210 |
add_action( $hook, 'infinite_uploads_outdated_php_version_notice' ); |
| 211 |
|
| 212 |
return false; |
| 213 |
} |
| 214 |
|
| 215 |
if ( version_compare( $wp_version, '5.3.0', '<' ) ) { |
| 216 |
add_action( $hook, 'infinite_uploads_outdated_wp_version_notice' ); |
| 217 |
|
| 218 |
return false; |
| 219 |
} |
| 220 |
|
| 221 |
return true; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Print an admin notice when the PHP version is not high enough. |
| 226 |
* |
| 227 |
* This has to be a named function for compatibility with PHP 5.2. |
| 228 |
*/ |
| 229 |
function infinite_uploads_outdated_php_version_notice() { |
| 230 |
?> |
| 231 |
<div class="notice notice-warning is-dismissible"><p> |
| 232 |
<?php printf( esc_html__( 'The Infinite Uploads plugin requires PHP version 5.5.0 or higher. Your server is running PHP version %s.', 'infinite-uploads' ), PHP_VERSION ); ?> |
| 233 |
</p></div> |
| 234 |
<?php |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Print an admin notice when the WP version is not high enough. |
| 239 |
* |
| 240 |
* This has to be a named function for compatibility with PHP 5.2. |
| 241 |
*/ |
| 242 |
function infinite_uploads_outdated_wp_version_notice() { |
| 243 |
global $wp_version; |
| 244 |
?> |
| 245 |
<div class="notice notice-warning is-dismissible"><p> |
| 246 |
<?php printf( esc_html__( 'The Infinite Uploads plugin requires WordPress version 5.3 or higher. Your server is running WordPress version %s.', 'infinite-uploads' ), $wp_version ); ?> |
| 247 |
</p></div> |
| 248 |
<?php |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* Check if URL rewriting is enabled. |
| 253 |
* |
| 254 |
* @return bool |
| 255 |
*/ |
| 256 |
function infinite_uploads_enabled() { |
| 257 |
return get_site_option( 'iup_enabled' ); |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Autoload callback. |
| 262 |
* |
| 263 |
* @param $class_name string Name of the class to load. |
| 264 |
*/ |
| 265 |
function infinite_uploads_autoload( $class_name ) { |
| 266 |
/* |
| 267 |
* Load plugin classes: |
| 268 |
* - Class name: Infinite_Uploads_Image_Editor_Imagick. |
| 269 |
* - File name: class-infinite-uploads-image-editor-imagick.php. |
| 270 |
*/ |
| 271 |
$class_file = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php'; |
| 272 |
$class_path = dirname( __FILE__ ) . '/inc/' . $class_file; |
| 273 |
|
| 274 |
if ( file_exists( $class_path ) ) { |
| 275 |
require $class_path; |
| 276 |
|
| 277 |
return; |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
// spl_autoload_register( 'infinite_uploads_autoload' ); |
| 282 |
|