A2 Optimized was developed by A2 Hosting to make it faster and easier to configure the caching of all aspects of a WordPress site.
This free plugin comes with many of the popular Optimizations that come with WordPress hosted at A2 Hosting.
To get the full advantage of A2 Optimized, host your site at A2 Hosting
Free Optimizations
Page Caching with W3 Total Cache
Page Caching stores full copies of pages on the disk so that PHP code and database queries can be skipped by the web server.
DB Caching with W3 Total Cache
Database cache stores copies of common database queries on disk or in memory to speed up page rendering.
Object Caching with W3 Total Cache
Object Caching stores commonly used elements such as menus, widgets and forms on disk or in memory to speed up page rendering.
Browser Caching with W3 Total Cache
Add Rules to the web server to tell the visitor's browser to store a copy of static files to reduce the load time for pages requested after the first page is loaded.
Minify HTML Pages
Auto Configure W3 Total Cache to remove excess white space and comments from HTML pages to compress their size.
Smaller html pages download faster.
Minify CSS Files
Auto Configure W3 Total Cache to condense CSS files.
Combines multiple css files into a single download.
Can provide significant speed imporvements for page loads.
Minify JS Files
Auto Configure W3 Total Cache to condense JavaScript files into non human-readable compressed files.
Combines multiple js files into a single download.
Can provide significant speed improvements for page loads.
Gzip Compression Enabled
Turns on gzip compression using W3 Total Cache.
Ensures that files are compressed before sending them to the visitor's browser.
Can provide significant speed improvements for page loads.
Reduces bandwidth required to serve web pages.
Deny Direct Access to Configuration Files and Comment Form
Enables WordPress hardening rules in .htaccess to prevent browser access to certain files.
Prevents bots from submitting to comment forms.
Turn this off if you use systems that post to the comment form without visiting the page.
Lock Editing of Plugins and Themes from the WP Admin
Turns off the file editor in the wp-admin.
Prevents plugins and themes from being tampered with from the wp-admin.
A2 Hosting Exclusive Optimizations
These one-click optimizations are only available while hosted at A2 Hosting.
Login URL Change
Move the login page from the default wp-login.php to a random URL.
Prevents bots from automatically brute-force attacking wp-login.php
reCAPTCHA on comments and login
Provides google reCAPTCHA on both the Login form and comments.
Prevents bots from automatically brute-force attacking wp-login.php
Prevents bots from automatically spamming comments.
Compress Images on Upload
Enables and configures EWWW Image Optimizer.
Compresses images that are uploaded to save bandwidth.
Improves page load times: especially on sites with many images.
Turbo Web Hosting
Take advantage of A2 Hosting's Turbo Web Hosting platform.
Faster serving of static files.
Pre-compiled .htaccess files on the web server for imporved performance.
PHP OpCode cache enabled by default
Custom PHP engine that is faster than Fast-CGI and FPM
Memcached Database and Object Cache
Database and Object cache in memory instead of on disk.
More secure and faster Memcached using Unix socket files.
Significant improvement in page load times, especially on pages that can not use full page cache such as wp-admin
$feedback
HTML;
ini_set('error_reporting', $ini_error_reporting);
}
public function get_plugin_status()
{
$thisclass = $this;
$opts = new A2_Optimized_Optimizations($thisclass);
$this->advanced_optimizations = $opts->get_advanced();
$this->optimizations = $opts->get_optimizations();
$this->plugin_list = get_plugins();
if (isset($_GET['activate'])) {
foreach ($this->plugin_list as $file => $plugin) {
if ($_GET['activate'] == $plugin['Name']) {
$this->activate_plugin($file);
}
}
}
if (isset($_GET['hide_login_url'])) {
$this->addOption('hide_login_url', true);
}
if (isset($_GET['deactivate'])) {
foreach ($this->plugin_list as $file => $plugin) {
if ($_GET['deactivate'] == $plugin['Name']) {
$this->deactivate_plugin($file);
}
}
}
if (isset($_GET['delete'])) {
foreach ($this->plugin_list as $file => $plugin) {
if ($_GET['delete'] == $plugin['Name']) {
$this->uninstall_plugin($file);
}
}
}
if (isset($_GET['disable_optimization'])) {
$hash = "";
if (isset($this->optimizations[$_GET['disable_optimization']])) {
$this->optimizations[$_GET['disable_optimization']]['disable']($_GET['disable_optimization']);
}
if (isset($this->advanced_optimizations[$_GET['disable_optimization']])) {
$this->advanced_optimizations[$_GET['disable_optimization']]['disable']($_GET['disable_optimization']);
$hash = "#optimization-advanced-tab";
}
echo <<
window.location = 'admin.php?page=A2_Optimized_Plugin_admin{$hash}';
JAVASCRIPT;
exit();
}
if (isset($_GET['enable_optimization'])) {
$hash = "";
if (isset($this->optimizations[$_GET['enable_optimization']])) {
$this->optimizations[$_GET['enable_optimization']]['enable']($_GET['enable_optimization']);
}
if (isset($this->advanced_optimizations[$_GET['enable_optimization']])) {
$this->advanced_optimizations[$_GET['enable_optimization']]['enable']($_GET['enable_optimization']);
$hash = "#optimization-advanced-tab";
}
echo <<
window.location = 'admin.php?page=A2_Optimized_Plugin_admin{$hash}';
JAVASCRIPT;
exit();
}
ini_set('disable_functions', '');
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$plugins_url = plugins_url();
$plugins_url = explode('/', $plugins_url);
array_shift($plugins_url);
array_shift($plugins_url);
array_shift($plugins_url);
$this->plugin_dir = ABSPATH . implode('/', $plugins_url);
$this->plugins_url = plugins_url();
validate_active_plugins();
$this->set_install_status('plugins', $this->plugin_list);
}
/**
* A wrapper function delegating to WP add_option() but it prefixes the input $optionName
* to enforce "scoping" the options in the WP options table thereby avoiding name conflicts
* @param $optionName string defined in settings.php and set as keys of $this->optionMetaData
* @param $value mixed the new value
* @return null from delegated call to delete_option()
*/
public function addOption($optionName, $value)
{
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
return add_option($prefixedOptionName, $value);
}
/**
* Get the prefixed version input $name suitable for storing in WP options
* Idempotent: if $optionName is already prefixed, it is not prefixed again, it is returned without change
* @param $name string option name to prefix. Defined in settings.php and set as keys of $this->optionMetaData
* @return string
*/
public function prefix($name)
{
$optionNamePrefix = $this->getOptionNamePrefix();
if (strpos($name, $optionNamePrefix) === 0) { // 0 but not false
return $name; // already prefixed
}
return $optionNamePrefix . $name;
}
public function getOptionNamePrefix()
{
return get_class($this) . '_';
}
public function deactivate_plugin($file)
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if (is_plugin_active($file)) {
deactivate_plugins($file);
$this->clear_w3_total_cache();
}
}
public function uninstall_plugin($file, $delete = true)
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$this->deactivate_plugin($file);
uninstall_plugin($file);
if ($delete) {
delete_plugins(array($file));
}
unset($this->plugin_list[$file]);
$this->clear_w3_total_cache();
}
public function set_install_status($name, $value)
{
if (!isset($this->install_status)) {
$this->install_status = new StdClass;
}
$this->install_status->{$name} = $value;
}
/**
* Define your options meta data here as an array, where each element in the array
* @return array of key=>display-name and/or key=>array(display-name, choice1, choice2, ...)
* key: an option name for the key (this name will be given a prefix when stored in
* the database to ensure it does not conflict with other plugin options)
* value: can be one of two things:
* (1) string display name for displaying the name of the option to the user on a web page
* (2) array where the first element is a display name (as above) and the rest of
* the elements are choices of values that the user can select
* e.g.
* array(
* 'item' => 'Item:', // key => display-name
* 'rating' => array( // key => array ( display-name, choice1, choice2, ...)
* 'CanDoOperationX' => array('Can do Operation X', 'Administrator', 'Editor', 'Author', 'Contributor', 'Subscriber'),
* 'Rating:', 'Excellent', 'Good', 'Fair', 'Poor')
*/
public function getOptionMetaData()
{
return array();
}
private function curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
/*public function get_litespeed(){
return get_option('a2_optimized_litespeed');
}*/
/*public function set_litespeed($litespeed = true){
update_option('a2_optimized_litespeed',$litespeed);
}*/
function get_optimization_status(&$item)
{
if ($item != null) {
$settings_slug = $this->getSettingsSlug();
if (isset($item['is_configured'])) {
$item['is_configured']($item);
}
$active_color = 'danger';
$active_text = 'Not Activated';
$glyph = 'exclamation-sign';
$links = array();
if ($item['configured']) {
$active_color = 'success';
$active_text = 'Configured';
$glyph = 'ok';
if (isset($item['disable'])) {
$links[] = array("?page=$settings_slug&disable_optimization={$item['slug']}", "Disable", "_self");
}
if (isset($item['settings'])) {
$links[] = array("{$item['settings']}", "Configure", "_self");
}
if (isset($item['configured_links'])) {
foreach ($item['configured_links'] as $name => $link) {
if (gettype($link) == 'array') {
$links[] = array($link[0], $name, $link[1]);
} else {
$links[] = array($link, $name, "_self");
}
}
}
} elseif (isset($item['partially_configured']) && $item['partially_configured']) {
$active_color = 'warning';
$active_text = "Partially Configured. {$item['partially_configured_message']}";
$glyph = 'warning-sign';
if (isset($item['disable'])) {
$links[] = array("?page=$settings_slug&disable_optimization={$item['slug']}", "Disable", "_self");
}
if (isset($item['settings'])) {
$links[] = array("{$item['settings']}", "Configure", "_self");
}
if (isset($item['partially_configured_links'])) {
foreach ($item['partially_configured_links'] as $name => $link) {
if (gettype($link) == 'array') {
$links[] = array($link[0], $name, $link[1]);
} else {
$links[] = array($link, $name, "_self");
}
}
}
} else {
if (isset($item['enable'])) {
$links[] = array("?page=$settings_slug&enable_optimization={$item['slug']}", "Enable", "_self");
}
if (isset($item['not_configured_links'])) {
foreach ($item['not_configured_links'] as $name => $link) {
if (gettype($link) == 'array') {
$links[] = array($link[0], $name, $link[1]);
} else {
$links[] = array($link, $name, "_self");
}
}
}
}
if (isset($item['kb'])) {
$links[] = array($item['kb'], "Learn More", "_blank");
}
$link_html = '';
foreach ($links as $i => $link) {
if (isset($link[0]) && isset($link[1]) && isset($link[2])) {
$link_html .= <<{$link[1]} |
HTML;
}
}
$premium = "";
if (isset($item['premium'])) {
$premium = '
Deactivated plugins should be deleted. Deactivating a plugin does not remove the plugin and its files from your website. Plugins with security flaws may still affect your site even when not active.
HTML;
}
public function get_advanced_optimizations()
{
return $this->advanced_optimizations;
}
public function set_lockdown($lockdown = true)
{
update_option('a2_optimized_lockdown', $lockdown);
}
public function set_nomods($lockdown = true)
{
update_option('a2_optimized_nomods', $lockdown);
}
public function set_deny_direct($deny = true)
{
update_option('a2_optimized_deny_direct', $deny);
}
public function write_wp_config()
{
$lockdown = $this->get_lockdown();
$nomods = $this->get_nomods();
touch(ABSPATH . 'wp-config.php');
copy(ABSPATH . 'wp-config.php', ABSPATH . 'wp-config.php.bak.a2');
$a2_config = "";
if ($lockdown) {
$a2_config = <<get_deny_direct()) {
//Append the new rules to .htaccess
//get the path to the WordPress install - nvm
//$rewrite_base = "/".trim(explode('/',str_replace(array('https://','http://'),'',site_url()),2)[1],"/")."/";
$a2hardening = <<
Order deny,allow
Deny from all
RewriteBase {$home_path}
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
RewriteRule ^wp-config\.php - [F,L]
RewriteRule ^php\.ini - [F,L]
RewriteRule \.htaccess - [F,L]
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*{$_SERVER['HTTP_HOST']}.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) - [F,L]
# END WordPress Hardening
APACHE;
}
$litespeed = "";
$htaccess = file_get_contents(ABSPATH . '.htaccess');
$pattern = "/[\r\n]*# BEGIN WordPress Hardening.*# END WordPress Hardening[\r\n]*/msiU";
$htaccess = preg_replace($pattern, '', $htaccess);
$htaccess = <<optionMetaData
* @return bool from delegated call to delete_option()
*/
public function deleteOption($optionName)
{
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
return delete_option($prefixedOptionName);
}
/**
* A wrapper function delegating to WP add_option() but it prefixes the input $optionName
* to enforce "scoping" the options in the WP options table thereby avoiding name conflicts
* @param $optionName string defined in settings.php and set as keys of $this->optionMetaData
* @param $value mixed the new value
* @return null from delegated call to delete_option()
*/
public function updateOption($optionName, $value)
{
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
return update_option($prefixedOptionName, $value);
}
/**
* Checks if a particular user has a role.
* Returns true if a match was found.
*
* @param string $role Role name.
* @param int $user_id (Optional) The ID of a user. Defaults to the current user.
* @return bool
*/
function checkUserRole($role, $user_id = null)
{
if (is_numeric($user_id)) {
$user = get_userdata($user_id);
} else {
$user = wp_get_current_user();
}
return empty($user) ? false : in_array($role, (array)$user->roles);
}
/**
* A wrapper function delegating to WP get_option() but it prefixes the input $optionName
* to enforce "scoping" the options in the WP options table thereby avoiding name conflicts
* @param $optionName string defined in settings.php and set as keys of $this->optionMetaData
* @param $default string default value to return if the option is not set
* @return string the value from delegated call to get_option(), or optional default value
* if option is not set.
*/
public function getOption($optionName, $default = null)
{
$prefixedOptionName = $this->prefix($optionName); // how it is stored in DB
$retVal = get_option($prefixedOptionName);
if (!$retVal && $default) {
$retVal = $default;
}
return $retVal;
}
/**
* @param $roleName string a standard WP role name like 'Administrator'
* @return bool
*/
public function isUserRoleEqualOrBetterThan($roleName)
{
if ('Anyone' == $roleName) {
return true;
}
$capability = $this->roleToCapability($roleName);
return $this->checkUserCapability($capability);
}
/**
* Given a WP role name, return a WP capability which only that role and roles above it have
* http://codex.wordpress.org/Roles_and_Capabilities
* @param $roleName
* @return string a WP capability or '' if unknown input role
*/
protected function roleToCapability($roleName)
{
switch ($roleName) {
case 'Super Admin':
return 'manage_options';
case 'Administrator':
return 'manage_options';
case 'Editor':
return 'publish_pages';
case 'Author':
return 'publish_posts';
case 'Contributor':
return 'edit_posts';
case 'Subscriber':
return 'read';
case 'Anyone':
return 'read';
}
return '';
}
/**
* Checks if a particular user has a given capability without calling current_user_can.
* Returns true if a match was found.
*
* @param string $capability Capability name.
* @param int $user_id (Optional) The ID of a user. Defaults to the current user.
* @return bool
*/
function checkUserCapability($capability, $user_id = null)
{
if (!is_numeric($user_id)) {
$user_id = wp_get_current_user();
}
if (is_numeric($user_id)) {
$user = get_userdata($user_id);
} else {
return false;
}
$capabilities = (array)$user->allcaps;
return empty($user) ? false : isset($capabilities["{$capability}"]) ? $capabilities["{$capability}"] : false;
}
private function plugin_display($plugin)
{
$links['Delete'] = admin_url() . "admin.php?page=" . $this->getSettingsSlug() . "&delete={$plugin['Name']}";
$glyph = 'warning-sign';
if (!$plugin['active']) {
$glyph = 'exclamation-sign';
$links['Activate'] = admin_url() . "admin.php?page=" . $this->getSettingsSlug() . "&activate={$plugin['Name']}";
} else {
$glyph = 'ok';
$links['Deactivate'] = admin_url() . "admin.php?page=" . $this->getSettingsSlug() . "&deactivate={$plugin['Name']}";
if (isset($plugin['config_url'])) {
$links['Configure'] = $plugin['config_url'];
}
}
$link_html = "";
foreach ($links as $name => $href) {
$link_html .= <<$name |
HTML;
}
$link_html = trim($link_html, " |");
return <<
{$plugin['Name']}
{$plugin['Description']}
{$link_html}
HTML;
}
protected function is_a2(){
if( is_dir("/opt/a2-optimized") ){
return true;
}
return false;
}
function get_plugin_description()
{
$description = <<