PluginProbe
ManageWP Worker / trunk
ManageWP Worker vtrunk
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Action / GetComponentsStats.php

GetComponentsStats.php in ManageWP Worker trunk, at src/MWP/Action/GetComponentsStats.php

96 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_Action_GetComponentsStats extends MWP_Action_Abstract
12 {
13 /** @var wpdb */
14 private $wpdb;
15
16 public function execute(array $params = array())
17 {
18 $this->wpdb = $this->container->getWordPressContext()->getDb();
19
20 if ($this->container->getWordPressContext()->isMultisite()) {
21 return $this->getNetworkStats($params);
22 }
23
24 $options = $this->getOptions($params);
25
26 $stateAction = new MWP_Action_GetState();
27 $stateAction->setContainer($this->container);
28 $stateData = $stateAction->execute($options);
29 $siteUrl = $this->container->getWordPressContext()->getSiteUrl();
30
31 return array(
32 'multisite' => false,
33 'data' => array(
34 $siteUrl => $stateData
35 )
36 );
37 }
38
39 private function getNetworkStats(array $params = array())
40 {
41 $network_blogs = $this->wpdb->get_results("select `blog_id`, `site_id`, `domain`, `path` from `{$this->wpdb->blogs}`");
42 if (empty($network_blogs)) {
43 return array(
44 'multisite' => true,
45 'data' => array()
46 );
47 }
48
49 $data = array();
50 $options = $this->getOptions($params);
51 /** @handled function */
52 $current_blog_id = get_current_blog_id();
53
54 foreach ($network_blogs as $network_blog) {
55 /** @handled function */
56 switch_to_blog($network_blog->blog_id);
57
58 $stateAction = new MWP_Action_GetState();
59 $stateAction->setContainer($this->container);
60
61 $network_blog_url = rtrim($network_blog->domain, '/').'/'.trim($network_blog->path, '/');
62
63 $data[$network_blog_url] = $stateAction->execute($options);
64 }
65
66 /** @handled function */
67 switch_to_blog($current_blog_id);
68
69 return array(
70 'multisite' => true,
71 'data' => $data
72 );
73 }
74
75 private function getOptions(array $params = array())
76 {
77 $options = array();
78
79 if (isset($params['getPluginStats']) && $params['getPluginStats'] === true) {
80 $options['plugins'] = array(
81 'type' => 'plugins',
82 'options' => array()
83 );
84 }
85
86 if (isset($params['getThemeStats']) && $params['getThemeStats'] === true) {
87 $options['themes'] = array(
88 'type' => 'themes',
89 'options' => array()
90 );
91 }
92
93 return $options;
94 }
95 }
96