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-webp.php
163 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Local WebP page. |
| 4 | * |
| 5 | * @package Smush\App\Pages |
| 6 | */ |
| 7 | |
| 8 | namespace Smush\App\Pages; |
| 9 | |
| 10 | use Smush\App\Abstract_Summary_Page; |
| 11 | use Smush\App\Interface_Page; |
| 12 | use WP_Smush; |
| 13 | |
| 14 | if ( ! defined( 'WPINC' ) ) { |
| 15 | die; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class WebP |
| 20 | */ |
| 21 | class WebP extends Abstract_Summary_Page implements Interface_Page { |
| 22 | |
| 23 | /** |
| 24 | * Enqueue scripts. |
| 25 | * |
| 26 | * @since 3.9.0 |
| 27 | * |
| 28 | * @param string $hook Hook from where the call is made. |
| 29 | */ |
| 30 | public function enqueue_scripts( $hook ) { |
| 31 | // We only need this script for the wizard. |
| 32 | if ( ! $this->is_wizard() ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | wp_enqueue_script( |
| 37 | 'smush-react-webp', |
| 38 | WP_SMUSH_URL . 'app/assets/js/smush-react-webp.min.js', |
| 39 | array( 'wp-i18n', 'smush-sui', 'clipboard' ), |
| 40 | WP_SMUSH_VERSION, |
| 41 | true |
| 42 | ); |
| 43 | |
| 44 | wp_add_inline_script( |
| 45 | 'smush-react-webp', |
| 46 | 'wp.i18n.setLocaleData( ' . wp_json_encode( $this->get_locale_data() ) . ', "wp-smushit" );', |
| 47 | 'before' |
| 48 | ); |
| 49 | |
| 50 | $webp = WP_Smush::get_instance()->core()->mod->webp; |
| 51 | |
| 52 | // Defining this here to esc_html before using dangerouslySetInnerHTML on frontend. |
| 53 | $third_step_message = ! is_multisite() |
| 54 | ? sprintf( |
| 55 | /* translators: 1. opening 'b' tag, 2. closing 'b' tag */ |
| 56 | esc_html__( |
| 57 | 'WebP versions of existing images in the Media Library can only be created by ‘smushing’ the originals via the Bulk Smush page. Click %1$sConvert Now%2$s to be redirected to the Bulk Smush page to start smushing your images.', |
| 58 | 'wp-smushit' |
| 59 | ), |
| 60 | '<b>', |
| 61 | '</b>' |
| 62 | ) |
| 63 | : sprintf( |
| 64 | /* translators: 1. opening 'b' tag, 2. closing 'b' tag */ |
| 65 | esc_html__( |
| 66 | 'WebP versions of existing images in the Media Library can only be created by ‘smushing’ the originals using the %1$sBulk Smush%2$s tool on each subsite.', |
| 67 | 'wp-smushit' |
| 68 | ), |
| 69 | '<b>', |
| 70 | '</b>' |
| 71 | ); |
| 72 | |
| 73 | wp_localize_script( |
| 74 | 'smush-react-webp', |
| 75 | 'smushReact', |
| 76 | array( |
| 77 | 'nonce' => wp_create_nonce( 'wp-smush-webp-nonce' ), |
| 78 | 'isPro' => WP_Smush::is_pro(), |
| 79 | 'detectedServer' => $webp->get_server_type(), |
| 80 | 'apacheRules' => $webp->get_apache_code_to_print(), |
| 81 | 'nginxRules' => $webp->get_nginx_code(), |
| 82 | 'startStep' => true !== $webp->is_configured() || ! WP_Smush::is_pro() ? 1 : 3, |
| 83 | 'isMultisite' => is_multisite(), |
| 84 | 'isWpmudevHost' => isset( $_SERVER['WPMUDEV_HOSTED'] ), |
| 85 | 'isWhitelabel' => apply_filters( 'wpmudev_branding_hide_doc_link', false ), |
| 86 | 'isS3Enabled' => $this->settings->get( 's3' ) && ! WP_Smush::get_instance()->core()->s3->setting_status(), |
| 87 | 'thirdStepMsg' => $third_step_message, |
| 88 | 'urls' => array( |
| 89 | 'bulkPage' => esc_url( admin_url( 'admin.php?page=smush-bulk' ) ), |
| 90 | 'support' => 'https://wpmudev.com/hub2/support/#get-support', |
| 91 | 'freeImg' => esc_url( WP_SMUSH_URL . 'app/assets/images/smush-no-media.png' ), |
| 92 | 'webpDoc' => 'https://wpmudev.com/blog/local-webp-support-smush/', |
| 93 | 'upsell' => add_query_arg( |
| 94 | array( |
| 95 | 'utm_source' => 'smush', |
| 96 | 'utm_medium' => 'plugin', |
| 97 | 'utm_campaign' => 'smush_webp_upgrade_button', |
| 98 | ), |
| 99 | $this->upgrade_url |
| 100 | ), |
| 101 | ), |
| 102 | ) |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Register meta boxes. |
| 108 | */ |
| 109 | public function register_meta_boxes() { |
| 110 | parent::register_meta_boxes(); |
| 111 | |
| 112 | if ( $this->is_wizard() ) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | if ( ! $this->settings->get( 'webp_mod' ) ) { |
| 117 | $this->add_meta_box( |
| 118 | 'webp/disabled', |
| 119 | __( 'Local WebP', 'wp-smushit' ), |
| 120 | null, |
| 121 | array( $this, 'webp_meta_box_header' ) |
| 122 | ); |
| 123 | |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | $this->add_meta_box( |
| 128 | 'webp/webp', |
| 129 | __( 'Local WebP', 'wp-smushit' ), |
| 130 | null, |
| 131 | array( $this, 'webp_meta_box_header' ) |
| 132 | ); |
| 133 | |
| 134 | $this->modals['webp-delete-all'] = array(); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * WebP meta box header. |
| 139 | * |
| 140 | * @since 3.8.0 |
| 141 | */ |
| 142 | public function webp_meta_box_header() { |
| 143 | $this->view( |
| 144 | 'webp/meta-box-header', |
| 145 | array( |
| 146 | 'is_disabled' => ! $this->settings->get( 'webp_mod' ), |
| 147 | 'is_configured' => true === WP_Smush::get_instance()->core()->mod->webp->is_configured(), |
| 148 | ) |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Whether the wizard should be displayed. |
| 154 | * |
| 155 | * @since 3.9.0 |
| 156 | * |
| 157 | * @return bool |
| 158 | */ |
| 159 | protected function is_wizard() { |
| 160 | return ( ! WP_Smush::is_pro() || ( $this->settings->get( 'webp_mod' ) && ! get_site_option( 'wp-smush-webp_hide_wizard' ) ) ); |
| 161 | } |
| 162 | } |
| 163 |