141 lines
3.5 KiB
PHP
141 lines
3.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Plugin Name: 1984 Hosting Support
|
|
* Version: 1.0.1
|
|
* Author: 1984 ehf
|
|
* Author URI: https://1984.hosting
|
|
* Description: Support plugin for 1984 Hosting customers.
|
|
* Update URI: https://git.1984.is/1984/1984-hosting-support/
|
|
*/
|
|
|
|
/**
|
|
* The main HostingSupport1984 class
|
|
*
|
|
* @package HostingSupport1984
|
|
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html GNU General Public License v2.0
|
|
*
|
|
* This is where basic constants such as the version number are pulled from.
|
|
* There are other classes that may depend on this file, so only remove it if
|
|
* you do not intend to use the plugin.
|
|
*/
|
|
class HostingSupport1984 {
|
|
const HOSTING_SUPPORT_VERSION = '0.4.0';
|
|
|
|
/**
|
|
* Construct a new HostingSupport1984 object
|
|
*/
|
|
public function __construct() {
|
|
// Loading the text domain for a mu-plugin is tricky.
|
|
// We need to use admin_init instead of plugins_loaded as we are only
|
|
// using the plugin in the admin interface.
|
|
add_action(
|
|
'admin_init',
|
|
array( $this, 'load_textdomain' )
|
|
);
|
|
|
|
// Register the activation hook.
|
|
register_activation_hook(
|
|
__FILE__,
|
|
array( $this, 'activation_hook' )
|
|
);
|
|
|
|
// Run on activation of any plugin.
|
|
add_action(
|
|
'activated_plugin',
|
|
array( $this, 'plugin_activation_hook' )
|
|
);
|
|
|
|
// Run on activation of theme.
|
|
add_action(
|
|
'switch_theme',
|
|
array( $this, 'theme_switch_hook' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Load the 'hosting_support_1984' text domain
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
public function load_textdomain() {
|
|
return load_plugin_textdomain(
|
|
'hostingsupport1984',
|
|
false,
|
|
'1984-hosting-support/languages'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Check if Patchstack is enabled.
|
|
*
|
|
* @return Boolean
|
|
*/
|
|
public function is_patchstack_active() {
|
|
return is_plugin_active( 'patchstack/patchstack.php' );
|
|
}
|
|
|
|
/**
|
|
* On activation of this plugin, set auto-update option for core,
|
|
* plus enable auto-updates for installed plugins and themes.
|
|
*
|
|
* This is skipped if Patchstack is active on the site.
|
|
*/
|
|
public function activation_hook() {
|
|
if ( $this->is_patchstack_active() ) {
|
|
// In case Patchstack is active, do not continue.
|
|
return;
|
|
}
|
|
|
|
// Auto-update WordPress core.
|
|
update_site_option( 'auto_update_core_major', 'enabled' );
|
|
|
|
// Auto-update plugins.
|
|
$all_plugins = apply_filters( 'all_plugins', get_plugins() );
|
|
|
|
update_site_option( 'auto_update_plugins', array_keys( $all_plugins ) );
|
|
|
|
// Auto-update themes.
|
|
$all_themes = wp_get_themes();
|
|
update_site_option( 'auto_update_themes', array_keys( $all_themes ) );
|
|
}
|
|
|
|
/**
|
|
* On plugin activation, add to auto-updated list of plugins.
|
|
*
|
|
* This is skipped if Patchstack is active on the site.
|
|
*/
|
|
public function plugin_activation_hook( $plugin ) {
|
|
if ( $this->is_patchstack_active() ) {
|
|
// In case Patchstack is active, do not continue.
|
|
return;
|
|
}
|
|
|
|
$auto_updated_plugins = (array) get_site_option( 'auto_update_plugins', array() );
|
|
$auto_updated_plugins[] = $plugin;
|
|
|
|
update_site_option( 'auto_update_plugins', array_unique( $auto_updated_plugins ) );
|
|
}
|
|
|
|
/**
|
|
* On theme switch, enable auto-update for all themes.
|
|
*
|
|
* This is skipped if Patchstack is active on the site.
|
|
*/
|
|
public function theme_switch_hook( $theme ) {
|
|
if ( $this->is_patchstack_active() ) {
|
|
// In case Patchstack is active, do not continue.
|
|
return;
|
|
}
|
|
|
|
$all_themes = wp_get_themes();
|
|
update_site_option( 'auto_update_themes', array_keys( $all_themes ) );
|
|
}
|
|
}
|
|
|
|
$hosting_support_1984 = new HostingSupport1984();
|
|
|
|
define( 'A1984_HOSTING_SUPPORT_BASE_FILE', __FILE__ );
|
|
|
|
require_once __DIR__ . '/1984-hosting-support-ui.php';
|