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

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