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

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