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
|
<?php namespace Imagify\Optimization\Process;
use Imagify\Optimization\File;
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
/** * Optimization class for the custom folders. * This class constructor accepts: * - A post ID (int). * - An array of data coming from the files DB table /!\ * - An object of data coming from the files DB table /!\ * - A \Imagify\Media\MediaInterface object. * - A \Imagify\Media\DataInterface object. * * @since 1.9 * @see Imagify\Media\CustomFolders * @author Grégory Viguier */ class CustomFolders extends AbstractProcess {
/** * Restore the thumbnails. * This context has no thumbnails. * * @since 1.9 * @access public * @author Grégory Viguier * * @return bool|WP_Error True on success. A \WP_Error instance on failure. */ protected function restore_thumbnails() { return true; }
/** ----------------------------------------------------------------------------------------- */ /** MISSING THUMBNAILS ====================================================================== */ /** ----------------------------------------------------------------------------------------- */
/** * Get the sizes for this media that have not get through optimization. * Since this context has no thumbnails, this will always return an empty array, unless an error is triggered. * * @since 1.9 * @access public * @author Grégory Viguier * * @return array|WP_Error A WP_Error object on failure. An empty array on success: this context has no thumbnails. * The tests are kept for consistency. */ public function get_missing_sizes() { // The media must have been optimized once and have a backup. if ( ! $this->is_valid() ) { return new \WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) ); }
$media = $this->get_media();
if ( ! $media->is_supported() ) { return new \WP_Error( 'media_not_supported', __( 'This media is not supported.', 'imagify' ) ); }
$data = $this->get_data();
if ( ! $data->is_optimized() ) { return new \WP_Error( 'media_not_optimized', __( 'This media is not optimized yet.', 'imagify' ) ); }
if ( ! $media->has_backup() ) { return new \WP_Error( 'no_backup', __( 'This file has no backup file.', 'imagify' ) ); }
if ( ! $media->is_image() ) { return new \WP_Error( 'media_not_an_image', __( 'This media is not an image.', 'imagify' ) ); }
return []; }
/** * Optimize missing thumbnail sizes. * Since this context has no thumbnails, this will always return a \WP_Error object. * * @since 1.9 * @access public * @author Grégory Viguier * * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure. */ public function optimize_missing_thumbnails() { if ( ! $this->is_valid() ) { return new \WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) ); }
if ( ! $this->get_media()->is_supported() ) { return new \WP_Error( 'media_not_supported', __( 'This media is not supported.', 'imagify' ) ); }
return new \WP_Error( 'no_sizes', __( 'No thumbnails seem to be missing.', 'imagify' ) ); } }
|