Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/MWP/Action
File: GetComponentsStats.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Action_GetComponentsStats extends MWP_Action_Abstract
[10] Fix | Delete
{
[11] Fix | Delete
/** @var wpdb */
[12] Fix | Delete
private $wpdb;
[13] Fix | Delete
[14] Fix | Delete
public function execute(array $params = array())
[15] Fix | Delete
{
[16] Fix | Delete
$this->wpdb = $this->container->getWordPressContext()->getDb();
[17] Fix | Delete
[18] Fix | Delete
if ($this->container->getWordPressContext()->isMultisite()) {
[19] Fix | Delete
return $this->getNetworkStats($params);
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
$options = $this->getOptions($params);
[23] Fix | Delete
[24] Fix | Delete
$stateAction = new MWP_Action_GetState();
[25] Fix | Delete
$stateAction->setContainer($this->container);
[26] Fix | Delete
$stateData = $stateAction->execute($options);
[27] Fix | Delete
$siteUrl = $this->container->getWordPressContext()->getSiteUrl();
[28] Fix | Delete
[29] Fix | Delete
return array(
[30] Fix | Delete
'multisite' => false,
[31] Fix | Delete
'data' => array(
[32] Fix | Delete
$siteUrl => $stateData
[33] Fix | Delete
)
[34] Fix | Delete
);
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
private function getNetworkStats(array $params = array())
[38] Fix | Delete
{
[39] Fix | Delete
$network_blogs = $this->wpdb->get_results("select `blog_id`, `site_id`, `domain`, `path` from `{$this->wpdb->blogs}`");
[40] Fix | Delete
if (empty($network_blogs)) {
[41] Fix | Delete
return array(
[42] Fix | Delete
'multisite' => true,
[43] Fix | Delete
'data' => array()
[44] Fix | Delete
);
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$data = array();
[48] Fix | Delete
$options = $this->getOptions($params);
[49] Fix | Delete
/** @handled function */
[50] Fix | Delete
$current_blog_id = get_current_blog_id();
[51] Fix | Delete
[52] Fix | Delete
foreach ($network_blogs as $network_blog) {
[53] Fix | Delete
/** @handled function */
[54] Fix | Delete
switch_to_blog($network_blog->blog_id);
[55] Fix | Delete
[56] Fix | Delete
$stateAction = new MWP_Action_GetState();
[57] Fix | Delete
$stateAction->setContainer($this->container);
[58] Fix | Delete
[59] Fix | Delete
$network_blog_url = rtrim($network_blog->domain, '/').'/'.trim($network_blog->path, '/');
[60] Fix | Delete
[61] Fix | Delete
$data[$network_blog_url] = $stateAction->execute($options);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/** @handled function */
[65] Fix | Delete
switch_to_blog($current_blog_id);
[66] Fix | Delete
[67] Fix | Delete
return array(
[68] Fix | Delete
'multisite' => true,
[69] Fix | Delete
'data' => $data
[70] Fix | Delete
);
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
private function getOptions(array $params = array())
[74] Fix | Delete
{
[75] Fix | Delete
$options = array();
[76] Fix | Delete
[77] Fix | Delete
if (isset($params['getPluginStats']) && $params['getPluginStats'] === true) {
[78] Fix | Delete
$options['plugins'] = array(
[79] Fix | Delete
'type' => 'plugins',
[80] Fix | Delete
'options' => array()
[81] Fix | Delete
);
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
if (isset($params['getThemeStats']) && $params['getThemeStats'] === true) {
[85] Fix | Delete
$options['themes'] = array(
[86] Fix | Delete
'type' => 'themes',
[87] Fix | Delete
'options' => array()
[88] Fix | Delete
);
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
return $options;
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function