| @@ -1,9 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Imagify\Context; |
| 3 | 3 | |
| 4 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 5 | - | |
| 6 | 4 | /** |
| 7 | 5 | * Abstract used for contexts. |
| 8 | 6 | * |
| 9 | 7 | * @since 1.9 |
| @@ -15,12 +13,11 @@ | ||
| 15 | 13 | * Context "short name". |
| 16 | 14 | * |
| 17 | 15 | * @var string |
| 18 | 16 | * @since 1.9 |
| 19 | - * @access protected | |
| 20 | 17 | * @author Grégory Viguier |
| 21 | 18 | */ |
| 22 | - protected $context; | |
| 19 | + protected $context = ''; | |
| 23 | 20 | |
| 24 | 21 | /** |
| 25 | 22 | * Tell if the media/context is network-wide. |
| 26 | 23 | * |
| @@ -25,9 +22,8 @@ | ||
| 25 | 22 | * Tell if the media/context is network-wide. |
| 26 | 23 | * |
| 27 | 24 | * @var bool |
| 28 | 25 | * @since 1.9 |
| 29 | - * @access protected | |
| 30 | 26 | * @author Grégory Viguier |
| 31 | 27 | */ |
| 32 | 28 | protected $is_network_wide = false; |
| 33 | 29 | |
| @@ -38,9 +34,8 @@ | ||
| 38 | 34 | * - 'all' to allow all types. |
| 39 | 35 | * - 'image' to allow only images. |
| 40 | 36 | * - 'not-image' to allow only pdf files. |
| 41 | 37 | * @since 1.9 |
| 42 | - * @access protected | |
| 43 | 38 | * @see imagify_get_mime_types() |
| 44 | 39 | * @author Grégory Viguier |
| 45 | 40 | */ |
| 46 | 41 | protected $allowed_mime_types = 'all'; |
| @@ -57,12 +52,11 @@ | ||
| 57 | 52 | * @type bool $crop True to crop, false to resize. |
| 58 | 53 | * @type string $name The size name. |
| 59 | 54 | * } |
| 60 | 55 | * @since 1.9 |
| 61 | - * @access protected | |
| 62 | 56 | * @author Grégory Viguier |
| 63 | 57 | */ |
| 64 | - protected $thumbnail_sizes; | |
| 58 | + protected $thumbnail_sizes = []; | |
| 65 | 59 | |
| 66 | 60 | /** |
| 67 | 61 | * Tell if the optimization process is allowed to backup in this context. |
| 68 | 62 | * |
| @@ -67,28 +61,16 @@ | ||
| 67 | 61 | * Tell if the optimization process is allowed to backup in this context. |
| 68 | 62 | * |
| 69 | 63 | * @var bool |
| 70 | 64 | * @since 1.9 |
| 71 | - * @access protected | |
| 72 | 65 | * @author Grégory Viguier |
| 73 | 66 | */ |
| 74 | - protected $can_backup; | |
| 67 | + protected $can_backup = false; | |
| 75 | 68 | |
| 76 | 69 | /** |
| 77 | - * Tell if the optimization process is allowed to keep exif in this context. | |
| 78 | - * | |
| 79 | - * @var bool | |
| 80 | - * @since 1.9 | |
| 81 | - * @access protected | |
| 82 | - * @author Grégory Viguier | |
| 83 | - */ | |
| 84 | - protected $can_keep_exif; | |
| 85 | - | |
| 86 | - /** | |
| 87 | 70 | * Get the context "short name". |
| 88 | 71 | * |
| 89 | 72 | * @since 1.9 |
| 90 | - * @access public | |
| 91 | 73 | * @author Grégory Viguier |
| 92 | 74 | * |
| 93 | 75 | * @return string |
| 94 | 76 | */ |
| @@ -99,9 +81,8 @@ | ||
| 99 | 81 | /** |
| 100 | 82 | * Tell if the context is network-wide. |
| 101 | 83 | * |
| 102 | 84 | * @since 1.9 |
| 103 | - * @access public | |
| 104 | 85 | * @author Grégory Viguier |
| 105 | 86 | * |
| 106 | 87 | * @return bool |
| 107 | 88 | */ |
| @@ -112,9 +93,8 @@ | ||
| 112 | 93 | /** |
| 113 | 94 | * Get the type of files this context allows. |
| 114 | 95 | * |
| 115 | 96 | * @since 1.9 |
| 116 | - * @access protected | |
| 117 | 97 | * @see imagify_get_mime_types() |
| 118 | 98 | * @author Grégory Viguier |
| 119 | 99 | * |
| 120 | 100 | * @return string Possible values are: |
| @@ -129,9 +109,8 @@ | ||
| 129 | 109 | /** |
| 130 | 110 | * Get the thumbnail sizes for this context, except the full size. |
| 131 | 111 | * |
| 132 | 112 | * @since 1.9 |
| 133 | - * @access public | |
| 134 | 113 | * @author Grégory Viguier |
| 135 | 114 | * |
| 136 | 115 | * @return array { |
| 137 | 116 | * Data for the currently registered thumbnail sizes. |
| @@ -150,9 +129,8 @@ | ||
| 150 | 129 | /** |
| 151 | 130 | * Tell if the optimization process is allowed resize in this context. |
| 152 | 131 | * |
| 153 | 132 | * @since 1.9 |
| 154 | - * @access public | |
| 155 | 133 | * @author Grégory Viguier |
| 156 | 134 | * |
| 157 | 135 | * @return bool |
| 158 | 136 | */ |
| @@ -163,9 +141,8 @@ | ||
| 163 | 141 | /** |
| 164 | 142 | * Tell if the optimization process is allowed to backup in this context. |
| 165 | 143 | * |
| 166 | 144 | * @since 1.9 |
| 167 | - * @access public | |
| 168 | 145 | * @author Grégory Viguier |
| 169 | 146 | * |
| 170 | 147 | * @return bool |
| 171 | 148 | */ |
| @@ -173,25 +150,11 @@ | ||
| 173 | 150 | return $this->can_backup; |
| 174 | 151 | } |
| 175 | 152 | |
| 176 | 153 | /** |
| 177 | - * Tell if the optimization process is allowed to keep exif in this context. | |
| 178 | - * | |
| 179 | - * @since 1.9 | |
| 180 | - * @access public | |
| 181 | - * @author Grégory Viguier | |
| 182 | - * | |
| 183 | - * @return bool | |
| 184 | - */ | |
| 185 | - public function can_keep_exif() { | |
| 186 | - return $this->can_keep_exif; | |
| 187 | - } | |
| 188 | - | |
| 189 | - /** | |
| 190 | 154 | * Tell if the current user is allowed to operate Imagify in this context. |
| 191 | 155 | * |
| 192 | 156 | * @since 1.9 |
| 193 | - * @access public | |
| 194 | 157 | * @author Grégory Viguier |
| 195 | 158 | * |
| 196 | 159 | * @param string $describer Capacity describer. See $this->get_capacity() for possible values. Can also be a "real" user capacity. |
| 197 | 160 | * @param int $media_id A media ID. |
| @@ -197,9 +160,9 @@ | ||
| 197 | 160 | * @param int $media_id A media ID. |
| 198 | 161 | * @return bool |
| 199 | 162 | */ |
| 200 | 163 | public function current_user_can( $describer, $media_id = null ) { |
| 201 | - return $this->user_can( null, $describer, $media_id ); | |
| 164 | + return $this->user_can( 0, $describer, $media_id ); | |
| 202 | 165 | } |
| 203 | 166 | |
| 204 | 167 | /** |
| 205 | 168 | * Tell if a user is allowed to operate Imagify in this context. |
| @@ -204,9 +167,8 @@ | ||
| 204 | 167 | /** |
| 205 | 168 | * Tell if a user is allowed to operate Imagify in this context. |
| 206 | 169 | * |
| 207 | 170 | * @since 1.9 |
| 208 | - * @access public | |
| 209 | 171 | * @author Grégory Viguier |
| 210 | 172 | * |
| 211 | 173 | * @param int|\WP_User $user_id A user ID or \WP_User object. Fallback to the current user ID. |
| 212 | 174 | * @param string $describer Capacity describer. See $this->get_capacity() for possible values. Can also be a "real" user capacity. |
| @@ -213,8 +175,9 @@ | ||
| 213 | 175 | * @param int $media_id A media ID. |
| 214 | 176 | * @return bool |
| 215 | 177 | */ |
| 216 | 178 | public function user_can( $user_id, $describer, $media_id = null ) { |
| 179 | + $user = 0; | |
| 217 | 180 | $current_user_id = get_current_user_id(); |
| 218 | 181 | |
| 219 | 182 | if ( ! $user_id ) { |
| 220 | 183 | $user = $current_user_id; |
| @@ -250,9 +213,9 @@ | ||
| 250 | 213 | * @param string $describer Capacity describer. See $this->get_capacity() for possible values. Can also be a "real" user capacity. |
| 251 | 214 | * @param int $media_id A media ID. |
| 252 | 215 | * @param string $context The context name. |
| 253 | 216 | */ |
| 254 | - $user_can = (bool) apply_filters( 'imagify_current_user_can', $user_can, $capacity, $describer, $media_id, $this->get_name() ); | |
| 217 | + $user_can = wpm_apply_filters_typed( 'boolean', 'imagify_current_user_can', $user_can, $capacity, $describer, $media_id, $this->get_name() ); | |
| 255 | 218 | } else { |
| 256 | 219 | $user_can = user_can( $user, $capacity, $media_id ); |
| 257 | 220 | } |
| 258 | 221 | |
| @@ -258,10 +221,9 @@ | ||
| 258 | 221 | |
| 259 | 222 | /** |
| 260 | 223 | * Tell if the given user is allowed to operate Imagify in this context. |
| 261 | 224 | * |
| 262 | - * @since 1.9 | |
| 263 | - * @author Grégory Viguier | |
| 225 | + * @since 1.9 | |
| 264 | 226 | * |
| 265 | 227 | * @param bool $user_can Tell if the given user is allowed to operate Imagify in this context. |
| 266 | 228 | * @param int $user_id The user ID. |
| 267 | 229 | * @param string $capacity The user capacity. |
| @@ -268,9 +230,9 @@ | ||
| 268 | 230 | * @param string $describer Capacity describer. See $this->get_capacity() for possible values. Can also be a "real" user capacity. |
| 269 | 231 | * @param int $media_id A media ID. |
| 270 | 232 | * @param string $context The context name. |
| 271 | 233 | */ |
| 272 | - return (bool) apply_filters( 'imagify_user_can', $user_can, $user_id, $capacity, $describer, $media_id, $this->get_name() ); | |
| 234 | + return wpm_apply_filters_typed( 'boolean', 'imagify_user_can', $user_can, $user_id, $capacity, $describer, $media_id, $this->get_name() ); | |
| 273 | 235 | } |
| 274 | 236 | |
| 275 | 237 | /** |
| 276 | 238 | * Filter a user capacity used to operate Imagify in this context. |
| @@ -275,9 +237,8 @@ | ||
| 275 | 237 | /** |
| 276 | 238 | * Filter a user capacity used to operate Imagify in this context. |
| 277 | 239 | * |
| 278 | 240 | * @since 1.9 |
| 279 | - * @access protected | |
| 280 | 241 | * @author Grégory Viguier |
| 281 | 242 | * |
| 282 | 243 | * @param string $capacity The user capacity. |
| 283 | 244 | * @param string $describer Capacity describer. Possible values are like 'manage', 'bulk-optimize', 'manual-optimize', 'auto-optimize'. |
| @@ -295,7 +256,7 @@ | ||
| 295 | 256 | * @param string $capacity The user capacity. |
| 296 | 257 | * @param string $describer Capacity describer. Possible values are like 'manage', 'bulk-optimize', 'manual-optimize', 'auto-optimize'. |
| 297 | 258 | * @param string $context The context name. |
| 298 | 259 | */ |
| 299 | - return (string) apply_filters( 'imagify_capacity', $capacity, $describer, $this->get_name() ); | |
| 260 | + return wpm_apply_filters_typed( 'string', 'imagify_capacity', $capacity, $describer, $this->get_name() ); | |
| 300 | 261 | } |
| 301 | 262 | } |