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-hooks.php

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

1,605 lines 48.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Hooks
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
11
12 /**
13 * Class MainWP_Hooks
14 *
15 * @package MainWP\Dashboard
16 */
17 class MainWP_Hooks {
18
19 /**
20 * MainWP_Hooks constructor.
21 *
22 * Initialize MainWP_Hooks actions/filters upon creation of the object.
23 *
24 * @deprecated 4.0.7. Hook deprecation - Please use filter `mainwp_get_error_message` instead of `mainwp_getErrorMessage`.
25 *
26 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_class_name()
27 * @uses \MainWP\Dashboard\MainWP_UI::get_class_name()
28 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name()
29 * @uses \MainWP\Dashboard\MainWP_Install_Bulk::get_class_name()
30 */
31 public function __construct() {
32 add_filter( 'mainwp_getspecificdir', array( MainWP_System_Utility::get_class_name(), 'get_mainwp_specific_dir' ), 10, 1 );
33 add_filter( 'mainwp_getmainwpdir', array( &$this, 'hook_get_mainwp_dir' ), 10, 3 );
34 add_filter( 'mainwp_is_multi_user', array( &$this, 'is_multi_user' ) );
35 add_filter( 'mainwp_qq2fileuploader', array( &$this, 'filter_qq2_file_uploader' ), 10, 2 );
36 add_action( 'mainwp_select_sites_box', array( &$this, 'select_sites_box' ), 10, 11 );
37 add_action( 'mainwp_add_categories_box', array( &$this, 'hook_add_categories_box' ), 10, 1 );
38 add_action( 'mainwp_prepareinstallplugintheme', array( MainWP_Install_Bulk::get_class_name(), 'prepare_install' ) );
39 add_action( 'mainwp_performinstallplugintheme', array( MainWP_Install_Bulk::get_class_name(), 'perform_install' ) );
40 add_filter( 'mainwp_getwpfilesystem', array( MainWP_System_Utility::get_class_name(), 'get_wp_file_system' ) );
41 add_filter( 'mainwp_getspecificurl', array( MainWP_System_Utility::get_class_name(), 'get_mainwp_specific_url' ), 10, 1 );
42 add_filter( 'mainwp_getdownloadurl', array( MainWP_System_Utility::get_class_name(), 'get_download_url' ), 10, 2 );
43 add_action( 'mainwp_renderHeader', array( MainWP_UI::get_class_name(), 'render_header' ), 10, 2 );
44 add_action( 'mainwp_renderFooter', array( MainWP_UI::get_class_name(), 'render_footer' ), 10, 0 );
45
46 add_action( 'mainwp_notify_user', array( &$this, 'hook_notify_user' ), 10, 3 );
47
48 /**
49 * The actions has been deprecated.
50 *
51 * @deprecated 4.3 Please use actions: mainwp_action_activeplugin, mainwp_action_deactiveplugin ....
52 */
53 add_action( 'mainwp_activePlugin', array( &$this, 'active_plugin' ), 10, 0 );
54 add_action( 'mainwp_deactivePlugin', array( &$this, 'deactive_plugin' ), 10, 0 );
55 add_action( 'mainwp_upgradePluginTheme', array( &$this, 'upgrade_plugin_theme' ), 10, 0 );
56 add_action( 'mainwp_deletePlugin', array( &$this, 'delete_plugin' ), 10, 0 );
57 add_action( 'mainwp_deleteTheme', array( &$this, 'delete_theme' ), 10, 0 );
58 // End.
59
60 /**
61 * Plugins/themes/core actions.
62 *
63 * @since 4.3
64 */
65 add_action( 'mainwp_action_activeplugin', array( &$this, 'active_plugin' ), 10, 0 );
66 add_action( 'mainwp_action_deactiveplugin', array( &$this, 'deactive_plugin' ), 10, 0 );
67 add_action( 'mainwp_action_upgradeplugintheme', array( &$this, 'upgrade_plugin_theme' ), 10, 0 );
68 add_action( 'mainwp_action_deleteplugin', array( &$this, 'delete_plugin' ), 10, 0 );
69 add_action( 'mainwp_action_deletetheme', array( &$this, 'delete_theme' ), 10, 0 );
70 add_action( 'mainwp_upgrade_wp', array( &$this, 'upgrade_wp' ), 10, 0 );
71 // End.
72
73 add_filter( 'mainwp_get_user_extension', array( &$this, 'hook_get_user_extension' ), 10, 2 );
74 add_filter( 'mainwp_update_user_extension', array( &$this, 'update_user_extension' ), 10, 3 );
75 add_filter( 'mainwp_getwebsitesbyurl', array( &$this, 'get_websites_by_url' ) );
76 add_filter( 'mainwp_getWebsitesByUrl', array( &$this, 'get_websites_by_url' ) );
77 add_action( 'mainwp_manage_posts_get_edit', array( &$this, 'hook_posts_get_edit' ), 10, 2 );
78 add_action( 'mainwp_manage_posts_bulk_posting', array( &$this, 'hook_posts_bulk_posting' ), 10, 2 );
79
80 /**
81 * The mainwp_getErrorMessage filter has been deprecated.
82 *
83 * @deprecated 4.0.7. Please use filter mainwp_get_error_message.
84 */
85 add_filter( 'mainwp_getErrorMessage', array( &$this, 'get_error_message' ), 10, 2 );
86 add_filter( 'mainwp_get_error_message', array( &$this, 'get_error_message' ), 10, 2 );
87
88 add_filter( 'mainwp_getwebsitesbygroupids', array( &$this, 'hook_get_websites_by_group_ids' ), 10, 2 );
89
90 add_filter( 'mainwp_cache_getcontext', array( &$this, 'cache_getcontext' ) );
91 add_action( 'mainwp_cache_echo_body', array( &$this, 'cache_echo_body' ) );
92 add_action( 'mainwp_cache_init', array( &$this, 'cache_init' ) );
93 add_action( 'mainwp_cache_add_context', array( &$this, 'cache_add_context' ), 10, 2 );
94 add_action( 'mainwp_cache_add_body', array( &$this, 'cache_add_body' ), 10, 2 );
95
96 add_filter( 'mainwp_get_metaboxes_post', array( &$this, 'get_metaboxes_post' ), 10, 0 );
97 add_filter( 'mainwp_getnotificationemail', array( &$this, 'hook_notification_email' ), 10, 1 );
98 add_filter( 'mainwp_getformatemail', array( &$this, 'get_formated_email' ), 10, 3 );
99 add_filter( 'mainwp-extension-available-check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_available' ) );
100 add_filter( 'mainwp_extension_is_activated', array( &$this, 'is_extension_activated' ), 10, 2 );
101 add_filter( 'mainwp_extension_is_pro_member', array( &$this, 'is_pro_member' ), 10, 1 );
102
103 /**
104 * Logging debug actions.
105 */
106 add_action( 'mainwp_log_debug', array( &$this, 'mainwp_log_debug' ), 10, 1 );
107 add_action( 'mainwp_log_info', array( &$this, 'mainwp_log_info' ), 10, 1 );
108 add_action( 'mainwp_log_warning', array( &$this, 'mainwp_log_warning' ), 10, 1 );
109 add_action( 'mainwp_log_action', array( &$this, 'mainwp_log_action' ), 10, 4 );
110 add_action( 'mainwp_log_execution_time', array( &$this, 'mainwp_log_execution_time' ), 10, 1 );
111 // END.
112
113 add_filter( 'mainwp_getactivateextensionnotice', array( &$this, 'get_activate_extension_notice' ), 10, 1 );
114 add_action( 'mainwp_enqueue_meta_boxes_scripts', array( &$this, 'enqueue_meta_boxes_scripts' ), 10, 1 );
115 add_filter( 'mainwp_addsite', array( &$this, 'mainwp_add_site' ), 10, 1 );
116 add_filter( 'mainwp_deletesite', array( &$this, 'hook_delete_site' ), 10, 1 );
117 add_filter( 'mainwp_clonesite', array( &$this, 'filter_clone_site' ), 10, 6 );
118 add_filter( 'mainwp_delete_clonesite', array( &$this, 'filter_delete_clone_site' ), 10, 4 );
119 add_filter( 'mainwp_editsite', array( &$this, 'mainwp_edit_site' ), 10, 1 );
120 add_action( 'mainwp_add_sub_leftmenu', array( &$this, 'hook_add_sub_left_menu' ), 10, 6 );
121 add_filter( 'mainwp_getwebsiteoptions', array( &$this, 'hook_get_site_options' ), 10, 3 );
122 add_filter( 'mainwp_updatewebsiteoptions', array( &$this, 'hook_update_site_options' ), 10, 4 );
123
124 add_filter( 'mainwp_getwebsitesbyuserid', array( &$this, 'hook_get_websites_by_user_id' ), 10, 5 );
125 add_filter( 'mainwp_getwebsite_by_id', array( &$this, 'hook_get_website_by_id' ), 10, 4 );
126
127 add_filter( 'mainwp_addgroup', array( MainWP_Extensions_Handler::get_class_name(), 'hook_add_group' ), 10, 3 );
128 add_filter( 'mainwp_getallposts', array( &$this, 'hook_get_all_posts' ), 10, 2 );
129 add_filter( 'mainwp_check_current_user_can', array( &$this, 'hook_current_user_can' ), 10, 3 );
130 add_filter( 'mainwp_escape_response_data', array( &$this, 'hook_escape_response' ), 10, 3 );
131 add_filter( 'mainwp_escape_content', array( &$this, 'hook_escape_content' ), 10, 3 );
132
133 add_filter( 'mainwp_db_query', array( &$this, 'hook_db_query' ), 10, 2 );
134 add_filter( 'mainwp_db_fetch_object', array( &$this, 'db_fetch_object' ), 10, 2 );
135 add_filter( 'mainwp_db_fetch_array', array( &$this, 'db_fetch_array' ), 10, 2 );
136 add_action( 'mainwp_db_data_seek', array( &$this, 'hook_db_data_seek' ), 10, 2 );
137 add_filter( 'mainwp_db_free_result', array( &$this, 'db_free_result' ), 10, 2 );
138 add_filter( 'mainwp_db_num_rows', array( &$this, 'db_num_rows' ), 10, 2 );
139 add_filter( 'mainwp_db_get_websites_for_current_user', array( &$this, 'db_get_websites_for_current_user' ), 10, 2 );
140
141 // Sync website.
142 add_filter( 'mainwp_sync_website', array( &$this, 'hook_sync_website' ), 10, 3 );
143
144 add_action( 'mainwp_secure_request', array( &$this, 'hook_secure_request' ), 10, 2 );
145 add_filter( 'mainwp_check_security_request', array( &$this, 'hook_check_security_request' ), 10, 3 );
146 add_filter( 'mainwp_notification_get_settings', array( &$this, 'get_notification_settings' ), 10, 2 );
147
148 add_filter( 'mainwp_send_wp_mail', array( &$this, 'hook_send_wp_mail' ), 10, 5 );
149 add_filter( 'mainwp_notification_get_template_content', array( &$this, 'hook_get_template_html' ), 10, 3 );
150 add_filter( 'mainwp_sitestable_getcolumns', array( $this, 'hook_atarim_default_sitestable_column' ), 10, 1 );
151 add_filter( 'mainwp_sitestable_item', array( $this, 'hook_atarim_manage_sites_default_item' ), 10, 1 );
152 add_filter( 'mainwp_monitoring_sitestable_getcolumns', array( $this, 'hook_atarim_default_sitestable_column' ), 10, 1 );
153 add_filter( 'mainwp_monitoring_sitestable_item', array( $this, 'hook_atarim_manage_sites_default_item' ), 10, 1 );
154 add_filter( 'mainwp_clients_get_website_client_tokens', array( &$this, 'hook_get_website_client_tokens' ), 10, 2 );
155 add_filter( 'mainwp_secure_get_download_sig', array( &$this, 'hook_get_download_sig' ), 10, 2 );
156 add_action( 'mainwp_secure_download', array( &$this, 'hook_secure_download' ), 10, 2 );
157 add_action( 'mainwp_ajax_add_action', array( &$this, 'hook_ajax_add_action' ), 10, 2 );
158 add_filter( 'mainwp_get_plugin_icon', array( &$this, 'hook_get_plugin_icon' ), 10, 2 );
159 add_filter( 'mainwp_get_theme_icon', array( &$this, 'hook_get_theme_icon' ), 10, 2 );
160 add_filter( 'mainwp_get_dir_slug', array( &$this, 'hook_get_dir_slug' ), 10, 2 );
161 add_action( 'mainwp_do_widget_boxes', array( &$this, 'hook_do_widget_boxes' ), 10, 3 );
162 add_action( 'mainwp_add_widget_box', array( &$this, 'hook_add_widget_box' ), 10, 6 );
163 add_action( 'mainwp_render_modal_upload_icon', array( &$this, 'hook_render_modal_upload_icon' ), 10, 2 );
164 add_action( 'mainwp_render_plugin_details_modal', array( &$this, 'hook_render_plugin_details_modal' ), 10, 2 );
165 add_action( 'mainwp_render_updates', array( &$this, 'hook_render_updates' ), 10, 2 );
166
167 /**
168 * Filter: mainwp_get_tokens_values
169 *
170 * Get tokens values for reports.
171 *
172 * @since 4.3.
173 */
174 add_filter( 'mainwp_get_reports_group_values_website', array( MainWP_Reports_Helper::get_instance(), 'hook_get_reports_group_values' ), 10, 6 );
175 }
176
177 /**
178 * Method mainwp_log_debug()
179 *
180 * MainWP debug log.
181 *
182 * @param string $text Debug text.
183 *
184 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
185 */
186 public function mainwp_log_debug( $text ) {
187 MainWP_Logger::instance()->debug( $text );
188 }
189
190 /**
191 * Method mainwp_log_info()
192 *
193 * MainWP log info.
194 *
195 * @param string $text Info Text.
196 *
197 * @uses \MainWP\Dashboard\MainWP_Logger::info()
198 */
199 public function mainwp_log_info( $text ) {
200 MainWP_Logger::instance()->info( $text );
201 }
202
203 /**
204 * Method mainwp_log_warning()
205 *
206 * MainWP log warning.
207 *
208 * @param string $text Warning text.
209 *
210 * @uses \MainWP\Dashboard\MainWP_Logger::warning()
211 */
212 public function mainwp_log_warning( $text ) {
213 MainWP_Logger::instance()->warning( $text );
214 }
215
216 /**
217 * Method mainwp_log_action()
218 *
219 * MainWP log action.
220 *
221 * @param string $text Debug text.
222 * @param int $priority priority.
223 * @param int $log_color Set color: 0 - LOG, 1 - WARNING, 2 - INFO, 3- DEBUG.
224 * @param bool $forced forced logging.
225 *
226 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
227 */
228 public function mainwp_log_action( $text, $priority = 0, $log_color = 0, $forced = false ) {
229 if ( ! empty( $priority ) ) {
230 MainWP_Logger::instance()->log_action( $text, $priority, $log_color, $forced );
231 }
232 }
233
234 /**
235 * Method mainwp_log_execution_time()
236 *
237 * MainWP log execution time.
238 *
239 * @param string $text Debug text.
240 *
241 * @uses \MainWP\Dashboard\MainWP_Logger::debug()
242 */
243 public function mainwp_log_execution_time( $text = '' ) {
244 MainWP_Logger::instance()->log_execution_time( $text );
245 }
246
247 /**
248 * Method enqueue_meta_boxes_scripts()
249 *
250 * Enqueue Scripts for all Meta boxes.
251 *
252 * @uses \MainWP\Dashboard\MainWP_System::enqueue_postbox_scripts()
253 */
254 public function enqueue_meta_boxes_scripts() {
255 MainWP_System::enqueue_postbox_scripts();
256 }
257
258 /**
259 * Method mainwp_add_site()
260 *
261 * Hook to add Child Site.
262 *
263 * @param array $params site data fields: url, name, wpadmin, unique_id, groupids, ssl_verify, ssl_version,
264 * http_user, http_pass, websiteid - if edit site.
265 *
266 * @return array $ret data fields: response, siteid.
267 *
268 * @throws \Exception Exception message.
269 *
270 * @since 3.2.2
271 *
272 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::update_wp_site()
273 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::add_wp_site()
274 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
275 */
276 public function mainwp_add_site( $params ) {
277 $ret = array();
278
279 if ( is_array( $params ) ) {
280 if ( isset( $params['websiteid'] ) && MainWP_Utility::ctype_digit( $params['websiteid'] ) ) {
281 $ret['siteid'] = MainWP_Manage_Sites_View::update_wp_site( $params );
282 return $ret;
283 } elseif ( isset( $params['url'] ) && isset( $params['wpadmin'] ) ) {
284 $website = MainWP_DB::instance()->get_websites_by_url( $params['url'] );
285 list( $message, $error, $site_id ) = MainWP_Manage_Sites_View::add_wp_site( $website, $params );
286
287 if ( '' !== $error ) {
288 return array( 'error' => $error );
289 }
290 $ret['response'] = $message;
291 $ret['siteid'] = $site_id;
292 }
293 }
294
295 return $ret;
296 }
297
298 /**
299 * Method hook_delete_site()
300 *
301 * Hook to delete Child Site.
302 *
303 * @param bool $site_id Child site ID.
304 *
305 * @return bool|array Return false if empty and return array error - Site not found | result - SUCCESS.
306 *
307 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system()
308 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_icons_dir()
309 */
310 public function hook_delete_site( $site_id = false ) {
311
312 if ( empty( $site_id ) ) {
313 return false;
314 }
315
316 $sql = MainWP_DB::instance()->get_sql_website_by_id( $site_id );
317 $websites = MainWP_DB::instance()->query( $sql );
318 $site = MainWP_DB::fetch_object( $websites );
319
320 if ( empty( $site ) ) {
321 return array( 'error' => esc_html__( 'Not found the website', 'mainwp' ) );
322 }
323 $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system();
324
325 /**
326 * WordPress files system object.
327 *
328 * @global object
329 */
330 global $wp_filesystem;
331
332 if ( $hasWPFileSystem ) {
333 $favi = MainWP_DB::instance()->get_website_option( $site, 'favi_icon', '' );
334 if ( ! empty( $favi ) && ( false !== strpos( $favi, 'favi-' . $site->id . '-' ) ) ) {
335 $dirs = MainWP_System_Utility::get_icons_dir();
336 if ( $wp_filesystem->exists( $dirs[0] . $favi ) ) {
337 $wp_filesystem->delete( $dirs[0] . $favi );
338 }
339 }
340 }
341
342 MainWP_DB::instance()->remove_website( $site->id );
343
344 /** This action is documented in pages\page-mainwp-manage-sites-handler.php */
345 do_action( 'mainwp_delete_site', $site );
346 return array( 'result' => 'SUCCESS' );
347 }
348
349 /**
350 * Method filter_clone_site()
351 *
352 * Hook to clone site.
353 *
354 * @since 3.4.4
355 * @param mixed $pluginFile Plugin file.
356 * @param mixed $key Key.
357 * @param mixed $websiteid Child site ID.
358 * @param mixed $cloneid Clone site ID.
359 * @param mixed $clone_url Clone site URL.
360 * @param bool $force_update Force the update, true|false, Default: false.
361 *
362 * @return array Site array to clone.
363 *
364 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_clone_site()
365 */
366 public function filter_clone_site( $pluginFile, $key, $websiteid, $cloneid, $clone_url, $force_update = false ) {
367 return MainWP_Extensions_Handler::hook_clone_site( $pluginFile, $key, $websiteid, $cloneid, $clone_url, $force_update );
368 }
369
370 /**
371 * Method filter_delete_clone_site()
372 *
373 * Hook to delete cloaned Child Site.
374 *
375 * @param mixed $pluginFile Plugin file.
376 * @param mixed $key Key.
377 * @param string $clone_url Clone site URL.
378 * @param bool $clone_site_id Clone site ID.
379 *
380 * @return array Site array to delete.
381 *
382 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_delete_clone_site()
383 */
384 public function filter_delete_clone_site( $pluginFile, $key, $clone_url = '', $clone_site_id = false ) {
385 return MainWP_Extensions_Handler::hook_delete_clone_site( $pluginFile, $key, $clone_url, $clone_site_id );
386 }
387
388 /**
389 * Method mainwp_edit_site()
390 *
391 * Hook to edit Child Site.
392 *
393 * @param array $params site data fields: websiteid, name, wpadmin, unique_id.
394 *
395 * @return array $ret Child site ID.
396 *
397 * @throws \Exception Exception message.
398 *
399 * @since 3.2.2
400 *
401 * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::update_wp_site()
402 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
403 */
404 public function mainwp_edit_site( $params ) {
405 $ret = array();
406 if ( is_array( $params ) ) {
407 if ( isset( $params['websiteid'] ) && MainWP_Utility::ctype_digit( $params['websiteid'] ) ) {
408 $ret['siteid'] = MainWP_Manage_Sites_View::update_wp_site( $params );
409 return $ret;
410 }
411 }
412 return $ret;
413 }
414
415 /**
416 * Method hook_add_sub_left_menu()
417 *
418 * Hook to add MainWP Left Menu item.
419 *
420 * @param string $title Menu title.
421 * @param string $slug Menu slug.
422 * @param string $href Menu link.
423 * @param integer $level Menu level.
424 * @param string $parent_key Parent menu.
425 *
426 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
427 */
428 public function hook_add_sub_left_menu( $title, $slug, $href, $level = 1, $parent_key = 'mainwp_tab' ) {
429 $item = array(
430 'title' => $title,
431 'parent_key' => $parent_key,
432 'slug' => $slug,
433 'href' => $href,
434 );
435 MainWP_Menu::add_left_menu( $item, $level );
436 }
437
438 /**
439 * Method is_extension_activated()
440 *
441 * Check for inactive MainWP Extensions.
442 *
443 * @param mixed $input Input value.
444 * @param mixed $slug MainWP Extension to check.
445 *
446 * @return bool Activation notice.
447 */
448 public function is_extension_activated( $input, $slug ) {
449 return MainWP_Extensions_Handler::is_extension_activated( $slug );
450 }
451
452 /**
453 * Method is_pro_member()
454 *
455 * Check for inactive MainWP Extensions.
456 *
457 * @param mixed $input Input value.
458 *
459 * @return bool Activation notice.
460 */
461 public function is_pro_member( $input = false ) {
462 $info = get_option( 'mainwp_extensions_plan_info' );
463 if ( ! empty( $info ) ) {
464 $info = json_decode( $info, true );
465 if ( is_array( $info ) && isset( $info['plan_purchased'] ) && isset( $info['plan_status'] ) ) {
466 if ( 'active' === $info['plan_status'] && in_array( $info['plan_purchased'], array( 'monthly', 'yearly', 'lifetime' ) ) ) {
467 return true;
468 }
469 }
470 }
471 return false;
472 }
473
474
475 /**
476 * Method get_activate_extension_notice()
477 *
478 * Check for inactive MainWP Extensions &
479 * return an activation warning message.
480 *
481 * @param mixed $pluginFile MainWP Extension to check.
482 *
483 * @return string Activation notice.
484 *
485 * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::is_extension_activated()
486 */
487 public function get_activate_extension_notice( $pluginFile ) {
488 $active = MainWP_Extensions_Handler::is_extension_activated( $pluginFile );
489 if ( $active ) {
490 return false;
491 }
492
493 $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
494 if ( is_array( $activate_notices ) ) {
495 $slug = basename( $pluginFile, '.php' );
496 if ( isset( $activate_notices[ $slug ] ) ) {
497 return false;
498 }
499 }
500
501 return sprintf( esc_html__( 'You have a MainWP extension that does not have an active API entered. This means you will not receive updates or support. Please visit the %1$sExtensions%2$s page and enter your API key.', 'mainwp' ), '<a href="admin.php?page=Extensions">', '</a>' );
502 }
503
504 /**
505 * Method cache_getcontext()
506 *
507 * Get cached search context for given page.
508 *
509 * @param string $page Current MainWP Page.
510 *
511 * @return array Cached Search Array.
512 */
513 public function cache_getcontext( $page ) {
514 return MainWP_Cache::get_cached_context( $page );
515 }
516
517 /**
518 * Method cache_echo_body()
519 *
520 * Echo Cached Search Body.
521 *
522 * @param string $page Current MainWP Page.
523 */
524 public function cache_echo_body( $page ) {
525 MainWP_Cache::echo_body( $page );
526 }
527
528 /**
529 * Method cache_init()
530 *
531 * Initiate search session variables for the current page.
532 *
533 * @param string $page Current MainWP Page.
534 */
535 public function cache_init( $page ) {
536 MainWP_Cache::init_cache( $page );
537 }
538
539 /**
540 * Method cache_add_context()
541 *
542 * Hook to add time & Search Context session variable.
543 *
544 * @param string $page Current MainWP Page.
545 * @param mixed $context Time of search.
546 */
547 public function cache_add_context( $page, $context ) {
548 MainWP_Cache::add_context( $page, $context );
549 }
550
551 /**
552 * Method cache_add_body()
553 *
554 * Hook to add Search Body Session variable.
555 *
556 * @param string $page Current MainWP Page.
557 * @param mixed $body Search body.
558 */
559 public function cache_add_body( $page, $body ) {
560 MainWP_Cache::add_body( $page, $body );
561 }
562
563 /**
564 * Method select_sites_box()
565 *
566 * Hook to select sites box.
567 *
568 * @param string $title Input title.
569 * @param string $type Input type, radio.
570 * @param bool $show_group Whether or not to show group, Default: true.
571 * @param bool $show_select_all Whether to show select all.
572 * @param string $class Default = ''.
573 * @param string $style Default = ''.
574 * @param array $selected_websites Selected Child Sites.
575 * @param array $selected_groups Selected Groups.
576 * @param bool $show_client Show Clients.
577 * @param array $selected_clients Selected Clients.
578 * @param mixed $post_id post ID.
579 */
580 public function select_sites_box( $title = '', $type = 'checkbox', $show_group = true, $show_select_all = true, $class = '', $style = '', $selected_websites = array(), $selected_groups = array(), $show_client = false, $selected_clients = array(), $post_id = false ) {
581 $sel_params = array(
582 'type' => $type,
583 'show_group' => $show_group,
584 'show_select_all' => $show_select_all,
585 'class' => $class,
586 'style' => $style,
587 'selected_sites' => $selected_websites,
588 'selected_groups' => $selected_groups,
589 'show_client' => $show_client,
590 'selected_clients' => $selected_clients,
591 'post_id' => $post_id,
592 );
593 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
594 }
595
596 /**
597 * Method hook_add_categories_box()
598 *
599 * General categories box.
600 *
601 * @param int $post_id Post ID.
602 */
603 public function hook_add_categories_box( $post_id = false ) {
604 MainWP_System::instance()->metaboxes->add_categories( $post_id );
605 }
606
607 /**
608 * Method hook_notify_user()
609 *
610 * Hook to send user a notification.
611 *
612 * @param int $userId User ID.
613 * @param string $subject Email Subject.
614 * @param string $content Email Content.
615 *
616 * @uses \MainWP\Dashboard\MainWP_Notification::send_notify_user()
617 */
618 public function hook_notify_user( $userId, $subject, $content ) {
619 MainWP_Notification::send_notify_user( $userId, $subject, $content );
620 }
621
622 /**
623 * Method get_error_message()
624 *
625 * Hook to get error message.
626 *
627 * @param object $msg Error message.
628 * @param object $extra HTTP error message.
629 *
630 * @return string Error message.
631 *
632 * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
633 */
634 public function get_error_message( $msg, $extra ) {
635 return MainWP_Error_Helper::get_error_message( new MainWP_Exception( $msg, $extra ) );
636 }
637
638 /**
639 * Method hook_get_user_extension()
640 *
641 * Hook to get user extension.
642 *
643 * @return object $row User extension.
644 */
645 public function hook_get_user_extension() {
646 return MainWP_DB_Common::instance()->get_user_extension();
647 }
648
649 /**
650 * Method update_user_extension()
651 *
652 * Hook to update user extension.
653 *
654 * @param bool $false input filter value.
655 * @param string $option_name option name.
656 * @param mixed $option_value option value.
657 *
658 * @return bool true.
659 */
660 public function update_user_extension( $false, $option_name, $option_value ) {
661 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
662 $userExtension->{$option_name} = wp_json_encode( $option_value );
663 MainWP_DB_Common::instance()->update_user_extension( $userExtension );
664 return true;
665 }
666
667 /**
668 * Method hook_get_site_options()
669 *
670 * Hook to get Child site options.
671 *
672 * @param mixed $boolean Boolean check.
673 * @param object $website Child site object.
674 * @param string|array $options Option table name.
675 *
676 * @return string|null Database query result (as string), or null on failure
677 */
678 public function hook_get_site_options( $boolean, $website, $options = '' ) {
679
680 if ( empty( $options ) ) {
681 return $boolean;
682 }
683
684 if ( is_string( $options ) ) {
685 return MainWP_DB::instance()->get_website_option( $website, $options );
686 } elseif ( is_array( $options ) ) {
687 return MainWP_DB::instance()->get_website_options_array( $website, $options );
688 }
689 return $boolean;
690 }
691
692 /**
693 * Method hook_update_site_options()
694 *
695 * Hook to get Child site options.
696 *
697 * @param mixed $boolean Boolean check.
698 * @param object $website Child site object.
699 * @param string $option Option name.
700 * @param string $value Option value.
701 *
702 * @return string|null Database query result (as string), or null on failure
703 */
704 public function hook_update_site_options( $boolean, $website, $option, $value ) {
705 if ( is_numeric( $website ) ) {
706 $obj = new \stdClass();
707 $obj->id = intval( $website );
708 $website = $obj;
709 } elseif ( ! is_object( $website ) || ! property_exists( $website, 'id' ) ) {
710 return false;
711 }
712 return MainWP_DB::instance()->update_website_option( $website, $option, $value );
713 }
714
715 /**
716 * Get sites by user ID.
717 *
718 * @param mixed $boolean Boolean check.
719 * @param int $userid User ID.
720 * @param bool $selectgroups Selected groups.
721 * @param null $search_site Site search field value.
722 * @param string $orderBy Order list by. Default: URL.
723 *
724 * @return object|null Database query results or null on failure.
725 */
726 public function hook_get_websites_by_user_id( $boolean, $userid, $selectgroups = false, $search_site = null, $orderBy = 'wp.url' ) {
727 return MainWP_DB::instance()->get_websites_by_user_id( $userid, $selectgroups, $search_site, $orderBy );
728 }
729
730 /**
731 * Get sites by website ID.
732 *
733 * @param mixed $boolean Boolean check.
734 * @param int $website_id User ID.
735 * @param bool $selectGroups Select groups.
736 * @param array $extra_view get extra option fields.
737 *
738 * @return object|null Database query results or null on failure.
739 */
740 public function hook_get_website_by_id( $boolean, $website_id, $selectGroups = false, $extra_view = array() ) {
741
742 if ( empty( $website_id ) ) {
743 return false;
744 }
745
746 $website = MainWP_DB::instance()->get_website_by_id( $website_id, $selectGroups, $extra_view );
747
748 if ( ! empty( $website ) && property_exists( $website, 'privkey' ) ) {
749 unset( $website->privkey );
750 }
751
752 if ( ! empty( $website ) && property_exists( $website, 'nosslkey' ) ) {
753 unset( $website->nosslkey );
754 }
755
756 return $website;
757 }
758
759
760 /**
761 * Method get_websites_by_url()
762 *
763 * Hook to get Child Site by URL.
764 *
765 * @param string $url Child Site URL.
766 *
767 * @return array|object|null Database query results.
768 */
769 public function get_websites_by_url( $url ) {
770 return MainWP_DB::instance()->get_websites_by_url( $url );
771 }
772
773 /**
774 * Method hook_get_all_posts()
775 * Hook to get posts from sites.
776 *
777 * @param object $sites Child Sites object.
778 * @param array $post_data with values: keyword, dtsstart, dtsstop, status, maxRecords, post_type.
779 *
780 * @return \stdClass $output All posts data array.
781 *
782 * @since 3.4.4
783 *
784 * @uses \MainWP\Dashboard\MainWP_Post::get_class_name()
785 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
786 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
787 */
788 public function hook_get_all_posts( $sites, $post_data = array() ) {
789
790 $dbwebsites = array();
791 $data = array( 'id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey', 'verify_certificate', 'http_user', 'http_pass', 'ssl_version' );
792
793 if ( '' !== $sites ) {
794 foreach ( $sites as $k => $v ) {
795 if ( MainWP_Utility::ctype_digit( $v ) ) {
796 $website = MainWP_DB::instance()->get_website_by_id( $v );
797 if ( '' == $website->sync_errors && ! MainWP_System_Utility::is_suspended_site( $website ) ) {
798 $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data );
799 }
800 }
801 }
802 }
803
804 $default_data = array(
805 'post_type' => 'post',
806 'status' => 'publish',
807 'maxRecords' => 10,
808 );
809
810 $post_data = array_merge( $default_data, $post_data );
811
812 $output = new \stdClass();
813 $output->results = array();
814 if ( $dbwebsites ) {
815 MainWP_Connect::fetch_urls_authed(
816 $dbwebsites,
817 'get_all_posts',
818 $post_data,
819 array(
820 MainWP_Post::get_class_name(),
821 'hook_posts_search_handler',
822 ),
823 $output,
824 $is_external_hook = true
825 );
826 }
827 return $output;
828 }
829
830 /**
831 * Method mainwp_current_user_have_right()
832 *
833 * Check permission level by hook mainwp_currentusercan of Team Control extension
834 *
835 * @param mixed $input Return value holder.
836 * @param string $can_type group or type of capabilities.
837 * @param string $which Which function to perform.
838 *
839 * @return bool $input Return true if the user can and false if they can not.
840 */
841 public function hook_current_user_can( $input, $can_type, $which ) {
842
843 if ( function_exists( 'mainwp_current_user_have_right' ) ) {
844 return mainwp_current_user_have_right( $can_type, $which );
845 }
846
847 return $input;
848 }
849
850 /**
851 * Method hook_escape_response()
852 *
853 * To escape response data.
854 *
855 * @param mixed $response response data.
856 * @param bool $fields fields of response data - option.
857 * @param array $more_allowed input allowed tags - option.
858 *
859 * @return mixed $response valid response data.
860 * @throws \Exception Exception message.
861 *
862 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
863 * @uses \MainWP\Dashboard\MainWP_Utility::esc_mixed_content()
864 */
865 public function hook_escape_response( $response, $fields = false, $more_allowed = array() ) {
866
867 if ( false === $fields || is_string( $response ) ) {
868 return MainWP_Utility::esc_content( $response );
869 }
870
871 if ( ! is_array( $fields ) ) {
872 return $response;
873 }
874
875 if ( ! in_array( 'error', $fields ) ) {
876 $fields[] = 'error'; // to sure to valid 'error' field, if that existed.
877 }
878
879 if ( ! in_array( 'message', $fields ) ) {
880 $fields[] = 'message'; // to sure to valid 'message' field, if that existed.
881 }
882
883 $depth = 10;
884
885 foreach ( $fields as $field ) {
886 if ( isset( $response[ $field ] ) ) {
887 $response[ $field ] = MainWP_Utility::esc_mixed_content( $response[ $field ], $depth, $more_allowed );
888 }
889 }
890 return $response;
891 }
892
893 /**
894 * Method hook_escape_content()
895 *
896 * To escape content.
897 *
898 * @param mixed $content response data.
899 * @param string $type content type for escape.
900 * @param array $more_allowed input allowed tags - option.
901 *
902 * @return mixed $response valid response data.
903 * @throws \Exception Exception message.
904 *
905 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
906 */
907 public function hook_escape_content( $content, $type = 'note', $more_allowed = array() ) {
908 return MainWP_Utility::esc_content( $content, $type, $more_allowed );
909 }
910
911
912 /**
913 * Method db_free_result()
914 *
915 * To escape response data.
916 *
917 * @param mixed $false input value.
918 * @param mixed $result result data.
919 *
920 * @return bool true.
921 */
922 public function db_free_result( $false, $result ) {
923 MainWP_DB::free_result( $result );
924 return true;
925 }
926
927 /**
928 * Method db_num_rows()
929 *
930 * To escape response data.
931 *
932 * @param mixed $false input value.
933 * @param mixed $result result data.
934 *
935 * @return bool true.
936 */
937 public function db_num_rows( $false, $result ) {
938 return MainWP_DB::num_rows( $result );
939 }
940
941
942 /**
943 * Method db_get_websites_for_current_user()
944 *
945 * To escape response data.
946 *
947 * @param mixed $false input value.
948 * @param array $params params data.
949 *
950 * @return mixed websites.
951 */
952 public function db_get_websites_for_current_user( $false = false, $params = array() ) {
953 if ( ! is_array( $params ) ) {
954 $params = array();
955 }
956
957 $orderBy = isset( $params['orderby'] ) ? MainWP_DB::instance()->escape( $params['orderby'] ) : 'wp.url';
958 $extra_view = isset( $params['extra_view'] ) ? $params['extra_view'] : array( 'favi_icon' );
959
960 if ( ! is_array( $extra_view ) ) {
961 $extra_view = array( 'favi_icon' );
962 }
963 return MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, $orderBy, false, false, null, false, $extra_view ) );
964 }
965
966
967 /**
968 * Method hook_sync_website()
969 *
970 * To escape response data.
971 *
972 * @param mixed $false input value.
973 * @param int $website_id Website ID.
974 * @param bool $fire_end_session to run the ending session or not.
975 *
976 * @return mixed websites.
977 */
978 public function hook_sync_website( $false, $website_id, $fire_end_session = true ) {
979 if ( empty( $website_id ) ) {
980 return $false;
981 }
982 $website = MainWP_DB::instance()->get_website_by_id( $website_id );
983 if ( empty( $website ) ) {
984 return $false;
985 }
986 return MainWP_Sync::sync_website( $website, $fire_end_session );
987 }
988
989 /**
990 * Method hook_db_data_seek()
991 *
992 * To escape response data.
993 *
994 * @param mixed $result result data.
995 * @param int $offset offset of data.
996 */
997 public function hook_db_data_seek( $result, $offset = 0 ) {
998 MainWP_DB::data_seek( $result, $offset );
999 }
1000
1001
1002 /**
1003 * Method hook_db_query()
1004 *
1005 * To query db.
1006 *
1007 * @param mixed $false filter input value.
1008 * @param string $sql result data.
1009 *
1010 * @return bool true.
1011 */
1012 public function hook_db_query( $false, $sql ) {
1013 return MainWP_DB::instance()->query( $sql );
1014 }
1015
1016 /**
1017 * Method db_fetch_object()
1018 *
1019 * To escape response data.
1020 *
1021 * @param mixed $false input value.
1022 * @param mixed $result result data.
1023 *
1024 * @return bool true.
1025 */
1026 public function db_fetch_object( $false, $result ) {
1027 return MainWP_DB::fetch_object( $result );
1028 }
1029
1030
1031 /**
1032 * Method db_fetch_array()
1033 *
1034 * To escape response data.
1035 *
1036 * @param mixed $false input value.
1037 * @param mixed $result result data.
1038 *
1039 * @return bool true.
1040 */
1041 public function db_fetch_array( $false, $result ) {
1042 return MainWP_DB::fetch_array( $result );
1043 }
1044
1045
1046 /**
1047 * Get notification email settings.
1048 *
1049 * @param string $settings hook settings input value.
1050 * @param string $type Notification type.
1051 *
1052 * @return array $gen_email_settings email settings.
1053 */
1054 public function get_notification_settings( $settings, $type ) {
1055 $gen_email_settings = MainWP_Notification_Settings::get_general_email_settings( $type );
1056 return $gen_email_settings;
1057 }
1058
1059 /**
1060 * Hook send_wp_mail().
1061 *
1062 * Send email via wp_mail().
1063 *
1064 * @param string $input hook input value.
1065 * @param string $email send to email.
1066 * @param string $subject email content.
1067 * @param bool $formated_content email content.
1068 * @param string $content_type Text format.
1069 */
1070 public function hook_send_wp_mail( $input, $email, $subject, $formated_content, $content_type = '' ) {
1071 return MainWP_Notification::send_wp_mail(
1072 $email,
1073 $subject,
1074 $formated_content,
1075 $content_type
1076 );
1077 }
1078
1079 /**
1080 * Hook get template HTML content.
1081 *
1082 * @param string $input hooks input value.
1083 * @param string $template_name Template name.
1084 * @param array $args Arguments. (default: array).
1085 *
1086 * @return string
1087 */
1088 public function hook_get_template_html( $input, $template_name, $args = array() ) {
1089 $mail_content = MainWP_Notification_Template::instance()->get_template_html(
1090 $template_name,
1091 $args
1092 );
1093 return $mail_content;
1094 }
1095
1096 /**
1097 * Method hook_secure_request()
1098 *
1099 * Security check to request parameter
1100 *
1101 * @param string $action Action to perform.
1102 * @param string $query_arg Query argument.
1103 *
1104 * @uses \MainWP\Dashboard\MainWP_Post_Handler::secure_request()
1105 */
1106 public function hook_secure_request( $action = '', $query_arg = 'security' ) {
1107 MainWP_Post_Handler::instance()->secure_request( $action, $query_arg );
1108 }
1109
1110 /**
1111 * Method hook_check_security_request()
1112 *
1113 * Security check to request parameter
1114 *
1115 * @param bool $false Input value.
1116 * @param string $action Action to perform.
1117 * @param string $query_arg Query argument.
1118 */
1119 public function hook_check_security_request( $false, $action = '', $query_arg = '' ) {
1120 if ( empty( $query_arg ) ) {
1121 $query_arg = $action; // to check wp_verify_nonce - sanitize_key( $_REQUEST[ $query_arg ] ) - $action.
1122 }
1123 return MainWP_Post_Handler::instance()->check_security( $action, $query_arg, false );
1124 }
1125
1126 /**
1127 * Method hook_get_mainwp_dir()
1128 *
1129 * Hook to get MainWP Directory.
1130 *
1131 * @param bool $false False.
1132 * @param null $dir WP files system diectories.
1133 * @param bool $direct_access Return true if Direct access file system. Default: false.
1134 *
1135 * @return array $newdir, $url.
1136 *
1137 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir()
1138 */
1139 public function hook_get_mainwp_dir( $false = false, $dir = null, $direct_access = false ) {
1140 return MainWP_System_Utility::get_mainwp_dir( $dir, $direct_access );
1141 }
1142
1143
1144 /**
1145 * Method is_multi_user()
1146 *
1147 * Hook to check if multi user.
1148 *
1149 * @return bool true|false.
1150 *
1151 * @uses \MainWP\Dashboard\MainWP_System::is_multi_user()
1152 */
1153 public function is_multi_user() {
1154 return MainWP_System::instance()->is_multi_user();
1155 }
1156
1157 /**
1158 * Method filter_qq2_file_uploader()
1159 *
1160 * Hook to create new MainWP_QQ2_File_Uploader() class.
1161 *
1162 * @param mixed $allowedExtensions Allowed files extentions.
1163 * @param mixed $sizeLimit Maximum file size allowed to be uploaded.
1164 *
1165 * @return MainWP_QQ2_File_Uploader Return instance of MainWP_QQ2_File_Uploader
1166 *
1167 * @uses \MainWP\Dashboard\MainWP_QQ2_File_Uploader
1168 */
1169 public function filter_qq2_file_uploader( $allowedExtensions, $sizeLimit ) {
1170 return new MainWP_QQ2_File_Uploader( $allowedExtensions, $sizeLimit );
1171 }
1172
1173 /**
1174 * Method get_metaboxes_post()
1175 *
1176 * Hook to get meta boxes.
1177 *
1178 * @return string|bool Return error or true.
1179 *
1180 * @uses \MainWP\Dashboard\MainWP_System::$metaboxes
1181 */
1182 public function get_metaboxes_post() {
1183 return MainWP_System::instance()->metaboxes;
1184 }
1185
1186 /**
1187 * Method hook_notification_email()
1188 *
1189 * Hook to get notification email.
1190 *
1191 * @return string Return email.
1192 */
1193 public function hook_notification_email() {
1194 return MainWP_Notification_Settings::get_general_email();
1195 }
1196
1197 /**
1198 * Method get_formated_email()
1199 *
1200 * Hook to format email.
1201 *
1202 * @param mixed $body Email body.
1203 * @param mixed $email Email address.
1204 * @param string $title Email title.
1205 *
1206 * @return string|bool Return error or true.
1207 *
1208 * @uses \MainWP\Dashboard\MainWP_Format::format_email()
1209 */
1210 public function get_formated_email( $body, $email, $title = '' ) {
1211 return MainWP_Format::format_email( $email, $body, $title );
1212 }
1213
1214 /**
1215 * Method active_plugin()
1216 *
1217 * Hook to activate plugins.
1218 *
1219 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::activate_plugins()
1220 */
1221 public function active_plugin() {
1222 MainWP_Plugins_Handler::activate_plugins();
1223 die();
1224 }
1225
1226 /**
1227 * Method deactive_plugin()
1228 *
1229 * Hook to deactivate plugins.
1230 *
1231 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::deactivate_plugins()
1232 */
1233 public function deactive_plugin() {
1234 MainWP_Plugins_Handler::deactivate_plugins();
1235 die();
1236 }
1237
1238 /**
1239 * Method delete_plugin()
1240 *
1241 * Hook to delete plugins.
1242 *
1243 * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::delete_plugins()
1244 */
1245 public function delete_plugin() {
1246 MainWP_Plugins_Handler::delete_plugins();
1247 die();
1248 }
1249
1250 /**
1251 * Method delete_theme()
1252 *
1253 * Hook to delete theme()
1254 *
1255 * @uses \MainWP\Dashboard\MainWP_Themes_Handler::delete_themes()
1256 */
1257 public function delete_theme() {
1258 MainWP_Themes_Handler::delete_themes();
1259 die();
1260 }
1261
1262 /**
1263 * Method upgrade_wp()
1264 *
1265 * Hook to upgrade WP.
1266 */
1267 public function upgrade_wp() {
1268
1269 if ( ! mainwp_current_user_have_right( 'dashboard', 'update_wordpress' ) ) {
1270 die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( esc_html__( 'update WordPress', 'mainwp' ), $echo = false ) ) ) );
1271 }
1272
1273 try {
1274 $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : false;
1275 die( wp_json_encode( array( 'result' => MainWP_Updates_Handler::upgrade_site( $id ) ) ) ); // ok.
1276 } catch ( MainWP_Exception $e ) {
1277 die(
1278 wp_json_encode(
1279 array(
1280 'error' => array(
1281 'message' => $e->getMessage(),
1282 'extra' => $e->get_message_extra(),
1283 ),
1284 )
1285 )
1286 );
1287 }
1288
1289 die();
1290 }
1291
1292 /**
1293 * Method upgrade_plugin_theme()
1294 *
1295 * Hook to update theme.
1296 *
1297 * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
1298 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1299 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
1300 */
1301 public function upgrade_plugin_theme() {
1302 try {
1303 $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : null;
1304 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : null;
1305 $slugs = isset( $_POST['slugs'] ) && is_array( $_POST['slugs'] ) ? wp_unslash( $_POST['slugs'] ) : array();
1306 $error = '';
1307 $erCode = '';
1308
1309 if ( 'plugin' === $type && ! mainwp_current_user_have_right( 'dashboard', 'update_plugins' ) ) {
1310 $error = mainwp_do_not_have_permissions( esc_html__( 'update plugins', 'mainwp' ), false );
1311 } elseif ( 'theme' === $type && ! mainwp_current_user_have_right( 'dashboard', 'update_themes' ) ) {
1312 $error = mainwp_do_not_have_permissions( esc_html__( 'update themes', 'mainwp' ), false );
1313 }
1314
1315 $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
1316
1317 if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
1318 $error = esc_html__( 'Suspended site.', 'mainwp' );
1319 $erCode = 'SUSPENDED_SITE';
1320 }
1321
1322 if ( ! empty( $error ) ) {
1323 wp_send_json(
1324 array(
1325 'error' => $error,
1326 'errorCode' => $erCode,
1327 )
1328 );
1329 }
1330
1331 if ( MainWP_Utility::ctype_digit( $websiteId ) ) {
1332 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
1333 /**
1334 * Action: mainwp_before_plugin_theme_translation_update
1335 *
1336 * Fires before plugin/theme/translation update actions.
1337 *
1338 * @since 4.1
1339 */
1340 do_action( 'mainwp_before_plugin_theme_translation_update', $type, implode( ',', $slugs ), $website );
1341
1342 $information = MainWP_Connect::fetch_url_authed(
1343 $website,
1344 'upgradeplugintheme',
1345 array(
1346 'type' => $type,
1347 'list' => urldecode( implode( ',', $slugs ) ),
1348 )
1349 );
1350
1351 /**
1352 * Action: mainwp_after_plugin_theme_translation_update
1353 *
1354 * Fires before plugin/theme/translation update actions.
1355 *
1356 * @since 4.1
1357 */
1358 do_action( 'mainwp_after_plugin_theme_translation_update', $information, $type, implode( ',', $slugs ), $website );
1359
1360 if ( isset( $information['sync'] ) ) {
1361 unset( $information['sync'] );
1362 }
1363
1364 wp_send_json( $information );
1365 }
1366 }
1367 } catch ( MainWP_Exception $e ) {
1368 die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) );
1369 }
1370
1371 die();
1372 }
1373
1374 /**
1375 * Method hook_get_websites_by_group_ids()
1376 *
1377 * Hook to get Child Sites by group ID.
1378 *
1379 * @param mixed $ids Group IDs.
1380 * @param null $userId Current user ID.
1381 *
1382 * @return (object|null) Database query result for get Child Sites by group ID or null on failure.
1383 */
1384 public function hook_get_websites_by_group_ids( $ids, $userId = null ) {
1385 return MainWP_DB::instance()->get_websites_by_group_ids( $ids, $userId );
1386 }
1387
1388 /**
1389 * Method hook_posts_get_edit()
1390 *
1391 * Get and create post to edit.
1392 *
1393 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
1394 */
1395 public function hook_posts_get_edit() {
1396 MainWP_Post_Page_Handler::get_post();
1397 die();
1398 }
1399
1400 /**
1401 * Method hook_posts_bulk_posting()
1402 *
1403 * Post Bulk posting.
1404 *
1405 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
1406 */
1407 public function hook_posts_bulk_posting() {
1408 $post_id = isset( $_POST['post_id'] ) && $_POST['post_id'] ? intval( $_POST['post_id'] ) : false;
1409 if ( $post_id ) {
1410 MainWP_Post_Page_Handler::posting_posts( $post_id, 'ajax_posting' );
1411 }
1412 die();
1413 }
1414
1415 /**
1416 * Method hook_atarim_default_sitestable_column()
1417 *
1418 * @param mixed $columns columns data.
1419 *
1420 * Hook Atarim default column.
1421 */
1422 public function hook_atarim_default_sitestable_column( $columns ) {
1423 if ( ! is_plugin_active( 'mainwp-atarim-extension/mainwp-atarim-extension.php' ) ) {
1424 $columns['atarim_tasks'] = esc_html__( 'Atarim', 'mainwp-atarim-extension' );
1425 }
1426 return $columns;
1427 }
1428
1429 /**
1430 * Method hook_atarim_manage_sites_default_item()
1431 *
1432 * @param mixed $item item row data.
1433 *
1434 * Hook Atarim manage sites default item.
1435 */
1436 public function hook_atarim_manage_sites_default_item( $item ) {
1437 if ( ! is_plugin_active( 'mainwp-atarim-extension/mainwp-atarim-extension.php' ) ) {
1438 if ( is_array( $item ) && isset( $item['url'] ) ) {
1439 $collaborate_link = 'https://app.atarim.io/fetching/?_from=mainwp&url=' . $item['url'];
1440 $item['atarim_tasks'] = '<a href="' . $collaborate_link . '" target="_balnk" data-tooltip="Collaborate on this website." data-inverted="" data-position="left center"><span class="ui blue icon label"><i class="comments icon"></i></span></a>';
1441 }
1442 }
1443 return $item;
1444 }
1445
1446 /**
1447 * Method hook_get_website_client_tokens()
1448 *
1449 * Hook get client tokens.
1450 *
1451 * @param mixed $false input filter value.
1452 * @param int $websiteid Website ID.
1453 *
1454 * @return mixed $result Result of tokens.
1455 */
1456 public function hook_get_website_client_tokens( $false, $websiteid = false ) {
1457 $client_tokens = MainWP_Client_Handler::instance()->get_website_client_tokens_data( $websiteid );
1458
1459 if ( false === $client_tokens ) {
1460 return $false;
1461 }
1462
1463 return $client_tokens;
1464 }
1465
1466 /**
1467 * Method hook_get_download_sig()
1468 *
1469 * Hook get download sig.
1470 *
1471 * @param string $false Input value.
1472 * @param string $fullfile Full file path.
1473 *
1474 * @return string
1475 */
1476 public function hook_get_download_sig( $false, $fullfile ) {
1477 return MainWP_System_Utility::get_download_sig( $fullfile );
1478 }
1479
1480 /**
1481 * Method hook_download_valid_sig().
1482 *
1483 * Hook get download sig.
1484 *
1485 * @param string $fullfile Full file path.
1486 * @param string $sig sig value.
1487 */
1488 public function hook_secure_download( $fullfile, $sig ) {
1489 $valid = MainWP_System_Utility::valid_download_sig( $fullfile, $sig );
1490 if ( ! $valid ) {
1491 wp_die( 'Invalid download.' );
1492 }
1493 }
1494
1495 /**
1496 * Method hook_ajax_add_action().
1497 *
1498 * Hook add ajax action.
1499 *
1500 * @param string $action action name.
1501 * @param string $callback callback function.
1502 */
1503 public function hook_ajax_add_action( $action, $callback ) {
1504 MainWP_Post_Handler::instance()->add_action( $action, $callback );
1505 }
1506
1507 /**
1508 * Method hook_get_plugin_icon().
1509 *
1510 * Hook get plugin icon.
1511 *
1512 * @param mixed $icon input icon.
1513 * @param string $slug Plugin slug.
1514 */
1515 public function hook_get_plugin_icon( $icon, $slug ) {
1516 return MainWP_System_Utility::get_plugin_icon( $slug );
1517 }
1518
1519 /**
1520 * Method hook_get_theme_icon().
1521 *
1522 * Hook get theme icon.
1523 *
1524 * @param mixed $icon input icon.
1525 * @param string $slug Theme slug.
1526 */
1527 public function hook_get_theme_icon( $icon, $slug ) {
1528 return MainWP_System_Utility::get_theme_icon( $slug );
1529 }
1530 /**
1531 * Method hook_get_dir_slug().
1532 *
1533 * Hook get dir slug of plugin/theme.
1534 *
1535 * @param mixed $input input value.
1536 * @param string $slug Plugin/Theme slug.
1537 */
1538 public function hook_get_dir_slug( $input, $slug ) {
1539 return MainWP_Utility::get_dir_slug( $slug );
1540 }
1541
1542 /**
1543 * Method hook_do_widget_boxes()
1544 *
1545 * Customize WordPress do_meta_boxes() function.
1546 *
1547 * @param mixed $screen Current page.
1548 * @param string|null $context right|null. If 3 columns then = 'middle'.
1549 * @param string $object Empty string.
1550 *
1551 * @return void Renders widget container box.
1552 */
1553 public function hook_do_widget_boxes( $screen, $context = null, $object = '' ) {
1554 MainWP_UI::do_widget_boxes( $screen, $context, $object );
1555 }
1556
1557
1558 /**
1559 * Method hook_add_widget_box()
1560 *
1561 * Hook add MainWP meta box.
1562 *
1563 * @param mixed $id Widget ID parameter.
1564 * @param mixed $callback Callback function.
1565 * @param null $screen Current page.
1566 * @param string|null $context right|null. If 3 columns then = 'middle'.
1567 * @param null $title Widget title.
1568 * @param string $priority high|core|default|low, Default: default.
1569 *
1570 * @return void Sets Global $mainwp_widget_boxes[ $page ][ $context ][ $priority ][ $id ].
1571 *
1572 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_page_id()
1573 */
1574 public function hook_add_widget_box( $id, $callback, $screen = null, $context = null, $title = null, $priority = 'default' ) {
1575 MainWP_UI::add_widget_box( $id, $callback, $screen, $context, $title, $priority );
1576 }
1577
1578 /**
1579 * Method hook_render_modal_upload_icon()
1580 *
1581 * Render modal window for upload plugins & themes icon.
1582 */
1583 public function hook_render_modal_upload_icon() {
1584 MainWP_UI::render_modal_upload_icon();
1585 }
1586
1587 /**
1588 * Method hook_render_plugin_details_modal()
1589 *
1590 * Render modal window plugin details.
1591 */
1592 public function hook_render_plugin_details_modal() {
1593 MainWP_Updates::render_plugin_details_modal();
1594 }
1595
1596 /**
1597 * Method hook_render_plugin_details_modal()
1598 *
1599 * Render modal window plugin details.
1600 */
1601 public function hook_render_updates() {
1602 MainWP_Updates::render();
1603 }
1604 }
1605