PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / 3rd-party / nextgen-gallery / classes / Context / NGG.php

NGG.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at inc/3rd-party/nextgen-gallery/classes/Context/NGG.php

134 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Imagify\ThirdParty\NGG\Context;
3
4 use Imagify\Context\AbstractContext;
5 use Imagify\Traits\InstanceGetterTrait;
6
7 /**
8 * Context class used for the WP media library.
9 *
10 * @since 1.9
11 * @author Grégory Viguier
12 */
13 class NGG extends AbstractContext {
14 use InstanceGetterTrait;
15
16 /**
17 * Context "short name".
18 *
19 * @var string
20 * @since 1.9
21 * @author Grégory Viguier
22 */
23 protected $context = 'ngg';
24
25 /**
26 * Type of files this context allows.
27 *
28 * @var string Possible values are:
29 * - 'all' to allow all types.
30 * - 'image' to allow only images.
31 * - 'not-image' to allow only pdf files.
32 * @since 1.9
33 * @see imagify_get_mime_types()
34 * @author Grégory Viguier
35 */
36 protected $allowed_mime_types = 'image';
37
38 /**
39 * The thumbnail sizes for this context, except the full size.
40 *
41 * @var array {
42 * Data for the currently registered thumbnail sizes.
43 * Size names are used as array keys.
44 *
45 * @type int $width The image width.
46 * @type int $height The image height.
47 * @type bool $crop True to crop, false to resize.
48 * @type string $name The size name.
49 * }
50 * @since 1.9
51 * @author Grégory Viguier
52 */
53 protected $thumbnail_sizes = [];
54
55 /**
56 * Tell if the optimization process is allowed to backup in this context.
57 *
58 * @var bool
59 * @since 1.9
60 * @author Grégory Viguier
61 */
62 protected $can_backup = true;
63
64 /**
65 * Get images max width for this context. This is used when resizing.
66 * 0 means to not resize.
67 *
68 * @since 1.9.8
69 * @author Grégory Viguier
70 *
71 * @return int
72 */
73 public function get_resizing_threshold() {
74 return 0;
75 }
76
77 /**
78 * Get user capacity to operate Imagify in this context.
79 *
80 * @since 1.9
81 * @author Grégory Viguier
82 *
83 * @param string $describer Capacity describer. Possible values are like 'manage', 'bulk-optimize', 'manual-optimize', 'auto-optimize'.
84 * @return string
85 */
86 public function get_capacity( $describer = 'manage' ) {
87 switch ( $describer ) {
88 case 'manage':
89 $capacity = 'NextGEN Change options';
90 break;
91
92 case 'bulk-optimize':
93 $capacity = 'NextGEN Manage others gallery';
94 break;
95
96 case 'optimize':
97 case 'restore':
98 case 'manual-optimize':
99 case 'manual-restore':
100 $capacity = 'NextGEN Manage gallery';
101 break;
102
103 case 'auto-optimize':
104 $capacity = 'NextGEN Upload images';
105 break;
106
107 default:
108 $capacity = $describer;
109 }
110
111 // NGG v4 may not register the v3 custom capabilities. Fall back to 'manage_options' so
112 // the submenu and bulk page remain accessible to site administrators on v4.
113 // @codeCoverageIgnoreStart — requires live NGG v4 class; not available in unit tests.
114 if ( class_exists( 'Imagely\NGG\Admin\App' ) && ! get_role( $capacity ) && ! wp_roles()->is_role( $capacity ) ) {
115 $wp_roles = wp_roles();
116 $has_cap = false;
117
118 foreach ( $wp_roles->roles as $role_data ) {
119 if ( ! empty( $role_data['capabilities'][ $capacity ] ) ) {
120 $has_cap = true;
121 break;
122 }
123 }
124
125 if ( ! $has_cap ) {
126 $capacity = 'manage_options';
127 }
128 }
129 // @codeCoverageIgnoreEnd
130
131 return $this->filter_capacity( $capacity, $describer );
132 }
133 }
134