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-tools.php
143 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tools 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 Tools |
| 20 | */ |
| 21 | class Tools 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 | add_action( 'smush_setting_column_right_inside', array( $this, 'detection_settings' ), 25, 2 ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Register meta boxes. |
| 31 | */ |
| 32 | public function register_meta_boxes() { |
| 33 | $box_body_class = WP_Smush::is_pro() ? '' : 'sui-upsell-items'; |
| 34 | |
| 35 | $this->add_meta_box( |
| 36 | 'tools', |
| 37 | __( 'Tools', 'wp-smushit' ), |
| 38 | array( $this, 'tools_meta_box' ), |
| 39 | null, |
| 40 | array( $this, 'common_meta_box_footer' ), |
| 41 | 'main', |
| 42 | array( |
| 43 | 'box_content_class' => "sui-box-body {$box_body_class}", |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | $this->modals['restore-images'] = array(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Common footer meta box. |
| 52 | * |
| 53 | * @since 3.2.0 |
| 54 | */ |
| 55 | public function common_meta_box_footer() { |
| 56 | $this->view( 'meta-box-footer', array(), 'common' ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Tools meta box. |
| 61 | * |
| 62 | * @since 3.2.1 |
| 63 | */ |
| 64 | public function tools_meta_box() { |
| 65 | $this->view( |
| 66 | 'tools/meta-box', |
| 67 | array( |
| 68 | 'detection' => $this->settings->get( 'detection' ), |
| 69 | 'backups_count' => count( WP_Smush::get_instance()->core()->mod->backup->get_attachments_with_backups() ), |
| 70 | ) |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Display a description in Tools - Image Resize Detection. |
| 76 | * |
| 77 | * @since 3.2.1 |
| 78 | * |
| 79 | * @param string $name Setting name. |
| 80 | */ |
| 81 | public function detection_settings( $name ) { |
| 82 | // Add only to full size settings. |
| 83 | if ( 'detection' !== $name ) { |
| 84 | return; |
| 85 | } |
| 86 | ?> |
| 87 | |
| 88 | <span class="sui-description sui-toggle-description"> |
| 89 | <?php esc_html_e( 'Note: The highlighting will only be visible to administrators – visitors won’t see the highlighting.', 'wp-smushit' ); ?> |
| 90 | <?php if ( $this->settings->get( 'detection' ) ) : ?> |
| 91 | <?php if ( $this->settings->get( 'cdn' ) && $this->settings->get( 'auto_resize' ) ) : ?> |
| 92 | <div class="sui-notice smush-highlighting-notice"> |
| 93 | <div class="sui-notice-content"> |
| 94 | <div class="sui-notice-message"> |
| 95 | <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i> |
| 96 | <p> |
| 97 | <?php |
| 98 | esc_html_e( |
| 99 | 'Note: Images served via the Smush CDN are automatically resized to fit their containers, these will be skipped.', |
| 100 | 'wp-smushit' |
| 101 | ); |
| 102 | ?> |
| 103 | </p> |
| 104 | </div> |
| 105 | </div> |
| 106 | </div> |
| 107 | <?php else : ?> |
| 108 | <div class="sui-notice sui-notice-info smush-highlighting-notice"> |
| 109 | <div class="sui-notice-content"> |
| 110 | <div class="sui-notice-message"> |
| 111 | <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i> |
| 112 | <p> |
| 113 | <?php |
| 114 | printf( |
| 115 | /* translators: %1$s: opening a tag, %2$s: closing a tag */ |
| 116 | esc_html__( |
| 117 | '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.', |
| 118 | 'wp-smushit' |
| 119 | ), |
| 120 | '<a href="' . esc_url( home_url() ) . '" target="_blank">', |
| 121 | '</a>' |
| 122 | ); |
| 123 | ?> |
| 124 | </p> |
| 125 | </div> |
| 126 | </div> |
| 127 | </div> |
| 128 | <?php endif; ?> |
| 129 | <?php else : ?> |
| 130 | <div class="sui-notice sui-notice-warning smush-highlighting-warning sui-hidden"> |
| 131 | <div class="sui-notice-content"> |
| 132 | <div class="sui-notice-message"> |
| 133 | <i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i> |
| 134 | <p><?php esc_html_e( 'Almost there! To finish activating this feature you must save your settings.', 'wp-smushit' ); ?></p> |
| 135 | </div> |
| 136 | </div> |
| 137 | </div> |
| 138 | <?php endif; ?> |
| 139 | </span> |
| 140 | <?php |
| 141 | } |
| 142 | } |
| 143 |