diff --git a/inc/admin/ui/notices.php b/inc/admin/ui/notices.php index 6eb02f6db..3700e37e6 100755 --- a/inc/admin/ui/notices.php +++ b/inc/admin/ui/notices.php @@ -353,14 +353,21 @@ function _imagify_warning_backup_folder_not_writable_notice() { return; } - $filesystem = imagify_get_filesystem(); - $has_backup_dir = wp_mkdir_p( get_imagify_backup_dir_path() ); - - if ( $has_backup_dir && $filesystem->is_writable( get_imagify_backup_dir_path() ) ) { + if ( imagify_backup_dir_is_writable() ) { return; } - $backup_path = imagify_make_file_path_replative( get_imagify_backup_dir_path() ); + $filesystem = imagify_get_filesystem(); + + if ( $filesystem->exists( get_imagify_backup_dir_path() ) ) { + /* translators: %s is a file path. */ + $message = __( 'The backup folder %s is not writable by the server, original images cannot be saved!', 'imagify' ); + } else { + /* translators: %s is a file path. */ + $message = __( 'The backup folder %s cannot be created. Is its parent directory writable by the server? Original images cannot be saved!', 'imagify' ); + } + + $backup_path = imagify_make_file_path_replative( get_imagify_backup_dir_path( true ) ); ?>
@@ -368,10 +375,7 @@ function _imagify_warning_backup_folder_not_writable_notice() {
-

$backup_path" ); - ?>

+

$backup_path" ); ?>

$backup_path" ); + printf( __( 'The backup folder %s cannot be created or is not writable by the server, original images cannot be saved!', 'imagify' ), "$backup_path" ); ?> diff --git a/inc/functions/attachments.php b/inc/functions/attachments.php index 3c6ac900f..247e547a2 100755 --- a/inc/functions/attachments.php +++ b/inc/functions/attachments.php @@ -50,16 +50,17 @@ function imagify_is_attachment_mime_type_supported( $attachment_id ) { * @since 1.6.8 * @author Grégory Viguier * - * @return string|bool Path to the backups directory. False on failure. + * @param bool $bypass_error True to return the path even if there is an error. This is used when we want to display this path in a message for example. + * @return string|bool Path to the backups directory. False on failure. */ -function get_imagify_backup_dir_path() { +function get_imagify_backup_dir_path( $bypass_error = false ) { static $backup_dir; if ( isset( $backup_dir ) ) { return $backup_dir; } - $upload_basedir = get_imagify_upload_basedir(); + $upload_basedir = get_imagify_upload_basedir( $bypass_error ); if ( ! $upload_basedir ) { return false; @@ -223,27 +224,30 @@ function get_imagify_thumbnail_sizes() { * A simple helper to get the upload basedir. * * @since 1.6.7 + * @since 1.6.8 Added the $bypass_error parameter. * @author Grégory Viguier * - * @return string|bool The path. False on failure. + * @param bool $bypass_error True to return the path even if there is an error. This is used when we want to display this path in a message for example. + * @return string|bool The path. False on failure. */ -function get_imagify_upload_basedir() { +function get_imagify_upload_basedir( $bypass_error = false ) { static $upload_basedir; + static $upload_basedir_or_error; if ( isset( $upload_basedir ) ) { - return $upload_basedir; + return $bypass_error ? $upload_basedir : $upload_basedir_or_error; } - $uploads = wp_upload_dir(); + $uploads = wp_upload_dir(); + $upload_basedir = trailingslashit( wp_normalize_path( $uploads['basedir'] ) ); if ( false !== $uploads['error'] ) { - $upload_basedir = false; - return $upload_basedir; + $upload_basedir_or_error = false; + } else { + $upload_basedir_or_error = $upload_basedir; } - $upload_basedir = trailingslashit( wp_normalize_path( $uploads['basedir'] ) ); - - return $upload_basedir; + return $bypass_error ? $upload_basedir : $upload_basedir_or_error; } /**