class-bulk.php
4 years ago
class-cdn.php
4 years ago
class-dashboard.php
4 years ago
class-directory.php
4 years ago
class-integrations.php
4 years ago
class-lazy.php
4 years ago
class-nextgen.php
4 years ago
class-settings.php
4 years ago
class-tools.php
4 years ago
class-tutorials.php
4 years ago
class-upgrade.php
4 years ago
class-webp.php
4 years ago
class-settings.php
198 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 | } |
| 45 | |
| 46 | /** |
| 47 | * Enqueue scripts. |
| 48 | * |
| 49 | * @since 3.9.0 |
| 50 | * |
| 51 | * @param string $hook Hook from where the call is made. |
| 52 | */ |
| 53 | public function enqueue_scripts( $hook ) { |
| 54 | // Scripts for Configs. |
| 55 | $this->enqueue_configs_scripts(); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Register meta boxes. |
| 60 | */ |
| 61 | public function register_meta_boxes() { |
| 62 | $this->add_meta_box( |
| 63 | 'settings/general', |
| 64 | __( 'General', 'wp-smushit' ), |
| 65 | array( $this, 'general_meta_box' ), |
| 66 | null, |
| 67 | array( $this, 'common_meta_box_footer' ), |
| 68 | 'general' |
| 69 | ); |
| 70 | |
| 71 | if ( is_multisite() && is_network_admin() ) { |
| 72 | $this->add_meta_box( |
| 73 | 'settings/permissions', |
| 74 | __( 'Permissions', 'wp-smushit' ), |
| 75 | array( $this, 'permissions_meta_box' ), |
| 76 | null, |
| 77 | array( $this, 'common_meta_box_footer' ), |
| 78 | 'permissions' |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | $this->add_meta_box( |
| 83 | 'settings/data', |
| 84 | __( 'Data & Settings', 'wp-smushit' ), |
| 85 | array( $this, 'data_meta_box' ), |
| 86 | null, |
| 87 | array( $this, 'common_meta_box_footer' ), |
| 88 | 'data' |
| 89 | ); |
| 90 | |
| 91 | $this->add_meta_box( |
| 92 | 'settings/accessibility', |
| 93 | __( 'Accessibility', 'wp-smushit' ), |
| 94 | array( $this, 'accessibility_meta_box' ), |
| 95 | null, |
| 96 | array( $this, 'common_meta_box_footer' ), |
| 97 | 'accessibility' |
| 98 | ); |
| 99 | |
| 100 | if ( 'data' === $this->get_current_tab() ) { |
| 101 | $this->modals['reset-settings'] = array(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Display a description in Settings - Usage Tracking. |
| 107 | * |
| 108 | * @since 3.1.0 |
| 109 | * |
| 110 | * @param string $name Setting name. |
| 111 | */ |
| 112 | public function usage_settings( $name ) { |
| 113 | // Add only to full size settings. |
| 114 | if ( 'usage' !== $name ) { |
| 115 | return; |
| 116 | } |
| 117 | ?> |
| 118 | |
| 119 | <span class="sui-description sui-toggle-description"> |
| 120 | <?php |
| 121 | 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' ); |
| 122 | ?> |
| 123 | </span> |
| 124 | <?php |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Common footer meta box. |
| 129 | * |
| 130 | * @since 3.2.0 |
| 131 | */ |
| 132 | public function common_meta_box_footer() { |
| 133 | $this->view( 'meta-box-footer', array(), 'common' ); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * General settings meta box. |
| 138 | */ |
| 139 | public function general_meta_box() { |
| 140 | $link = WP_Smush::is_pro() ? 'https://wpmudev.com/translate/projects/wp-smushit/' : 'https://translate.wordpress.org/projects/wp-plugins/wp-smushit'; |
| 141 | |
| 142 | $site_locale = get_locale(); |
| 143 | |
| 144 | if ( 'en' === $site_locale || 'en_US' === $site_locale ) { |
| 145 | $site_language = 'English'; |
| 146 | } else { |
| 147 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 148 | $translations = wp_get_available_translations(); |
| 149 | $site_language = isset( $translations[ $site_locale ] ) ? $translations[ $site_locale ]['native_name'] : __( 'Error detecting language', 'wp-smushit' ); |
| 150 | } |
| 151 | |
| 152 | $this->view( |
| 153 | 'settings/general-meta-box', |
| 154 | array( |
| 155 | 'site_language' => $site_language, |
| 156 | 'tracking' => (bool) $this->settings->get( 'usage' ), |
| 157 | 'translation_link' => $link, |
| 158 | ) |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Permissions meta box. |
| 164 | */ |
| 165 | public function permissions_meta_box() { |
| 166 | $this->view( |
| 167 | 'settings/permissions-meta-box', |
| 168 | array( |
| 169 | 'networkwide' => get_site_option( 'wp-smush-networkwide' ), |
| 170 | ) |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Data & Settings meta box. |
| 176 | */ |
| 177 | public function data_meta_box() { |
| 178 | $this->view( |
| 179 | 'settings/data-meta-box', |
| 180 | array( |
| 181 | 'keep_data' => (bool) $this->settings->get( 'keep_data' ), |
| 182 | ) |
| 183 | ); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Accessibility meta box. |
| 188 | */ |
| 189 | public function accessibility_meta_box() { |
| 190 | $this->view( |
| 191 | 'settings/accessibility-meta-box', |
| 192 | array( |
| 193 | 'accessible_colors' => (bool) $this->settings->get( 'accessible_colors' ), |
| 194 | ) |
| 195 | ); |
| 196 | } |
| 197 | } |
| 198 |