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