diff --git a/README.md b/README.md index 5490ef0..a34c2bc 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ For multisites or to enforce Azure Blob Storage settings, you can define the fol * MICROSOFT_AZURE_CONTAINER - Azure Blob Container * MICROSOFT_AZURE_CNAME - Domain: must start with http(s):// * MICROSOFT_AZURE_USE_FOR_DEFAULT_UPLOAD - boolean (default false) - +* MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH - Override Container name in the Image URL , can be just "/" See Settings->Microsoft Azure for more information. ## Upgrade Notice diff --git a/includes/class-windows-azure-helper.php b/includes/class-windows-azure-helper.php index 71b0a6d..3d646c3 100644 --- a/includes/class-windows-azure-helper.php +++ b/includes/class-windows-azure-helper.php @@ -105,6 +105,19 @@ static public function get_account_key() { : get_option( 'azure_storage_account_primary_access_key' ); } + /** + * Return override container name. + * + * @since 4.5.0 + * + * @return mixed|void Account key. + */ + static public function get_azure_storage_override_container_path() { + return defined( 'MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH' ) + ? MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH + : get_option( 'azure_storage_override_container_path' ); + } + /** * Return CNAME url. * diff --git a/readme.txt b/readme.txt index 62caca1..64ef0e4 100644 --- a/readme.txt +++ b/readme.txt @@ -28,6 +28,7 @@ For multisites or to enforce Azure Blob Storage settings, you can define the fol * MICROSOFT_AZURE_CONTAINER - Azure Blob Container * MICROSOFT_AZURE_CNAME - Domain: must start with http(s):// * MICROSOFT_AZURE_USE_FOR_DEFAULT_UPLOAD - boolean (default false) +* MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH - Override Container name in the Image URL , can be just "/" See Settings->Microsoft Azure for more information. diff --git a/windows-azure-storage-settings.php b/windows-azure-storage-settings.php index 57440e6..65bfe87 100644 --- a/windows-azure-storage-settings.php +++ b/windows-azure-storage-settings.php @@ -117,6 +117,10 @@ function windows_azure_storage_plugin_register_settings() { register_setting( 'windows-azure-storage-settings-group', 'cname', 'esc_url_raw' ); } + if ( ! defined( 'MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH' ) ) { + register_setting( 'windows-azure-storage-settings-group', 'azure_storage_override_container_path', 'sanitize_text_field' ); + } + if ( ! defined( 'MICROSOFT_AZURE_USE_FOR_DEFAULT_UPLOAD' ) ) { register_setting( 'windows-azure-storage-settings-group', 'azure_storage_use_for_default_upload', 'wp_validate_boolean' ); } @@ -164,6 +168,16 @@ function windows_azure_storage_plugin_register_settings() { 'windows-azure-storage-plugin-options', 'windows-azure-storage-settings' ); + /** + * @since 4.5.0 + */ + add_settings_field( + 'azure_storage_override_container_path', + __( 'Override Container Path', 'windows-azure-storage' ), + 'windows_azure_storage_override_container_path', + 'windows-azure-storage-plugin-options', + 'windows-azure-storage-settings' + ); /** * @since 4.0.0 */ @@ -331,6 +345,27 @@ function windows_azure_storage_setting_storage_container() { echo '
'; } +/** + * Container ovveride path setting callback function. + * + * @since 4.5.0 + * + * @return void + */ +function windows_azure_storage_override_container_path() { + $azure_storage_override_container_path = Windows_Azure_Helper::get_azure_storage_override_container_path(); + + if ( defined( 'MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH' ) ) { + echo ''; + } else { + echo ''; + } + + echo '';
+ _e( 'Use this option if you do not like to display container name in the image URLs like http://mydomain.com/uploads
instead of http://mydomain.com/[container_name]/
. As sometime container name can be wired and log and also container names can change during migration resulting in URL change for the images. Using this option image urls will remain same. You can use MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH
constant to override it.', 'windows-azure-storage' );
+ echo '