htaccess = new \nicomartin\Htaccess( 'Advanced WPPerformance' ); } public function run() { add_action( 'awpp_settings', [ $this, 'register_system_recs' ] ); add_action( 'awpp_settings', [ $this, 'register_settings' ] ); add_action( 'awpp_sanitize', [ $this, 'do_htaccess' ] ); register_uninstall_hook( awpp_get_instance()->file, [ 'clean_up' ] ); } public function register_system_recs() { $section = awpp_settings()->add_section( awpp_settings_page_server(), 'systemcheck', __( 'System Recommendations', 'awpp' ) ); /** * PHP Version */ $content = ''; if ( version_compare( PHP_VERSION, '7.0.0', '>=' ) ) { $content .= '

' . __( 'Great!', 'awpp' ) . '

'; $content .= '

' . __( 'Your are using PHP 7 or higher.', 'awpp' ) . '

'; } else { $content .= '

' . __( 'Needs work!', 'awpp' ) . '

'; // translators: Currently you are using PHP Version {PHP_VERSION}. Version 7.0.0 brought some enormous performance improvements. We highly recommend to contact you hosting provider to upgrade to min PHP Version 7.0.0 $content .= '

' . sprintf( __( 'Currently you are using PHP Version %1$s. Version 7.0.0 brought some enormous performance improvements. We highly recommend to contact you hosting provider to upgrade to min PHP Version 7.0.0.', 'awpp' ), '' . PHP_VERSION . '' ) . '

'; } awpp_settings()->add_message( $section, 'php7', __( 'PHP Version', 'awpp' ), $content ); /** * HTTP Version */ $env = getenv( 'X_SPDY' ); $http = $_SERVER['SERVER_PROTOCOL']; $http_version = explode( '/', $http )[1]; if ( version_compare( $http_version, '2', '>=' ) || '' != $env ) { $content = '

' . __( 'Great!', 'awpp' ) . '

'; $content .= '

' . __( 'Your are using min. HTTP/2.', 'awpp' ) . '

'; } else { $content = '

' . __( 'Needs work!', 'awpp' ) . '

'; // translators: This Plugin uses the advantages of {HTTP_VERSION}. Currently your server supports %1$s. We highly recommend to contact you hosting provider to upgrade to HTTP/2 $content .= '

' . sprintf( __( 'This Plugin uses the advantages of HTTP/2. Currently your server supports %1$s. We highly recommend to contact you hosting provider to upgrade to HTTP/2', 'awpp' ), $http ) . '

'; } awpp_settings()->add_message( $section, 'http2', __( 'HTTP Version', 'awpp' ), $content ); } public function register_settings() { $section = awpp_settings()->add_section( awpp_settings_page_server(), 'server', __( 'Server Settings', 'awpp' ) ); $args = [ 'after_field' => '

' . __( 'If enabled, Advanced WPPerformance will add compression using "AddOutputFilterByType DEFLATE" inside your .htaccess for common file types.', 'awpp' ) . '

', ]; awpp_settings()->add_checkbox( $section, 'compression', __( 'Enable Compression', 'awpp' ), '', $args ); $args = [ 'after_field' => '

' . __( 'If enabled, Advanced WPPerformance will set Cache-Control Headers to your .htaccess. One year for images and one month for CSS and JS files.', 'awpp' ) . '

', ]; awpp_settings()->add_checkbox( $section, 'cachingheaders', __( 'Set caching headers', 'awpp' ), '', $args ); } public function do_htaccess( $data ) { if ( isset( $data['compression'] ) || isset( $data['cachingheaders'] ) ) { $add = ''; if ( $data['compression'] ) { $add .= "\n"; $add .= "AddOutputFilterByType DEFLATE text/plain\n"; $add .= "AddOutputFilterByType DEFLATE text/html\n"; $add .= "AddOutputFilterByType DEFLATE text/xml\n"; $add .= "AddOutputFilterByType DEFLATE text/shtml\n"; $add .= "AddOutputFilterByType DEFLATE text/css\n"; $add .= "AddOutputFilterByType DEFLATE application/xml\n"; $add .= "AddOutputFilterByType DEFLATE application/xhtml+xml\n"; $add .= "AddOutputFilterByType DEFLATE application/rss+xml\n"; $add .= "AddOutputFilterByType DEFLATE application/javascript\n"; $add .= "AddOutputFilterByType DEFLATE application/x-javascript\n"; $add .= "\n"; } if ( $data['cachingheaders'] ) { $add .= "\n"; $add .= "\n"; $add .= "Header set Cache-Control \"max-age=31536000, public\"\n"; $add .= "\n"; $add .= "\n"; $add .= "Header set Cache-Control \"max-age=2628000, public\"\n"; $add .= "\n"; $add .= "\n"; } $this->htaccess->set( $add ); } } public function clean_up() { $this->htaccess->delete(); } }