class-bulk.php
2 years ago
class-cdn.php
2 years ago
class-dashboard.php
2 years ago
class-directory.php
2 years ago
class-integrations.php
2 years ago
class-lazy.php
2 years ago
class-nextgen.php
2 years ago
class-settings.php
2 years ago
class-tutorials.php
2 years ago
class-upgrade.php
2 years ago
class-webp.php
2 years ago
class-settings.php
269 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Settings page. |
| 4 | * |
| 5 | * @package Smush\App\Pages |
| 6 | */ |
| 7 | |
| 8 | namespace Smush\App\Pages; |
| 9 | |
| 10 | use Smush\App\Abstract_Page; |
| 11 | use Smush\App\Interface_Page; |
| 12 | use WP_Smush; |
| 13 | |
| 14 | if ( ! defined( 'WPINC' ) ) { |
| 15 | die; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class Settings |
| 20 | */ |
| 21 | class Settings extends Abstract_Page implements Interface_Page { |
| 22 | /** |
| 23 | * Function triggered when the page is loaded before render any content. |
| 24 | */ |
| 25 | public function on_load() { |
| 26 | // Init the tabs. |
| 27 | $this->tabs = apply_filters( |
| 28 | 'smush_setting_tabs', |
| 29 | array( |
| 30 | 'general' => __( 'General', 'wp-smushit' ), |
| 31 | 'configs' => __( 'Configs', 'wp-smushit' ), |
| 32 | 'permissions' => __( 'Permissions', 'wp-smushit' ), |
| 33 | 'data' => __( 'Data & Settings', 'wp-smushit' ), |
| 34 | 'accessibility' => __( 'Accessibility', 'wp-smushit' ), |
| 35 | ) |
| 36 | ); |
| 37 | |
| 38 | // Disabled on all subsites. |
| 39 | if ( ! is_multisite() || ! is_network_admin() ) { |
| 40 | unset( $this->tabs['permissions'] ); |
| 41 | } |
| 42 | |
| 43 | add_action( 'smush_setting_column_right_inside', array( $this, 'usage_settings' ), 25, 2 ); |
| 44 | add_action( 'smush_setting_column_right_inside', array( $this, 'detection_settings' ), 25, 2 ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Enqueue scripts. |
| 49 | * |
| 50 | * @since 3.9.0 |
| 51 | * |
| 52 | * @param string $hook Hook from where the call is made. |
| 53 | */ |
| 54 | public function enqueue_scripts( $hook ) { |
| 55 | // Scripts for Configs. |
| 56 | $this->enqueue_configs_scripts(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Register meta boxes. |
| 61 | */ |
| 62 | public function register_meta_boxes() { |
| 63 | $this->add_meta_box( |
| 64 | 'settings/general', |
| 65 | __( 'General', 'wp-smushit' ), |
| 66 | array( $this, 'general_meta_box' ), |
| 67 | null, |
| 68 | array( $this, 'common_meta_box_footer' ), |
| 69 | 'general' |
| 70 | ); |
| 71 | |
| 72 | if ( is_multisite() && is_network_admin() ) { |
| 73 | $this->add_meta_box( |
| 74 | 'settings/permissions', |
| 75 | __( 'Permissions', 'wp-smushit' ), |
| 76 | array( $this, 'permissions_meta_box' ), |
| 77 | null, |
| 78 | array( $this, 'common_meta_box_footer' ), |
| 79 | 'permissions' |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | $this->add_meta_box( |
| 84 | 'settings/data', |
| 85 | __( 'Data & Settings', 'wp-smushit' ), |
| 86 | array( $this, 'data_meta_box' ), |
| 87 | null, |
| 88 | array( $this, 'common_meta_box_footer' ), |
| 89 | 'data' |
| 90 | ); |
| 91 | |
| 92 | $this->add_meta_box( |
| 93 | 'settings/accessibility', |
| 94 | __( 'Accessibility', 'wp-smushit' ), |
| 95 | array( $this, 'accessibility_meta_box' ), |
| 96 | null, |
| 97 | array( $this, 'common_meta_box_footer' ), |
| 98 | 'accessibility' |
| 99 | ); |
| 100 | |
| 101 | if ( 'data' === $this->get_current_tab() ) { |
| 102 | $this->modals['reset-settings'] = array(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Display a description in Settings - Usage Tracking. |
| 108 | * |
| 109 | * @since 3.1.0 |
| 110 | * |
| 111 | * @param string $name Setting name. |
| 112 | */ |
| 113 | public function usage_settings( $name ) { |
| 114 | // Add only to full size settings. |
| 115 | if ( 'usage' !== $name ) { |
| 116 | return; |
| 117 | } |
| 118 | ?> |
| 119 | |
| 120 | <span class="sui-description sui-toggle-description"> |
| 121 | <?php |
| 122 | esc_html_e( 'Note: Usage tracking is completely anonymous. We are only tracking what features you are/aren’t using to make our feature decisions more informed.', 'wp-smushit' ); |
| 123 | ?> |
| 124 | </span> |
| 125 | <?php |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Display a description in Settings - Image Resize Detection. |
| 130 | * |
| 131 | * @since 3.2.1 |
| 132 | * |
| 133 | * @param string $name Setting name. |
| 134 | */ |
| 135 | public function detection_settings( $name ) { |
| 136 | // Add only to full size settings. |
| 137 | if ( 'detection' !== $name ) { |
| 138 | return; |
| 139 | } |
| 140 | ?> |
| 141 | |
| 142 | <span class="sui-description sui-toggle-description"> |
| 143 | <?php esc_html_e( 'Note: The highlighting will only be visible to administrators – visitors won’t see the highlighting.', 'wp-smushit' ); ?> |
| 144 | <?php if ( $this->settings->get( 'detection' ) ) : ?> |
| 145 | <?php if ( $this->settings->get( 'cdn' ) && $this->settings->get( 'auto_resize' ) ) : ?> |
| 146 | <div class="sui-notice smush-highlighting-notice"> |
| 147 | <div class="sui-notice-content"> |
| 148 | <div class="sui-notice-message"> |
| 149 | <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i> |
| 150 | <p> |
| 151 | <?php |
| 152 | esc_html_e( |
| 153 | 'Note: Images served via the Smush CDN are automatically resized to fit their containers, these will be skipped.', |
| 154 | 'wp-smushit' |
| 155 | ); |
| 156 | ?> |
| 157 | </p> |
| 158 | </div> |
| 159 | </div> |
| 160 | </div> |
| 161 | <?php else : ?> |
| 162 | <div class="sui-notice sui-notice-info smush-highlighting-notice"> |
| 163 | <div class="sui-notice-content"> |
| 164 | <div class="sui-notice-message"> |
| 165 | <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i> |
| 166 | <p> |
| 167 | <?php |
| 168 | printf( |
| 169 | /* translators: %1$s: opening a tag, %2$s: closing a tag */ |
| 170 | esc_html__( |
| 171 | 'Incorrect image size highlighting is active. %1$sView the frontend%2$s of your website to see if any images aren\'t the correct size for their containers.', |
| 172 | 'wp-smushit' |
| 173 | ), |
| 174 | '<a href="' . esc_url( home_url() ) . '" target="_blank">', |
| 175 | '</a>' |
| 176 | ); |
| 177 | ?> |
| 178 | </p> |
| 179 | </div> |
| 180 | </div> |
| 181 | </div> |
| 182 | <?php endif; ?> |
| 183 | <?php else : ?> |
| 184 | <div class="sui-notice sui-notice-warning smush-highlighting-warning sui-hidden"> |
| 185 | <div class="sui-notice-content"> |
| 186 | <div class="sui-notice-message"> |
| 187 | <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i> |
| 188 | <p><?php esc_html_e( 'Almost there! To finish activating this feature you must save your settings.', 'wp-smushit' ); ?></p> |
| 189 | </div> |
| 190 | </div> |
| 191 | </div> |
| 192 | <?php endif; ?> |
| 193 | </span> |
| 194 | <?php |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Common footer meta box. |
| 199 | * |
| 200 | * @since 3.2.0 |
| 201 | */ |
| 202 | public function common_meta_box_footer() { |
| 203 | $this->view( 'meta-box-footer', array(), 'common' ); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * General settings meta box. |
| 208 | */ |
| 209 | public function general_meta_box() { |
| 210 | $link = WP_Smush::is_pro() ? 'https://wpmudev.com/translate/projects/wp-smushit/' : 'https://translate.wordpress.org/projects/wp-plugins/wp-smushit'; |
| 211 | |
| 212 | $site_locale = get_locale(); |
| 213 | |
| 214 | if ( 'en' === $site_locale || 'en_US' === $site_locale ) { |
| 215 | $site_language = 'English'; |
| 216 | } else { |
| 217 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 218 | $translations = wp_get_available_translations(); |
| 219 | $site_language = isset( $translations[ $site_locale ] ) ? $translations[ $site_locale ]['native_name'] : __( 'Error detecting language', 'wp-smushit' ); |
| 220 | } |
| 221 | |
| 222 | $this->view( |
| 223 | 'settings/general-meta-box', |
| 224 | array( |
| 225 | 'detection' => $this->settings->get( 'detection' ), |
| 226 | 'site_language' => $site_language, |
| 227 | 'tracking' => (bool) $this->settings->get( 'usage' ), |
| 228 | 'translation_link' => $link, |
| 229 | ) |
| 230 | ); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Permissions meta box. |
| 235 | */ |
| 236 | public function permissions_meta_box() { |
| 237 | $this->view( |
| 238 | 'settings/permissions-meta-box', |
| 239 | array( |
| 240 | 'networkwide' => get_site_option( 'wp-smush-networkwide' ), |
| 241 | ) |
| 242 | ); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Data & Settings meta box. |
| 247 | */ |
| 248 | public function data_meta_box() { |
| 249 | $this->view( |
| 250 | 'settings/data-meta-box', |
| 251 | array( |
| 252 | 'keep_data' => (bool) $this->settings->get( 'keep_data' ), |
| 253 | ) |
| 254 | ); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Accessibility meta box. |
| 259 | */ |
| 260 | public function accessibility_meta_box() { |
| 261 | $this->view( |
| 262 | 'settings/accessibility-meta-box', |
| 263 | array( |
| 264 | 'accessible_colors' => (bool) $this->settings->get( 'accessible_colors' ), |
| 265 | ) |
| 266 | ); |
| 267 | } |
| 268 | } |
| 269 |