Skip to content

Commit 270b3e0

Browse files
committed
Adde AAM child implementation
1 parent 5c17f9c commit 270b3e0

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

class/class-mainwp-child-aam.php

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
/**
3+
* MainWP Child AAM.
4+
*
5+
* MainWP AAM Extension handler.
6+
*
7+
* @link https://aamportal.com/integration/mainwp
8+
*
9+
* @package MainWP\Child
10+
*
11+
* Credits
12+
*
13+
* Plugin-Name: Advanced Access Manager
14+
* Plugin URI: https://wordpress.org/plugins/advanced-access-manager/
15+
* Author: Vasyltech
16+
* Author URI: https://vasyltech.com/
17+
*
18+
* The code is used for the MainWP AAM Extension
19+
* Extension URL: https://aamportal.com/integration/mainwp
20+
*/
21+
22+
namespace MainWP\Child;
23+
24+
use AAM_Service_SecurityAudit;
25+
26+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- Required to achieve desired results. Pull requests appreciated.
27+
28+
/**
29+
* Class MainWP_Child_Aam
30+
*
31+
* MainWP Staging Extension handler.
32+
*/
33+
class MainWP_Child_Aam {
34+
35+
/**
36+
* Public static variable to hold the single instance of the class.
37+
*
38+
* @var mixed Default null
39+
*/
40+
public static $instance = null;
41+
42+
/**
43+
* Public variable to hold the information if the WP Staging plugin is installed on the child site.
44+
*
45+
* @var bool If WP Staging installed, return true, if not, return false.
46+
*/
47+
public $is_plugin_installed = false;
48+
49+
/**
50+
* Public variable to hold the information if the WP Staging plugin is installed on the child site.
51+
*
52+
* @var string version string.
53+
*/
54+
public $plugin_version = false;
55+
56+
/**
57+
* Create a public static instance of MainWP_Child_Aam.
58+
*
59+
* @return MainWP_Child_Aam
60+
*/
61+
public static function instance() {
62+
if ( null === static::$instance ) {
63+
static::$instance = new self();
64+
}
65+
return static::$instance;
66+
}
67+
68+
/**
69+
* MainWP_Child_Aam constructor.
70+
*
71+
* Run any time class is called.
72+
*/
73+
public function __construct() {
74+
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // NOSONAR - WP compatible.
75+
76+
if ( is_plugin_active( 'advanced-access-manager/aam.php' ) && defined( 'AAM_KEY' ) ) {
77+
$this->is_plugin_installed = true;
78+
}
79+
80+
if ( ! $this->is_plugin_installed ) {
81+
return;
82+
}
83+
84+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
85+
}
86+
87+
/**
88+
* Sync others data.
89+
*
90+
* Get an array of available clones of this Child Sites.
91+
*
92+
* @param array $information Holder for available clones.
93+
* @param array $data Array of existing clones.
94+
*
95+
* @return array $information An array of available clones.
96+
*/
97+
public function sync_others_data( $information, $data = array() ) {
98+
if ( !empty( $data['aam'] ) ) {
99+
try {
100+
$aam_info = [];
101+
102+
// Get list of data point we would like to fetch
103+
foreach($data['aam'] as $data_point) {
104+
$method = '_get_' . $data_point;
105+
106+
if (method_exists( $this, $method )) {
107+
$aam_info[$data_point] = $this->{$method}();
108+
}
109+
}
110+
111+
$information['aam'] = $aam_info;
112+
} catch ( MainWP_Exception $e ) {
113+
// error!
114+
}
115+
}
116+
117+
return $information;
118+
}
119+
120+
/**
121+
* Get security audit score
122+
*
123+
* @return int|null
124+
* @access private
125+
*/
126+
private function _get_security_score() {
127+
return get_option( AAM_Service_SecurityAudit::DB_SCOPE_OPTION, null );
128+
}
129+
130+
/**
131+
* Get report summary
132+
*
133+
* @return array
134+
* @access private
135+
*/
136+
private function _get_issues_summary() {
137+
$result = [];
138+
$report = get_option( AAM_Service_SecurityAudit::DB_OPTION, [] );
139+
140+
if (is_array( $report )) {
141+
$result = [
142+
'error' => 0,
143+
'notice' => 0,
144+
'warning' => 0,
145+
'critical' => 0
146+
];
147+
148+
foreach($report as $group) {
149+
foreach($group['issues'] as $issue) {
150+
$result[$issue['type']]++;
151+
}
152+
}
153+
}
154+
155+
return $result;
156+
}
157+
158+
}

class/class-mainwp-child.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ public function admin_init() {
412412
* @uses \MainWP\Child\MainWP_Child_Pagespeed::init()
413413
* @uses \MainWP\Child\MainWP_Child_Links_Checker::init()
414414
* @uses \MainWP\Child\MainWP_Child_WPvivid_BackupRestore::init()
415+
* @uses \MainWP\Child\MainWP_Child_Aam::instance()
415416
*/
416417
private function parse_init_extensions() {
417418
MainWP_Child_Branding::instance()->branding_init();
@@ -431,6 +432,7 @@ private function parse_init_extensions() {
431432
MainWP_Child_DB_Updater::instance();
432433
MainWP_Child_Jetpack_Protect::instance();
433434
MainWP_Child_Jetpack_Scan::instance();
435+
MainWP_Child_Aam::instance();
434436
MainWP_Custom_Post_Type::instance();
435437
}
436438

0 commit comments

Comments
 (0)