css_forcepath', 'autoptimize_ccss_deferjquery', 'autoptimize_ccss_domain', 'autoptimize_ccss_unloadccss', 'autoptimize_installed_before_compatibility', ); if ( ! is_multisite() ) { foreach ( $delete_options as $del_opt ) { delete_option( $del_opt ); } autoptimizeMain::remove_cronjobs(); } else { global $wpdb; $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); $original_blog_id = get_current_blog_id(); foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); foreach ( $delete_options as $del_opt ) { delete_option( $del_opt ); } autoptimizeMain::remove_cronjobs(); } switch_to_blog( $original_blog_id ); } // Remove AO CCSS cached files and directory. $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/'; if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) && defined( 'GLOB_BRACE' ) ) { // fixme: should check for subdirs when in multisite and remove contents of those as well. // fixme: if GLOB_BRACE is not avaible we need to remove AO_CCSS_DIR differently? array_map( 'unlink', glob( $ao_ccss_dir . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) ); rmdir( $ao_ccss_dir ); } // Remove 404-handler (although that should have been removed in clearall already). $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php'; if ( file_exists( $_fallback_php ) ) { unlink( $_fallback_php ); } } public static function on_deactivation() { if ( is_multisite() && is_network_admin() ) { global $wpdb; $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); $original_blog_id = get_current_blog_id(); foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); autoptimizeMain::remove_cronjobs(); } switch_to_blog( $original_blog_id ); } else { autoptimizeMain::remove_cronjobs(); } autoptimizeCache::clearall(); } public static function remove_cronjobs() { // Remove scheduled events. foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance', 'ao_ccss_keychecker' ) as $_event ) { if ( wp_get_schedule( $_event ) ) { wp_clear_scheduled_hook( $_event ); } } } public static function notice_cache_unavailable() { echo '

'; // Translators: %s is the cache directory location. printf( esc_html__( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR ); echo '

'; } public static function notice_installed() { echo '

'; // translators: the variables contain opening and closing tags to link to the settings page. printf( esc_html__( 'Thank you for installing and activating Autoptimize. Your site is being optimized immediately, please test the frontend to ensure everything still works as expected. If needed you can change JavaScript or CSS optimization settings under %1$sSettings -> Autoptimize%2$s .', 'autoptimize' ), '', '' ); echo '

'; } public static function notice_updated() { echo '

'; printf( esc_html_e( 'Autoptimize has just been updated. Please %1$stest your site now%2$s and adapt Autoptimize config if needed.', 'autoptimize' ), '', '' ); echo '

'; } public static function notice_plug_imgopt() { // Translators: the URL added points to the Autopmize Extra settings. $_ao_imgopt_plug_notice = sprintf( esc_html__( 'Did you know that Autoptimize offers on-the-fly image optimization (with support for WebP and AVIF) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to enable this option.', 'autoptimize' ), '', '' ); $_ao_imgopt_plug_notice = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice ); $_ao_imgopt_launch_ok = autoptimizeImages::launch_ok_wrapper(); $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123'; $_ao_imgopt_active = autoptimizeImages::imgopt_active(); $_is_ao_settings_page = autoptimizeUtils::is_ao_settings(); if ( current_user_can( 'manage_options' ) && ! defined( 'AO_PRO_VERSION' ) && $_is_ao_settings_page && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { echo '

'; echo $_ao_imgopt_plug_notice; echo '

'; } } public static function notice_imgopt_issue() { // Translators: the URL added points to the Autopmize Extra settings. $_ao_imgopt_issue_notice = sprintf( esc_html__( 'Shortpixel reports it cannot always reach your site, which might mean some images are not optimized. You can %1$sread more about why this happens and how you can fix that problem here%2$s.', 'autoptimize' ), '', '' ); $_ao_imgopt_issue_notice = apply_filters( 'autoptimize_filter_main_imgopt_issue_notice', $_ao_imgopt_issue_notice ); $_ao_imgopt_issue_dismissible = 'ao-img-opt-issue-14'; $_ao_imgopt_active = autoptimizeImages::imgopt_active(); $_ao_imgopt_status = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' ); if ( is_array( $_ao_imgopt_status ) && array_key_exists( 'TemporaryRedirectOrigin', $_ao_imgopt_status ) && ( $_ao_imgopt_status['TemporaryRedirectOrigin'] === "true" || $_ao_imgopt_status['TemporaryRedirectOrigin'] === true ) ) { $_ao_imgopt_status_redirect_warning = true; } else { $_ao_imgopt_status_redirect_warning = false; } if ( current_user_can( 'manage_options' ) && $_ao_imgopt_active && $_ao_imgopt_status_redirect_warning && '' !== $_ao_imgopt_issue_notice && PAnD::is_admin_notice_active( $_ao_imgopt_issue_dismissible ) ) { echo '

'; echo $_ao_imgopt_issue_notice; echo '

'; } } public static function notice_nopagecache() { /* * Autoptimize does not do page caching (yet) but not everyone knows, so below logic tries to find out if page caching is available and if not show a notice on the AO Settings pages. * * uses helper function in autoptimizeUtils.php */ // translators: strong tags and a break. $_ao_nopagecache_notice = sprintf( esc_html__( 'It looks like your site might not have %1$spage caching%2$s which is a %1$smust-have for performance%2$s. If you are sure you have a page cache, you can close this notice.%3$sWhen in doubt check with your host if they offer this or install a free page caching plugin like for example KeyCDN Cache Enabler', 'autoptimize' ), '', '', '
' ); // translators: strong tags. $_ao_nopagecache_notice .= ' ' . esc_html__('or consider ', 'autoptimize') . 'Autoptimize Pro' . sprintf( esc_html__( ' which not only has page caching but also image optimization, critical CSS and advanced booster options %1$sto make your site significantly faster%2$s!', 'autoptimize' ), '', '' ); $_ao_nopagecache_dismissible = 'ao-nopagecache-forever'; // the notice is only shown once and will not re-appear when dismissed. $_is_ao_settings_page = autoptimizeUtils::is_ao_settings(); if ( current_user_can( 'manage_options' ) && $_is_ao_settings_page && PAnD::is_admin_notice_active( $_ao_nopagecache_dismissible ) && true === apply_filters( 'autoptimize_filter_main_show_pagecache_notice', true ) ) { if ( false === autoptimizeUtils::find_pagecache() ) { echo '

'; echo $_ao_nopagecache_notice; echo '

'; } } } public static function notice_potential_conflict() { /* * Using other plugins to do CSS/ JS optimization can cause unexpected and hard to troubleshoot issues, warn users who seem to be in that situation. */ // Translators: some strong tags + the sentence will be finished with the name of the offending plugin and a final stop. $_ao_potential_conflict_notice = sprintf( esc_html__( 'It looks like you have %1$sanother plugin also doing CSS and/ or JS optimization%2$s, which can result in hard to troubleshoot %1$sconflicts%2$s. For this reason it is recommended to disable this functionality in', 'autoptimize' ), '', '' ) . ' '; $_ao_potential_conflict_dismissible = 'ao-potential-conflict-forever'; // the notice is only shown once and will not re-appear when dismissed. $_is_ao_settings_page = autoptimizeUtils::is_ao_settings(); if ( current_user_can( 'manage_options' ) && $_is_ao_settings_page && PAnD::is_admin_notice_active( $_ao_potential_conflict_dismissible ) && true === apply_filters( 'autoptimize_filter_main_show_potential_conclict_notice', true ) ) { $_potential_conflicts = autoptimizeUtils::find_potential_conflicts(); if ( false !== $_potential_conflicts ) { $_ao_potential_conflict_notice .= '' . $_potential_conflicts . '.'; echo '

'; echo $_ao_potential_conflict_notice; echo '

'; } } } }