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.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 5.2.1 All 155 releases
← All changes | class/class-mainwp-post-handler.php +1972 -1296 5.0.3.1 → 6.2.1 View file →
@@ -6,8 +6,18 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +use MainWP\Dashboard\Module\Log\Log_DB_Helper;
11 +use MainWP\Dashboard\Module\Log\Log_Changes_Logs_Helper;
12 +
13 +// Exit if accessed directly.
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit;
16 +}
17 +
18 +// phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
19 +
10 20 /**
11 21 * Class MainWP_Post_Handler
12 22 *
13 23 * @package MainWP\Dashboard
@@ -13,1447 +23,2113 @@
13 23 * @package MainWP\Dashboard
14 24 *
15 25 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
16 26 */
17 -class MainWP_Post_Handler extends MainWP_Post_Base_Handler {
27 +class MainWP_Post_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore -- NOSONAR - Complex.
18 28
19 - // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated.
29 + /**
30 + * Private static variable to hold the single instance of the class.
31 + *
32 + * @static
33 + *
34 + * @var mixed Default null
35 + */
36 + private static $instance = null;
20 37
21 - /**
22 - * Private static variable to hold the single instance of the class.
23 - *
24 - * @static
25 - *
26 - * @var mixed Default null
27 - */
28 - private static $instance = null;
38 + /**
39 + * Method instance()
40 + *
41 + * Create a public static instance.
42 + *
43 + * @static
44 + * @return MainWP_Post_Handler
45 + */
46 + public static function instance() {
47 + if ( null === static::$instance ) {
48 + static::$instance = new self();
49 + }
50 + return static::$instance;
51 + }
29 52
30 - /**
31 - * Method instance()
32 - *
33 - * Create a public static instance.
34 - *
35 - * @static
36 - * @return MainWP_Post_Handler
37 - */
38 - public static function instance() {
39 - if ( null === self::$instance ) {
40 - self::$instance = new self();
41 - }
42 - return self::$instance;
43 - }
53 + /**
54 + * Initiate all actions.
55 + *
56 + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name()
57 + */
58 + public function init() {
59 + // Page: ManageSites.
60 + $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
44 61
45 - /**
46 - * Initiate all actions.
47 - *
48 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name()
49 - */
50 - public function init() {
51 - // Page: ManageSites.
52 - $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
62 + // Page: BulkAddUser.
63 + $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
64 + $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
53 65
54 - // Page: BulkAddUser.
55 - $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
56 - $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
66 + // Widget: RightNow.
67 + $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
57 68
58 - // Widget: RightNow.
59 - $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
69 + if ( \mainwp_current_user_can( 'dashboard', 'manage_security_issues' ) ) {
70 + // Page: SecurityIssues.
71 + $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) );
72 + $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) );
73 + $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) );
74 + }
60 75
61 - if ( mainwp_current_user_have_right( 'dashboard', 'manage_security_issues' ) ) {
62 - // Page: SecurityIssues.
63 - $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) );
64 - $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) );
65 - $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) );
66 - }
76 + $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
77 + $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) );
78 + $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) );
79 + $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
80 + $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
81 + $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
82 + $this->add_action( 'mainwp_guided_tours_option_update', array( &$this, 'ajax_guided_tours_option_update' ) );
83 + $this->add_action( 'mainwp_help_modal_content_update', array( &$this, 'ajax_mainwp_help_modal_content_update' ) );
84 + $this->add_action( 'mainwp_widgets_connections_status_details_display_rows', array( MainWP_Connection_Status::instance(), 'ajax_display_rows' ) );
67 85
68 - $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
69 - $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) );
70 - $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) );
71 - $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
72 - $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
73 - $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
74 - $this->add_action( 'mainwp_guided_tours_option_update', array( &$this, 'ajax_guided_tours_option_update' ) );
86 + // Page: Recent Posts.
87 + if ( \mainwp_current_user_can( 'dashboard', 'manage_posts' ) ) {
88 + $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
89 + $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
90 + $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
91 + $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
92 + $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
93 + $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
94 + }
95 + $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) );
96 + // Page: Pages.
97 + if ( \mainwp_current_user_can( 'dashboard', 'manage_pages' ) ) {
98 + $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
99 + $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
100 + $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
101 + $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
102 + $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
103 + }
104 + // Page: Users.
105 + $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
106 + $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
107 + $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
108 + $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
75 109
76 - // Page: Recent Posts.
77 - if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
78 - $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
79 - $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
80 - $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
81 - $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
82 - $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
83 - $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
84 - }
85 - $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) );
86 - // Page: Pages.
87 - if ( mainwp_current_user_have_right( 'dashboard', 'manage_pages' ) ) {
88 - $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
89 - $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
90 - $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
91 - $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
92 - $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
93 - }
94 - // Page: Users.
95 - $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
96 - $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
97 - $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
98 - $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
110 + // Page: Posts.
111 + $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) );
112 + $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) );
113 + $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
114 + $this->add_action( 'mainwp_post_postingbulk', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_posting_posts' ) );
115 + $this->add_action( 'mainwp_get_sites_of_groups', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_get_sites_of_groups' ) );
99 116
100 - // Page: Posts.
101 - $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) );
102 - $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) );
103 - $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
104 - $this->add_action( 'mainwp_post_postingbulk', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_posting_posts' ) );
105 - $this->add_action( 'mainwp_get_sites_of_groups', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_get_sites_of_groups' ) );
117 + // Page: Pages.
118 + $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) );
119 + // Page: User.
120 + $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
106 121
107 - // Page: Pages.
108 - $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) );
109 - // Page: User.
110 - $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
122 + $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
123 + $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
124 + $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
125 + $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
126 + $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
127 + $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
128 + $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) );
129 + $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
130 + $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
131 + $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) );
132 + $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) );
111 133
112 - $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
113 - $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
114 - $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
115 - $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
116 - $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
117 - $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
118 - $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) );
119 - $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
120 - $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
121 - $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) );
122 - $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) );
134 + $this->add_action_nonce( 'mainwp-common-nonce' );
123 135
124 - $this->add_action_nonce( 'mainwp-common-nonce' );
136 + // Page: Clients.
137 + $this->add_action( 'mainwp_clients_add_client', array( &$this, 'mainwp_clients_add_client' ) );
138 + $this->add_action( 'mainwp_clients_delete_client', array( &$this, 'mainwp_clients_delete_client' ) );
125 139
126 - // Page: Clients.
127 - $this->add_action( 'mainwp_clients_add_client', array( &$this, 'mainwp_clients_add_client' ) );
128 - $this->add_action( 'mainwp_clients_delete_client', array( &$this, 'mainwp_clients_delete_client' ) );
140 + $this->add_action( 'mainwp_clients_save_field', array( &$this, 'mainwp_clients_save_field' ) );
141 + $this->add_action( 'mainwp_clients_delete_general_field', array( &$this, 'mainwp_clients_delete_general_field' ) );
142 + $this->add_action( 'mainwp_clients_bulk_delete_fields', array( &$this, 'mainwp_clients_bulk_delete_fields' ) );
143 + $this->add_action( 'mainwp_clients_delete_field', array( &$this, 'mainwp_clients_delete_field' ) );
144 + $this->add_action( 'mainwp_clients_notes_save', array( &$this, 'mainwp_clients_notes_save' ) );
145 + $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
146 + $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
147 + $this->add_action( 'mainwp_upload_custom_icon', array( &$this, 'ajax_upload_custom_icon' ) );
148 + $this->add_action( 'mainwp_select_custom_theme', array( &$this, 'ajax_select_custom_theme' ) );
149 + $this->add_action( 'mainwp_import_demo_data', array( &$this, 'ajax_import_demo_data' ) );
150 + $this->add_action( 'mainwp_delete_demo_data', array( &$this, 'ajax_delete_demo_data' ) );
151 + $this->add_action( 'mainwp_prepare_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_prepare_renew_connections' ) );
152 + $this->add_action( 'mainwp_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_renew_connections' ) );
129 153
130 - $this->add_action( 'mainwp_clients_save_field', array( &$this, 'mainwp_clients_save_field' ) );
131 - $this->add_action( 'mainwp_clients_delete_general_field', array( &$this, 'mainwp_clients_delete_general_field' ) );
132 - $this->add_action( 'mainwp_clients_delete_field', array( &$this, 'mainwp_clients_delete_field' ) );
133 - $this->add_action( 'mainwp_clients_notes_save', array( &$this, 'mainwp_clients_notes_save' ) );
134 - $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
135 - $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
136 - $this->add_action( 'mainwp_upload_custom_icon', array( &$this, 'ajax_upload_custom_icon' ) );
137 - $this->add_action( 'mainwp_select_custom_theme', array( &$this, 'ajax_select_custom_theme' ) );
138 - $this->add_action( 'mainwp_site_actions_dismiss', array( &$this, 'ajax_site_actions_dismiss' ) );
139 - $this->add_action( 'mainwp_delete_non_mainwp_actions', array( &$this, 'ajax_delete_non_mainwp_actions' ) );
140 - $this->add_action( 'mainwp_import_demo_data', array( &$this, 'ajax_import_demo_data' ) );
141 - $this->add_action( 'mainwp_delete_demo_data', array( &$this, 'ajax_delete_demo_data' ) );
142 - $this->add_action( 'mainwp_prepare_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_prepare_renew_connections' ) );
143 - $this->add_action( 'mainwp_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_renew_connections' ) );
144 - }
154 + $this->add_action( 'mainwp_clients_check_client', array( &$this, 'mainwp_clients_check_client' ) );
155 + $this->add_action( 'mainwp_clients_import_client', array( &$this, 'mainwp_clients_import_client' ) );
145 156
146 - /**
147 - * Method add_post_action()
148 - *
149 - * Add ajax action.
150 - *
151 - * @param string $action Action to perform.
152 - * @param string $callback Callback to perform.
153 - */
154 - public function add_post_action( $action, $callback ) {
155 - $this->add_action( $action, $callback );
156 - }
157 + // Page: managesites.
158 + $this->add_action( 'mainwp_save_temp_import_website', array( &$this, 'ajax_save_temp_import_website' ) );
159 + $this->add_action( 'mainwp_delete_temp_import_website', array( &$this, 'ajax_delete_temp_import_website' ) );
160 + $this->add_action( 'mainwp_import_website_add_client', array( &$this, 'ajax_import_website_add_client' ) );
161 + $this->add_action( 'mainwp_import_website_add_client_no_site', array( &$this, 'ajax_import_website_add_client_no_site' ) );
157 162
158 - /**
159 - * Method mainwp_installation_warning_hide()
160 - *
161 - * Hide the installation warning.
162 - */
163 - public function mainwp_installation_warning_hide() {
164 - $this->secure_request( 'mainwp_installation_warning_hide' );
163 + // Page:: mainwp-setup.
164 + $this->add_action( 'mainwp_clients_add_multi_client', array( &$this, 'ajax_clients_add_multi_client' ) );
165 + $this->add_action( 'mainwp_increase_connection_security', array( &$this, 'ajax_increase_connection_security' ) );
166 + $this->add_action( 'mainwp_qsw_ui_mode_detected', array( &$this, 'ajax_ui_mode_detected' ) );
165 167
166 - update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
167 - die( 'ok' );
168 - }
168 + $this->add_action( 'mainwp_changes_logs_get_item_changes', array( &$this, 'ajax_get_item_changes_logs' ) );
169 + }
169 170
170 - /**
171 - * Method mainwp_users_search()
172 - *
173 - * Search Post handler,
174 - * Page: User.
175 - *
176 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
177 - * @uses \MainWP\Dashboard\MainWP_User::render_table()
178 - */
179 - public function mainwp_users_search() {
180 - $this->secure_request( 'mainwp_users_search' );
181 - MainWP_Cache::init_session();
171 + /**
172 + * Method add_post_action()
173 + *
174 + * Add ajax action.
175 + *
176 + * @param string $action Action to perform.
177 + * @param string $callback Callback to perform.
178 + */
179 + public function add_post_action( $action, $callback ) {
180 + $this->add_action( $action, $callback );
181 + }
182 182
183 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
184 - $role = isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : '';
185 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
186 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
187 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
188 - $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
189 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
190 - MainWP_User::render_table( false, $role, $groups, $sites, $search, $clients );
191 - die();
192 - }
183 + /**
184 + * Method mainwp_installation_warning_hide()
185 + *
186 + * Hide the installation warning.
187 + */
188 + public function mainwp_installation_warning_hide() {
189 + $this->secure_request( 'mainwp_installation_warning_hide' );
193 190
194 - /**
195 - * Method mainwp_posts_search()
196 - *
197 - * Search Post handler,
198 - * Page: Posts.
199 - *
200 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
201 - * @uses \MainWP\Dashboard\MainWP_Post::render_table()
202 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
203 - */
204 - public function mainwp_posts_search() { // phpcs:ignore -- complex.
205 - $this->secure_request( 'mainwp_posts_search' );
206 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
207 - $post_type = ( isset( $_POST['post_type'] ) && 0 < strlen( sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' );
208 - if ( isset( $_POST['maximum'] ) ) {
209 - MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
210 - }
211 - $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
212 - $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstart'] ) ) ) : '';
213 - $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstop'] ) ) ) : '';
214 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
215 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
216 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
217 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
218 - $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : '';
219 - $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : '';
220 - $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
221 - $table_content_only = isset( $_POST['table_content'] ) && wp_unslash( $_POST['table_content'] ) ? true : false;
222 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
191 + update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
192 + die( 'ok' );
193 + }
223 194
224 - MainWP_Cache::init_session();
225 - if ( $table_content_only ) {
226 - MainWP_Post::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, true, $clients );
227 - } else {
228 - MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, $clients );
229 - }
230 - die();
231 - }
232 - /**
233 - * Method mainwp_pages_search()
234 - *
235 - * Search Post handler,
236 - * Page: Pages.
237 - *
238 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
239 - * @uses \MainWP\Dashboard\MainWP_Page::render_table()
240 - *
241 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
242 - */
243 - public function mainwp_pages_search() {
244 - $this->secure_request( 'mainwp_pages_search' );
245 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
246 - if ( isset( $_POST['maximum'] ) ) {
247 - MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
248 - }
249 - $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
250 - $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
251 - $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
252 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
253 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
254 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
255 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
256 - $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
257 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
258 - MainWP_Cache::init_session();
259 - MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $search_on, $clients );
260 - die();
261 - }
195 + /**
196 + * Method mainwp_users_search()
197 + *
198 + * Search Post handler,
199 + * Page: User.
200 + *
201 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
202 + * @uses \MainWP\Dashboard\MainWP_User::render_table()
203 + */
204 + public function mainwp_users_search() {
205 + $this->secure_request( 'mainwp_users_search' );
206 + MainWP_Cache::init_session();
262 207
263 - /**
264 - * Method mainwp_get_categories()
265 - *
266 - * Get post/page categories.
267 - *
268 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories()
269 - */
270 - public function mainwp_get_categories() {
271 - $this->secure_request( 'mainwp_get_categories' );
272 - MainWP_Post_Page_Handler::ajax_handle_get_categories();
273 - die();
274 - }
208 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
209 + $role = isset( $_POST['urole'] ) ? sanitize_text_field( wp_unslash( $_POST['urole'] ) ) : '';
210 + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
211 + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
212 + $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
213 + $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
214 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
215 + MainWP_User::render_table( false, $role, $groups, $sites, $search, $clients );
216 + session_write_close();
217 + die();
218 + }
275 219
276 - /**
277 - * Method mainwp_post_get_edit()
278 - *
279 - * Get post to edit.
280 - *
281 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
282 - */
283 - public function mainwp_post_get_edit() {
284 - $this->secure_request( 'mainwp_post_get_edit' );
285 - MainWP_Post_Page_Handler::get_post();
286 - die();
287 - }
220 + /**
221 + * Method mainwp_posts_search()
222 + *
223 + * Search Post handler,
224 + * Page: Posts.
225 + *
226 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
227 + * @uses \MainWP\Dashboard\MainWP_Post::render_table()
228 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
229 + */
230 + public function mainwp_posts_search() { // phpcs:ignore -- NOSONAR - complex.
231 + $this->secure_request( 'mainwp_posts_search' );
232 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
233 + $post_type = ( isset( $_POST['post_type'] ) && 0 < strlen( sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' );
234 + if ( isset( $_POST['maximum'] ) ) {
235 + MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
236 + }
237 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
238 + $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstart'] ) ) ) : '';
239 + $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstop'] ) ) ) : '';
240 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
241 + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
242 + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
243 + $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
244 + $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : '';
245 + $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : '';
246 + $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
247 + $table_content_only = isset( $_POST['table_content'] ) && wp_unslash( $_POST['table_content'] ) ? true : false;
248 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
288 249
289 - /**
290 - * Method mainwp_user_delete()
291 - *
292 - * Delete User from Child Site,
293 - * Page: Users.
294 - *
295 - * @uses \MainWP\Dashboard\MainWP_User::delete()
296 - */
297 - public function mainwp_user_delete() {
298 - $this->secure_request( 'mainwp_user_delete' );
299 - MainWP_User::delete();
300 - }
250 + MainWP_Cache::init_session();
251 + if ( $table_content_only ) {
252 + MainWP_Post::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, true, $clients );
253 + } else {
254 + $params = array(
255 + 'groups' => $groups,
256 + 'sites' => $sites,
257 + 'postId' => $postId,
258 + 'userId' => $userId,
259 + 'post_type' => $post_type,
260 + 'search_on' => $search_on,
261 + 'clients' => $clients,
262 + );
263 + MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
264 + }
265 + die();
266 + }
267 + /**
268 + * Method mainwp_pages_search()
269 + *
270 + * Search Post handler,
271 + * Page: Pages.
272 + *
273 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
274 + * @uses \MainWP\Dashboard\MainWP_Page::render_table()
275 + *
276 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
277 + */
278 + public function mainwp_pages_search() {
279 + $this->secure_request( 'mainwp_pages_search' );
280 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
281 + if ( isset( $_POST['maximum'] ) ) {
282 + MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
283 + }
284 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
285 + $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
286 + $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
287 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
288 + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
289 + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
290 + $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
291 + $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
292 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
293 + MainWP_Cache::init_session();
301 294
302 - /**
303 - * Method mainwp_user_edit()
304 - *
305 - * Edit User from Child Site,
306 - * Page: Users.
307 - *
308 - * @uses \MainWP\Dashboard\MainWP_User::edit()
309 - */
310 - public function mainwp_user_edit() {
311 - $this->secure_request( 'mainwp_user_edit' );
312 - MainWP_User::edit();
313 - }
295 + $params = array(
296 + 'groups' => $groups,
297 + 'sites' => $sites,
298 + 'search_on' => $search_on,
299 + 'clients' => $clients,
300 + );
314 301
315 - /**
316 - * Method mainwp_user_update_password(
317 - *
318 - * Update User password from Child Site,
319 - * Page: Users.
320 - *
321 - * @uses \MainWP\Dashboard\MainWP_User::update_password()
322 - */
323 - public function mainwp_user_update_password() {
324 - $this->secure_request( 'mainwp_user_update_password' );
325 - MainWP_User::update_password();
326 - }
302 + MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
303 + die();
304 + }
327 305
328 - /**
329 - * Method mainwp_user_update_user()
330 - *
331 - * Update User from Child Site,
332 - * Page: Users.
333 - *
334 - * @uses \MainWP\Dashboard\MainWP_User::update_user()
335 - */
336 - public function mainwp_user_update_user() {
337 - $this->secure_request( 'mainwp_user_update_user' );
338 - MainWP_User::update_user();
339 - }
306 + /**
307 + * Method mainwp_get_categories()
308 + *
309 + * Get post/page categories.
310 + *
311 + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories()
312 + */
313 + public function mainwp_get_categories() {
314 + $this->secure_request( 'mainwp_get_categories' );
315 + MainWP_Post_Page_Handler::ajax_handle_get_categories();
316 + die();
317 + }
340 318
341 - /**
342 - * Method mainwp_post_unpublish()
343 - *
344 - * Unpublish post from Child Site,
345 - * Page: Recent Posts.
346 - *
347 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish()
348 - */
349 - public function mainwp_post_unpublish() {
350 - $this->secure_request( 'mainwp_post_unpublish' );
351 - MainWP_Recent_Posts::unpublish();
352 - }
319 + /**
320 + * Method mainwp_post_get_edit()
321 + *
322 + * Get post to edit.
323 + *
324 + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
325 + */
326 + public function mainwp_post_get_edit() {
327 + $this->secure_request( 'mainwp_post_get_edit' );
328 + MainWP_Post_Page_Handler::get_post();
329 + die();
330 + }
353 331
354 - /**
355 - * Method mainwp_post_publish()
356 - *
357 - * Publish post on Child Site,
358 - * Page: Recent Posts.
359 - *
360 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish()
361 - */
362 - public function mainwp_post_publish() {
363 - $this->secure_request( 'mainwp_post_publish' );
364 - MainWP_Recent_Posts::publish();
365 - }
332 + /**
333 + * Method mainwp_user_delete()
334 + *
335 + * Delete User from Child Site,
336 + * Page: Users.
337 + *
338 + * @uses \MainWP\Dashboard\MainWP_User::delete()
339 + */
340 + public function mainwp_user_delete() {
341 + $this->secure_request( 'mainwp_user_delete' );
342 + MainWP_User::delete();
343 + }
366 344
367 - /**
368 - * Method mainwp_post_approve()
369 - *
370 - * Approve post on Child Site,
371 - * Page: Recent Posts.
372 - *
373 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve()
374 - */
375 - public function mainwp_post_approve() {
376 - $this->secure_request( 'mainwp_post_approve' );
377 - MainWP_Recent_Posts::approve();
378 - }
345 + /**
346 + * Method mainwp_user_edit()
347 + *
348 + * Edit User from Child Site,
349 + * Page: Users.
350 + *
351 + * @uses \MainWP\Dashboard\MainWP_User::edit()
352 + */
353 + public function mainwp_user_edit() {
354 + $this->secure_request( 'mainwp_user_edit' );
355 + MainWP_User::edit();
356 + }
379 357
380 - /**
381 - * Method mainwp_post_trash()
382 - *
383 - * Trash post on Child Site,
384 - * Page: Recent Posts.
385 - *
386 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash()
387 - */
388 - public function mainwp_post_trash() {
389 - $this->secure_request( 'mainwp_post_trash' );
358 + /**
359 + * Method mainwp_user_update_password(
360 + *
361 + * Update User password from Child Site,
362 + * Page: Users.
363 + *
364 + * @uses \MainWP\Dashboard\MainWP_User::update_password()
365 + */
366 + public function mainwp_user_update_password() {
367 + $this->secure_request( 'mainwp_user_update_password' );
368 + MainWP_User::update_password();
369 + }
390 370
391 - MainWP_Recent_Posts::trash();
392 - }
371 + /**
372 + * Method mainwp_user_update_user()
373 + *
374 + * Update User from Child Site,
375 + * Page: Users.
376 + *
377 + * @uses \MainWP\Dashboard\MainWP_User::update_user()
378 + */
379 + public function mainwp_user_update_user() {
380 + $this->secure_request( 'mainwp_user_update_user' );
381 + MainWP_User::update_user();
382 + }
393 383
394 - /**
395 - * Method mainwp_post_delete()
396 - *
397 - * Delete post on Child Site,
398 - * Page: Recent Posts.
399 - *
400 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete()
401 - */
402 - public function mainwp_post_delete() {
403 - $this->secure_request( 'mainwp_post_delete' );
384 + /**
385 + * Method mainwp_post_unpublish()
386 + *
387 + * Unpublish post from Child Site,
388 + * Page: Recent Posts.
389 + *
390 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish()
391 + */
392 + public function mainwp_post_unpublish() {
393 + $this->secure_request( 'mainwp_post_unpublish' );
394 + MainWP_Recent_Posts::unpublish();
395 + }
404 396
405 - MainWP_Recent_Posts::delete();
406 - }
397 + /**
398 + * Method mainwp_post_publish()
399 + *
400 + * Publish post on Child Site,
401 + * Page: Recent Posts.
402 + *
403 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish()
404 + */
405 + public function mainwp_post_publish() {
406 + $this->secure_request( 'mainwp_post_publish' );
407 + MainWP_Recent_Posts::publish();
408 + }
407 409
408 - /**
409 - * Method mainwp_post_restore()
410 - *
411 - * Restore post,
412 - * Page: Recent Posts.
413 - *
414 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore()
415 - */
416 - public function mainwp_post_restore() {
417 - $this->secure_request( 'mainwp_post_restore' );
410 + /**
411 + * Method mainwp_post_approve()
412 + *
413 + * Approve post on Child Site,
414 + * Page: Recent Posts.
415 + *
416 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve()
417 + */
418 + public function mainwp_post_approve() {
419 + $this->secure_request( 'mainwp_post_approve' );
420 + MainWP_Recent_Posts::approve();
421 + }
418 422
419 - MainWP_Recent_Posts::restore();
420 - }
423 + /**
424 + * Method mainwp_post_trash()
425 + *
426 + * Trash post on Child Site,
427 + * Page: Recent Posts.
428 + *
429 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash()
430 + */
431 + public function mainwp_post_trash() {
432 + $this->secure_request( 'mainwp_post_trash' );
421 433
422 - /**
423 - * Method mainwp_page_unpublish()
424 - *
425 - * Unpublish page,
426 - * Page: Recent Pages.
427 - *
428 - * @uses \MainWP\Dashboard\MainWP_Page::unpublish()
429 - */
430 - public function mainwp_page_unpublish() {
431 - $this->secure_request( 'mainwp_page_unpublish' );
432 - MainWP_Page::unpublish();
433 - }
434 + MainWP_Recent_Posts::trash();
435 + }
434 436
435 - /**
436 - * Method mainwp_page_publish()
437 - *
438 - * Publish page,
439 - * Page: Recent Pages.
440 - *
441 - * @uses \MainWP\Dashboard\MainWP_Page::publish()
442 - */
443 - public function mainwp_page_publish() {
444 - $this->secure_request( 'mainwp_page_publish' );
445 - MainWP_Page::publish();
446 - }
437 + /**
438 + * Method mainwp_post_delete()
439 + *
440 + * Delete post on Child Site,
441 + * Page: Recent Posts.
442 + *
443 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete()
444 + */
445 + public function mainwp_post_delete() {
446 + $this->secure_request( 'mainwp_post_delete' );
447 447
448 - /**
449 - * Method mainwp_page_trash()
450 - *
451 - * Trash page,
452 - * Page: Recent Pages.
453 - *
454 - * @uses \MainWP\Dashboard\MainWP_Page::trash()
455 - */
456 - public function mainwp_page_trash() {
457 - $this->secure_request( 'mainwp_page_trash' );
458 - MainWP_Page::trash();
459 - }
448 + MainWP_Recent_Posts::delete();
449 + }
460 450
461 - /**
462 - * Method mainwp_page_delete()
463 - *
464 - * Delete page,
465 - * Page: Recent Pages.
466 - *
467 - * @uses \MainWP\Dashboard\MainWP_Page::delete()
468 - */
469 - public function mainwp_page_delete() {
470 - $this->secure_request( 'mainwp_page_delete' );
471 - MainWP_Page::delete();
472 - }
451 + /**
452 + * Method mainwp_post_restore()
453 + *
454 + * Restore post,
455 + * Page: Recent Posts.
456 + *
457 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore()
458 + */
459 + public function mainwp_post_restore() {
460 + $this->secure_request( 'mainwp_post_restore' );
473 461
474 - /**
475 - * Method mainwp_page_restor()
476 - *
477 - * Restore page,
478 - * Page: Recent Pages.
479 - *
480 - * @uses \MainWP\Dashboard\MainWP_Page::restore()
481 - */
482 - public function mainwp_page_restore() {
483 - $this->secure_request( 'mainwp_page_restore' );
484 - MainWP_Page::restore();
485 - }
462 + MainWP_Recent_Posts::restore();
463 + }
486 464
487 - /**
488 - * Method mainwp_notice_status_update()
489 - *
490 - * Hide after installation notices,
491 - * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
492 - *
493 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
494 - */
495 - public function mainwp_notice_status_update() {
496 - $this->secure_request( 'mainwp_notice_status_update' );
465 + /**
466 + * Method mainwp_page_unpublish()
467 + *
468 + * Unpublish page,
469 + * Page: Recent Pages.
470 + *
471 + * @uses \MainWP\Dashboard\MainWP_Page::unpublish()
472 + */
473 + public function mainwp_page_unpublish() {
474 + $this->secure_request( 'mainwp_page_unpublish' );
475 + MainWP_Page::unpublish();
476 + }
497 477
498 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
499 - $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
500 - if ( 'mail_failed' === $no_id ) {
501 - MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
502 - die( 'ok' );
503 - }
478 + /**
479 + * Method mainwp_page_publish()
480 + *
481 + * Publish page,
482 + * Page: Recent Pages.
483 + *
484 + * @uses \MainWP\Dashboard\MainWP_Page::publish()
485 + */
486 + public function mainwp_page_publish() {
487 + $this->secure_request( 'mainwp_page_publish' );
488 + MainWP_Page::publish();
489 + }
504 490
505 - /**
506 - * Current user global.
507 - *
508 - * @global string
509 - */
510 - global $current_user;
511 - $user_id = $current_user->ID;
512 - if ( $user_id ) {
513 - $status = get_user_option( 'mainwp_notice_saved_status' );
514 - if ( ! is_array( $status ) ) {
515 - $status = array();
516 - }
517 - if ( ! empty( $no_id ) ) {
518 - $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
519 - if ( $time_set ) {
520 - $status[ $no_id ] = time();
521 - } else {
522 - $status[ $no_id ] = 1;
523 - }
524 - update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
525 - }
526 - }
527 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
528 - die( 1 );
529 - }
491 + /**
492 + * Method mainwp_page_trash()
493 + *
494 + * Trash page,
495 + * Page: Recent Pages.
496 + *
497 + * @uses \MainWP\Dashboard\MainWP_Page::trash()
498 + */
499 + public function mainwp_page_trash() {
500 + $this->secure_request( 'mainwp_page_trash' );
501 + MainWP_Page::trash();
502 + }
530 503
531 - /**
532 - * Method mainwp_status_saving()
533 - *
534 - * Save last_sync_sites time() or mainwp_status_saved_values.
535 - */
536 - public function mainwp_status_saving() {
537 - $this->secure_request( 'mainwp_status_saving' );
538 - $values = get_option( 'mainwp_status_saved_values' );
504 + /**
505 + * Method mainwp_page_delete()
506 + *
507 + * Delete page,
508 + * Page: Recent Pages.
509 + *
510 + * @uses \MainWP\Dashboard\MainWP_Page::delete()
511 + */
512 + public function mainwp_page_delete() {
513 + $this->secure_request( 'mainwp_page_delete' );
514 + MainWP_Page::delete();
515 + }
539 516
540 - if ( ! is_array( $values ) ) {
541 - $values = array();
542 - }
517 + /**
518 + * Method mainwp_page_restor()
519 + *
520 + * Restore page,
521 + * Page: Recent Pages.
522 + *
523 + * @uses \MainWP\Dashboard\MainWP_Page::restore()
524 + */
525 + public function mainwp_page_restore() {
526 + $this->secure_request( 'mainwp_page_restore' );
527 + MainWP_Page::restore();
528 + }
543 529
544 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
545 - if ( ! isset( $_POST['status'] ) ) {
546 - die( -1 );
547 - }
530 + /**
531 + * Method mainwp_notice_status_update()
532 + *
533 + * Hide after installation notices,
534 + * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
535 + *
536 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
537 + */
538 + public function mainwp_notice_status_update() {
539 + $this->secure_request( 'mainwp_notice_status_update' );
548 540
549 - if ( 'save_indicator_values' === $_POST['status'] ) {
541 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
542 + $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
550 543
551 - if ( ! empty( $_POST['name'] ) ) {
552 - $current_values = is_array( $values ) && isset( $values['save_indicator_values'] ) && ! empty( $values['save_indicator_values'] ) ? json_decode( $values['save_indicator_values'], true ) : array();
553 - if ( ! is_array( $current_values ) ) {
554 - $current_values = array();
555 - }
556 - $current_values[ sanitize_text_field( wp_unslash( $_POST['name'] ) ) ] = isset( $_POST['value'] ) ? intval( wp_unslash( $_POST['value'] ) ) : 0;
544 + if ( ! empty( $_POST['short_term'] ) ) {
545 + if ( empty( $no_id ) ) {
546 + die( 'invalid' );
547 + }
557 548
558 - $values['save_indicator_values'] = wp_json_encode( $current_values );
559 - update_option( 'mainwp_status_saved_values', $values );
560 - die( 'ok' );
561 - }
562 - die( 'failed' );
563 - }
549 + $keys = explode( ';', $no_id );
550 + foreach ( $keys as $key ) {
551 + MainWP_Utility::dismiss_short_term_notice( $key );
552 + }
553 + die( 'dismissed' );
554 + }
564 555
565 - if ( 'last_sync_sites' === $_POST['status'] ) {
566 - if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
567 - update_option( 'mainwp_last_synced_all_sites', time() );
556 + if ( 'mail_failed' === $no_id ) {
557 + MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
558 + die( 'ok' );
559 + }
568 560
569 - /**
570 - * Action: mainwp_synced_all_sites
571 - *
572 - * Fires upon successfull synchronization process.
573 - *
574 - * @since 3.5.1
575 - */
576 - do_action( 'mainwp_synced_all_sites' );
577 - }
578 - die( 'ok' );
579 - }
561 + if ( 'phpver_8_0' === $no_id ) {
562 + MainWP_Utility::update_user_option( 'lasttime_hidden_phpver_8_0', time() );
563 + }
580 564
581 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
582 - $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
583 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
565 + $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
566 + $this->hide_dashboard_notice_status( $no_id, $time_set );
567 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
568 + die( 1 );
569 + }
584 570
585 - if ( ! empty( $status ) ) {
586 - if ( empty( $value ) ) {
587 - if ( isset( $values[ $status ] ) ) {
588 - unset( $values[ $status ] );
589 - }
590 - } else {
591 - $values[ $status ] = $value;
592 - }
593 - update_option( 'mainwp_status_saved_values', $values );
594 - }
571 + /**
572 + * Method hide dashboard notice status.
573 + *
574 + * @param mixed $no_id notice id.
575 + * @param mixed $time_set time.
576 + * @param bool $hide_noti hide notice.
577 + * @return void
578 + */
579 + public function hide_dashboard_notice_status( $no_id, $time_set = false, $hide_noti = true ) { //phpcs:ignore -- NOSONAR - complexity.
580 + /**
581 + * Current user global.
582 + *
583 + * @global string
584 + */
585 + global $current_user;
586 + $user_id = $current_user->ID;
587 + if ( $user_id ) {
588 + $status = get_user_option( 'mainwp_notice_saved_status' );
589 + if ( ! is_array( $status ) ) {
590 + $status = array();
591 + }
592 + if ( ! empty( $no_id ) ) {
593 + if ( 'mainwp_secure_priv_key_notice' === $no_id ) {
594 + MainWP_Utility::update_option( 'mainwp_not_start_encrypt_keys', 1 ); // to show the button.
595 + }
596 + if ( $hide_noti ) {
597 + if ( $time_set ) {
598 + $status[ $no_id ] = time();
599 + } else {
600 + $status[ $no_id ] = 1;
601 + }
602 + } elseif ( ! empty( $status[ $no_id ] ) ) {
603 + unset( $status[ $no_id ] );
604 + }
605 + update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
606 + }
607 + }
608 + }
595 609
596 - die( 'ok' );
597 - }
610 + /**
611 + * Method mainwp_status_saving()
612 + *
613 + * Save last_sync_sites time().
614 + */
615 + public function mainwp_status_saving() { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
616 + $this->secure_request( 'mainwp_status_saving' );
617 + $values = get_option( 'mainwp_status_saved_values' );
598 618
599 - /**
600 - * Method ajax_widget_order()
601 - *
602 - * Update saved widget order.
603 - */
604 - public function ajax_widgets_order() {
619 + if ( ! is_array( $values ) ) {
620 + $values = array();
621 + }
605 622
606 - $this->secure_request( 'mainwp_widgets_order' );
607 - $user = wp_get_current_user();
608 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
609 - if ( $user && ! empty( $_POST['page'] ) ) {
610 - $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
611 - $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
612 - $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
623 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
624 + if ( ! isset( $_POST['status'] ) ) {
625 + die( -1 );
626 + }
613 627
614 - $wgs_orders = array();
628 + if ( 'last_sync_sites' === $_POST['status'] ) {
629 + if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
630 + update_option( 'mainwp_last_synced_all_sites', time() );
615 631
616 - if ( ! empty( $wgids ) ) {
617 - $wgids = json_decode( $wgids, true );
618 - $order = json_decode( $order, true );
619 - if ( is_array( $wgids ) && is_array( $order ) ) {
620 - foreach ( $wgids as $idx => $wgid ) {
621 - if ( isset( $order[ $idx ] ) ) {
622 - $pre = 'widget-';
623 - if ( 0 === strpos( $wgid, $pre ) ) {
624 - $wgid = substr( $wgid, strlen( $pre ) );
625 - }
626 - $wgs_orders[ $wgid ] = $order[ $idx ];
627 - }
628 - }
629 - }
630 - }
632 + /**
633 + * Action: mainwp_synced_all_sites
634 + *
635 + * Fires upon successfull synchronization process.
636 + *
637 + * @since 3.5.1
638 + */
639 + do_action( 'mainwp_synced_all_sites' );
640 + }
641 + die( 'ok' );
642 + }
631 643
632 - if ( 'mainwp_page_manageclients' === $page ) {
633 - $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
634 - $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
635 - if ( ! empty( $sorted_array ) ) {
636 - $sorted_array = json_decode( $sorted_array, true );
637 - }
638 - if ( ! is_array( $sorted_array ) ) {
639 - $sorted_array = array();
640 - }
641 - $sorted_array[ $item_id ] = $wgs_orders;
642 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
643 - } else {
644 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
645 - }
646 - die( 'ok' );
647 - }
648 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
649 - die( -1 );
650 - }
644 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
645 + $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
646 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
651 647
652 - /**
653 - * Method ajax_mainwp_save_settings()
654 - *
655 - * Update saved MainWP Settings.
656 - *
657 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
658 - */
659 - public function ajax_mainwp_save_settings() {
660 - $this->secure_request( 'mainwp_save_settings' );
661 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
662 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
663 - if ( ! empty( $name ) ) {
664 - $option_name = 'mainwp_' . $name;
665 - $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
666 - MainWP_Utility::update_option( $option_name, $val );
667 - }
668 - // phpcs:enable
669 - die( 'ok' );
670 - }
648 + if ( ! empty( $status ) ) {
649 + if ( empty( $value ) ) {
650 + if ( isset( $values[ $status ] ) ) {
651 + unset( $values[ $status ] );
652 + }
653 + } else {
654 + $values[ $status ] = $value;
655 + }
656 + update_option( 'mainwp_status_saved_values', $values );
657 + }
671 658
672 - /**
673 - * Method ajax_guided_tours_option_update()
674 - *
675 - * Update saved MainWP Settings.
676 - *
677 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
678 - */
679 - public function ajax_guided_tours_option_update() {
680 - $this->secure_request( 'mainwp_guided_tours_option_update' );
681 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
682 - $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
683 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
684 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
685 - die( 'ok' );
686 - }
659 + die( 'ok' );
660 + }
687 661
688 - /**
689 - * Method mainwp_leftmenu_filter_group()
690 - *
691 - * MainWP left menu filter by group.
692 - *
693 - * @uses \MainWP\Dashboard\MainWP_DB::query()
694 - * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
695 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
696 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
697 - */
698 - public function mainwp_leftmenu_filter_group() {
699 - $this->secure_request( 'mainwp_leftmenu_filter_group' );
662 + /**
663 + * Method ajax_widget_order()
664 + *
665 + * Update saved widget order.
666 + */
667 + public function ajax_widgets_order() { //phpcs:ignore -- NOSONAR - complex.
700 668
701 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
702 - $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
703 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
669 + $this->secure_request( 'mainwp_widgets_order' );
670 + $user = wp_get_current_user();
671 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
672 + if ( $user && ! empty( $_POST['page'] ) ) {
673 + $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
674 + $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
675 + $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
676 + $page_widget = isset( $_POST['page_widget'] ) ? sanitize_text_field( wp_unslash( $_POST['page_widget'] ) ) : '';
704 677
705 - if ( ! empty( $gid ) ) {
706 - $ids = '';
707 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
708 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
709 - $ids .= $website->id . ',';
710 - }
711 - MainWP_DB::free_result( $websites );
712 - $ids = rtrim( $ids, ',' );
713 - die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
714 - }
715 - die( '' );
716 - }
678 + $wgs_orders = array();
717 679
718 - /**
719 - * Method dismiss_activate_notice()
720 - *
721 - * Dismiss activate notice.
722 - */
723 - public function dismiss_activate_notice() {
724 - $this->secure_request( 'mainwp_dismiss_activate_notice' );
680 + if ( ! empty( $wgids ) ) {
681 + $wgids = json_decode( $wgids, true );
682 + $order = json_decode( $order, true );
683 + if ( is_array( $wgids ) && is_array( $order ) ) {
684 + foreach ( $wgids as $idx => $wgid ) {
685 + if ( isset( $order[ $idx ] ) ) {
686 + $pre = 'widget-'; // #compatible-widgetid.
687 + if ( 0 === strpos( $wgid, $pre ) ) {
688 + $wgid = substr( $wgid, strlen( $pre ) );
689 + }
690 + $wgs_orders[ $wgid ] = $order[ $idx ];
691 + }
692 + }
693 + }
694 + }
725 695
726 - /**
727 - * Current user global.
728 - *
729 - * @global string
730 - */
731 - global $current_user;
732 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
733 - $user_id = $current_user->ID;
734 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
735 - if ( $user_id && ! empty( $slug ) ) {
736 - $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
737 - if ( ! is_array( $activate_notices ) ) {
738 - $activate_notices = array();
739 - }
696 + if ( 'mainwp_page_manageclients' === $page ) {
697 + $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
698 + $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
699 + if ( ! empty( $sorted_array ) ) {
700 + $sorted_array = json_decode( $sorted_array, true );
701 + }
702 + if ( ! is_array( $sorted_array ) ) {
703 + $sorted_array = array();
704 + }
705 + $sorted_array[ $item_id ] = $wgs_orders;
706 + update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
707 + } else {
708 + update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
709 + }
710 + MainWP_Cache_Warm_Helper::invalidate_manage_pages( array( $page_widget ) );
711 + die( 'ok' );
712 + }
713 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
714 + die( -1 );
715 + }
740 716
741 - $activate_notices[ $slug ] = time();
742 - update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
743 - }
744 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
745 - die( 1 );
746 - }
717 + /**
718 + * Method ajax_mainwp_save_settings()
719 + *
720 + * Update saved MainWP Settings.
721 + *
722 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
723 + */
724 + public function ajax_mainwp_save_settings() {
725 + $this->secure_request( 'mainwp_save_settings' );
726 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
727 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
728 + if ( ! empty( $name ) ) {
729 + $option_name = 'mainwp_' . $name;
730 + $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
731 + MainWP_Utility::update_option( $option_name, $val );
732 + }
733 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
734 + die( 'ok' );
735 + }
747 736
737 + /**
738 + * Method ajax_guided_tours_option_update()
739 + *
740 + * Update saved MainWP Settings.
741 + *
742 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
743 + */
744 + public function ajax_guided_tours_option_update() {
745 + $this->secure_request( 'mainwp_guided_tours_option_update' );
746 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
747 + $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
748 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
749 + MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
750 + die( 'ok ' . intval( $enable ) );
751 + }
748 752
753 + /**
754 + * Method mainwp_help_modal_content_update()
755 + *
756 + * Update saved MainWP Settings.
757 + *
758 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
759 + */
760 + public function ajax_mainwp_help_modal_content_update() {
761 + $this->secure_request( 'mainwp_help_modal_content_update' );
762 + MainWP_Utility::update_option( 'mainwp_enable_guided_tours', ( int)$_POST['enable_tour'] ); //phpcs:ignore -- NOSONAR verify.
763 + MainWP_Utility::update_option( 'mainwp_enable_guided_video', (int)$_POST['enable_video'] ); //phpcs:ignore -- NOSONAR verify.
764 + MainWP_Utility::update_option( 'mainwp_enable_guided_chatbase', (int)$_POST['enable_chatbase'] ); //phpcs:ignore -- NOSONAR verify.
765 + die( 'ok' );
766 + }
749 767
750 - /**
751 - * Method mainwp_security_issues_request()
752 - *
753 - * Post handler for,
754 - * Page: SecurityIssues.
755 - *
756 - * @uses \MainWP\Dashboard\MainWP_Exception
757 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
758 - */
759 - public function mainwp_security_issues_request() {
760 - $this->secure_request( 'mainwp_security_issues_request' );
768 + /**
769 + * Method mainwp_leftmenu_filter_group()
770 + *
771 + * MainWP left menu filter by group.
772 + *
773 + * @uses \MainWP\Dashboard\MainWP_DB::query()
774 + * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
775 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
776 + * @uses \MainWP\Dashboard\MainWP_DB::free_result()
777 + */
778 + public function mainwp_leftmenu_filter_group() {
779 + $this->secure_request( 'mainwp_leftmenu_filter_group' );
761 780
762 - try {
763 - wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
764 - } catch ( MainWP_Exception $e ) {
765 - die(
766 - wp_json_encode(
767 - array(
768 - 'error' => array(
769 - 'message' => $e->getMessage(),
770 - 'extra' => $e->get_message_extra(),
771 - ),
772 - )
773 - )
774 - );
775 - }
776 - }
781 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
782 + $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
783 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
777 784
778 - /**
779 - * Method mainwp_security_issues_fix()
780 - *
781 - * Post handler for 'fix issues',
782 - * Page: SecurityIssues.
783 - *
784 - * @uses \MainWP\Dashboard\MainWP_Exception
785 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
786 - */
787 - public function mainwp_security_issues_fix() {
788 - $this->secure_request( 'mainwp_security_issues_fix' );
785 + if ( ! empty( $gid ) ) {
786 + $ids = '';
787 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
788 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
789 + $ids .= $website->id . ',';
790 + }
791 + MainWP_DB::free_result( $websites );
792 + $ids = rtrim( $ids, ',' );
793 + die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
794 + }
795 + die( '' );
796 + }
789 797
790 - try {
791 - wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
792 - } catch ( MainWP_Exception $e ) {
793 - die(
794 - wp_json_encode(
795 - array(
796 - 'error' => array(
797 - 'message' => $e->getMessage(),
798 - 'extra' => $e->get_message_extra(),
799 - ),
800 - )
801 - )
802 - );
803 - }
804 - }
798 + /**
799 + * Method dismiss_activate_notice()
800 + *
801 + * Dismiss activate notice.
802 + */
803 + public function dismiss_activate_notice() {
804 + $this->secure_request( 'mainwp_dismiss_activate_notice' );
805 805
806 - /**
807 - * Method mainwp_security_issues_unfix()
808 - *
809 - * Post handler for 'unfix issues',
810 - * Page: SecurityIssues.
811 - *
812 - * @uses \MainWP\Dashboard\MainWP_Exception
813 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
814 - */
815 - public function mainwp_security_issues_unfix() {
816 - $this->secure_request( 'mainwp_security_issues_unfix' );
806 + /**
807 + * Current user global.
808 + *
809 + * @global string
810 + */
811 + global $current_user;
812 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
813 + $user_id = $current_user->ID;
814 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
815 + if ( $user_id && ! empty( $slug ) ) {
816 + $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
817 + if ( ! is_array( $activate_notices ) ) {
818 + $activate_notices = array();
819 + }
817 820
818 - try {
819 - wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
820 - } catch ( MainWP_Exception $e ) {
821 - die(
822 - wp_json_encode(
823 - array(
824 - 'error' => array(
825 - 'message' => $e->getMessage(),
826 - 'extra' => $e->get_message_extra(),
827 - ),
828 - )
829 - )
830 - );
831 - }
832 - }
821 + $activate_notices[ $slug ] = time();
822 + update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
823 + }
824 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
825 + die( 1 );
826 + }
833 827
834 - /**
835 - * Method ajax_disconnect_site()
836 - *
837 - * Disconnect Child Site.
838 - *
839 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
840 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
841 - */
842 - public function ajax_disconnect_site() {
843 - $this->secure_request( 'mainwp_disconnect_site' );
844 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
845 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
846 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
847 828
848 - if ( empty( $siteid ) ) {
849 - die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
850 - }
851 829
852 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
830 + /**
831 + * Method mainwp_security_issues_request()
832 + *
833 + * Post handler for,
834 + * Page: SecurityIssues.
835 + *
836 + * @uses \MainWP\Dashboard\MainWP_Exception
837 + * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
838 + */
839 + public function mainwp_security_issues_request() {
840 + $this->secure_request( 'mainwp_security_issues_request' );
853 841
854 - if ( ! $website ) {
855 - die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
856 - }
842 + try {
843 + wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
844 + } catch ( MainWP_Exception $e ) {
845 + die(
846 + wp_json_encode(
847 + array(
848 + 'error' => array(
849 + 'message' => $e->getMessage(),
850 + 'extra' => $e->get_message_extra(),
851 + ),
852 + )
853 + )
854 + );
855 + }
856 + }
857 857
858 - try {
859 - $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
860 - } catch ( \Exception $e ) {
861 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
862 - }
858 + /**
859 + * Method mainwp_security_issues_fix()
860 + *
861 + * Post handler for 'fix issues',
862 + * Page: SecurityIssues.
863 + *
864 + * @uses \MainWP\Dashboard\MainWP_Exception
865 + * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
866 + */
867 + public function mainwp_security_issues_fix() {
868 + $this->secure_request( 'mainwp_security_issues_fix' );
863 869
864 - wp_send_json( $information );
865 - }
870 + try {
871 + wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
872 + } catch ( MainWP_Exception $e ) {
873 + die(
874 + wp_json_encode(
875 + array(
876 + 'error' => array(
877 + 'message' => $e->getMessage(),
878 + 'extra' => $e->get_message_extra(),
879 + ),
880 + )
881 + )
882 + );
883 + }
884 + }
866 885
867 - /**
868 - * Method ajax_sites_display_rows()
869 - *
870 - * Display rows via ajax,
871 - * Page: Manage Sites.
872 - *
873 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
874 - */
875 - public function ajax_sites_display_rows() {
876 - $this->secure_request( 'mainwp_manage_sites_display_rows' );
877 - MainWP_Manage_Sites::ajax_optimize_display_rows();
878 - }
886 + /**
887 + * Method mainwp_security_issues_unfix()
888 + *
889 + * Post handler for 'unfix issues',
890 + * Page: SecurityIssues.
891 + *
892 + * @uses \MainWP\Dashboard\MainWP_Exception
893 + * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
894 + */
895 + public function mainwp_security_issues_unfix() {
896 + $this->secure_request( 'mainwp_security_issues_unfix' );
879 897
880 - /**
881 - * Method ajax_monitoring_display_rows()
882 - *
883 - * Display rows via ajax,
884 - * Page: Monitoring Sites.
885 - *
886 - * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
887 - */
888 - public function ajax_monitoring_display_rows() {
889 - $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
890 - MainWP_Monitoring::ajax_optimize_display_rows();
891 - }
898 + try {
899 + wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
900 + } catch ( MainWP_Exception $e ) {
901 + die(
902 + wp_json_encode(
903 + array(
904 + 'error' => array(
905 + 'message' => $e->getMessage(),
906 + 'extra' => $e->get_message_extra(),
907 + ),
908 + )
909 + )
910 + );
911 + }
912 + }
892 913
914 + /**
915 + * Method ajax_disconnect_site()
916 + *
917 + * Disconnect Child Site.
918 + *
919 + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
920 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
921 + */
922 + public function ajax_disconnect_site() {
923 + $this->secure_request( 'mainwp_disconnect_site' );
924 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
925 + $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
926 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
893 927
894 - /**
895 - * Method mainwp_bulkadduser()
896 - *
897 - * Bulk Add User for,
898 - * Page: BulkAddUser.
899 - *
900 - * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
901 - */
902 - public function mainwp_bulkadduser() {
903 - $this->check_security( 'mainwp_bulkadduser' );
904 - MainWP_User::do_bulk_add();
905 - die();
906 - }
928 + if ( empty( $siteid ) ) {
929 + die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
930 + }
907 931
908 - /**
909 - * Method mainwp_importuser()
910 - *
911 - * Import user.
912 - *
913 - * @uses \MainWP\Dashboard\MainWP_User::do_import()
914 - */
915 - public function mainwp_importuser() {
916 - $this->secure_request( 'mainwp_importuser' );
917 - MainWP_User::do_import();
918 - }
932 + $website = MainWP_DB::instance()->get_website_by_id( $siteid );
919 933
920 - /**
921 - * Method mainwp_clients_add_client()
922 - *
923 - * Add Client for,
924 - * Page: BulkAddClient.
925 - */
926 - public function mainwp_clients_add_client() {
927 - $this->check_security( 'mainwp_clients_add_client' );
928 - MainWP_Client::add_client();
929 - die();
930 - }
934 + if ( ! $website ) {
935 + die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
936 + }
931 937
932 - /**
933 - * Method mainwp_clients_delete_client()
934 - *
935 - * Add Client for,
936 - * Page: BulkAddClient.
937 - */
938 - public function mainwp_clients_delete_client() {
939 - $this->check_security( 'mainwp_clients_delete_client' );
940 - $ret = array( 'success' => false );
941 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
942 - $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
943 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
944 - if ( $client_id ) {
945 - MainWP_DB_Client::instance()->delete_client( $client_id );
946 - $ret['success'] = 'SUCCESS';
947 - $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
948 - } else {
949 - $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
950 - }
938 + try {
939 + $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
940 + } catch ( \Exception $e ) {
941 + $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
942 + }
951 943
952 - echo wp_json_encode( $ret );
953 - exit;
954 - }
944 + wp_send_json( $information );
945 + }
955 946
956 - /**
957 - * Method mainwp_clients_save_field()
958 - *
959 - * Save client custom fields.
960 - */
961 - public function mainwp_clients_save_field() {
962 - $this->check_security( 'mainwp_clients_save_field' );
963 - MainWP_Client::save_client_field();
964 - die();
965 - }
947 + /**
948 + * Method ajax_sites_display_rows()
949 + *
950 + * Display rows via ajax,
951 + * Page: Manage Sites.
952 + *
953 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
954 + */
955 + public function ajax_sites_display_rows() {
956 + $this->secure_request( 'mainwp_manage_sites_display_rows' );
957 + MainWP_Manage_Sites::ajax_optimize_display_rows();
958 + }
966 959
960 + /**
961 + * Method ajax_monitoring_display_rows()
962 + *
963 + * Display rows via ajax,
964 + * Page: Monitoring Sites.
965 + *
966 + * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
967 + */
968 + public function ajax_monitoring_display_rows() {
969 + $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
970 + MainWP_Monitoring::ajax_optimize_display_rows();
971 + }
967 972
968 - /**
969 - * Method mainwp_clients_delete_general_field()
970 - *
971 - * Delete client general fields.
972 - */
973 - public function mainwp_clients_delete_general_field() {
974 - $this->check_security( 'mainwp_clients_delete_general_field' );
975 - $ret = array( 'success' => false );
976 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
977 - $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
978 - $client_id = 0; // 0 general fields.
979 - if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
980 - $ret['success'] = true;
981 - }
982 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
983 - echo wp_json_encode( $ret );
984 - exit;
985 - }
986 973
974 + /**
975 + * Method mainwp_bulkadduser()
976 + *
977 + * Bulk Add User for,
978 + * Page: BulkAddUser.
979 + *
980 + * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
981 + */
982 + public function mainwp_bulkadduser() {
983 + $this->check_security( 'mainwp_bulkadduser' );
984 + MainWP_User::do_bulk_add();
985 + die();
986 + }
987 987
988 - /**
989 - * Method mainwp_clients_delete_field()
990 - *
991 - * Delete client custom fields.
992 - */
993 - public function mainwp_clients_delete_field() {
994 - $this->check_security( 'mainwp_clients_delete_field' );
995 - $ret = array( 'success' => false );
996 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
997 - $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
998 - $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
999 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1000 - if ( $client_id ) {
1001 - if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1002 - $ret['success'] = true;
1003 - }
1004 - }
1005 - echo wp_json_encode( $ret );
1006 - exit;
1007 - }
988 + /**
989 + * Method mainwp_importuser()
990 + *
991 + * Import user.
992 + *
993 + * @uses \MainWP\Dashboard\MainWP_User::do_import()
994 + */
995 + public function mainwp_importuser() {
996 + $this->secure_request( 'mainwp_importuser' );
997 + MainWP_User::do_import();
998 + }
1008 999
1009 - /**
1010 - * Method mainwp_notes_save()
1011 - *
1012 - * Post handler for save notes on,
1013 - * Page: Manage Sites.
1014 - *
1015 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1016 - */
1017 - public function mainwp_notes_save() {
1018 - $this->secure_request( 'mainwp_notes_save' );
1019 - MainWP_Manage_Sites_Handler::save_note();
1020 - }
1000 + /**
1001 + * Method mainwp_clients_add_client()
1002 + *
1003 + * Add Client for,
1004 + * Page: BulkAddClient.
1005 + */
1006 + public function mainwp_clients_add_client() {
1007 + $this->check_security( 'mainwp_clients_add_client' );
1008 + MainWP_Client::add_client();
1009 + die();
1010 + }
1021 1011
1022 - /**
1023 - * Method mainwp_clients_notes_save()
1024 - *
1025 - * Post handler for save notes on,
1026 - * Page: Manage Sites.
1027 - *
1028 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1029 - */
1030 - public function mainwp_clients_notes_save() {
1031 - $this->secure_request( 'mainwp_clients_notes_save' );
1032 - MainWP_Client::save_note();
1033 - }
1012 + /**
1013 + * Method mainwp_clients_delete_client()
1014 + *
1015 + * Add Client for,
1016 + * Page: BulkAddClient.
1017 + */
1018 + public function mainwp_clients_delete_client() {
1019 + $this->check_security( 'mainwp_clients_delete_client' );
1020 + $ret = array( 'success' => false );
1021 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1022 + $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1023 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1024 + if ( $client_id ) {
1025 + MainWP_DB_Client::instance()->delete_client( $client_id );
1026 + $ret['success'] = 'SUCCESS';
1027 + $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
1028 + MainWP_Client::invalidate_warm_cache();
1029 + } else {
1030 + $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
1031 + }
1034 1032
1035 - /**
1036 - * Method mainwp_clients_suspend_client()
1037 - *
1038 - * Post handler for suspend client,
1039 - * Page: Manage Sites.
1040 - *
1041 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1042 - */
1043 - public function mainwp_clients_suspend_client() {
1044 - $this->secure_request( 'mainwp_clients_suspend_client' );
1045 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1046 - $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1047 - $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1048 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1033 + echo wp_json_encode( $ret );
1034 + exit;
1035 + }
1049 1036
1050 - if ( empty( $clientid ) ) {
1051 - wp_die( 'Error - empty client id!' );
1052 - }
1037 + /**
1038 + * Method mainwp_clients_save_field()
1039 + *
1040 + * Save client custom fields.
1041 + */
1042 + public function mainwp_clients_save_field() {
1043 + $this->check_security( 'mainwp_clients_save_field' );
1044 + MainWP_Client::invalidate_warm_cache();
1045 + MainWP_Client::save_client_field();
1046 + die();
1047 + }
1053 1048
1054 - $params = array(
1055 - 'client_id' => $clientid,
1056 - 'suspended' => $suspended,
1057 - );
1058 1049
1059 - MainWP_DB_Client::instance()->update_client( $params );
1050 + /**
1051 + * Method mainwp_clients_delete_general_field()
1052 + *
1053 + * Delete client general fields.
1054 + */
1055 + public function mainwp_clients_delete_general_field() {
1056 + $this->check_security( 'mainwp_clients_delete_general_field' );
1057 + $ret = array( 'success' => false );
1058 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1059 + $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1060 + $client_id = 0; // 0 general fields.
1061 + if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1062 + $ret['success'] = true;
1063 + }
1064 + MainWP_Client::invalidate_warm_cache();
1065 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1066 + echo wp_json_encode( $ret );
1067 + exit;
1068 + }
1060 1069
1061 - $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1070 + /**
1071 + * Method mainwp_clients_bulk_delete_fields()
1072 + *
1073 + * Bulk delete client general fields.
1074 + */
1075 + public function mainwp_clients_bulk_delete_fields() {
1076 + $this->check_security( 'mainwp_clients_bulk_delete_fields' );
1077 + $ret = array( 'success' => false );
1078 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1079 + $field_ids = isset( $_POST['field_ids'] ) && is_array( $_POST['field_ids'] ) ? array_map( 'intval', $_POST['field_ids'] ) : array();
1080 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1062 1081
1063 - /**
1064 - * Fires immediately after update client suspend/unsuspend.
1065 - *
1066 - * @since 4.5.1.1
1067 - *
1068 - * @param object $client client data.
1069 - * @param bool $suspended true|false.
1070 - */
1071 - do_action( 'mainwp_client_suspend', $client, $suspended );
1082 + if ( empty( $field_ids ) ) {
1083 + $ret['data'] = array( 'message' => __( 'No fields selected.', 'mainwp' ) );
1084 + echo wp_json_encode( $ret );
1085 + exit;
1086 + }
1072 1087
1073 - MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1088 + $client_id = 0; // 0 general fields.
1089 + $deleted_count = 0;
1090 + foreach ( $field_ids as $field_id ) {
1091 + if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1092 + ++$deleted_count;
1093 + }
1094 + }
1074 1095
1075 - wp_die( 'success' );
1076 - }
1096 + if ( $deleted_count > 0 ) {
1097 + $ret['success'] = true;
1098 + MainWP_Client::invalidate_warm_cache();
1099 + } else {
1100 + $ret['data'] = array( 'message' => __( 'Failed to delete fields.', 'mainwp' ) );
1101 + }
1077 1102
1078 - /**
1079 - * Method mainwp_syncerrors_dismiss()
1080 - *
1081 - * Dismiss Sync errors for,
1082 - * Widget: RightNow.
1083 - *
1084 - * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1085 - */
1086 - public function mainwp_syncerrors_dismiss() {
1103 + echo wp_json_encode( $ret );
1104 + exit;
1105 + }
1087 1106
1088 - $this->secure_request( 'mainwp_syncerrors_dismiss' );
1107 + /**
1108 + * Method mainwp_clients_delete_field()
1109 + *
1110 + * Delete client custom fields.
1111 + */
1112 + public function mainwp_clients_delete_field() {
1113 + $this->check_security( 'mainwp_clients_delete_field' );
1114 + $ret = array( 'success' => false );
1115 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1116 + $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1117 + $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
1118 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1119 + if ( $client_id && MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1120 + $ret['success'] = true;
1121 + }
1122 + echo wp_json_encode( $ret );
1123 + exit;
1124 + }
1089 1125
1090 - try {
1091 - die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1092 - } catch ( \Exception $e ) {
1093 - die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
1094 - }
1095 - }
1126 + /**
1127 + * Method mainwp_notes_save()
1128 + *
1129 + * Post handler for save notes on,
1130 + * Page: Manage Sites.
1131 + *
1132 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1133 + */
1134 + public function mainwp_notes_save() {
1135 + $this->secure_request( 'mainwp_notes_save' );
1136 + MainWP_Manage_Sites_Handler::save_note();
1137 + }
1096 1138
1097 - /**
1098 - * Method mainwp_events_notice_hide()
1099 - *
1100 - * Hide events notice.
1101 - */
1102 - public function mainwp_events_notice_hide() {
1103 - $this->secure_request( 'mainwp_events_notice_hide' );
1104 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1105 - if ( isset( $_POST['notice'] ) ) {
1106 - $current_options = get_option( 'mainwp_showhide_events_notice' );
1107 - if ( ! is_array( $current_options ) ) {
1108 - $current_options = array();
1109 - }
1110 - if ( 'first_site' === $_POST['notice'] ) {
1111 - update_option( 'mainwp_first_site_events_notice', '' );
1112 - } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1113 - $current_options['request_reviews1'] = 15;
1114 - $current_options['request_reviews1_starttime'] = time();
1115 - } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1116 - $current_options['request_reviews1'] = 'forever';
1117 - $current_options['request_reviews2'] = 'forever';
1118 - } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1119 - $current_options['request_reviews2'] = 15;
1120 - $current_options['request_reviews2_starttime'] = time();
1121 - } elseif ( 'trust_child' === $_POST['notice'] ) {
1122 - $current_options['trust_child'] = 1;
1123 - } elseif ( 'multi_site' === $_POST['notice'] ) {
1124 - $current_options['hide_multi_site_notice'] = 1;
1125 - }
1126 - update_option( 'mainwp_showhide_events_notice', $current_options );
1127 - }
1128 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1129 - die( 'ok' );
1130 - }
1139 + /**
1140 + * Method mainwp_clients_notes_save()
1141 + *
1142 + * Post handler for save notes on,
1143 + * Page: Manage Sites.
1144 + *
1145 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1146 + */
1147 + public function mainwp_clients_notes_save() {
1148 + $this->secure_request( 'mainwp_clients_notes_save' );
1149 + MainWP_Client::save_note();
1150 + }
1131 1151
1132 - /**
1133 - * Method mainwp_showhide_sections()
1134 - *
1135 - * Show/Hide sections.
1136 - */
1137 - public function mainwp_showhide_sections() {
1138 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1139 - if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1140 - $opts = get_option( 'mainwp_opts_showhide_sections' );
1141 - if ( ! is_array( $opts ) ) {
1142 - $opts = array();
1143 - }
1144 - $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1145 - update_option( 'mainwp_opts_showhide_sections', $opts );
1146 - die( 'ok' );
1147 - }
1148 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1149 - die( 'failed' );
1150 - }
1152 + /**
1153 + * Method mainwp_clients_suspend_client()
1154 + *
1155 + * Post handler for suspend client,
1156 + * Page: Manage Sites.
1157 + *
1158 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1159 + */
1160 + public function mainwp_clients_suspend_client() {
1161 + $this->secure_request( 'mainwp_clients_suspend_client' );
1162 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1163 + $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1164 + $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1165 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1151 1166
1152 - /**
1153 - * Method mainwp_saving_status()
1154 - *
1155 - * MainWP Saving Status.
1156 - */
1157 - public function mainwp_saving_status() {
1158 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1159 - if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1160 - die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1161 - }
1162 - $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1163 - if ( ! empty( $saving_status ) ) {
1164 - $current_options = get_option( 'mainwp_opts_saving_status' );
1165 - if ( ! is_array( $current_options ) ) {
1166 - $current_options = array();
1167 - }
1168 - if ( isset( $_POST['value'] ) ) {
1169 - $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1170 - }
1171 - update_option( 'mainwp_opts_saving_status', $current_options );
1172 - }
1173 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1174 - die( 'ok' );
1175 - }
1167 + if ( empty( $clientid ) ) {
1168 + wp_die( 'Error - empty client id!' );
1169 + }
1176 1170
1177 - /**
1178 - * Method ajax_recheck_http()
1179 - *
1180 - * Recheck Child Site http status code & message.
1181 - *
1182 - * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1183 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1184 - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1185 - */
1186 - public function ajax_recheck_http() {
1187 - $this->check_security( 'mainwp_recheck_http' );
1188 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1189 - if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1190 - die( -1 );
1191 - }
1171 + $params = array(
1172 + 'client_id' => $clientid,
1173 + 'suspended' => $suspended,
1174 + );
1192 1175
1193 - $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1194 - if ( empty( $website ) ) {
1195 - die( -1 );
1196 - }
1197 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1176 + MainWP_DB_Client::instance()->update_client( $params );
1198 1177
1199 - $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1200 - $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1201 - $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
1202 - die(
1203 - wp_json_encode(
1204 - array(
1205 - 'httpcode' => esc_html( $http_code ),
1206 - 'status' => $check_result ? 1 : 0,
1207 - )
1208 - )
1209 - );
1210 - }
1178 + $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1211 1179
1212 - /**
1213 - * Method mainwp_ignore_http_response()
1214 - *
1215 - * Ignore Child Site https response.
1216 - *
1217 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1218 - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1219 - */
1220 - public function mainwp_ignore_http_response() {
1221 - $this->check_security( 'mainwp_ignore_http_response' );
1222 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1223 - $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1224 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1225 - if ( empty( $siteid ) ) {
1226 - die( -1 );
1227 - }
1180 + /**
1181 + * Fires immediately after update client suspend/unsuspend.
1182 + *
1183 + * @since 4.5.1.1
1184 + *
1185 + * @param object $client client data.
1186 + * @param bool $suspended true|false.
1187 + */
1188 + do_action( 'mainwp_client_suspend', $client, $suspended );
1228 1189
1229 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1230 - if ( empty( $website ) ) {
1231 - die( -1 );
1232 - }
1190 + MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1233 1191
1234 - MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1235 - die( wp_json_encode( array( 'ok' => 1 ) ) );
1236 - }
1192 + wp_die( 'success' );
1193 + }
1237 1194
1238 - /**
1239 - * Method mainwp_autoupdate_and_trust_child()
1240 - *
1241 - * Set MainWP Child Plugin to Trusted & AutoUpdate.
1242 - *
1243 - * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1244 - */
1245 - public function mainwp_autoupdate_and_trust_child() {
1246 - $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1247 - if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1248 - update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1249 - }
1250 - MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1251 - die( 'ok' );
1252 - }
1195 + /**
1196 + * Method mainwp_clients_check_client()
1197 + *
1198 + * The client check has been created in the system yet.
1199 + *
1200 + * @uses \MainWP_DB_Client::instance()->get_wp_client_by()
1201 + */
1202 + public function mainwp_clients_check_client() {
1203 + $this->secure_request( 'mainwp_clients_check_client' );
1204 + // phpcs:disable WordPress.Security.NonceVerification
1205 + $client_email = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '';
1206 + // phpcs:enable WordPress.Security.NonceVerification
1207 + $client_existed = MainWP_DB_Client::instance()->get_wp_client_by( 'client_email', $client_email, ARRAY_A );
1208 + if ( is_array( $client_existed ) && isset( $client_existed['client_id'] ) ) {
1209 + return wp_send_json_error( array( 'error' => esc_html__( 'Client email exists. Please try again.', 'mainwp' ) ) );
1210 + }
1211 + return wp_send_json_success( array( 'result' => esc_html__( 'Client email not exists.', 'mainwp' ) ) );
1212 + }
1253 1213
1254 - /**
1255 - * Method mainwp_force_destroy_sessions()
1256 - *
1257 - * Force destroy sessions.
1258 - *
1259 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1260 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1261 - *
1262 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1263 - */
1264 - public function mainwp_force_destroy_sessions() {
1265 - $this->secure_request( 'mainwp_force_destroy_sessions' );
1214 + /**
1215 + * Method mainwp_clients_import_client()
1216 + *
1217 + * Import new client
1218 + *
1219 + * @uses \MainWP_DB::instance()->get_websites_by_url()
1220 + * @uses \MainWP_Client_Handler::get_default_client_fields()
1221 + * @uses \MainWP_DB_Client::instance()->update_client()
1222 + * @uses \MainWP_DB_Client::instance()->update_selected_sites_for_client()
1223 + */
1224 + public function mainwp_clients_import_client() { // phpcs:ignore -- NOSONAR
1225 + $this->secure_request( 'mainwp_clients_import_client' );
1226 + // phpcs:disable
1227 + // Set value from POST data.
1228 + $default_values = array(
1229 + 'client.name' => ! empty( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '',
1230 + 'client.email' => ! empty( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '',
1231 + 'client.contact.address.1' => ! empty( $_POST['address_1'] ) ? sanitize_text_field( wp_unslash( $_POST['address_1'] ) ) : '',
1232 + 'client.contact.address.2' => ! empty( $_POST['address_2'] ) ? sanitize_text_field( wp_unslash( $_POST['address_2'] ) ) : '',
1233 + 'client.city' => ! empty( $_POST['city'] ) ? sanitize_text_field( wp_unslash( $_POST['city'] ) ) : '',
1234 + 'client.state' => ! empty( $_POST['state'] ) ? sanitize_text_field( wp_unslash( $_POST['state'] ) ) : '',
1235 + 'client.zip' => ! empty( $_POST['zip'] ) ? sanitize_text_field( wp_unslash( $_POST['zip'] ) ) : '',
1236 + 'client.country' => ! empty( $_POST['country'] ) ? sanitize_text_field( wp_unslash( $_POST['country'] ) ) : '',
1237 + 'client.suspended' => ! empty( $_POST['suspended'] ) ? sanitize_text_field( wp_unslash( $_POST['suspended'] ) ) : 0,
1238 + );
1239 + // Get Site id.
1240 + $selected_sites = array();
1241 + if ( ! empty( $_POST['urls'] ) ) {
1242 + $urls = array_map( 'sanitize_text_field', wp_unslash( $_POST['urls'] ) );
1243 + $selected_sites = array_filter(
1244 + array_map(
1245 + function ( $v_url ) {
1246 + $url = esc_url( $v_url );
1247 + $website = MainWP_DB::instance()->get_websites_by_url( $url );
1248 + return ! empty( $website ) ? current( $website )->id : null;
1249 + },
1250 + $urls
1251 + )
1252 + );
1253 + }
1254 + // phpcs:enable
1255 + $client_to_add = array();
1256 + $default_client_fields = MainWP_Client_Handler::get_default_client_fields(); // Get client field database.
1257 + foreach ( $default_values as $key_client => $val_client ) {
1258 + if ( isset( $default_client_fields[ $key_client ] ) && ! empty( $default_client_fields[ $key_client ]['db_field'] ) && ! empty( $val_client ) ) {
1259 + $client_to_add[ $default_client_fields[ $key_client ]['db_field'] ] = $val_client; // Assign data to customers according to DB Field.
1260 + }
1261 + }
1266 1262
1267 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1268 - $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1269 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1270 - if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1271 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1272 - }
1263 + if ( ! empty( $client_to_add ) ) {
1264 + // Set default values.
1265 + $client_to_add['created'] = time();
1266 + $client_to_add['primary_contact_id'] = 0;
1267 + // Inset client.
1268 + $inserted = MainWP_DB_Client::instance()->update_client( $client_to_add, true );
1273 1269
1274 - $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1275 - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1276 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1277 - }
1270 + if ( ! empty( $inserted ) && is_object( $inserted ) ) {
1271 + if ( ! empty( $selected_sites ) ) {
1272 + MainWP_DB_Client::instance()->update_selected_sites_for_client( $inserted->client_id, $selected_sites ); // Set client to selected sites.
1273 + }
1274 + // Set default color and icon .
1275 + $update = array(
1276 + 'client_id' => $inserted->client_id,
1277 + 'selected_icon_info' => 'selected:wordpress;color:#34424d',
1278 + );
1279 + MainWP_DB_Client::instance()->update_client( $update ); // Update Client.
1278 1280
1279 - try {
1280 - $information = MainWP_Connect::fetch_url_authed(
1281 - $website,
1282 - 'settings_tools',
1283 - array(
1284 - 'action' => 'force_destroy_sessions',
1285 - )
1286 - );
1287 - } catch ( \Exception $e ) {
1288 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1289 - }
1281 + return wp_send_json_success(
1282 + array(
1283 + 'message' => esc_html__( 'successful client.', 'mainwp' ),
1284 + 'client' => $inserted,
1285 + )
1286 + );
1287 + }
1288 + return wp_send_json_error(
1289 + array(
1290 + 'message' => esc_html__( 'unsuccessful client.', 'mainwp' ),
1291 + )
1292 + );
1293 + }
1294 + return wp_send_json_error(
1295 + array(
1296 + 'message' => esc_html__( 'Error, please try again later.', 'mainwp' ),
1297 + )
1298 + );
1299 + }
1290 1300
1291 - wp_send_json( $information );
1292 - }
1301 + /**
1302 + * Method mainwp_syncerrors_dismiss()
1303 + *
1304 + * Dismiss Sync errors for,
1305 + * Widget: RightNow.
1306 + *
1307 + * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1308 + */
1309 + public function mainwp_syncerrors_dismiss() {
1293 1310
1294 - /**
1295 - * Method ajax_refresh_icon()
1296 - */
1297 - public function ajax_refresh_icon() {
1298 - $this->secure_request( 'mainwp_refresh_icon' );
1299 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1300 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1301 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1302 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1311 + $this->secure_request( 'mainwp_syncerrors_dismiss' );
1303 1312
1304 - if ( empty( $slug ) ) {
1305 - wp_die( 'failed' );
1306 - }
1313 + try {
1314 + die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1315 + } catch ( \Exception $e ) {
1316 + die( wp_json_encode( array( 'error' => sanitize_text_field( $e->getMessage() ) ) ) );
1317 + }
1318 + }
1307 1319
1308 - $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1320 + /**
1321 + * Method mainwp_events_notice_hide()
1322 + *
1323 + * Hide events notice.
1324 + */
1325 + public function mainwp_events_notice_hide() {
1326 + $this->secure_request( 'mainwp_events_notice_hide' );
1327 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1328 + if ( isset( $_POST['notice'] ) ) {
1329 + $current_options = get_option( 'mainwp_showhide_events_notice' );
1330 + if ( ! is_array( $current_options ) ) {
1331 + $current_options = array();
1332 + }
1333 + if ( 'first_site' === $_POST['notice'] ) {
1334 + update_option( 'mainwp_first_site_events_notice', '' );
1335 + } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1336 + $current_options['request_reviews1'] = 15;
1337 + $current_options['request_reviews1_starttime'] = time();
1338 + } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1339 + $current_options['request_reviews1'] = 'forever';
1340 + $current_options['request_reviews2'] = 'forever';
1341 + } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1342 + $current_options['request_reviews2'] = 15;
1343 + $current_options['request_reviews2_starttime'] = time();
1344 + } elseif ( 'trust_child' === $_POST['notice'] ) {
1345 + $current_options['trust_child'] = 1;
1346 + } elseif ( 'multi_site' === $_POST['notice'] ) {
1347 + $current_options['hide_multi_site_notice'] = 1;
1348 + }
1349 + update_option( 'mainwp_showhide_events_notice', $current_options );
1350 + }
1351 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1352 + die( 'ok' );
1353 + }
1309 1354
1310 - if ( ! empty( $fet_icon ) ) {
1311 - wp_die( 'success' );
1312 - } else {
1313 - wp_die( 'failed' );
1314 - }
1315 - }
1355 + /**
1356 + * Method mainwp_showhide_sections()
1357 + *
1358 + * Show/Hide sections.
1359 + */
1360 + public function mainwp_showhide_sections() {
1361 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1362 + if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1363 + $opts = get_option( 'mainwp_opts_showhide_sections' );
1364 + if ( ! is_array( $opts ) ) {
1365 + $opts = array();
1366 + }
1367 + $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1368 + update_option( 'mainwp_opts_showhide_sections', $opts );
1369 + die( 'ok' );
1370 + }
1371 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1372 + die( 'failed' );
1373 + }
1316 1374
1317 - /**
1318 - * Method ajax_upload_custom_icon()
1319 - */
1320 - public function ajax_upload_custom_icon() {
1321 - $this->secure_request( 'mainwp_upload_custom_icon' );
1322 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1323 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1324 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1325 - $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1375 + /**
1376 + * Method mainwp_saving_status()
1377 + *
1378 + * MainWP Saving Status.
1379 + */
1380 + public function mainwp_saving_status() {
1381 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1382 + if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1383 + die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1384 + }
1385 + $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1386 + if ( ! empty( $saving_status ) ) {
1387 + $current_options = get_option( 'mainwp_opts_saving_status' );
1388 + if ( ! is_array( $current_options ) ) {
1389 + $current_options = array();
1390 + }
1391 + if ( isset( $_POST['value'] ) ) {
1392 + $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1393 + }
1394 + update_option( 'mainwp_opts_saving_status', $current_options );
1395 + }
1396 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1397 + die( 'ok' );
1398 + }
1326 1399
1327 - if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1328 - wp_die( 'invalid data!' );
1329 - }
1400 + /**
1401 + * Method ajax_recheck_http()
1402 + *
1403 + * Recheck Child Site http status code & message.
1404 + *
1405 + * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1406 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1407 + * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1408 + */
1409 + public function ajax_recheck_http() {
1410 + $this->check_security( 'mainwp_recheck_http' );
1411 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1412 + if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1413 + die( -1 );
1414 + }
1330 1415
1331 - $sub_folder = '';
1416 + $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1417 + if ( empty( $website ) ) {
1418 + die( -1 );
1419 + }
1420 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1332 1421
1333 - if ( 'plugin' === $type ) {
1334 - $sub_folder = 'plugin-icons';
1335 - } elseif ( 'theme' === $type ) {
1336 - $sub_folder = 'theme-icons';
1337 - } else {
1338 - wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1339 - }
1422 + $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1423 + $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1424 + $check_result = MainWP_Connect::check_ignored_http_code( $http_code, $website );
1340 1425
1341 - if ( $delete ) {
1342 - MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1343 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1344 - }
1426 + if ( is_array( $result ) && isset( $result['new_uptime_status'] ) ) {
1427 + $check_result = $result['new_uptime_status'];
1428 + }
1345 1429
1346 - $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1347 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1430 + die(
1431 + wp_json_encode(
1432 + array(
1433 + 'httpcode' => esc_html( $http_code ),
1434 + 'status' => $check_result ? 1 : 0,
1435 + )
1436 + )
1437 + );
1438 + }
1348 1439
1349 - $uploaded_icon = 'NOTCHANGE';
1350 - if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1351 - $uploaded_icon = $output['filename'];
1352 - }
1440 + /**
1441 + * Method mainwp_ignore_http_response()
1442 + *
1443 + * Ignore Child Site https response.
1444 + *
1445 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1446 + * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1447 + */
1448 + public function mainwp_ignore_http_response() {
1449 + $this->check_security( 'mainwp_ignore_http_response' );
1450 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1451 + $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1452 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1453 + if ( empty( $siteid ) ) {
1454 + die( -1 );
1455 + }
1353 1456
1354 - if ( 'NOTCHANGE' !== $uploaded_icon ) {
1355 - MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1356 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1357 - } else {
1358 - wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1359 - }
1360 - }
1457 + $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1458 + if ( empty( $website ) ) {
1459 + die( -1 );
1460 + }
1361 1461
1362 - /**
1363 - * Method ajax_select_custom_theme()
1364 - */
1365 - public function ajax_select_custom_theme() {
1366 - $this->secure_request( 'mainwp_select_custom_theme' );
1367 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1368 - $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1369 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1370 - if ( empty( $theme ) ) {
1371 - wp_die( 'failed' );
1372 - }
1462 + MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1463 + die( wp_json_encode( array( 'ok' => 1 ) ) );
1464 + }
1373 1465
1374 - $user = wp_get_current_user();
1375 - if ( empty( $user ) || empty( $user->ID ) ) {
1376 - wp_die( 'failed' );
1377 - }
1466 + /**
1467 + * Method mainwp_autoupdate_and_trust_child()
1468 + *
1469 + * Set MainWP Child Plugin to Trusted & AutoUpdate.
1470 + *
1471 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1472 + */
1473 + public function mainwp_autoupdate_and_trust_child() {
1474 + $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1475 + if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1476 + update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1477 + }
1478 + MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1479 + die( 'ok' );
1480 + }
1378 1481
1379 - update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1380 - wp_die( 'success' );
1381 - }
1482 + /**
1483 + * Method mainwp_force_destroy_sessions()
1484 + *
1485 + * Force destroy sessions.
1486 + *
1487 + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1488 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1489 + *
1490 + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1491 + */
1492 + public function mainwp_force_destroy_sessions() {
1493 + $this->secure_request( 'mainwp_force_destroy_sessions' );
1382 1494
1495 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1496 + $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1497 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1498 + if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1499 + die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1500 + }
1383 1501
1384 - /**
1385 - * Method ajax_site_actions_dismiss()
1386 - */
1387 - public function ajax_site_actions_dismiss() {
1388 - $this->secure_request( 'mainwp_site_actions_dismiss' );
1389 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1390 - $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1391 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1502 + $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1503 + if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1504 + die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1505 + }
1392 1506
1393 - if ( empty( $action_id ) ) {
1394 - wp_die( 'failed' );
1395 - }
1396 - $update = array(
1397 - 'dismiss' => 1,
1398 - );
1399 - MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1400 - wp_die( 'success' );
1401 - }
1507 + try {
1508 + $information = MainWP_Connect::fetch_url_authed(
1509 + $website,
1510 + 'settings_tools',
1511 + array(
1512 + 'action' => 'force_destroy_sessions',
1513 + )
1514 + );
1515 + } catch ( \Exception $e ) {
1516 + $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1517 + }
1402 1518
1403 - /**
1404 - * Method ajax_site_actions_dismiss()
1405 - */
1406 - public function ajax_delete_non_mainwp_actions() {
1407 - $this->secure_request( 'mainwp_delete_non_mainwp_actions' );
1408 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1409 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
1410 - if ( empty( $siteid ) ) {
1411 - wp_die( wp_json_encode( array( 'error' => 'Empty site ID' ) ) );
1412 - }
1413 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1414 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1415 - $success = false;
1416 - $error = '';
1417 - try {
1418 - $response = MainWP_Connect::fetch_url_authed( $website, 'delete_actions', array( 'del' => 'act' ) );
1419 - if ( is_array( $response ) ) {
1420 - if ( isset( $response['success'] ) ) {
1421 - $success = true;
1422 - } elseif ( isset( $response['error'] ) ) {
1423 - $error = $response['error'];
1424 - }
1425 - }
1426 - } catch ( \Exception $e ) {
1427 - // ok!
1428 - }
1429 - if ( $success ) {
1430 - MainWP_DB_Site_Actions::instance()->delete_action_by( 'wpid', $siteid );
1431 - wp_die( wp_json_encode( array( 'success' => 'ok' ) ) );
1432 - }
1519 + wp_send_json( $information );
1520 + }
1433 1521
1434 - if ( empty( $error ) ) {
1435 - $error = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1436 - }
1437 - wp_die( wp_json_encode( array( 'error' => $error ) ) );
1438 - }
1522 + /**
1523 + * Method ajax_refresh_icon()
1524 + */
1525 + public function ajax_refresh_icon() {
1526 + $this->secure_request( 'mainwp_refresh_icon' );
1527 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1528 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1529 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1530 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1439 1531
1440 - /**
1441 - * Method ajax_import_demo_data().
1442 - */
1443 - public function ajax_import_demo_data() {
1444 - $this->secure_request( 'mainwp_import_demo_data' );
1445 - $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1446 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1447 - wp_die( wp_json_encode( $data ) );
1448 - }
1532 + if ( empty( $slug ) ) {
1533 + wp_die( 'failed' );
1534 + }
1449 1535
1450 - /**
1451 - * Method ajax_delete_demo_data().
1452 - */
1453 - public function ajax_delete_demo_data() {
1454 - $this->secure_request( 'mainwp_delete_demo_data' );
1455 - $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1456 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1457 - wp_die( wp_json_encode( $data ) );
1458 - }
1536 + $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1537 +
1538 + if ( ! empty( $fet_icon ) ) {
1539 + wp_die( 'success' );
1540 + } else {
1541 + wp_die( 'failed' );
1542 + }
1543 + }
1544 +
1545 + /**
1546 + * Method ajax_upload_custom_icon()
1547 + */
1548 + public function ajax_upload_custom_icon() { //phpcs:ignore -- NOSONAR -complex.
1549 + $this->secure_request( 'mainwp_upload_custom_icon' );
1550 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1551 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1552 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1553 + $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1554 +
1555 + if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1556 + wp_die( 'Invalid data! Type or empty slug' );
1557 + }
1558 +
1559 + $sub_folder = '';
1560 +
1561 + if ( 'plugin' === $type ) {
1562 + $sub_folder = 'plugin-icons';
1563 + } elseif ( 'theme' === $type ) {
1564 + $sub_folder = 'theme-icons';
1565 + } else {
1566 + wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1567 + }
1568 +
1569 + if ( $delete ) {
1570 + MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1571 + wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1572 + }
1573 +
1574 + $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1575 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1576 +
1577 + $uploaded_icon = 'NOTCHANGE';
1578 + if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1579 + $uploaded_icon = $output['filename'];
1580 + }
1581 +
1582 + if ( 'NOTCHANGE' !== $uploaded_icon ) {
1583 + MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1584 + wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1585 + } else {
1586 + $result = array(
1587 + 'result' => 'failed',
1588 + );
1589 + $error = static::get_upload_icon_error( $output );
1590 + if ( ! empty( $error ) ) {
1591 + $result['error'] = esc_html( $error );
1592 + }
1593 + wp_die( wp_json_encode( $result ) );
1594 + }
1595 + }
1596 +
1597 + /**
1598 + * Method get_upload_icon_error().
1599 + *
1600 + * @param mixed $results Upload results.
1601 + *
1602 + * @return string
1603 + */
1604 + public static function get_upload_icon_error( $results ) {
1605 + $error = '';
1606 + if ( is_array( $results ) && ! empty( $results['error'] ) && is_array( $results['error'] ) ) {
1607 + $error_code = $results['error'][0];
1608 + switch ( $error_code ) {
1609 + case 3:
1610 + $error = __( 'File size is too big. Please try a smaller file.', 'mainwp' );
1611 + break;
1612 + case 4:
1613 + $error = __( 'File type is not allowed. Please use a different file type.', 'mainwp' );
1614 + break;
1615 + case 5:
1616 + $error = __( 'File extension is not allowed. Please use a different file type.', 'mainwp' );
1617 + break;
1618 + case 6:
1619 + $error = __( 'Cannot copy file. Please try again.', 'mainwp' );
1620 + break;
1621 + case 9:
1622 + $error = __( 'Failed to crop file. Please try again.', 'mainwp' );
1623 + break;
1624 + default:
1625 + $error = __( 'Undefined error. Please try again.', 'mainwp' );
1626 + break;
1627 + }
1628 + }
1629 + return $error;
1630 + }
1631 +
1632 + /**
1633 + * Method ajax_select_custom_theme()
1634 + */
1635 + public function ajax_select_custom_theme() {
1636 + $this->secure_request( 'mainwp_select_custom_theme' );
1637 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1638 + $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1639 + // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1640 + if ( empty( $theme ) ) {
1641 + wp_die( 'failed' );
1642 + }
1643 +
1644 + $user = wp_get_current_user();
1645 + if ( empty( $user ) || empty( $user->ID ) ) {
1646 + wp_die( 'failed' );
1647 + }
1648 +
1649 + update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1650 + wp_die( 'success' );
1651 + }
1652 +
1653 + /**
1654 + * Method ajax_import_demo_data().
1655 + */
1656 + public function ajax_import_demo_data() {
1657 + $this->secure_request( 'mainwp_import_demo_data' );
1658 + $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1659 + MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1660 + wp_die( wp_json_encode( $data ) );
1661 + }
1662 +
1663 + /**
1664 + * Method ajax_delete_demo_data().
1665 + */
1666 + public function ajax_delete_demo_data() {
1667 + $this->secure_request( 'mainwp_delete_demo_data' );
1668 + $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1669 + MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1670 + wp_die( wp_json_encode( $data ) );
1671 + }
1672 +
1673 + /**
1674 + * Method ajax_save_temp_import_website()
1675 + *
1676 + * Save temp import website.
1677 + *
1678 + * @uses MainWP_DB::instance()->get_general_option()
1679 + * @uses MainWP_DB::instance()->update_general_option(()
1680 + */
1681 + public function ajax_save_temp_import_website() {
1682 + $this->secure_request( 'mainwp_save_temp_import_website' ); // Check secure.
1683 + $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1684 + // Get previously saved temporary data (if any).
1685 + $values = MainWP_DB::instance()->get_general_option( 'temp_import_sites', 'array' );
1686 + $status = $this->mainwp_get_sanitized_post( 'status' );
1687 + $index = $this->mainwp_get_sanitized_post( 'row_index', 'intval' ) ?? 1;
1688 + if ( empty( $status ) || '' === $index ) {
1689 + wp_die( wp_send_json_error( $error_msg ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1690 + }
1691 +
1692 + $is_update = false;
1693 + if ( 'delete_temp' === $status ) { // Handling remove temp data.
1694 + $is_update = $this->mainwp_handle_delete_temp_import_website( $values, $index );
1695 + } elseif ( 'save_temp' === $status ) { // Handling save row data.
1696 + // Update row data into array.
1697 + $row_item = array(
1698 + 'site_url' => $this->mainwp_get_sanitized_post( 'site_url' ),
1699 + 'admin_name' => $this->mainwp_get_sanitized_post( 'admin_name' ),
1700 + 'admin_password' => $this->mainwp_get_sanitized_post( 'admin_password' ),
1701 + 'site_name' => $this->mainwp_get_sanitized_post( 'site_name' ),
1702 + 'tag' => $this->mainwp_get_sanitized_post( 'tag' ),
1703 + 'security_id' => $this->mainwp_get_sanitized_post( 'security_id' ),
1704 + 'http_username' => $this->mainwp_get_sanitized_post( 'http_username' ),
1705 + 'http_password' => $this->mainwp_get_sanitized_post( 'http_password' ),
1706 + 'verify_certificate' => $this->mainwp_get_sanitized_post( 'verify_certificate', 'intval' ) ?? 1,
1707 + 'ssl_version' => $this->mainwp_get_sanitized_post( 'ssl_version' ) ?? 'auto',
1708 + );
1709 +
1710 + $is_update = $this->mainwp_handle_save_temp_import_website( $values, $index, $row_item );
1711 + }
1712 + // Save data to options table.
1713 + if ( $is_update ) {
1714 + MainWP_DB::instance()->update_general_option( 'temp_import_sites', $values, 'array' );
1715 + wp_die( wp_send_json_success( esc_html( __( 'Row data saved successfully.', 'mainwp' ) ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1716 + }
1717 +
1718 + // In case of no updates.
1719 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1720 + }
1721 +
1722 + /**
1723 + * Method mainwp_handle_delete_temp_import_website()
1724 + *
1725 + * Handling remove temp data.
1726 + *
1727 + * @param mixed $values temp import sites.
1728 + * @param int $index row key.
1729 + *
1730 + * @return bool true|false.
1731 + */
1732 + private function mainwp_handle_delete_temp_import_website( &$values, $index ) {
1733 + // Check if row data stream exists.
1734 + if ( ! empty( $values ) && is_array( $values ) && array_key_exists( $index, $values ) ) {
1735 + unset( $values[ $index ] ); // Remove row data.
1736 + return true;
1737 + }
1738 + return false;
1739 + }
1740 +
1741 + /**
1742 + * Method mainwp_handle_save_temp_import_website()
1743 + *
1744 + * Create value if empty or array key exists.
1745 + *
1746 + * @param mixed $values temp import sites.
1747 + * @param int $index row key.
1748 + * @param array $row_item new row.
1749 + *
1750 + * @return bool true.
1751 + */
1752 + private function mainwp_handle_save_temp_import_website( &$values, $index, $row_item ) {
1753 + if ( empty( $values ) || ! array_key_exists( $index, $values ) ) {
1754 + $index = 0 !== $index ? $index : 0;
1755 + $values[ $index ] = $row_item;
1756 + } else {
1757 + $values[ $index ] = $row_item;
1758 + }
1759 + return true;
1760 + }
1761 +
1762 + /**
1763 + * Method ajax_delete_temp_import_website().
1764 + *
1765 + * Delete data temp if has been added website.
1766 + *
1767 + * @uses MainWP_DB::instance()->get_general_option().
1768 + * @uses MainWP_DB::instance()->update_general_option().
1769 + */
1770 + public function ajax_delete_temp_import_website() {
1771 + $this->secure_request( 'mainwp_delete_temp_import_website' ); // Check secure.
1772 + $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1773 + // Get option temp import sites data.
1774 + $temp_sites = MainWP_DB::instance()->get_general_option( 'temp_import_sites', 'array' );
1775 + if ( empty( $temp_sites ) || ! is_array( $temp_sites ) ) { // Check if temp_sites data exists and is an array.
1776 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1777 + }
1778 +
1779 + // Get wpurl, wpadmin from POST.
1780 + $wp_url = $this->mainwp_get_sanitized_post( 'managesites_add_wpurl' );
1781 + $wp_admin = $this->mainwp_get_sanitized_post( 'managesites_add_wpadmin' );
1782 + if ( empty( $wp_url ) || empty( $wp_admin ) ) { // Check wpurl, wpadmin has data or empty.
1783 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1784 + }
1785 + $is_delete = false;
1786 +
1787 + if ( ! empty( $temp_sites ) && is_array( $temp_sites ) ) {
1788 + foreach ( $temp_sites as $k_site => $val_site ) { // Loop through data to remove added website.
1789 + // Check if row data stream exists.
1790 + if ( rtrim( $wp_url, '/' ) === $val_site['site_url'] && $wp_admin === $val_site['admin_name'] ) {
1791 + // Remove row data.
1792 + unset( $temp_sites[ $k_site ] );
1793 + $is_delete = true;
1794 + break;
1795 + }
1796 + }
1797 + }
1798 +
1799 + // Save data to options table.
1800 + if ( $is_delete ) {
1801 + MainWP_DB::instance()->update_general_option( 'temp_import_sites', $temp_sites, 'array' );
1802 + wp_die( wp_send_json_success( esc_html__( 'Delete import row successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1803 + }
1804 +
1805 + // In case of no delete.
1806 + wp_die( wp_send_json_error( $error_msg ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1807 + }
1808 +
1809 + /**
1810 + * Method ajax_import_website_add_client()
1811 + *
1812 + * Create client.
1813 + */
1814 + public function ajax_import_website_add_client() {
1815 + $this->secure_request( 'mainwp_import_website_add_client' ); // Check secure.
1816 + $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1817 + try {
1818 + // Retrieve client data.
1819 + $data = $this->mainwp_get_sanitized_post( 'client' );
1820 + $site_id = $this->mainwp_get_sanitized_post( 'site_id' );
1821 +
1822 + if ( empty( $data ) ) {
1823 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1824 + }
1825 +
1826 + $client_data = json_decode( $data, true );
1827 + // Create client.
1828 + $client = $this->mainwp_handle_create_client( $client_data );
1829 + if ( $client ) {
1830 + // Add groups website and client.
1831 + if ( ! empty( $site_id ) ) {
1832 + $this->mainwp_handle_selected_sites_for_client( $client, $site_id );
1833 + }
1834 +
1835 + wp_die( wp_send_json_success( esc_html__( 'Created client successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1836 + }
1837 + } catch ( \Exception $e ) {
1838 + wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1839 + }
1840 + // In case of no created.
1841 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1842 + }
1843 +
1844 + /**
1845 + * Method ajax_import_website_add_client_no_site()
1846 + *
1847 + * Create client dont has a website.
1848 + */
1849 + public function ajax_import_website_add_client_no_site() {
1850 + $this->secure_request( 'mainwp_import_website_add_client_no_site' ); // Check secure.
1851 + $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1852 + try {
1853 + $data = ! empty( $_POST['client'] ) ? rest_sanitize_array( $_POST['client'] ) : array(); //phpcs:ignore -- NonceVerification.
1854 +
1855 + if ( empty( $data ) || ! is_array( $data ) ) {
1856 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1857 + }
1858 +
1859 + foreach ( $data as $val_data ) {
1860 + $client_data = json_decode( stripslashes( $val_data ), true ); // Decode client data.
1861 + $this->mainwp_handle_create_client( $client_data ); // Update or instert new client.
1862 + }
1863 + } catch ( \Exception $e ) {
1864 + wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1865 + }
1866 + // In case of no created.
1867 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1868 + }
1869 +
1870 + /**
1871 + * Method ajax_clients_add_multi_client
1872 + *
1873 + * Create Multi Client form QSW.
1874 + */
1875 + public function ajax_clients_add_multi_client() {
1876 + $error_msg = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1877 + $this->check_security( 'mainwp_clients_add_multi_client' );
1878 + $dataes = isset( $_POST['data'] ) ? $_POST['data'] : array(); //phpcs:ignore -- NonceVerification.
1879 + try {
1880 + if ( ! empty( $dataes ) ) {
1881 + foreach ( $dataes as $val_data ) {
1882 + $client_data = array(
1883 + 'image' => '',
1884 + 'name' => $val_data['client_name'] ?? '',
1885 + 'address_1' => '',
1886 + 'address_2' => '',
1887 + 'city' => '',
1888 + 'zip' => '',
1889 + 'state' => '',
1890 + 'country' => '',
1891 + 'note' => '',
1892 + 'selected_icon_info' => 'selected:wordpress;color:#34424d',
1893 + 'client_email' => $val_data['client_email'] ?? '',
1894 + 'client_phone' => '',
1895 + 'client_facebook' => '',
1896 + 'client_twitter' => '',
1897 + 'client_instagram' => '',
1898 + 'client_linkedin' => '',
1899 + 'suspended' => 0,
1900 + 'primary_contact_id' => 0,
1901 + );
1902 +
1903 + // Create client.
1904 + $client = $this->mainwp_handle_create_client( $client_data );
1905 +
1906 + // Create client successfy.
1907 + if ( ! empty( $client ) && ! empty( $val_data['website_id'] ) ) {
1908 + // Add groups website and client.
1909 + $this->mainwp_handle_selected_sites_for_client( $client, $val_data['website_id'] );
1910 + }
1911 + // Create client contact.
1912 + if ( ! empty( $val_data['contacts_field'] ) ) {
1913 + $this->mainwp_handle_create_contact_for_client( $client, $val_data['contacts_field'] );
1914 + }
1915 + }
1916 + wp_die( wp_send_json_success( esc_html__( 'Created client successfully.', 'mainwp' ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1917 + }
1918 + } catch ( \Exception $e ) {
1919 + wp_die( wp_send_json_error( sanitize_text_field( $e->getMessage() ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1920 + }
1921 +
1922 + wp_die( wp_send_json_error( esc_html( $error_msg ) ) ); //phpcs:ignore WordPress.Security.EscapeOutput
1923 + }
1924 +
1925 + /**
1926 + * Method ajax_increase_connection_security
1927 + */
1928 + public function ajax_increase_connection_security() {
1929 + $this->check_security( 'mainwp_increase_connection_security' );
1930 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
1931 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1932 + // try to decrypt priv key.
1933 + $de_privkey = MainWP_Encrypt_Data_Lib::instance()->decrypt_privkey( base64_decode( $website->privkey ), $website->id ); // phpcs:ignore -- NOSONAR - base64_encode trust.
1934 + if ( empty( $de_privkey ) ) { // key is not encrypted.
1935 + $en_privkey = MainWP_Encrypt_Data_Lib::instance()->encrypt_privkey( base64_decode( $website->privkey ), $website->id, true ); //phpcs:ignore -- NOSONAR - trust - create encrypt priv key for the site.
1936 + if ( ! empty( $en_privkey['en_data'] ) ) {
1937 + MainWP_DB::instance()->update_website_values(
1938 + $website->id,
1939 + array(
1940 + 'privkey' => base64_encode( $en_privkey['en_data'] ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- NOSONAR - base64_encode trust.
1941 + )
1942 + );
1943 + }
1944 + }
1945 + }
1946 + MainWP_DB::free_result( $websites );
1947 + $this->hide_dashboard_notice_status( 'mainwp_secure_priv_key_notice' );
1948 + delete_option( 'mainwp_not_start_encrypt_keys' );
1949 + wp_die( wp_json_encode( array( 'success' => 1 ) ) );
1950 + }
1951 +
1952 + /**
1953 + * Method ajax_ui_mode_detected
1954 + */
1955 + public function ajax_ui_mode_detected() {
1956 + $this->check_security( 'mainwp_qsw_ui_mode_detected' );
1957 +
1958 + $detected_ui = isset( $_POST['ui_mode'] ) ? sanitize_text_field( wp_unslash( $_POST['ui_mode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1959 +
1960 + $current_user_theme = get_user_option( 'mainwp_selected_theme' );
1961 + if ( empty( $current_user_theme ) ) {
1962 + if ( 'dark' === $detected_ui ) {
1963 + MainWP_Utility::update_user_option( 'mainwp_selected_theme', 'default-dark' );
1964 + } else {
1965 + MainWP_Utility::update_user_option( 'mainwp_selected_theme', 'default' );
1966 + }
1967 + }
1968 +
1969 + wp_die( wp_json_encode( array( 'success' => 1 ) ) );
1970 + }
1971 +
1972 +
1973 +
1974 + /**
1975 + * Handle ajax get changes logs for plugins/themes.
1976 + */
1977 + public function ajax_get_item_changes_logs() { //phpcs:ignore -- NOSONAR -complex.
1978 + $this->check_security( 'mainwp_changes_logs_get_item_changes' );
1979 +
1980 + $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1981 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1982 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1983 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( urldecode( $_POST['name'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1984 +
1985 + if ( 'plugin' === $type && ! empty( $slug ) ) {
1986 + if ( false !== strpos( $slug, '/' ) ) {
1987 + $parts = explode( '/', $slug );
1988 + $slug = $parts[0];
1989 + } else {
1990 + $slug = basename( $slug, '.php' );
1991 + }
1992 + } elseif ( 'theme' === $type && ! empty( $slug ) ) {
1993 + $slug = strtolower( $slug );
1994 + }
1995 +
1996 + // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1997 + $target_dt = ! empty( $_POST['target_date'] ) ? sanitize_text_field( wp_unslash( $_POST['target_date'] ) ) : '';
1998 +
1999 + if ( ! in_array( $type, array( 'plugin', 'theme' ) ) || ( empty( $target_dt ) && ( empty( $siteId ) || ( empty( $slug ) && empty( $name ) ) ) ) ) {
2000 + wp_send_json( array( 'error' => esc_html__( 'Invalid request data. Please try again.', 'mainwp' ) ) );
2001 + }
2002 +
2003 + // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2004 + $from_date = isset( $_POST['from_date'] ) ? sanitize_text_field( wp_unslash( $_POST['from_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2005 +
2006 + $results = Log_Changes_Logs_Helper::instance()->get_history_changes(
2007 + array(
2008 + 'wpid' => $siteId,
2009 + 'from_date' => $from_date,
2010 + 'days_number' => 10,
2011 + 'slug' => $slug,
2012 + 'type' => $type,
2013 + 'name' => $name,
2014 + 'target_date' => $target_dt,
2015 + )
2016 + );
2017 +
2018 + if ( ! is_array( $results ) ) {
2019 + $results = array();
2020 + }
2021 +
2022 + wp_send_json( $results );
2023 + }
2024 +
2025 + /**
2026 + * Handle self_connect action.
2027 + */
2028 + public function ajax_self_connect() {
2029 +
2030 + $mainwp_run = isset( $_POST['mainwp_run'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_run'] ) ) : ''; // phpcs:ignore -- NOSONAR -ok.
2031 +
2032 + if ( 'self_connect' !== $mainwp_run ) {
2033 + status_header( 400 );
2034 + exit;
2035 + }
2036 +
2037 + MainWP_System_Utility::instance()->handle_self_connect();
2038 +
2039 + exit;
2040 + }
2041 +
2042 +
2043 + /**
2044 + * Method mainwp_get_sanitized_post()
2045 + *
2046 + * Sanitized post field.
2047 + *
2048 + * @param string $key key to get from POST.
2049 + * @param string $callback cleaning method.
2050 + *
2051 + * @return mixed data value.
2052 + */
2053 + public function mainwp_get_sanitized_post( $key, $callback = 'sanitize_text_field' ) {
2054 + return isset( $_POST[ $key ] ) ? $callback( wp_unslash( $_POST[ $key ] ) ) : ''; //phpcs:ignore -- NonceVerification.
2055 + }
2056 +
2057 + /**
2058 + * Method mainwp_handle_create_client()
2059 + *
2060 + * Create new client or return client data.
2061 + *
2062 + * @uses MainWP_DB_Client::instance()->get_wp_client_by()
2063 + * @uses MainWP_DB_Client::instance()->update_client()
2064 + *
2065 + * @param array $client_data new client creation data.
2066 + *
2067 + * @return object client data.
2068 + */
2069 + public function mainwp_handle_create_client( $client_data ) {
2070 + // Check if client does not exist then create new one.
2071 + $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_email', $client_data['client_email'], OBJECT );
2072 + if ( empty( $client ) ) {
2073 + $client = MainWP_DB_Client::instance()->update_client( $client_data ); // Create client.
2074 + }
2075 +
2076 + return $client;
2077 + }
2078 +
2079 + /**
2080 + * Method mainwp_handle_selected_sites_for_client()
2081 + *
2082 + * Update selected sites for client.
2083 + *
2084 + * @uses MainWP_DB_Client::instance()->get_websites_by_client_ids()
2085 + * @uses MainWP_DB_Client::instance()->update_selected_sites_for_client()
2086 + *
2087 + * @param object $client client data.
2088 + * @param int $website_id id.
2089 + */
2090 + public function mainwp_handle_selected_sites_for_client( $client, $website_id ) {
2091 + $sites_ids = MainWP_DB_Client::instance()->get_websites_by_client_ids( $client->client_id );
2092 + $ids = isset( $sites_ids ) && ! empty( $sites_ids ) ? array_column( $sites_ids, 'id' ) : array();
2093 + $ids[] = $website_id;
2094 + MainWP_DB_Client::instance()->update_selected_sites_for_client( $client->client_id, $ids );
2095 + }
2096 +
2097 + /**
2098 + * Method mainwp_handle_create_contact_for_client()
2099 + *
2100 + * Handle create contact for client.
2101 + *
2102 + * @uses MainWP_DB_Client::instance()->update_client_contact()
2103 + * @uses MMainWP_DB_Client::instance()->update_client()
2104 + *
2105 + * @param object $client client data.
2106 + * @param array $contacts_data contacts Data.
2107 + */
2108 + public function mainwp_handle_create_contact_for_client( $client, $contacts_data ) {
2109 + $contacts = array_filter( $contacts_data );
2110 + // Check required fields.
2111 + if ( ( isset( $contacts['contact_name'] ) && '' !== $contacts['contact_name'] ) && ( isset( $contacts['contact_email'] ) && $contacts['contact_email'] ) ) {
2112 + $contact_data = array(
2113 + 'contact_name' => $contacts['contact_name'] ?? '',
2114 + 'contact_email' => $contacts['contact_email'] ?? '',
2115 + 'contact_role' => $contacts['contact_role'] ?? '',
2116 + 'contact_client_id' => $client->client_id,
2117 + 'contact_phone' => '',
2118 + 'facebook' => '',
2119 + 'twitter' => '',
2120 + 'instagram' => '',
2121 + 'linkedin' => '',
2122 + 'contact_icon_info' => '',
2123 + );
2124 + $inserted = MainWP_DB_Client::instance()->update_client_contact( $contact_data ); // Create or update contact of client.
2125 + // If the update is successful, the client will be updated again.
2126 + if ( $inserted ) {
2127 + $update = array(
2128 + 'client_id' => $client->client_id,
2129 + 'primary_contact_id' => $inserted->contact_id,
2130 + );
2131 + MainWP_DB_Client::instance()->update_client( $update );
2132 + }
2133 + }
2134 + }
1459 2135 }