PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.4.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-common-functions.php

class-mainwp-common-functions.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.4.1, at class/class-mainwp-common-functions.php

176 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP System Utility Helper
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Common_Functions
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Common_Functions {
16
17 /**
18 * Private static variable to hold the single instance of the class.
19 *
20 * @var mixed Default null
21 */
22 private static $instance = null;
23
24 /**
25 * Protected variable to hold User extension.
26 *
27 * @var mixed Default null.
28 */
29 protected $userExtension = null;
30
31 /**
32 * Method get_class_name()
33 *
34 * Get Class Name.
35 *
36 * @return object
37 */
38 public static function get_class_name() {
39 return __CLASS__;
40 }
41
42 /**
43 * Method instance()
44 *
45 * Create public static instance.
46 *
47 * @static
48 * @return MainWP_DB_Common
49 */
50 public static function instance() {
51 if ( null == self::$instance ) {
52 self::$instance = new self();
53 }
54 return self::$instance;
55 }
56
57 /**
58 * MainWP_Common_Functions constructor.
59 *
60 * Runs any time class is called.
61 */
62 public function __construct() {
63 self::$instance = $this;
64 if ( null == $this->userExtension ) {
65 $this->userExtension = MainWP_DB_Common::instance()->get_user_extension();
66 }
67 }
68
69 /**
70 * Get child site ids that have available updates.
71 *
72 * @return array $site_ids Array of Child Site ID's that have updates.
73 *
74 * @uses \MainWP\Dashboard\MainWP_DB::instance()::query()
75 * @uses \MainWP\Dashboard\MainWP_DB::instance()::get_sql_websites_for_current_user()
76 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
77 * @uses \MainWP\Dashboard\MainWP_DB::instance()::get_website_options_array()
78 */
79 public function get_available_update_siteids() { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
80 $site_ids = array();
81 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
82
83 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
84 $hasSyncErrors = ( '' !== $website->sync_errors );
85 $cnt = 0;
86 if ( 1 == $website->offline_check_result && ! $hasSyncErrors ) {
87 $total_wp_upgrades = 0;
88 $total_plugin_upgrades = 0;
89 $total_theme_upgrades = 0;
90
91 $site_options = MainWP_DB::instance()->get_website_options_array( $website, array( 'wp_upgrades', 'premium_upgrades' ) );
92 $wp_upgrades = isset( $site_options['wp_upgrades'] ) && ! empty( $site_options['wp_upgrades'] ) ? json_decode( $site_options['wp_upgrades'], true ) : array();
93
94 if ( $website->is_ignoreCoreUpdates ) {
95 $wp_upgrades = array();
96 }
97
98 if ( is_array( $wp_upgrades ) && 0 < count( $wp_upgrades ) ) {
99 $total_wp_upgrades ++;
100 }
101
102 $plugin_upgrades = ! empty( $website->plugin_upgrades ) ? json_decode( $website->plugin_upgrades, true ) : array();
103 if ( $website->is_ignorePluginUpdates ) {
104 $plugin_upgrades = array();
105 }
106
107 $theme_upgrades = ! empty( $website->theme_upgrades ) ? json_decode( $website->theme_upgrades, true ) : array();
108 if ( $website->is_ignoreThemeUpdates ) {
109 $theme_upgrades = array();
110 }
111
112 $decodedPremiumUpgrades = isset( $site_options['premium_upgrades'] ) ? json_decode( $site_options['premium_upgrades'], true ) : array();
113
114 if ( is_array( $decodedPremiumUpgrades ) ) {
115 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
116 $premiumUpgrade['premium'] = true;
117
118 if ( 'plugin' === $premiumUpgrade['type'] ) {
119 if ( ! is_array( $plugin_upgrades ) ) {
120 $plugin_upgrades = array();
121 }
122 if ( ! $website->is_ignorePluginUpdates ) {
123 $plugin_upgrades[ $crrSlug ] = $premiumUpgrade;
124 }
125 } elseif ( 'theme' === $premiumUpgrade['type'] ) {
126 if ( ! is_array( $theme_upgrades ) ) {
127 $theme_upgrades = array();
128 }
129 if ( ! $website->is_ignoreThemeUpdates ) {
130 $theme_upgrades[ $crrSlug ] = $premiumUpgrade;
131 }
132 }
133 }
134 }
135
136 if ( is_array( $plugin_upgrades ) ) {
137 $ignored_plugins = json_decode( $website->ignored_plugins, true );
138 if ( is_array( $ignored_plugins ) ) {
139 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
140 }
141
142 $ignored_plugins = json_decode( $this->userExtension->ignored_plugins, true );
143 if ( is_array( $ignored_plugins ) ) {
144 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
145 }
146
147 $total_plugin_upgrades += count( $plugin_upgrades );
148 }
149
150 if ( is_array( $theme_upgrades ) ) {
151 $ignored_themes = json_decode( $website->ignored_themes, true );
152 if ( is_array( $ignored_themes ) ) {
153 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
154 }
155
156 $ignored_themes = json_decode( $this->userExtension->ignored_themes, true );
157 if ( is_array( $ignored_themes ) ) {
158 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
159 }
160
161 $total_theme_upgrades += count( $theme_upgrades );
162 }
163
164 $cnt = $total_wp_upgrades + $total_plugin_upgrades + $total_theme_upgrades;
165
166 if ( 0 < $cnt ) {
167 $site_ids[] = $website->id;
168 }
169 }
170 }
171
172 return $site_ids;
173 }
174
175 }
176