-
Notifications
You must be signed in to change notification settings - Fork 46
/
windows-azure-storage-settings.php
588 lines (536 loc) · 22.1 KB
/
windows-azure-storage-settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
<?php
/**
* Shows various settings for Microsoft Azure Storage Plugin
*
* Version: 3.0.1
*
* Author: Microsoft Open Technologies, Inc.
*
* Author URI: http://www.microsoft.com/
*
* License: New BSD License (BSD)
*
* Copyright (c) Microsoft Open Technologies, Inc.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* PHP Version 5
*
* @category WordPress_Plugin
* @package Microsoft_Azure_Storage_For_WordPress
* @author Microsoft Open Technologies, Inc. <msopentech@microsoft.com>
* @copyright Microsoft Open Technologies, Inc.
* @license New BSD license, (http://www.opensource.org/licenses/bsd-license.php)
* @link http://www.microsoft.com
*/
/**
* Preamble text on Microsoft Azure Storage plugin settings page.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_plugin_settings_preamble() {
?><div class="wrap">
<h2>
<img src="<?php echo esc_url( MSFT_AZURE_PLUGIN_URL . 'images/azure-icon.png' ); ?>" alt="<?php esc_attr_e( 'Microsoft Azure', 'windows-azure-storage' ); ?>" style="width:32px">
<?php esc_html_e( 'Microsoft Azure Storage for WordPress', 'windows-azure-storage' ); ?>
</h2>
<p>
<?php esc_html_e(
'This WordPress plugin allows you to use Microsoft Azure Storage Service to host your media for your WordPress powered blog. Microsoft Azure provides storage in the cloud with authenticated access and triple replication to help keep your data safe. Applications work with data using REST conventions and standard HTTP operations to identify and expose data using URIs. This plugin allows you to easily upload, retrieve, and link to files stored on Microsoft Azure Storage service from within WordPress.',
'windows-azure-storage'
); ?>
</p>
<p style="margin-bottom:4em">
<?php echo __( 'For more details on Microsoft Azure Storage Services, please visit the <a href="https://azure.microsoft.com/en-us/">Microsoft Azure Platform web-site</a>.', 'windows-azure-storage' ); ?><br>
<b><?php esc_html_e( 'Plugin Web Site:', 'windows-azure-storage' ); ?></b>
<a href="https://wordpress.org/plugins/windows-azure-storage/">https://wordpress.org/plugins/windows-azure-storage/</a>
</p>
</div><?php
}
/**
* WordPress hook for displaying plugin options page.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_plugin_options_page() {
windows_azure_storage_plugin_settings_preamble();
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br/></div>
<form method="post" name="azure-settings-form" id="azure-settings-form" action="options.php">
<?php
settings_fields( 'windows-azure-storage-settings-group' );
do_settings_sections( 'windows-azure-storage-plugin-options' );
submit_button( __( 'Save Changes', 'windows-azure-storage' ), 'submit primary', 'azure-submit-button', true );
?>
</form>
</div>
<?php
}
/**
* Register custom settings for Microsoft Azure Storage Plugin.
*
* @return void
*/
function windows_azure_storage_plugin_register_settings() {
register_setting( 'windows-azure-storage-settings-group', 'azure_storage_keep_local_file', 'wp_validate_boolean' );
register_setting( 'windows-azure-storage-settings-group', 'azure_browse_cache_results', 'intval' );
if ( ! defined( 'MICROSOFT_AZURE_ACCOUNT_NAME' ) ) {
register_setting( 'windows-azure-storage-settings-group', 'azure_storage_account_name', 'sanitize_text_field' );
}
if ( ! defined( 'MICROSOFT_AZURE_ACCOUNT_KEY' ) ) {
register_setting( 'windows-azure-storage-settings-group', 'azure_storage_account_primary_access_key', 'sanitize_text_field' );
}
if ( ! defined( 'MICROSOFT_AZURE_CONTAINER' ) ) {
register_setting( 'windows-azure-storage-settings-group', 'default_azure_storage_account_container_name', 'sanitize_text_field' );
}
if ( ! defined( 'MICROSOFT_AZURE_CNAME' ) ) {
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' );
}
if ( ! defined( 'MICROSOFT_AZURE_CACHE_CONTROL' ) ) {
register_setting( 'windows-azure-storage-settings-group', 'azure_cache_control', 'sanitize_text_field' );
}
/**
* @since 4.0.0
*/
add_settings_section(
'windows-azure-storage-settings',
__( 'Microsoft Azure Storage Settings', 'windows-azure-storage' ),
'windows_azure_storage_plugin_settings_section',
'windows-azure-storage-plugin-options'
);
/**
* @since 4.0.0
*/
add_settings_field(
'azure_storage_account_name',
__( 'Store Account Name', 'windows-azure-storage' ),
'windows_azure_storage_setting_account_name',
'windows-azure-storage-plugin-options',
'windows-azure-storage-settings'
);
/**
* @since 4.0.0
*/
add_settings_field(
'azure_storage_account_key',
__( 'Store Account Key', 'windows-azure-storage' ),
'windows_azure_storage_setting_account_key',
'windows-azure-storage-plugin-options',
'windows-azure-storage-settings'
);
/**
* @since 4.0.0
*/
add_settings_field(
'azure_storage_default_container',
__( 'Default Storage Container', 'windows-azure-storage' ),
'windows_azure_storage_setting_storage_container',
'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
*/
add_settings_field(
'azure_storage_cname',
__( 'CNAME', 'windows-azure-storage' ),
'windows_azure_storage_setting_cname',
'windows-azure-storage-plugin-options',
'windows-azure-storage-settings'
);
/**
* @since 4.0.0
*/
add_settings_field(
'azure_storage_handle_uploads',
__( 'Use for default upload', 'windows-azure-storage' ),
'windows_azure_storage_setting_handle_uploads',
'windows-azure-storage-plugin-options',
'windows-azure-storage-settings'
);
/**
* @since 4.0.0
*/
add_settings_field(
'azure_storage_keep_local_file',
__( 'Keep local files', 'windows-azure-storage' ),
'windows_azure_storage_setting_keep_local_file',
'windows-azure-storage-plugin-options',
'windows-azure-storage-settings'
);
/**
* @since 4.0.0
*/
add_settings_field(
'azure_browse_cache_results',
__( 'Timeout for azure file list cache in seconds', 'windows-azure-storage' ),
'windows_azure_browse_cache_results',
'windows-azure-storage-plugin-options',
'windows-azure-storage-settings'
);
/**
* @since 4.1.0
*/
add_settings_field(
'azure_cache_control',
__( 'Cache control in seconds', 'windows-azure-storage' ),
'windows_azure_cache_control',
'windows-azure-storage-plugin-options',
'windows-azure-storage-settings'
);
}
/**
* Settings section callback function.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_plugin_settings_section() {
?>
<p><?php echo __( 'If you do not have Microsoft Azure Storage Account, please <a href="https://azure.microsoft.com/en-us/free/">register </a>for Microsoft Azure Services.', 'windows-azure-storage' ); ?></p>
<?php
}
/**
* Account name setting callback function.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_setting_account_name() {
$storage_account_name = Windows_Azure_Helper::get_account_name();
if ( defined( 'MICROSOFT_AZURE_ACCOUNT_NAME' ) ) {
echo '<input type="text" class="regular-text" value="', esc_attr( $storage_account_name ), '" readonly disabled>';
} else {
echo '<input type="text" name="azure_storage_account_name" class="regular-text" value="', esc_attr( $storage_account_name ), '">';
}
echo '<p>';
_e( 'Microsoft Azure Storage Account Name. You can define <code>MICROSOFT_AZURE_ACCOUNT_NAME</code> constant to override it.', 'windows-azure-storage' );
echo '</p>';
}
/**
* Account key setting callback function.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_setting_account_key() {
$storage_account_key = Windows_Azure_Helper::get_account_key();
if ( defined( 'MICROSOFT_AZURE_ACCOUNT_KEY' ) ) {
echo '<input type="text" class="large-text" value="', esc_attr( $storage_account_key ), '" readonly disabled>';
} else {
echo '<input type="text" name="azure_storage_account_primary_access_key" class="large-text" value="', esc_attr( $storage_account_key ), '">';
}
echo '<p>';
_e( 'Microsoft Azure Storage Account Primary Access Key. You can define <code>MICROSOFT_AZURE_ACCOUNT_KEY</code> constant to override it.', 'windows-azure-storage' );
echo '</p>';
}
/**
* Default storage container setting callback function.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_setting_storage_container() {
$default_container = Windows_Azure_Helper::get_default_container();
if ( defined( 'MICROSOFT_AZURE_CONTAINER' ) ) {
echo '<input type="text" class="regular-text" value="', $default_container, '" readonly disabled>';
} else {
$containers_list = Windows_Azure_Helper::list_containers();
$new_container_name = isset( $_POST['newcontainer'] ) ? sanitize_text_field( wp_unslash( $_POST['newcontainer'] ) ) : '';
$container_creation_failed = apply_filters( 'windows_azure_storage_container_creation_failed', false );
?><select name="default_azure_storage_account_container_name" class="azure-container-selector regular-text"><?php
if ( ! is_wp_error( $containers_list ) ) {
foreach ( $containers_list as $container ) {
if ( empty( $default_container ) ) {
$default_container = $container['Name'];
Windows_Azure_Helper::set_default_container( $default_container );
}
?><option value="<?php echo esc_attr( $container['Name'] ); ?>"
<?php if ( ! $container_creation_failed ) {
selected( $container['Name'], $default_container );
} ?>>
<?php echo esc_html( $container['Name'] ); ?>
</option><?php
}
if ( current_user_can( 'manage_options' ) ) {
?><option value="__newContainer__" <?php selected( $container_creation_failed ); ?>>
— <?php esc_html_e( 'Create New Container', 'windows-azure-storage' ); ?> —
</option><?php
}
}
?></select><?php
if ( current_user_can( 'manage_options' ) ) :
wp_nonce_field( 'create_container', 'create_new_container_settings' );
?><div id="div-create-container" name="div-create-container" <?php if ( ! $container_creation_failed ) : ?>style="display:none;"<?php endif; ?>>
<p>
<label for="newcontainer" title="<?php __( 'Name of the new container to create', 'windows-azure-storage' ); ?>"><?php echo __( 'New container name: ', 'windows-azure-storage' ); ?></label>
<input type="text" name="newcontainer" class="regular-text" title="<?php __( 'Name of the new container to create', 'windows-azure-storage' ); ?>" value="<?php echo esc_attr( $new_container_name ); ?>"/>
</p>
<p>
<input type="button" class="button-primary azure-create-container-button" value="<?php esc_attr_e( 'Create', 'windows-azure-storage' ); ?>" data-container-url="<?php echo esc_attr( sprintf( '%s', esc_url( $_SERVER['REQUEST_URI'] ) ) ); ?>"/>
</p>
</div><?php
endif;
}
echo '<p>';
_e( 'Default container to be used for storing media files. You can define <code>MICROSOFT_AZURE_CONTAINER</code> constant to override it.', 'windows-azure-storage' );
echo '</p>';
}
/**
* 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 '<input type="text" class="regular-text" value="', esc_attr( $azure_storage_override_container_path ), '" readonly disabled>';
} else {
echo '<input type="text" name="azure_storage_override_container_path" class="regular-text" value="', esc_attr( $azure_storage_override_container_path ), '">';
}
echo '<p>';
_e( 'Use this option if you do not like to display container name in the image URLs like <code>http://mydomain.com/uploads</code> instead of <code>http://mydomain.com/[container_name]/</code>. 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 <code>MICROSOFT_AZURE_OVERRIDE_CONTAINER_PATH</code> constant to override it.', 'windows-azure-storage' );
echo '</p>';
}
/**
* CNAME setting callback function.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_setting_cname() {
$cname = Windows_Azure_Helper::get_cname();
if ( defined( 'MICROSOFT_AZURE_CNAME' ) ) {
echo '<input type="url" class="regular-text" value="', esc_attr( $cname ), '" readonly disabled>';
} else {
echo '<input type="url" name="cname" class="regular-text" value="', esc_attr( $cname ), '">';
}
echo '<p>';
_e( 'Use this option if you would like to display image URLs belonging to your domain like <code>http://mydomain.com/</code> instead of <code>http://your-account-name.blob.core.windows.net/</code>. This CNAME must start with <code>http(s)://</code> and the administrator will have to update <abbr title="Domain Name System">DNS</abbr> entries accordingly. You can use <code>MICROSOFT_AZURE_CNAME</code> constant to override it.', 'windows-azure-storage' );
echo '</p>';
}
/**
* Account key setting callback function.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_setting_handle_uploads() {
$use_for_upload = Windows_Azure_Helper::get_use_for_default_upload();
if ( defined( 'MICROSOFT_AZURE_USE_FOR_DEFAULT_UPLOAD' ) ) {
echo '<input type="checkbox" id="azure_storage_use_for_default_upload"', checked( $use_for_upload, true, false ), ' readonly disabled>';
} else {
echo '<input type="checkbox" name="azure_storage_use_for_default_upload" value="1" id="azure_storage_use_for_default_upload"', checked( $use_for_upload, true, false ), '>';
}
echo '<label for="azure_storage_use_for_default_upload">';
esc_html_e( 'Use Microsoft Azure Storage for all media uploads on this site.', 'windows-azure-storage' );
echo '</label>';
echo '<p>';
_e( 'Note: Uncheck this to store uploads on your web server by default. This setting can be overriden using the <code>MICROSOFT_AZURE_USE_FOR_DEFAULT_UPLOAD</code> PHP constant.', 'windows-azure-storage' );
echo '</p>';
}
/**
* Keep local file setting callback function.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_setting_keep_local_file() {
?>
<input type="checkbox" name="azure_storage_keep_local_file" title="<?php esc_attr_e( 'Do not delete local files after uploading them to Azure Storage.', 'windows-azure-storage' ) ?>" value="1" id="azure_storage_keep_local_file" <?php checked( (bool) get_option( 'azure_storage_keep_local_file' ) ); ?> />
<label for="azure_storage_keep_local_file">
<?php esc_html_e( 'Keep local files after uploading them to Azure Storage.', 'windows-azure-storage' ); ?>
</label>
<?php
}
/**
* Browse cache results setting.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_browse_cache_results() {
$ttl = Windows_Azure_Helper::get_cache_ttl();
?>
<input type="number" name="azure_browse_cache_results" class="regular-text" title="<?php esc_attr_e( 'Browse azure file list cache TTL', 'windows-azure-storage' ); ?>" value="<?php echo esc_attr( $ttl ); ?>"/>
<p class="field-description">
<?php
echo __(
'Note: If you want to disable azure file list caching please set this value to 0.',
'windows-azure-storage'
);
?>
</p>
<?php
}
/**
* Displays cache-control setting.
*
* @since 4.1.0
*
* @return void
*/
function windows_azure_cache_control() {
$cache_control = Windows_Azure_Helper::get_cache_control();
if ( defined( 'MICROSOFT_AZURE_CACHE_CONTROL' ) ) {
echo '<input type="text" class="regular-text" value="', esc_attr( $cache_control ), '" readonly disabled>';
} else {
echo '<input type="text" name="azure_cache_control" class="regular-text" value="', esc_attr( $cache_control ), '">';
}
echo '<p>';
_e( 'Setting Cache-Control on publicly accessible Microsoft Azure Blobs can help reduce bandwidth by preventing consumers from having to continuously download resources. Specify a relative amount of time in seconds to cache data after it was received or enter exact cache-control value which you want to use for your assets. You can define <code>MICROSOFT_AZURE_CACHE_CONTROL</code> constant to override it.', 'windows-azure-storage' );
echo '</p>';
}
/**
* Try to create a container.
*
* @since 4.0.0
*
* @param boolean $success True if the operation succeeded, false otherwise. Deprecated.
*
* @return string|WP_Error|null Success message or WP_Error on failure.
*/
function create_container_if_required( &$success = null ) {
$success = false;
$post_array = wp_unslash( $_POST );
$action_set = isset( $post_array['newcontainer'] ) && $permissions = current_user_can( 'manage_options' ) && $admin_referer = check_admin_referer( 'create_container', 'create_new_container_settings' );
if ( $action_set ) {
if ( ! empty( $post_array['newcontainer'] ) ) {
if ( empty( $post_array['azure_storage_account_name'] ) || empty( $post_array['azure_storage_account_primary_access_key'] ) ) {
return new WP_Error( -2, __( 'Please specify Storage Account Name and Primary Access Key to create container.', 'windows-azure-storage' ) );
}
try {
$account_name = $post_array['azure_storage_account_name'];
$account_key = $post_array['azure_storage_account_primary_access_key'];
$result = Windows_Azure_Helper::create_container( sanitize_text_field( $post_array['newcontainer'] ), $account_name, $account_key );
if ( ! is_wp_error( $result ) ) {
return sprintf(
__( 'The container <strong>%1$s</strong> successfully created. To use this container as default container, select it from the above drop down and click <strong>Save Changes</strong>.', 'windows-azure-storage' ),
esc_html( $result )
);
} else {
$success = true;
return $result;
}
} catch ( Exception $e ) {
return new WP_Error( -3, sprintf( __( 'Container creation failed, Error: %s', 'windows-azure-storage' ), $e->getMessage() ) );
}
}
return new WP_Error( -4, __( 'Please specify name of the container to create', 'windows-azure-storage' ) );
} elseif ( $action_set ) {
$error_message = __( 'Unable to create new container. Try again.', 'windows-azure-storage' );
if ( ! $permissions ) {
$error_message = __( 'You do not have permissions to create new container.', 'windows-azure-storage' );
} elseif ( ! $admin_referer ) {
$error_message = __( 'Form validation failed. Try again.', 'windows-azure-storage' );
}
return new WP_Error( -1, $error_message );
}
return null;
}
/**
* Action hook for load-settings_page_windows-azure-storage-plugin-options.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_load_settings_page() {
$result = create_container_if_required();
if ( null === $result ) {
return;
}
add_action( 'admin_notices', function () use ( $result ) {
if ( is_wp_error( $result ) ) {
$notice_class = 'notice-error';
$notice = sprintf( __( 'Container creation failed. Error: %s', 'windows-azure-storage' ), $result->get_error_message() );
add_filter( 'windows_azure_storage_container_creation_failed', '__return_true' );
} elseif ( is_string( $result ) ) {
$notice_class = 'notice-success';
$notice = $result;
}
?>
<div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible">
<p><?php echo wp_kses( $notice, array( 'strong' => array() ) ); ?></p>
</div>
<?php
} );
}
/**
* Action hook for load-settings_page_windows-azure-storage-plugin-options.
*
* @since 4.0.0
*
* @return void
*/
function windows_azure_storage_check_container_access_policy() {
if ( ! isset( $_REQUEST['settings-updated'] ) || 'true' !== $_REQUEST['settings-updated'] ) {
return;
}
$container = Windows_Azure_Helper::get_default_container();
$container_acl = Windows_Azure_Helper::get_container_acl( $container );
if ( Windows_Azure_Rest_Api_Client::CONTAINER_VISIBILITY_PRIVATE !== $container_acl ) {
return;
}
add_action( 'admin_notices', function () use ( $container ) {
$private_container_warning = sprintf(
__(
'Warning: The container <strong>%1$s</strong> is set to <strong>private</strong> and cannot be used. Please choose a public container as the default, or set the <strong>%1$s</strong> container to <strong>public</strong> in your Azure Storage settings.',
'windows-azure-storage'
),
$container
);
?>
<div class="notice notice-warning is-dismissible">
<p><?php echo $private_container_warning; ?></p>
</div>
<?php
} );
}