PHP Class Amazon_S3_And_CloudFront, wp-amazon-s3-and-cloudfront

Inheritance: extends AWS_Plugin_Base
Show file Open project: deliciousbrains/wp-amazon-s3-and-cloudfront Class Usage Examples

Public Properties

Property Type Description
$filter_local AS3CF_Local_To_S3
$filter_s3 AS3CF_S3_To_Local
$hook_suffix string
$notices AS3CF_Notices
$plugin_compat AS3CF_Plugin_Compatibility

Protected Properties

Property Type Description
$admin_notices array
$buckets_check Store if each bucket, used by the plugin and addons, is writable
$default_tab string
$plugin_menu_title string
$plugin_page
$plugin_prefix string
$plugin_title string

Public Methods

Method Description
__construct ( string $plugin_file_path, Amazon_Web_Services $aws, string | null $slug = null )
_exit ( integer | string $exit_code ) : void Helper function for terminating script execution. Easily testable.
_throw_error ( string $code, string $message = '', mixed $data = '' ) : WP_Error Throw error
add_media_row_actions ( array $actions = [], WP_Post | integer $post ) : array Conditionally adds copy, remove and download S3 action links for an attachment on the Media library list view
admin_menu ( Amazon_Web_Services $aws ) Add the settings menu item
ajax_check_bucket ( )
ajax_create_bucket ( ) Handler for AJAX callback to create a bucket in S3
ajax_get_attachment_s3_details ( ) Handle retieving the S3 details for attachment modals.
ajax_get_buckets ( ) AJAX handler for get_buckets()
ajax_get_diagnostic_info ( ) AJAX handler for get_diagnostic_info()
ajax_get_url_preview ( ) AJAX handler for get_url_preview()
ajax_save_bucket ( ) Handler for AJAX callback to save the selection of a bucket
apply_file_suffix ( string $file, string $suffix ) : string Helper to apply a suffix to a file path
attachment_s3_actions_meta_box ( ) Render the S3 attachment meta box
attachment_s3_meta_box ( ) Add the S3 meta box to the attachment screen
check_for_gd_imagick ( ) Check if PHP GD and Imagick is installed
check_write_permission ( string $bucket = null, string $region = null ) : boolean | WP_Error Checks the user has write permission for S3
clear_scheduled_event ( string $hook ) Wrapper for clearing scheduled events for a specific cron job
count_attachments ( string $prefix, null | boolean $uploaded_to_s3 = null ) : integer Count attachments on a site
create_bucket ( string $bucket_name, null | string $region = null ) : boolean | WP_Error Create an S3 bucket
dbrains_link ( string $url, string $text, string $hash = '', boolean $append_campaign = true ) : string Create a site link for given url, link text and optional anchor, usually with campaign.
decode_filename_in_path ( string $file ) : string Decode file name.
delete_attachment ( integer $post_id, boolean $force_new_s3_client = false ) Removes an attachment and intermediate image size files from S3
delete_s3_objects ( string $region, string $bucket, array $objects, boolean $log_error = false, boolean $return_on_error = false, boolean $force_new_s3_client = false ) : boolean Delete bulk objects from an S3 bucket
does_file_exist ( string $filename, string $time ) : boolean Does file exist
does_file_exist_local ( string $filename, string $time ) : boolean Does file exist local
does_file_exist_s3 ( string $filename, string $time ) : boolean Does file exist s3
encode_filename_in_path ( string $file ) : string Encode file names according to RFC 3986 when generating urls As per Amazon https://forums.aws.amazon.com/thread.jspa?threadID=55746#jive-message-244233
end_ajax ( array $return = [] ) Helper method for returning data to AJAX call
filter_input ( string $variable, integer $type = INPUT_GET, integer $filter = FILTER_DEFAULT, mixed $options = [] ) : mixed Helper function for filtering super globals. Easily testable.
filter_settings ( array $settings ) : array Filter in defined settings with sensible defaults.
gd_enabled ( ) : boolean Detect if PHP GD is enabled
generate_unique_filename ( string $name, string $ext, string $time ) : string Generate unique filename
get_access_denied_notice_message ( boolean $single = true ) : string Get the access denied bucket error notice message
get_acl_display_name ( string $acl ) : string Return human friendly ACL name
get_all_blog_table_prefixes ( array $exclude_blog_ids = [] ) : array Get all the table prefixes for the blogs in the site. MS compatible
get_allowed_mime_types ( ) : array Allowed mime types array that can be edited for specific S3 uploading
get_attached_file ( string $file, integer $attachment_id ) : string Return the S3 URL when the local file is missing unless we know the calling process is and we are happy to copy the file back to the server to be used
get_attachment_file_paths ( integer $attachment_id, boolean $exists_locally = true, array | boolean $meta = false, boolean $include_backups = true ) : array Get file paths for all attachment versions.
get_attachment_folder_time ( integer $post_id ) : integer | string Get the time of attachment upload.
get_attachment_local_url ( integer $post_id ) : string | false Get attachment local URL.
get_attachment_local_url_size ( integer $post_id, string | null $size = null ) : false | string Get attachment local URL size.
get_attachment_s3_info ( integer $post_id ) : mixed Get attachment s3 info
get_attachment_s3_url ( integer $post_id, array $s3object, null | integer $expires = null, null | string | array $size = null, null | array $meta = null, array $headers = [] ) : mixed | WP_Error Get the S3 URL for an attachment
get_attachment_url ( integer $post_id, integer | null $expires = null, string | null $size = null, array | null $meta = null, array $headers = [], boolean $skip_rewrite_check = false ) : boolean | mixed | void | WP_Error Get the url of the file from Amazon S3
get_aws_bucket_link ( string $bucket = '', string $prefix = '' ) : string Get the link to the bucket on the AWS console
get_aws_regions ( ) : array Get all AWS regions
get_blog_ids ( ) : false | array Get all the blog IDs for the multisite network used for table prefixes
get_bucket_region ( string $bucket ) : string | WP_Error Get the region of a bucket
get_buckets ( ) : array | WP_Error Get a list of buckets from S3
get_default_object_prefix ( ) : string Return the default object prefix
get_dynamic_prefix ( string $time = null ) : string Get the prefix path for the files. Ignores WP media library year month subdirectory setting and just uses S3 setting
get_file_prefix ( null | string $time = null ) : string Get the file prefix
get_folder_time_from_url ( string $url ) : null | string Get the upload folder time from given URL
get_formatted_s3_info ( integer $id, array | null $s3object = null ) : array Return a formatted S3 info with display friendly defaults
get_image_sizes_details ( ) : string Output image size names and dimensions to a string
get_media_action_strings ( null | string $string = null ) : array | string Get all strings or a specific string used for the media actions
get_memory_limit ( ) : integer Get memory limit
get_object_prefix ( string $toggle_setting = 'enable-object-prefix' ) : string Get the custom object prefix if enabled
get_object_version_string ( ) : string Get the object versioning string prefix
get_plugin_details ( string $plugin_path, string $suffix = '' ) : string Helper to display plugin details
get_plugin_page_title ( ) : string Get the plugin title to be used in page headings
get_plugin_page_url ( array $args = [], string $url_method = 'network', boolean $escape = true ) : string Helper method to return the settings page URL for the plugin
get_plugin_prefix_slug ( ) : string Get the plugin prefix in slug format, ie. replace underscores with hyphens
get_post_time ( integer $post_id ) : string Get post time
get_s3_url_domain ( string $bucket, string $region = '', integer $expires = null, array $args = [], boolean $preview = false ) : mixed | string | void Get the S3 url for the files
get_s3_url_prefix ( string $region = '', null | integer $expires = null ) : string Get the region specific prefix for S3 URL
get_s3_url_scheme ( boolean | null $use_ssl = null ) : string Return the scheme to be used in URLs
get_s3client ( boolean | string $region = false, boolean $force = false ) : Aws\S3\S3Client Get the S3 client
get_s3object_region ( array $s3object, integer $post_id = null ) : string | WP_Error Get the region of the bucket stored in the S3 metadata.
get_secure_attachment_url ( integer $post_id, integer | null $expires = null, string | null $size = null, array $headers = [], boolean $skip_rewrite_check = false ) : mixed | void | WP_Error Generate a link to download a file from Amazon S3 using query string authentication. This link is only valid for a limited amount of time.
get_setting ( string $key, mixed $default = '' ) : integer | mixed | string | WP_Error Accessor for a plugin setting with conditions to defaults and upgrades
get_setting_args ( string $key ) : array Gets arguements used to render a setting view.
get_setting_bucket ( string $key, string $value, string $constant = 'AS3CF_BUCKET' ) : string | false Get the bucket and if a constant save to database and clear region
get_setting_region ( array $settings, string $key, mixed $default ) : boolean | string | WP_Error Get the region setting
get_settings_nonce_key ( ) : string Get the nonce key for the settings form of the plugin
get_settings_tabs ( ) : array Get the tabs available for the plugin settings page
get_settings_whitelist ( ) : array Whitelist of settings allowed to be saved
get_skip_sanitize_settings ( ) : array List of settings that should skip full sanitize.
get_url_preview ( boolean $escape = true, string $suffix = 'photo.jpg' ) : string Generate a preview of the URL of files uploaded to S3
get_year_month_directory_name ( string $time = null ) : string Generate the year and month sub-directory from $time if provided, then POST time if available, otherwise use current time
handle_post_request ( ) Handle the saving of the settings page
http_prepare_download_log ( ) : void Check for as3cf-download-log and related nonce and if found begin the download of the diagnostic log
imagick_enabled ( ) : boolean Detect is Imagick is enabled
init ( string $plugin_file_path ) Abstract class constructor
is_attachment_served_by_s3 ( integer $attachment_id, boolean $skip_rewrite_check = false ) : boolean | array Is attachment served by S3.
is_current_blog ( integer $blog_id ) : boolean Is the current blog ID that specified in wp-config.php
is_plugin_setup ( ) : boolean Check the plugin is correctly setup
is_pro ( ) : boolean Check whether the pro addon is installed.
load_attachment_assets ( $hook_suffix ) Load the attachment assets only when editing an attachment
load_media_assets ( ) Load media assets.
make_acl_admin_notice ( array $s3object ) Make admin notice for when object ACL has changed
maybe_disable_save_button ( string $defined_settings = [] ) : string Disables the save button if all settings have been defined.
maybe_encode_get_image_tag ( string $html, integer $id, string $alt, string $title, string $align, string $size ) : string Maybe encode attachment URLs when retrieving the image tag
maybe_encode_image_get_intermediate_size ( array $data, integer $post_id, string | array $size ) : array Maybe encode URLs when retrieving intermediate sizes.
maybe_encode_wp_get_attachment_image_src ( array | boolean $image, integer $attachment_id, string | array $size, boolean $icon ) : array Maybe encode URLs for images that represent an attachment
maybe_encode_wp_prepare_attachment_for_js ( array $response, integer | object $attachment, array $meta ) : array Maybe encode URLs when outputting attachments in the media grid
maybe_remove_query_string ( string $url ) : string Maybe remove query string from URL.
maybe_update_cloudfront_path ( string $path ) : string Potentially update path for CloudFront URLs.
memory_exceeded ( null | string $filter_name = null ) : boolean Memory exceeded
more_info_link ( string $url, string $hash = '', boolean $append_campaign = true ) : string More info link
multisite_get_spaced_used ( $space_used ) : float | integer Used to give a realistic total of storage space used on a Multisite subsite, when there have been attachments uploaded to S3 but removed from server
on_off ( string $key ) : string Helper for displaying settings
open_ssl_enabled ( ) : boolean Detect if OpenSSL is enabled
output_diagnostic_info ( boolean $escape = true ) : string Diagnostic information for the support tab
plugin_deactivated_notice ( ) Display a notice after either lite or pro plugin has been auto deactivated
plugin_load ( )
pre_set_setting ( string $key, string $value ) Perform custom actions before the setting is saved
prepare_bucket_error ( WP_Error $object, boolean $single = true ) : array Prepare the bucket error before returning to JS
register_modal_assets ( ) Register modal scripts and styles so they can be enqueued later
remove_attachment_files_from_s3 ( integer $post_id, array $s3object, boolean $remove_backup_sizes = true, boolean $log_error = false, boolean $return_on_error = false, boolean $force_new_s3_client = false ) Removes an attachment's files from S3.
remove_local_files ( array $file_paths ) Remove files from the local site
remove_scheme ( string $url ) : string Remove scheme from URL.
remove_size_from_filename ( string $url, boolean $remove_extension = false ) : string Remove size from filename (image[-100x100].jpeg).
remove_wp_plugin_dir ( string $path ) : string Helper to remove the plugin directory from the plugin path
render_bucket_permission_errors ( ) Render error messages in a view for bucket permission and access issues
render_page ( ) Display the main settings page for the plugin
restore_current_blog ( ) Helper to restore to the current Multisite blog
sanitize_custom_domain ( string $domain ) : string Sanitize custom domain
save_bucket ( string $bucket_name, boolean $manual = false, null | string $region = null ) : string | boolean Save bucket and bucket's region
save_bucket_for_ajax ( string $bucket, boolean | false $manual_select = false, null | string $region = null, array $defaults = [] ) Wrapper method for saving a bucket when creating or selecting
schedule_event ( string $hook, null | string $interval = null, array $args = [] ) Wrapper for scheduling cron jobs
set_attachment_acl_on_s3 ( integer $post_id, array $s3object, string $acl ) : array | boolean | WP_Error Apply ACL to an attachment and associated files
set_client ( Aws\S3\S3Client $client ) Setter for S3 client
set_setting ( string $key, mixed $value ) Setter for a plugin setting with custom hooks
settings_more_info_link ( string $hash ) : string Settings more info link
show_deprecated_domain_setting ( null | string $domain = null ) : boolean Show the deprecated Domain option setting?
switch_to_blog ( integer | boolean $blog_id = false ) Helper to switch to a Multisite blog - If the site is MS - If the blog is not the current blog defined
translate_region ( $region ) : string Translate older bucket locations to newer S3 region names http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
update_attached_file ( string $file, integer $attachment_id ) : string Allow processes to update the file on S3 via update_attached_file()
update_site_option ( string $option, mixed $value, boolean $autoload = true ) : boolean Update site option.
upgrade_virtual_host ( ) : string Upgrade the 'virtual host' / 'bucket as domain' setting to the new CloudFront / Domain setting
upload_attachment_to_s3 ( integer $post_id, array | null $data = null, string | null $file_path = null, boolean $force_new_s3_client = false, boolean $remove_local_files = true ) : array | WP_Error Upload attachment to S3
use_ssl ( boolean | null $use_ssl = null ) : boolean Determine when to use https in URLS
verify_ajax_request ( )
verify_media_actions ( ) : boolean Check we can do the media actions
wp_get_attachment_url ( string $url, integer $post_id ) : boolean | mixed | void | WP_Error Get attachment url
wp_handle_upload_prefilter ( array $file ) : array Create unique names for file to be uploaded to AWS This only applies when the remove local file option is enabled
wp_update_attachment_metadata ( array $data, integer $post_id ) : array Handles the upload of the attachment to S3 when an attachment is updated using the 'wp_update_attachment_metadata' filter

Protected Methods

Method Description
convert_dimensions_to_size_name ( integer $attachment_id, array $dimensions ) : null | string Convert dimensions to size
diagnostic_media_counts ( ) : array Get the total attachment and total S3 attachment counts for the diagnostic log
get_acl_value_string ( array $acl ) : string Get ACL value string.
get_local_url_preview ( boolean $escape = true, string $suffix = 'photo.jpg' ) : string Get local URL preview.
get_mime_types_to_gzip ( boolean $media_library = false ) : array Get mime types to gzip
maybe_convert_size_to_string ( integer $attachment_id, mixed $size ) : null | string Maybe convert size to string
maybe_display_deprecated_http_notice ( ) Display a notice if using setting to force HTTP as url scheme, removed in 1.3.
maybe_sign_intermediate_size ( string $url, integer $attachment_id, string | array $size, boolean | array $s3object = false ) : mixed | WP_Error Sign intermediate size.
normalize_object_prefix ( string $prefix ) : string Normalize object prefix.
return_upload_error ( string $error_msg, array | null $return = null ) : array | WP_Error Helper to return meta data on upload error
should_gzip_file ( string $file_path, string $type ) : boolean Should gzip file

Private Methods

Method Description
more_info_campaign_url ( string $url ) : string Create a More Info campaign url for given url.

Method Details

__construct() public method

public __construct ( string $plugin_file_path, Amazon_Web_Services $aws, string | null $slug = null )
$plugin_file_path string
$aws Amazon_Web_Services
$slug string | null

_exit() public method

Helper function for terminating script execution. Easily testable.
public _exit ( integer | string $exit_code ) : void
$exit_code integer | string
return void

_throw_error() public method

Throw error
public _throw_error ( string $code, string $message = '', mixed $data = '' ) : WP_Error
$code string
$message string
$data mixed
return WP_Error

add_media_row_actions() public method

Conditionally adds copy, remove and download S3 action links for an attachment on the Media library list view
public add_media_row_actions ( array $actions = [], WP_Post | integer $post ) : array
$actions array
$post WP_Post | integer
return array

admin_menu() public method

Add the settings menu item
public admin_menu ( Amazon_Web_Services $aws )
$aws Amazon_Web_Services

ajax_check_bucket() public method

public ajax_check_bucket ( )

ajax_create_bucket() public method

Handler for AJAX callback to create a bucket in S3
public ajax_create_bucket ( )

ajax_get_attachment_s3_details() public method

Handle retieving the S3 details for attachment modals.

ajax_get_buckets() public method

AJAX handler for get_buckets()
public ajax_get_buckets ( )

ajax_get_diagnostic_info() public method

AJAX handler for get_diagnostic_info()

ajax_get_url_preview() public method

AJAX handler for get_url_preview()

ajax_save_bucket() public method

Handler for AJAX callback to save the selection of a bucket
public ajax_save_bucket ( )

apply_file_suffix() public method

Helper to apply a suffix to a file path
public apply_file_suffix ( string $file, string $suffix ) : string
$file string
$suffix string
return string

attachment_s3_actions_meta_box() public method

Render the S3 attachment meta box

attachment_s3_meta_box() public method

Add the S3 meta box to the attachment screen

check_for_gd_imagick() public method

Check if PHP GD and Imagick is installed

check_write_permission() public method

Checks the user has write permission for S3
public check_write_permission ( string $bucket = null, string $region = null ) : boolean | WP_Error
$bucket string
$region string
return boolean | WP_Error

clear_scheduled_event() public method

Wrapper for clearing scheduled events for a specific cron job
public clear_scheduled_event ( string $hook )
$hook string

convert_dimensions_to_size_name() protected method

Convert dimensions to size
protected convert_dimensions_to_size_name ( integer $attachment_id, array $dimensions ) : null | string
$attachment_id integer
$dimensions array
return null | string

count_attachments() public method

Count attachments on a site
public count_attachments ( string $prefix, null | boolean $uploaded_to_s3 = null ) : integer
$prefix string
$uploaded_to_s3 null | boolean null - All attachments true - Attachments only uploaded to S3 false - Attachments not uploaded to S3
return integer

create_bucket() public method

Create an S3 bucket
public create_bucket ( string $bucket_name, null | string $region = null ) : boolean | WP_Error
$bucket_name string
$region null | string option location constraint
return boolean | WP_Error

decode_filename_in_path() public method

Decode file name.
public decode_filename_in_path ( string $file ) : string
$file string
return string

delete_attachment() public method

Removes an attachment and intermediate image size files from S3
public delete_attachment ( integer $post_id, boolean $force_new_s3_client = false )
$post_id integer
$force_new_s3_client boolean if we are deleting in bulk, force new S3 client to cope with possible different regions

delete_s3_objects() public method

Delete bulk objects from an S3 bucket
public delete_s3_objects ( string $region, string $bucket, array $objects, boolean $log_error = false, boolean $return_on_error = false, boolean $force_new_s3_client = false ) : boolean
$region string
$bucket string
$objects array
$log_error boolean
$return_on_error boolean
$force_new_s3_client boolean if we are deleting in bulk, force new S3 client to cope with possible different regions
return boolean

diagnostic_media_counts() protected method

Get the total attachment and total S3 attachment counts for the diagnostic log
protected diagnostic_media_counts ( ) : array
return array

does_file_exist() public method

Does file exist
public does_file_exist ( string $filename, string $time ) : boolean
$filename string
$time string
return boolean

does_file_exist_local() public method

Does file exist local
public does_file_exist_local ( string $filename, string $time ) : boolean
$filename string
$time string
return boolean

does_file_exist_s3() public method

Does file exist s3
public does_file_exist_s3 ( string $filename, string $time ) : boolean
$filename string
$time string
return boolean

encode_filename_in_path() public method

Encode file names according to RFC 3986 when generating urls As per Amazon https://forums.aws.amazon.com/thread.jspa?threadID=55746#jive-message-244233
public encode_filename_in_path ( string $file ) : string
$file string
return string Encoded filename

end_ajax() public method

Helper method for returning data to AJAX call
public end_ajax ( array $return = [] )
$return array

filter_input() public method

Helper function for filtering super globals. Easily testable.
public filter_input ( string $variable, integer $type = INPUT_GET, integer $filter = FILTER_DEFAULT, mixed $options = [] ) : mixed
$variable string
$type integer
$filter integer
$options mixed
return mixed

filter_settings() public method

Filter in defined settings with sensible defaults.
public filter_settings ( array $settings ) : array
$settings array
return array $settings

gd_enabled() public method

Detect if PHP GD is enabled
public gd_enabled ( ) : boolean
return boolean

generate_unique_filename() public method

Generate unique filename
public generate_unique_filename ( string $name, string $ext, string $time ) : string
$name string
$ext string
$time string
return string

get_access_denied_notice_message() public method

Get the access denied bucket error notice message
public get_access_denied_notice_message ( boolean $single = true ) : string
$single boolean
return string

get_acl_display_name() public method

Return human friendly ACL name
public get_acl_display_name ( string $acl ) : string
$acl string
return string

get_acl_value_string() protected method

Get ACL value string.
protected get_acl_value_string ( array $acl ) : string
$acl array
return string

get_all_blog_table_prefixes() public method

Get all the table prefixes for the blogs in the site. MS compatible
public get_all_blog_table_prefixes ( array $exclude_blog_ids = [] ) : array
$exclude_blog_ids array blog ids to exclude
return array associative array with blog ID as key, prefix as value

get_allowed_mime_types() public method

Allowed mime types array that can be edited for specific S3 uploading
public get_allowed_mime_types ( ) : array
return array

get_attached_file() public method

Return the S3 URL when the local file is missing unless we know the calling process is and we are happy to copy the file back to the server to be used
public get_attached_file ( string $file, integer $attachment_id ) : string
$file string
$attachment_id integer
return string

get_attachment_file_paths() public method

Get file paths for all attachment versions.
public get_attachment_file_paths ( integer $attachment_id, boolean $exists_locally = true, array | boolean $meta = false, boolean $include_backups = true ) : array
$attachment_id integer
$exists_locally boolean
$meta array | boolean
$include_backups boolean
return array

get_attachment_folder_time() public method

Use post datetime if attached.
public get_attachment_folder_time ( integer $post_id ) : integer | string
$post_id integer
return integer | string

get_attachment_local_url() public method

This is a direct copy of wp_get_attachment_url() from /wp-includes/post.php as we filter the URL in AS3CF and can't remove this filter using the current implementation of globals for class instances.
public get_attachment_local_url ( integer $post_id ) : string | false
$post_id integer
return string | false Attachment URL, otherwise false.

get_attachment_local_url_size() public method

Get attachment local URL size.
public get_attachment_local_url_size ( integer $post_id, string | null $size = null ) : false | string
$post_id integer
$size string | null
return false | string

get_attachment_s3_info() public method

Get attachment s3 info
public get_attachment_s3_info ( integer $post_id ) : mixed
$post_id integer
return mixed

get_attachment_s3_url() public method

Get the S3 URL for an attachment
public get_attachment_s3_url ( integer $post_id, array $s3object, null | integer $expires = null, null | string | array $size = null, null | array $meta = null, array $headers = [] ) : mixed | WP_Error
$post_id integer
$s3object array
$expires null | integer
$size null | string | array
$meta null | array
$headers array
return mixed | WP_Error

get_attachment_url() public method

Get the url of the file from Amazon S3
public get_attachment_url ( integer $post_id, integer | null $expires = null, string | null $size = null, array | null $meta = null, array $headers = [], boolean $skip_rewrite_check = false ) : boolean | mixed | void | WP_Error
$post_id integer Post ID of the attachment
$expires integer | null Seconds for the link to live
$size string | null Size of the image to get
$meta array | null Pre retrieved _wp_attachment_metadata for the attachment
$headers array Header overrides for request
$skip_rewrite_check boolean Always return the URL regardless of the 'Rewrite File URLs' setting. Useful for the EDD and Woo addons to not break download URLs when the option is disabled.
return boolean | mixed | void | WP_Error

get_aws_regions() public method

Get all AWS regions
public get_aws_regions ( ) : array
return array

get_blog_ids() public method

Get all the blog IDs for the multisite network used for table prefixes
public get_blog_ids ( ) : false | array
return false | array

get_bucket_region() public method

Get the region of a bucket
public get_bucket_region ( string $bucket ) : string | WP_Error
$bucket string
return string | WP_Error

get_buckets() public method

Get a list of buckets from S3
public get_buckets ( ) : array | WP_Error
return array | WP_Error - list of buckets

get_default_object_prefix() public method

Return the default object prefix

get_dynamic_prefix() public method

Get the prefix path for the files. Ignores WP media library year month subdirectory setting and just uses S3 setting
public get_dynamic_prefix ( string $time = null ) : string
$time string
return string

get_file_prefix() public method

Get the file prefix
public get_file_prefix ( null | string $time = null ) : string
$time null | string
return string

get_folder_time_from_url() public method

Get the upload folder time from given URL
public get_folder_time_from_url ( string $url ) : null | string
$url string
return null | string

get_formatted_s3_info() public method

Return a formatted S3 info with display friendly defaults
public get_formatted_s3_info ( integer $id, array | null $s3object = null ) : array
$id integer
$s3object array | null
return array

get_image_sizes_details() public method

Output image size names and dimensions to a string
public get_image_sizes_details ( ) : string
return string

get_local_url_preview() protected method

Get local URL preview.
protected get_local_url_preview ( boolean $escape = true, string $suffix = 'photo.jpg' ) : string
$escape boolean
$suffix string
return string

get_media_action_strings() public method

Get all strings or a specific string used for the media actions
public get_media_action_strings ( null | string $string = null ) : array | string
$string null | string
return array | string

get_memory_limit() public method

Get memory limit
public get_memory_limit ( ) : integer
return integer

get_mime_types_to_gzip() protected method

Get mime types to gzip
protected get_mime_types_to_gzip ( boolean $media_library = false ) : array
$media_library boolean
return array

get_object_prefix() public method

Get the custom object prefix if enabled
public get_object_prefix ( string $toggle_setting = 'enable-object-prefix' ) : string
$toggle_setting string
return string

get_object_version_string() public method

Get the object versioning string prefix

get_plugin_details() public method

Helper to display plugin details
public get_plugin_details ( string $plugin_path, string $suffix = '' ) : string
$plugin_path string
$suffix string
return string

get_plugin_page_title() public method

Get the plugin title to be used in page headings
public get_plugin_page_title ( ) : string
return string

get_plugin_page_url() public method

Helper method to return the settings page URL for the plugin
public get_plugin_page_url ( array $args = [], string $url_method = 'network', boolean $escape = true ) : string
$args array
$url_method string To prepend to admin_url()
$escape boolean Should we escape the URL
return string

get_plugin_prefix_slug() public method

Get the plugin prefix in slug format, ie. replace underscores with hyphens
public get_plugin_prefix_slug ( ) : string
return string

get_post_time() public method

Get post time
public get_post_time ( integer $post_id ) : string
$post_id integer
return string

get_s3_url_domain() public method

Get the S3 url for the files
public get_s3_url_domain ( string $bucket, string $region = '', integer $expires = null, array $args = [], boolean $preview = false ) : mixed | string | void
$bucket string
$region string
$expires integer
$args array Allows you to specify custom URL settings
$preview boolean When generating the URL preview sanitize certain output
return mixed | string | void

get_s3_url_prefix() public method

Get the region specific prefix for S3 URL
public get_s3_url_prefix ( string $region = '', null | integer $expires = null ) : string
$region string
$expires null | integer
return string

get_s3_url_scheme() public method

Return the scheme to be used in URLs
public get_s3_url_scheme ( boolean | null $use_ssl = null ) : string
$use_ssl boolean | null
return string

get_s3client() public method

Get the S3 client
public get_s3client ( boolean | string $region = false, boolean $force = false ) : Aws\S3\S3Client
$region boolean | string specify region to client for signature
$force boolean force return of new S3 client when swapping regions
return Aws\S3\S3Client

get_s3object_region() public method

Get the region of the bucket stored in the S3 metadata.
public get_s3object_region ( array $s3object, integer $post_id = null ) : string | WP_Error
$s3object array
$post_id integer - if supplied will update the s3 meta if no region found
return string | WP_Error - region name

get_secure_attachment_url() public method

Generate a link to download a file from Amazon S3 using query string authentication. This link is only valid for a limited amount of time.
public get_secure_attachment_url ( integer $post_id, integer | null $expires = null, string | null $size = null, array $headers = [], boolean $skip_rewrite_check = false ) : mixed | void | WP_Error
$post_id integer Post ID of the attachment
$expires integer | null Seconds for the link to live
$size string | null Size of the image to get
$headers array Header overrides for request
$skip_rewrite_check boolean
return mixed | void | WP_Error

get_setting() public method

Accessor for a plugin setting with conditions to defaults and upgrades
public get_setting ( string $key, mixed $default = '' ) : integer | mixed | string | WP_Error
$key string
$default mixed
return integer | mixed | string | WP_Error

get_setting_args() public method

Gets arguements used to render a setting view.
public get_setting_args ( string $key ) : array
$key string
return array

get_setting_bucket() public method

Get the bucket and if a constant save to database and clear region
public get_setting_bucket ( string $key, string $value, string $constant = 'AS3CF_BUCKET' ) : string | false
$key string
$value string
$constant string
return string | false

get_setting_region() public method

Get the region setting
public get_setting_region ( array $settings, string $key, mixed $default ) : boolean | string | WP_Error
$settings array
$key string
$default mixed
return boolean | string | WP_Error

get_settings_nonce_key() public method

Get the nonce key for the settings form of the plugin
public get_settings_nonce_key ( ) : string
return string

get_settings_tabs() public method

Get the tabs available for the plugin settings page
public get_settings_tabs ( ) : array
return array

get_settings_whitelist() public method

Whitelist of settings allowed to be saved
public get_settings_whitelist ( ) : array
return array

get_skip_sanitize_settings() public method

List of settings that should skip full sanitize.
public get_skip_sanitize_settings ( ) : array
return array

get_url_preview() public method

Generate a preview of the URL of files uploaded to S3
public get_url_preview ( boolean $escape = true, string $suffix = 'photo.jpg' ) : string
$escape boolean
$suffix string
return string

get_year_month_directory_name() public method

Generate the year and month sub-directory from $time if provided, then POST time if available, otherwise use current time
public get_year_month_directory_name ( string $time = null ) : string
$time string
return string

handle_post_request() public method

Handle the saving of the settings page
public handle_post_request ( )

http_prepare_download_log() public method

Check for as3cf-download-log and related nonce and if found begin the download of the diagnostic log
public http_prepare_download_log ( ) : void
return void

imagick_enabled() public method

Detect is Imagick is enabled
public imagick_enabled ( ) : boolean
return boolean

init() public method

Abstract class constructor
public init ( string $plugin_file_path )
$plugin_file_path string

is_attachment_served_by_s3() public method

Is attachment served by S3.
public is_attachment_served_by_s3 ( integer $attachment_id, boolean $skip_rewrite_check = false ) : boolean | array
$attachment_id integer
$skip_rewrite_check boolean
return boolean | array

is_current_blog() public method

Is the current blog ID that specified in wp-config.php
public is_current_blog ( integer $blog_id ) : boolean
$blog_id integer
return boolean

is_plugin_setup() public method

Check the plugin is correctly setup
public is_plugin_setup ( ) : boolean
return boolean

is_pro() public method

Check whether the pro addon is installed.
public is_pro ( ) : boolean
return boolean

load_attachment_assets() public method

Load the attachment assets only when editing an attachment
public load_attachment_assets ( $hook_suffix )
$hook_suffix

load_media_assets() public method

Load media assets.
public load_media_assets ( )

make_acl_admin_notice() public method

Make admin notice for when object ACL has changed
public make_acl_admin_notice ( array $s3object )
$s3object array

maybe_convert_size_to_string() protected method

Maybe convert size to string
protected maybe_convert_size_to_string ( integer $attachment_id, mixed $size ) : null | string
$attachment_id integer
$size mixed
return null | string

maybe_disable_save_button() public method

Disables the save button if all settings have been defined.
public maybe_disable_save_button ( string $defined_settings = [] ) : string
$defined_settings string
return string

maybe_display_deprecated_http_notice() protected method

Display a notice if using setting to force HTTP as url scheme, removed in 1.3.

maybe_encode_get_image_tag() public method

Maybe encode attachment URLs when retrieving the image tag
public maybe_encode_get_image_tag ( string $html, integer $id, string $alt, string $title, string $align, string $size ) : string
$html string
$id integer
$alt string
$title string
$align string
$size string
return string

maybe_encode_image_get_intermediate_size() public method

Maybe encode URLs when retrieving intermediate sizes.
public maybe_encode_image_get_intermediate_size ( array $data, integer $post_id, string | array $size ) : array
$data array
$post_id integer
$size string | array
return array

maybe_encode_wp_get_attachment_image_src() public method

Maybe encode URLs for images that represent an attachment
public maybe_encode_wp_get_attachment_image_src ( array | boolean $image, integer $attachment_id, string | array $size, boolean $icon ) : array
$image array | boolean
$attachment_id integer
$size string | array
$icon boolean
return array

maybe_encode_wp_prepare_attachment_for_js() public method

Maybe encode URLs when outputting attachments in the media grid
public maybe_encode_wp_prepare_attachment_for_js ( array $response, integer | object $attachment, array $meta ) : array
$response array
$attachment integer | object
$meta array
return array

maybe_remove_query_string() public method

Maybe remove query string from URL.
public maybe_remove_query_string ( string $url ) : string
$url string
return string

maybe_sign_intermediate_size() protected method

Sign intermediate size.
protected maybe_sign_intermediate_size ( string $url, integer $attachment_id, string | array $size, boolean | array $s3object = false ) : mixed | WP_Error
$url string
$attachment_id integer
$size string | array
$s3object boolean | array
return mixed | WP_Error

maybe_update_cloudfront_path() public method

Potentially update path for CloudFront URLs.
public maybe_update_cloudfront_path ( string $path ) : string
$path string
return string

memory_exceeded() public method

Ensures the a process never exceeds 90% of the maximum WordPress memory.
public memory_exceeded ( null | string $filter_name = null ) : boolean
$filter_name null | string Name of filter to apply to the return
return boolean

multisite_get_spaced_used() public method

Used to give a realistic total of storage space used on a Multisite subsite, when there have been attachments uploaded to S3 but removed from server
public multisite_get_spaced_used ( $space_used ) : float | integer
$space_used bool
return float | integer

normalize_object_prefix() protected method

Normalize object prefix.
protected normalize_object_prefix ( string $prefix ) : string
$prefix string
return string

on_off() public method

Helper for displaying settings
public on_off ( string $key ) : string
$key string setting key
return string

open_ssl_enabled() public method

Detect if OpenSSL is enabled
public open_ssl_enabled ( ) : boolean
return boolean

output_diagnostic_info() public method

Diagnostic information for the support tab
public output_diagnostic_info ( boolean $escape = true ) : string
$escape boolean
return string

plugin_deactivated_notice() public method

Display a notice after either lite or pro plugin has been auto deactivated

plugin_load() public method

public plugin_load ( )

pre_set_setting() public method

Perform custom actions before the setting is saved
public pre_set_setting ( string $key, string $value )
$key string
$value string

prepare_bucket_error() public method

Prepare the bucket error before returning to JS
public prepare_bucket_error ( WP_Error $object, boolean $single = true ) : array
$object WP_Error
$single boolean Are we dealing with a single bucket?
return array

register_modal_assets() public method

Register modal scripts and styles so they can be enqueued later

remove_attachment_files_from_s3() public method

Removes an attachment's files from S3.
public remove_attachment_files_from_s3 ( integer $post_id, array $s3object, boolean $remove_backup_sizes = true, boolean $log_error = false, boolean $return_on_error = false, boolean $force_new_s3_client = false )
$post_id integer
$s3object array
$remove_backup_sizes boolean remove previous edited image versions
$log_error boolean
$return_on_error boolean
$force_new_s3_client boolean if we are deleting in bulk, force new S3 client to cope with possible different regions

remove_local_files() public method

Remove files from the local site
public remove_local_files ( array $file_paths )
$file_paths array array of files to remove

remove_scheme() public method

Remove scheme from URL.
public remove_scheme ( string $url ) : string
$url string
return string

remove_size_from_filename() public method

Remove size from filename (image[-100x100].jpeg).
public remove_size_from_filename ( string $url, boolean $remove_extension = false ) : string
$url string
$remove_extension boolean
return string

remove_wp_plugin_dir() public method

Helper to remove the plugin directory from the plugin path
public remove_wp_plugin_dir ( string $path ) : string
$path string
return string

render_bucket_permission_errors() public method

Render error messages in a view for bucket permission and access issues

render_page() public method

Display the main settings page for the plugin
public render_page ( )

restore_current_blog() public method

Helper to restore to the current Multisite blog

return_upload_error() protected method

Helper to return meta data on upload error
protected return_upload_error ( string $error_msg, array | null $return = null ) : array | WP_Error
$error_msg string
$return array | null
return array | WP_Error

sanitize_custom_domain() public method

Sanitize custom domain
public sanitize_custom_domain ( string $domain ) : string
$domain string
return string

save_bucket() public method

Save bucket and bucket's region
public save_bucket ( string $bucket_name, boolean $manual = false, null | string $region = null ) : string | boolean
$bucket_name string
$manual boolean if we are entering the bucket via the manual input form
$region null | string
return string | boolean region on success

save_bucket_for_ajax() public method

Wrapper method for saving a bucket when creating or selecting
public save_bucket_for_ajax ( string $bucket, boolean | false $manual_select = false, null | string $region = null, array $defaults = [] )
$bucket string
$manual_select boolean | false
$region null | string
$defaults array

schedule_event() public method

Wrapper for scheduling cron jobs
public schedule_event ( string $hook, null | string $interval = null, array $args = [] )
$hook string
$interval null | string Defaults to hook if not supplied
$args array

set_attachment_acl_on_s3() public method

Apply ACL to an attachment and associated files
public set_attachment_acl_on_s3 ( integer $post_id, array $s3object, string $acl ) : array | boolean | WP_Error
$post_id integer
$s3object array
$acl string
return array | boolean | WP_Error

set_client() public method

Setter for S3 client
public set_client ( Aws\S3\S3Client $client )
$client Aws\S3\S3Client

set_setting() public method

Setter for a plugin setting with custom hooks
public set_setting ( string $key, mixed $value )
$key string
$value mixed

should_gzip_file() protected method

Should gzip file
protected should_gzip_file ( string $file_path, string $type ) : boolean
$file_path string
$type string
return boolean

show_deprecated_domain_setting() public method

Show the deprecated Domain option setting?
public show_deprecated_domain_setting ( null | string $domain = null ) : boolean
$domain null | string
return boolean

switch_to_blog() public method

Helper to switch to a Multisite blog - If the site is MS - If the blog is not the current blog defined
public switch_to_blog ( integer | boolean $blog_id = false )
$blog_id integer | boolean

translate_region() public method

Translate older bucket locations to newer S3 region names http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
public translate_region ( $region ) : string
$region
return string

update_attached_file() public method

Allow processes to update the file on S3 via update_attached_file()
public update_attached_file ( string $file, integer $attachment_id ) : string
$file string
$attachment_id integer
return string

update_site_option() public method

Update site option.
public update_site_option ( string $option, mixed $value, boolean $autoload = true ) : boolean
$option string
$value mixed
$autoload boolean
return boolean

upgrade_virtual_host() public method

Upgrade the 'virtual host' / 'bucket as domain' setting to the new CloudFront / Domain setting
public upgrade_virtual_host ( ) : string
return string

upload_attachment_to_s3() public method

Upload attachment to S3
public upload_attachment_to_s3 ( integer $post_id, array | null $data = null, string | null $file_path = null, boolean $force_new_s3_client = false, boolean $remove_local_files = true ) : array | WP_Error
$post_id integer
$data array | null
$file_path string | null
$force_new_s3_client boolean if we are uploading in bulk, force new S3 client to cope with possible different regions
$remove_local_files boolean
return array | WP_Error $s3object|$meta If meta is supplied, return it. Else return S3 meta

use_ssl() public method

Determine when to use https in URLS
public use_ssl ( boolean | null $use_ssl = null ) : boolean
$use_ssl boolean | null
return boolean

verify_ajax_request() public method

public verify_ajax_request ( )

verify_media_actions() public method

Check we can do the media actions
public verify_media_actions ( ) : boolean
return boolean

wp_get_attachment_url() public method

Get attachment url
public wp_get_attachment_url ( string $url, integer $post_id ) : boolean | mixed | void | WP_Error
$url string
$post_id integer
return boolean | mixed | void | WP_Error

wp_handle_upload_prefilter() public method

Create unique names for file to be uploaded to AWS This only applies when the remove local file option is enabled
public wp_handle_upload_prefilter ( array $file ) : array
$file array An array of data for a single file.
return array $file The altered file array with AWS unique filename.

wp_update_attachment_metadata() public method

Handles the upload of the attachment to S3 when an attachment is updated using the 'wp_update_attachment_metadata' filter
public wp_update_attachment_metadata ( array $data, integer $post_id ) : array
$data array meta data for attachment
$post_id integer
return array

Property Details

$admin_notices protected static property

protected static array $admin_notices
return array

$buckets_check protected static property

Store if each bucket, used by the plugin and addons, is writable
protected static $buckets_check

$default_tab protected property

protected string $default_tab
return string

$filter_local public property

public AS3CF_Local_To_S3 $filter_local
return AS3CF_Local_To_S3

$filter_s3 public property

public AS3CF_S3_To_Local $filter_s3
return AS3CF_S3_To_Local

$hook_suffix public property

public string $hook_suffix
return string

$notices public property

public AS3CF_Notices $notices
return AS3CF_Notices

$plugin_compat public property

public AS3CF_Plugin_Compatibility $plugin_compat
return AS3CF_Plugin_Compatibility

$plugin_menu_title protected property

protected string $plugin_menu_title
return string

$plugin_page protected static property

protected static $plugin_page

$plugin_prefix protected property

protected string $plugin_prefix
return string

$plugin_title protected property

protected string $plugin_title
return string