PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.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 All 155 releases
← All changes | widgets/widget-mainwp-widget-themes.php +290 -322 5.0.3 → 6.2.2 View file →
@@ -8,349 +8,317 @@
8 8 */
9 9
10 10 namespace MainWP\Dashboard;
11 11
12 +// Exit if accessed directly.
13 +if ( ! defined( 'ABSPATH' ) ) {
14 + exit;
15 +}
16 +
12 17 /**
13 18 * Class MainWP_Widget_Themes
14 19 */
15 -class MainWP_Widget_Themes {
16 - /**
17 - * Method get_class_name()
18 - *
19 - * Get Class Name
20 - *
21 - * @return string __CLASS__ Class Name.
22 - */
23 - public static function get_class_name() {
24 - return __CLASS__;
25 - }
20 +class MainWP_Widget_Themes { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
26 21
27 - /**
28 - * Method render()
29 - *
30 - * Fire off render_widget().
31 - */
32 - public static function render() {
33 - self::render_widget();
34 - }
22 + /**
23 + * Method get_class_name()
24 + *
25 + * Get Class Name
26 + *
27 + * @return string __CLASS__ Class Name.
28 + */
29 + public static function get_class_name() {
30 + return __CLASS__;
31 + }
35 32
33 + /**
34 + * Method render()
35 + *
36 + * Fire off render_widget().
37 + */
38 + public static function render() {
39 + static::render_widget();
40 + }
36 41
37 - /**
38 - * Method render_widget()
39 - *
40 - * Build themes widget.
41 - *
42 - * @uses \MainWP\Dashboard\MainWP_DB::query()
43 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_website_by_id()
44 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
45 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
46 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
47 - */
48 - public static function render_widget() {
49 - $current_wpid = MainWP_System_Utility::get_current_wpid();
50 - if ( empty( $current_wpid ) ) {
51 - return;
52 - }
53 42
54 - $sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid );
55 - $websites = MainWP_DB::instance()->query( $sql );
56 - $allThemes = array();
57 - if ( $websites ) {
58 - $website = MainWP_DB::fetch_object( $websites );
59 - if ( $website && '' !== $website->themes ) {
60 - $themes = json_decode( $website->themes, 1 );
61 - if ( is_array( $themes ) && 0 !== count( $themes ) ) {
62 - foreach ( $themes as $theme ) {
63 - $allThemes[] = $theme;
64 - }
65 - }
66 - }
67 - MainWP_DB::free_result( $websites );
68 - }
43 + /**
44 + * Method render_widget()
45 + *
46 + * Build themes widget.
47 + *
48 + * @uses \MainWP\Dashboard\MainWP_DB::query()
49 + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_website_by_id()
50 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
51 + * @uses \MainWP\Dashboard\MainWP_DB::free_result()
52 + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
53 + */
54 + public static function render_widget() {
55 + $current_wpid = MainWP_System_Utility::get_current_wpid();
56 + if ( empty( $current_wpid ) ) {
57 + return;
58 + }
69 59
70 - self::render_html_widget( $website, $allThemes );
71 - }
60 + $sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid );
61 + $websites = MainWP_DB::instance()->query( $sql );
62 + $allThemes = array();
63 + if ( $websites ) {
64 + $website = MainWP_DB::fetch_object( $websites );
65 + if ( $website && '' !== $website->themes ) {
66 + $themes = json_decode( $website->themes, 1 );
67 + if ( is_array( $themes ) && ! empty( $themes ) ) {
68 + foreach ( $themes as $theme ) {
69 + $allThemes[] = $theme;
70 + }
71 + }
72 + }
73 + MainWP_DB::free_result( $websites );
74 + }
72 75
73 - /**
74 - *
75 - * Method render_html_widget().
76 - *
77 - * Render html themes widget for current site.
78 - *
79 - * @param object $website Object containing the child site info.
80 - * @param array $allThemes Array containing all detected themes data.
81 - *
82 - * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
83 - * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
84 - */
85 - public static function render_html_widget( $website, $allThemes ) {
76 + static::render_html_widget( $website, $allThemes );
77 + }
86 78
87 - $is_demo = MainWP_Demo_Handle::is_demo_mode();
79 + /**
80 + *
81 + * Method render_html_widget().
82 + *
83 + * Render html themes widget for current site.
84 + *
85 + * @param object $website Object containing the child site info.
86 + * @param array $allThemes Array containing all detected themes data.
87 + *
88 + * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
89 + * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
90 + */
91 + public static function render_html_widget( $website, $allThemes ) { // phpcs:ignore -- NOSONAR - complex.
88 92
89 - $actived_themes = MainWP_Utility::get_sub_array_having( $allThemes, 'active', 1 );
90 - $actived_themes = MainWP_Utility::sortmulti( $actived_themes, 'name', 'asc' );
93 + $is_demo = MainWP_Demo_Handle::is_demo_mode();
91 94
92 - $inactive_themes = MainWP_Utility::get_sub_array_having( $allThemes, 'active', 0 );
93 - $inactive_themes = MainWP_Utility::sortmulti( $inactive_themes, 'name', 'asc' );
95 + $actived_themes = MainWP_Utility::get_sub_array_having( $allThemes, 'active', 1 );
96 + $actived_themes = MainWP_Utility::sortmulti( $actived_themes, 'name', 'asc' );
94 97
95 - ?>
96 - <div class="ui grid mainwp-widget-header">
97 - <div class="twelve wide column">
98 - <h3 class="ui header handle-drag">
99 - <?php
100 - /**
101 - * Filter: mainwp_themes_widget_title
102 - *
103 - * Filters the Themes widget title text.
104 - *
105 - * @since 4.1
106 - */
107 - echo esc_html( apply_filters( 'mainwp_themes_widget_title', esc_html__( 'Themes', 'mainwp' ), $website ) );
108 - ?>
109 - <div class="sub header"><?php esc_html_e( 'Installed themes on the child site', 'mainwp' ); ?></div>
110 - </h3>
111 - </div>
112 - <div class="four wide column right aligned">
113 - <div class="ui dropdown right pointing mainwp-dropdown-tab">
114 - <div class="text"><?php esc_html_e( 'Active', 'mainwp' ); ?></div>
115 - <i class="dropdown icon"></i>
116 - <div class="menu">
117 - <a class="item" data-tab="active_themes" data-value="active_themes" title="<?php esc_attr_e( 'Active', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Active', 'mainwp' ); ?></a>
118 - <a class="item" data-tab="inactive_themes" data-value="inactive_themes" title="<?php esc_attr_e( 'Inactive', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Inactive', 'mainwp' ); ?></a>
119 - </div>
120 - </div>
121 - </div>
122 - </div>
123 - <div class="mainwp-scrolly-overflow">
124 - <?php
125 - /**
126 - * Action: mainwp_themes_widget_top
127 - *
128 - * Fires at the top of the Themes widget on the Individual site overview page.
129 - *
130 - * @param object $website Object containing the child site info.
131 - * @param array $allThemes Array containing all detected themes data.
132 - *
133 - * @since 4.1
134 - */
135 - do_action( 'mainwp_themes_widget_top', $website, $allThemes );
136 - ?>
137 - <div id="mainwp-widget-active-themes" class="ui tab active" data-tab="active_themes">
138 - <?php
139 - /**
140 - * Action: mainwp_before_active_themes_list
141 - *
142 - * Fires before the active theme list in the Themes widget on the Individual site overview page.
143 - *
144 - * @param object $website Object containing the child site info.
145 - * @param array $actived_themes Array containing all active themes data.
146 - *
147 - * @since 4.1
148 - */
149 - do_action( 'mainwp_before_active_themes_list', $website, $actived_themes );
150 - ?>
151 - <div class="ui divided selection list">
152 - <?php
153 - $_count = count( $actived_themes );
154 - for ( $i = 0; $i < $_count; $i++ ) {
155 - $slug = $actived_themes[ $i ]['slug'];
156 - ?>
157 - <div class="item">
158 - <input class="themeSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $actived_themes[ $i ]['slug'] ) ); ?>"/>
159 - <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/>
160 - <div class="right floated content themesAction">
161 - <a href="#" disabled class="button ui mini grey basic" data-position="left center" data-tooltip="<?php esc_attr_e( 'Active theme cannot be deactivated.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></a>
162 - </div>
163 - <div class="middle aligned content">
164 - <?php echo MainWP_System_Utility::get_theme_icon( $slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?>&nbsp;&nbsp;&nbsp;&nbsp;
165 - <?php echo esc_html( $actived_themes[ $i ]['name'] . ' ' . $actived_themes[ $i ]['version'] ); ?>
166 - </div>
167 - <div class="mainwp-row-actions-working">
168 - <i class="ui active inline loader tiny"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?>
169 - </div>
170 - </div>
171 - <?php } ?>
172 - </div>
173 - <?php
174 - /**
175 - * Action: mainwp_after_active_themes_list
176 - *
177 - * Fires after the active themes list in the Themes widget on the Individual site overview page.
178 - *
179 - * @param object $website Object containing the child site info.
180 - * @param array $actived_themes Array containing all active themes data.
181 - *
182 - * @since 4.1
183 - */
184 - do_action( 'mainwp_after_active_themes_list', $website, $actived_themes );
185 - ?>
186 - </div>
187 - <div id="mainwp-widget-inactive-themes" class="ui tab" data-tab="inactive_themes">
188 - <?php
189 - /**
190 - * Action: mainwp_before_inactive_themes_list
191 - *
192 - * Fires before the inactive themes list in the Themes widget on the Individual site overview page.
193 - *
194 - * @param object $website Object containing the child site info.
195 - * @param array $inactive_themes Array containing all inactive themes data.
196 - *
197 - * @since 4.1
198 - */
199 - do_action( 'mainwp_before_inactive_themes_list', $website, $inactive_themes );
200 - ?>
201 - <div class="ui divided selection list">
202 - <?php
203 - $_count = count( $inactive_themes );
204 - for ( $i = 0; $i < $_count; $i++ ) {
205 - $slug = $inactive_themes[ $i ]['slug'];
206 - $is_parent = ( isset( $inactive_themes[ $i ]['parent_active'] ) && 1 === (int) $inactive_themes[ $i ]['parent_active'] ) ? true : false;
207 - ?>
208 - <div class="item">
209 - <input class="themeName" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $inactive_themes[ $i ]['name'] ) ); ?>"/>
210 - <input class="themeSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $inactive_themes[ $i ]['slug'] ) ); ?>"/>
211 - <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/>
212 - <div class="right floated content themesAction">
213 - <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_themes' ) ) { ?>
214 - <a href="#" class="mainwp-theme-activate ui mini green button <?php echo $is_demo ? 'disabled' : ''; ?>" data-position="left center" data-tooltip="<?php esc_attr_e( 'Activate the ', 'mainwp' ) . wp_strip_all_tags( $inactive_themes[ $i ]['name'] ) . esc_attr_e( ' theme on the child site.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Activate', 'mainwp' ); ?></a>
215 - <?php } ?>
216 - <?php
217 - if ( mainwp_current_user_have_right( 'dashboard', 'delete_themes' ) ) {
218 - $parent_str = sprintf( esc_html__( 'Parent theme of the active theme (%s) on the site can not be deleted.', 'mainwp' ), isset( $inactive_themes[ $i ]['child_theme'] ) ? $inactive_themes[ $i ]['child_theme'] : '' );
219 - ?>
220 - <a href="#" class="<?php echo $is_parent ? '' : 'mainwp-theme-delete'; ?> ui mini basic button <?php echo $is_demo ? 'disabled' : ''; ?>" data-position="left center" data-tooltip="<?php echo ! $is_parent ? esc_attr__( 'Delete the ', 'mainwp' ) . wp_strip_all_tags( $inactive_themes[ $i ]['name'] ) . esc_attr__( ' theme from the child site.', 'mainwp' ) : $parent_str; // phpcs:ignore WordPress.Security.EscapeOutput ?>" <?php echo $is_parent ? 'disabled onclick="javascript:void(0)"' : ''; ?> data-inverted=""><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
221 - <?php } ?>
222 - </div>
223 - <div class="middle aligned content">
224 - <?php echo MainWP_System_Utility::get_theme_icon( $slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?>&nbsp;&nbsp;&nbsp;&nbsp;
225 - <?php echo esc_html( $inactive_themes[ $i ]['name'] . ' ' . $inactive_themes[ $i ]['version'] ); ?>
226 - </div>
227 - <div class="mainwp-row-actions-working">
228 - <i class="ui active inline loader tiny"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?>
229 - </div>
230 - </div>
231 - <?php } ?>
232 - </div>
233 - <?php
234 - /**
235 - * Action: mainwp_after_inactive_themes_list
236 - *
237 - * Fires after the inactive themes list in the Themes widget on the Individual site overview page.
238 - *
239 - * @param object $website Object containing the child site info.
240 - * @param array $inactive_themes Array containing all inactive themes data.
241 - *
242 - * @since 4.1
243 - */
244 - do_action( 'mainwp_after_inactive_themes_list', $website, $inactive_themes );
245 - ?>
246 - </div>
247 - </div>
248 - <?php
249 - /**
250 - * Action: mainwp_themes_widget_bottom
251 - *
252 - * Fires at the bottom of the Themes widget on the Individual site overview page.
253 - *
254 - * @param object $website Object containing the child site info.
255 - * @param array $allThemes Array containing all detected themes data.
256 - *
257 - * @since 4.1
258 - */
259 - do_action( 'mainwp_themes_widget_bottom', $website, $allThemes );
260 - }
98 + $inactive_themes = MainWP_Utility::get_sub_array_having( $allThemes, 'active', 0 );
99 + $inactive_themes = MainWP_Utility::sortmulti( $inactive_themes, 'name', 'asc' );
261 100
262 - /**
263 - * Method activate_theme()
264 - *
265 - * Fire off Action activate & display result
266 - */
267 - public static function activate_theme() {
268 - self::action( 'activate' );
269 - die( wp_json_encode( array( 'result' => esc_html__( 'Theme has been activated!', 'mainwp' ) ) ) );
270 - }
101 + $wp_info = MainWP_DB::instance()->get_website_option( $website, 'site_info' );
102 + $wp_info = ! empty( $wp_info ) ? json_decode( $wp_info, true ) : array();
271 103
272 - /**
273 - * Method delete_theme()
274 - *
275 - * Fire off action deactivate & display result
276 - */
277 - public static function delete_theme() {
278 - self::action( 'delete' );
279 - die( wp_json_encode( array( 'result' => esc_html__( 'Theme has been permanently deleted!', 'mainwp' ) ) ) );
280 - }
104 + if ( ! is_array( $wp_info ) ) {
105 + $wp_info = array();
106 + }
281 107
282 - /**
283 - * Method action()
284 - *
285 - * Initiate try catch for chosen Action.
286 - *
287 - * @param mixed $action Theme Action.
288 - *
289 - * @throws \Exception Error message.
290 - *
291 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
292 - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
293 - * @uses \MainWP\Dashboard\MainWP_Exception
294 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
295 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
296 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
297 - */
298 - public static function action( $action ) {
299 - $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
300 - $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
108 + $use_tzformat = ! empty( $wp_info['format_datetime'] ) && is_array( $wp_info['format_datetime'] ) ? $wp_info['format_datetime'] : array();
109 + $offs = ! empty( $use_tzformat['gmt_offset'] ) ? intval( $use_tzformat['gmt_offset'] ) : 0;
110 + $offs_info = esc_html__( ' - Timezone:', 'mainwp' ) . ' UTC ' . ( $offs >= 0 ? '+' . $offs : $offs );
111 + $site_info = $website->name . ' (' . $website->url . ') ' . ( ! empty( $offs_info ) ? $offs_info : '' );
301 112
302 - if ( empty( $theme ) || empty( $websiteId ) ) {
303 - die( wp_json_encode( array( 'error' => esc_html__( 'Theme or site ID not found. Please, reload the page and try again.', 'mainwp' ) ) ) );
304 - }
113 + ?>
114 + <div class="mainwp-widget-header">
115 + <h2 class="ui header handle-drag">
116 + <?php
117 + /**
118 + * Filter: mainwp_themes_widget_title
119 + *
120 + * Filters the Themes widget title text.
121 + *
122 + * @since 4.1
123 + */
124 + echo esc_html( apply_filters( 'mainwp_themes_widget_title', esc_html__( 'Themes', 'mainwp' ), $website ) );
125 + ?>
126 + <div class="sub header"><?php esc_html_e( 'Inactive themes on the child site', 'mainwp' ); ?></div>
127 + </h2>
128 + </div>
129 + <div class="mainwp-scrolly-overflow">
130 + <?php
131 + /**
132 + * Action: mainwp_themes_widget_top
133 + *
134 + * Fires at the top of the Themes widget on the Individual site overview page.
135 + *
136 + * @param object $website Object containing the child site info.
137 + * @param array $allThemes Array containing all detected themes data.
138 + *
139 + * @since 4.1
140 + */
141 + do_action( 'mainwp_themes_widget_top', $website, $allThemes );
142 + ?>
143 + <div id="mainwp-widget-inactive-themes" site-info="<?php echo esc_attr( $site_info ); ?>" site-id="<?php echo intval( $website->id ); ?>">
144 + <?php
145 + /**
146 + * Action: mainwp_before_inactive_themes_list
147 + *
148 + * Fires before the inactive themes list in the Themes widget on the Individual site overview page.
149 + *
150 + * @param object $website Object containing the child site info.
151 + * @param array $inactive_themes Array containing all inactive themes data.
152 + *
153 + * @since 4.1
154 + */
155 + do_action( 'mainwp_before_inactive_themes_list', $website, $inactive_themes );
156 + ?>
157 + <div class="ui divided list">
158 + <?php
159 + $_count = count( $inactive_themes );
160 + for ( $i = 0; $i < $_count; $i++ ) {
161 + $slug = $inactive_themes[ $i ]['slug'];
162 + $is_parent = ( isset( $inactive_themes[ $i ]['parent_active'] ) && 1 === (int) $inactive_themes[ $i ]['parent_active'] ) ? true : false;
163 + ?>
164 + <div class="item row-manage-item">
165 + <input class="themeName" type="hidden" name="name" value="<?php echo esc_attr( wp_strip_all_tags( $inactive_themes[ $i ]['name'] ) ); ?>"/>
166 + <input class="themeSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $inactive_themes[ $i ]['slug'] ) ); ?>"/>
167 + <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/>
168 + <div class="right floated content themesAction">
169 + <div class="ui right pointing dropdown">
170 + <i class="ellipsis vertical icon"></i>
171 + <div class="menu">
172 + <?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_themes' ) ) : ?>
173 + <a href="#" class="mainwp-theme-activate item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Activate', 'mainwp' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></a>
174 + <?php endif; ?>
175 + <?php if ( \mainwp_current_user_can( 'dashboard', 'delete_themes' ) ) : ?>
176 + <a href="#" class="<?php echo $is_parent ? '' : 'mainwp-theme-delete'; ?> item <?php echo $is_demo ? 'disabled' : ''; ?>" <?php echo $is_parent ? 'disabled onclick="javascript:void(0)"' : ''; ?>><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
177 + <?php endif; ?>
178 + <a href="#" history-view="widget-themes" class="mainwp-show-history item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'History', 'mainwp' ); ?></a>
179 + </div>
180 + </div>
181 + </div>
182 + <div class="middle aligned content">
183 + <?php echo MainWP_System_Utility::get_theme_icon( $slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?>&nbsp;&nbsp;&nbsp;&nbsp;
184 + <?php echo esc_html( $inactive_themes[ $i ]['name'] . ' ' . $inactive_themes[ $i ]['version'] ); ?>
185 + </div>
186 + <div class="mainwp-row-actions-working">
187 + <i class="ui active inline loader tiny"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?>
188 + </div>
189 + </div>
190 + <?php } ?>
191 + </div>
192 + <?php
193 + /**
194 + * Action: mainwp_after_inactive_themes_list
195 + *
196 + * Fires after the inactive themes list in the Themes widget on the Individual site overview page.
197 + *
198 + * @param object $website Object containing the child site info.
199 + * @param array $inactive_themes Array containing all inactive themes data.
200 + *
201 + * @since 4.1
202 + */
203 + do_action( 'mainwp_after_inactive_themes_list', $website, $inactive_themes );
204 + ?>
205 + </div>
206 + </div>
305 207
306 - $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
307 - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
308 - die( wp_json_encode( array( 'error' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) );
309 - }
208 + <?php
209 + /**
210 + * Action: mainwp_themes_widget_bottom
211 + *
212 + * Fires at the bottom of the Themes widget on the Individual site overview page.
213 + *
214 + * @param object $website Object containing the child site info.
215 + * @param array $allThemes Array containing all detected themes data.
216 + *
217 + * @since 4.1
218 + */
219 + do_action( 'mainwp_themes_widget_bottom', $website, $allThemes );
220 + ?>
221 + <div class="ui two column grid mainwp-widget-footer">
222 + <div class="left aligned middle aligned column"></div>
223 + <div class="right aligned middle aligned column">
224 + <a href="admin.php?page=ThemesManage" class="ui mini basic button"><?php esc_html_e( 'Manage Themes', 'mainwp' ); ?></a>
225 + </div>
226 + </div>
227 + <?php
228 + }
310 229
311 - if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
312 - die(
313 - wp_json_encode(
314 - array(
315 - 'error' => esc_html__( 'Suspended site.', 'mainwp' ),
316 - 'errorCode' => 'SUSPENDED_SITE',
317 - )
318 - )
319 - );
320 - }
230 + /**
231 + * Method activate_theme()
232 + *
233 + * Fire off Action activate & display result
234 + */
235 + public static function activate_theme() {
236 + static::action( 'activate' );
237 + die( wp_json_encode( array( 'result' => esc_html__( 'Theme has been activated!', 'mainwp' ) ) ) );
238 + }
321 239
322 - /**
323 - * Action: mainwp_before_theme_action
324 - *
325 - * Fires before theme activate/delete actions.
326 - *
327 - * @since 4.1
328 - */
329 - do_action( 'mainwp_before_theme_action', $action, $theme, $website );
330 - try {
331 - $information = MainWP_Connect::fetch_url_authed(
332 - $website,
333 - 'theme_action',
334 - array(
335 - 'action' => $action,
336 - 'theme' => $theme,
337 - )
338 - );
339 - } catch ( MainWP_Exception $e ) {
340 - die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) );
341 - }
240 + /**
241 + * Method delete_theme()
242 + *
243 + * Fire off action deactivate & display result
244 + */
245 + public static function delete_theme() {
246 + static::action( 'delete' );
247 + die( wp_json_encode( array( 'result' => esc_html__( 'Theme has been permanently deleted!', 'mainwp' ) ) ) );
248 + }
342 249
343 - /**
344 - * Action: mainwp_after_theme_action
345 - *
346 - * Fires after theme activate/delete actions.
347 - *
348 - * @since 4.1
349 - */
350 - do_action( 'mainwp_after_theme_action', $information, $action, $theme, $website );
250 + /**
251 + * Method action()
252 + *
253 + * Initiate try catch for chosen Action.
254 + *
255 + * @param mixed $action Theme Action.
256 + *
257 + * @throws \MainWP_Exception Error message.
258 + *
259 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
260 + * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
261 + * @uses \MainWP\Dashboard\MainWP_Exception
262 + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
263 + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
264 + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
265 + */
266 + public static function action( $action ) {
267 + $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
268 + $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
351 269
352 - if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) {
353 - die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) );
354 - }
355 - }
270 + if ( empty( $theme ) || empty( $websiteId ) ) {
271 + die( wp_json_encode( array( 'error' => esc_html__( 'Theme or site ID not found. Please, reload the page and try again.', 'mainwp' ) ) ) );
272 + }
273 +
274 + $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
275 + if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
276 + die( wp_json_encode( array( 'error' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) );
277 + }
278 +
279 + if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
280 + die(
281 + wp_json_encode(
282 + array(
283 + 'error' => esc_html__( 'Suspended site.', 'mainwp' ),
284 + 'errorCode' => 'SUSPENDED_SITE',
285 + )
286 + )
287 + );
288 + }
289 +
290 + /**
291 + * Action: mainwp_before_theme_action
292 + *
293 + * Fires before theme activate/delete actions.
294 + *
295 + * @since 4.1
296 + */
297 + do_action( 'mainwp_before_theme_action', $action, $theme, $website );
298 + try {
299 + $information = MainWP_Connect::fetch_url_authed(
300 + $website,
301 + 'theme_action',
302 + array(
303 + 'action' => $action,
304 + 'theme' => $theme,
305 + )
306 + );
307 + } catch ( MainWP_Exception $e ) {
308 + die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) );
309 + }
310 +
311 + /**
312 + * Action: mainwp_after_theme_action
313 + *
314 + * Fires after theme activate/delete actions.
315 + *
316 + * @since 4.1
317 + */
318 + do_action( 'mainwp_after_theme_action', $information, $action, $theme, $website );
319 +
320 + if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) {
321 + die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) );
322 + }
323 + }
356 324 }