PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0
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 5.0, at class/class-mainwp-hooks.php

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