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 +1976 -1280 5.0.2 → 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,1427 +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::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 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
541 - if ( ! isset( $_POST['status'] ) ) {
542 - die( -1 );
543 - }
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 + }
544 529
545 - if ( 'last_sync_sites' === $_POST['status'] ) {
546 - if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
547 - update_option( 'mainwp_last_synced_all_sites', time() );
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 - /**
550 - * Action: mainwp_synced_all_sites
551 - *
552 - * Fires upon successfull synchronization process.
553 - *
554 - * @since 3.5.1
555 - */
556 - do_action( 'mainwp_synced_all_sites' );
557 - }
558 - die( 'ok' );
559 - }
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;
560 543
561 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
562 - $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
563 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
544 + if ( ! empty( $_POST['short_term'] ) ) {
545 + if ( empty( $no_id ) ) {
546 + die( 'invalid' );
547 + }
564 548
565 - if ( ! empty( $status ) ) {
566 - if ( empty( $value ) ) {
567 - if ( isset( $values[ $status ] ) ) {
568 - unset( $values[ $status ] );
569 - }
570 - } else {
571 - $values[ $status ] = $value;
572 - }
573 - update_option( 'mainwp_status_saved_values', $values );
574 - }
549 + $keys = explode( ';', $no_id );
550 + foreach ( $keys as $key ) {
551 + MainWP_Utility::dismiss_short_term_notice( $key );
552 + }
553 + die( 'dismissed' );
554 + }
575 555
576 - die( 'ok' );
577 - }
556 + if ( 'mail_failed' === $no_id ) {
557 + MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
558 + die( 'ok' );
559 + }
578 560
579 - /**
580 - * Method ajax_widget_order()
581 - *
582 - * Update saved widget order.
583 - */
584 - public function ajax_widgets_order() {
561 + if ( 'phpver_8_0' === $no_id ) {
562 + MainWP_Utility::update_user_option( 'lasttime_hidden_phpver_8_0', time() );
563 + }
585 564
586 - $this->secure_request( 'mainwp_widgets_order' );
587 - $user = wp_get_current_user();
588 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
589 - if ( $user && ! empty( $_POST['page'] ) ) {
590 - $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
591 - $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
592 - $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
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 + }
593 570
594 - $wgs_orders = array();
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 - if ( ! empty( $wgids ) ) {
597 - $wgids = json_decode( $wgids, true );
598 - $order = json_decode( $order, true );
599 - if ( is_array( $wgids ) && is_array( $order ) ) {
600 - foreach ( $wgids as $idx => $wgid ) {
601 - if ( isset( $order[ $idx ] ) ) {
602 - $pre = 'widget-';
603 - if ( 0 === strpos( $wgid, $pre ) ) {
604 - $wgid = substr( $wgid, strlen( $pre ) );
605 - }
606 - $wgs_orders[ $wgid ] = $order[ $idx ];
607 - }
608 - }
609 - }
610 - }
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' );
611 618
612 - if ( 'mainwp_page_manageclients' === $page ) {
613 - $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
614 - $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
615 - if ( ! empty( $sorted_array ) ) {
616 - $sorted_array = json_decode( $sorted_array, true );
617 - }
618 - if ( ! is_array( $sorted_array ) ) {
619 - $sorted_array = array();
620 - }
621 - $sorted_array[ $item_id ] = $wgs_orders;
622 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
623 - } else {
624 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
625 - }
626 - die( 'ok' );
627 - }
628 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
629 - die( -1 );
630 - }
619 + if ( ! is_array( $values ) ) {
620 + $values = array();
621 + }
631 622
632 - /**
633 - * Method ajax_mainwp_save_settings()
634 - *
635 - * Update saved MainWP Settings.
636 - *
637 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
638 - */
639 - public function ajax_mainwp_save_settings() {
640 - $this->secure_request( 'mainwp_save_settings' );
641 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
642 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
643 - if ( ! empty( $name ) ) {
644 - $option_name = 'mainwp_' . $name;
645 - $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
646 - MainWP_Utility::update_option( $option_name, $val );
647 - }
648 - // phpcs:enable
649 - die( 'ok' );
650 - }
623 + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
624 + if ( ! isset( $_POST['status'] ) ) {
625 + die( -1 );
626 + }
651 627
652 - /**
653 - * Method ajax_guided_tours_option_update()
654 - *
655 - * Update saved MainWP Settings.
656 - *
657 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
658 - */
659 - public function ajax_guided_tours_option_update() {
660 - $this->secure_request( 'mainwp_guided_tours_option_update' );
661 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
662 - $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
663 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
664 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
665 - die( 'ok' );
666 - }
628 + if ( 'last_sync_sites' === $_POST['status'] ) {
629 + if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
630 + update_option( 'mainwp_last_synced_all_sites', time() );
667 631
668 - /**
669 - * Method mainwp_leftmenu_filter_group()
670 - *
671 - * MainWP left menu filter by group.
672 - *
673 - * @uses \MainWP\Dashboard\MainWP_DB::query()
674 - * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
675 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
676 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
677 - */
678 - public function mainwp_leftmenu_filter_group() {
679 - $this->secure_request( 'mainwp_leftmenu_filter_group' );
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 + }
680 643
681 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
682 - $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
683 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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
684 647
685 - if ( ! empty( $gid ) ) {
686 - $ids = '';
687 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
688 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
689 - $ids .= $website->id . ',';
690 - }
691 - MainWP_DB::free_result( $websites );
692 - $ids = rtrim( $ids, ',' );
693 - die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
694 - }
695 - die( '' );
696 - }
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 + }
697 658
698 - /**
699 - * Method dismiss_activate_notice()
700 - *
701 - * Dismiss activate notice.
702 - */
703 - public function dismiss_activate_notice() {
704 - $this->secure_request( 'mainwp_dismiss_activate_notice' );
659 + die( 'ok' );
660 + }
705 661
706 - /**
707 - * Current user global.
708 - *
709 - * @global string
710 - */
711 - global $current_user;
712 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
713 - $user_id = $current_user->ID;
714 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
715 - if ( $user_id && ! empty( $slug ) ) {
716 - $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
717 - if ( ! is_array( $activate_notices ) ) {
718 - $activate_notices = array();
719 - }
662 + /**
663 + * Method ajax_widget_order()
664 + *
665 + * Update saved widget order.
666 + */
667 + public function ajax_widgets_order() { //phpcs:ignore -- NOSONAR - complex.
720 668
721 - $activate_notices[ $slug ] = time();
722 - update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
723 - }
724 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
725 - die( 1 );
726 - }
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'] ) ) : '';
727 677
678 + $wgs_orders = array();
728 679
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 + }
729 695
730 - /**
731 - * Method mainwp_security_issues_request()
732 - *
733 - * Post handler for,
734 - * Page: SecurityIssues.
735 - *
736 - * @uses \MainWP\Dashboard\MainWP_Exception
737 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
738 - */
739 - public function mainwp_security_issues_request() {
740 - $this->secure_request( 'mainwp_security_issues_request' );
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 + }
741 716
742 - try {
743 - wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
744 - } catch ( MainWP_Exception $e ) {
745 - die(
746 - wp_json_encode(
747 - array(
748 - 'error' => array(
749 - 'message' => $e->getMessage(),
750 - 'extra' => $e->get_message_extra(),
751 - ),
752 - )
753 - )
754 - );
755 - }
756 - }
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 + }
757 736
758 - /**
759 - * Method mainwp_security_issues_fix()
760 - *
761 - * Post handler for 'fix issues',
762 - * Page: SecurityIssues.
763 - *
764 - * @uses \MainWP\Dashboard\MainWP_Exception
765 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
766 - */
767 - public function mainwp_security_issues_fix() {
768 - $this->secure_request( 'mainwp_security_issues_fix' );
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 + }
769 752
770 - try {
771 - wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
772 - } catch ( MainWP_Exception $e ) {
773 - die(
774 - wp_json_encode(
775 - array(
776 - 'error' => array(
777 - 'message' => $e->getMessage(),
778 - 'extra' => $e->get_message_extra(),
779 - ),
780 - )
781 - )
782 - );
783 - }
784 - }
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 + }
785 767
786 - /**
787 - * Method mainwp_security_issues_unfix()
788 - *
789 - * Post handler for 'unfix issues',
790 - * Page: SecurityIssues.
791 - *
792 - * @uses \MainWP\Dashboard\MainWP_Exception
793 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
794 - */
795 - public function mainwp_security_issues_unfix() {
796 - $this->secure_request( 'mainwp_security_issues_unfix' );
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' );
797 780
798 - try {
799 - wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
800 - } catch ( MainWP_Exception $e ) {
801 - die(
802 - wp_json_encode(
803 - array(
804 - 'error' => array(
805 - 'message' => $e->getMessage(),
806 - 'extra' => $e->get_message_extra(),
807 - ),
808 - )
809 - )
810 - );
811 - }
812 - }
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
813 784
814 - /**
815 - * Method ajax_disconnect_site()
816 - *
817 - * Disconnect Child Site.
818 - *
819 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
820 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
821 - */
822 - public function ajax_disconnect_site() {
823 - $this->secure_request( 'mainwp_disconnect_site' );
824 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
825 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
826 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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 + }
827 797
828 - if ( empty( $siteid ) ) {
829 - die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
830 - }
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' );
831 805
832 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
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 + }
833 820
834 - if ( ! $website ) {
835 - die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
836 - }
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 + }
837 827
838 - try {
839 - $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
840 - } catch ( \Exception $e ) {
841 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
842 - }
843 828
844 - wp_send_json( $information );
845 - }
846 829
847 - /**
848 - * Method ajax_sites_display_rows()
849 - *
850 - * Display rows via ajax,
851 - * Page: Manage Sites.
852 - *
853 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
854 - */
855 - public function ajax_sites_display_rows() {
856 - $this->secure_request( 'mainwp_manage_sites_display_rows' );
857 - MainWP_Manage_Sites::ajax_optimize_display_rows();
858 - }
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' );
859 841
860 - /**
861 - * Method ajax_monitoring_display_rows()
862 - *
863 - * Display rows via ajax,
864 - * Page: Monitoring Sites.
865 - *
866 - * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
867 - */
868 - public function ajax_monitoring_display_rows() {
869 - $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
870 - MainWP_Monitoring::ajax_optimize_display_rows();
871 - }
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 + }
872 857
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' );
873 869
874 - /**
875 - * Method mainwp_bulkadduser()
876 - *
877 - * Bulk Add User for,
878 - * Page: BulkAddUser.
879 - *
880 - * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
881 - */
882 - public function mainwp_bulkadduser() {
883 - $this->check_security( 'mainwp_bulkadduser' );
884 - MainWP_User::do_bulk_add();
885 - die();
886 - }
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 + }
887 885
888 - /**
889 - * Method mainwp_importuser()
890 - *
891 - * Import user.
892 - *
893 - * @uses \MainWP\Dashboard\MainWP_User::do_import()
894 - */
895 - public function mainwp_importuser() {
896 - $this->secure_request( 'mainwp_importuser' );
897 - MainWP_User::do_import();
898 - }
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' );
899 897
900 - /**
901 - * Method mainwp_clients_add_client()
902 - *
903 - * Add Client for,
904 - * Page: BulkAddClient.
905 - */
906 - public function mainwp_clients_add_client() {
907 - $this->check_security( 'mainwp_clients_add_client' );
908 - MainWP_Client::add_client();
909 - die();
910 - }
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 + }
911 913
912 - /**
913 - * Method mainwp_clients_delete_client()
914 - *
915 - * Add Client for,
916 - * Page: BulkAddClient.
917 - */
918 - public function mainwp_clients_delete_client() {
919 - $this->check_security( 'mainwp_clients_delete_client' );
920 - $ret = array( 'success' => false );
921 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
922 - $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
923 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
924 - if ( $client_id ) {
925 - MainWP_DB_Client::instance()->delete_client( $client_id );
926 - $ret['success'] = 'SUCCESS';
927 - $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
928 - } else {
929 - $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
930 - }
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
931 927
932 - echo wp_json_encode( $ret );
933 - exit;
934 - }
928 + if ( empty( $siteid ) ) {
929 + die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
930 + }
935 931
936 - /**
937 - * Method mainwp_clients_save_field()
938 - *
939 - * Save client custom fields.
940 - */
941 - public function mainwp_clients_save_field() {
942 - $this->check_security( 'mainwp_clients_save_field' );
943 - MainWP_Client::save_client_field();
944 - die();
945 - }
932 + $website = MainWP_DB::instance()->get_website_by_id( $siteid );
946 933
934 + if ( ! $website ) {
935 + die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
936 + }
947 937
948 - /**
949 - * Method mainwp_clients_delete_general_field()
950 - *
951 - * Delete client general fields.
952 - */
953 - public function mainwp_clients_delete_general_field() {
954 - $this->check_security( 'mainwp_clients_delete_general_field' );
955 - $ret = array( 'success' => false );
956 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
957 - $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
958 - $client_id = 0; // 0 general fields.
959 - if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
960 - $ret['success'] = true;
961 - }
962 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
963 - echo wp_json_encode( $ret );
964 - exit;
965 - }
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 + }
966 943
944 + wp_send_json( $information );
945 + }
967 946
968 - /**
969 - * Method mainwp_clients_delete_field()
970 - *
971 - * Delete client custom fields.
972 - */
973 - public function mainwp_clients_delete_field() {
974 - $this->check_security( 'mainwp_clients_delete_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 = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
979 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
980 - if ( $client_id ) {
981 - if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
982 - $ret['success'] = true;
983 - }
984 - }
985 - echo wp_json_encode( $ret );
986 - exit;
987 - }
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 + }
988 959
989 - /**
990 - * Method mainwp_notes_save()
991 - *
992 - * Post handler for save notes on,
993 - * Page: Manage Sites.
994 - *
995 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
996 - */
997 - public function mainwp_notes_save() {
998 - $this->secure_request( 'mainwp_notes_save' );
999 - MainWP_Manage_Sites_Handler::save_note();
1000 - }
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 + }
1001 972
1002 - /**
1003 - * Method mainwp_clients_notes_save()
1004 - *
1005 - * Post handler for save notes on,
1006 - * Page: Manage Sites.
1007 - *
1008 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1009 - */
1010 - public function mainwp_clients_notes_save() {
1011 - $this->secure_request( 'mainwp_clients_notes_save' );
1012 - MainWP_Client::save_note();
1013 - }
1014 973
1015 - /**
1016 - * Method mainwp_clients_suspend_client()
1017 - *
1018 - * Post handler for suspend client,
1019 - * Page: Manage Sites.
1020 - *
1021 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1022 - */
1023 - public function mainwp_clients_suspend_client() {
1024 - $this->secure_request( 'mainwp_clients_suspend_client' );
1025 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1026 - $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1027 - $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1028 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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 + }
1029 987
1030 - if ( empty( $clientid ) ) {
1031 - wp_die( 'Error - empty client id!' );
1032 - }
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 + }
1033 999
1034 - $params = array(
1035 - 'client_id' => $clientid,
1036 - 'suspended' => $suspended,
1037 - );
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 + }
1038 1011
1039 - MainWP_DB_Client::instance()->update_client( $params );
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 + }
1040 1032
1041 - $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1033 + echo wp_json_encode( $ret );
1034 + exit;
1035 + }
1042 1036
1043 - /**
1044 - * Fires immediately after update client suspend/unsuspend.
1045 - *
1046 - * @since 4.5.1.1
1047 - *
1048 - * @param object $client client data.
1049 - * @param bool $suspended true|false.
1050 - */
1051 - do_action( 'mainwp_client_suspend', $client, $suspended );
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 + }
1052 1048
1053 - MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1054 1049
1055 - wp_die( 'success' );
1056 - }
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 + }
1057 1069
1058 - /**
1059 - * Method mainwp_syncerrors_dismiss()
1060 - *
1061 - * Dismiss Sync errors for,
1062 - * Widget: RightNow.
1063 - *
1064 - * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1065 - */
1066 - public function mainwp_syncerrors_dismiss() {
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
1067 1081
1068 - $this->secure_request( 'mainwp_syncerrors_dismiss' );
1082 + if ( empty( $field_ids ) ) {
1083 + $ret['data'] = array( 'message' => __( 'No fields selected.', 'mainwp' ) );
1084 + echo wp_json_encode( $ret );
1085 + exit;
1086 + }
1069 1087
1070 - try {
1071 - die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1072 - } catch ( \Exception $e ) {
1073 - die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
1074 - }
1075 - }
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 + }
1076 1095
1077 - /**
1078 - * Method mainwp_events_notice_hide()
1079 - *
1080 - * Hide events notice.
1081 - */
1082 - public function mainwp_events_notice_hide() {
1083 - $this->secure_request( 'mainwp_events_notice_hide' );
1084 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1085 - if ( isset( $_POST['notice'] ) ) {
1086 - $current_options = get_option( 'mainwp_showhide_events_notice' );
1087 - if ( ! is_array( $current_options ) ) {
1088 - $current_options = array();
1089 - }
1090 - if ( 'first_site' === $_POST['notice'] ) {
1091 - update_option( 'mainwp_first_site_events_notice', '' );
1092 - } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1093 - $current_options['request_reviews1'] = 15;
1094 - $current_options['request_reviews1_starttime'] = time();
1095 - } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1096 - $current_options['request_reviews1'] = 'forever';
1097 - $current_options['request_reviews2'] = 'forever';
1098 - } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1099 - $current_options['request_reviews2'] = 15;
1100 - $current_options['request_reviews2_starttime'] = time();
1101 - } elseif ( 'trust_child' === $_POST['notice'] ) {
1102 - $current_options['trust_child'] = 1;
1103 - } elseif ( 'multi_site' === $_POST['notice'] ) {
1104 - $current_options['hide_multi_site_notice'] = 1;
1105 - }
1106 - update_option( 'mainwp_showhide_events_notice', $current_options );
1107 - }
1108 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1109 - die( 'ok' );
1110 - }
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 + }
1111 1102
1112 - /**
1113 - * Method mainwp_showhide_sections()
1114 - *
1115 - * Show/Hide sections.
1116 - */
1117 - public function mainwp_showhide_sections() {
1118 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1119 - if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1120 - $opts = get_option( 'mainwp_opts_showhide_sections' );
1121 - if ( ! is_array( $opts ) ) {
1122 - $opts = array();
1123 - }
1124 - $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1125 - update_option( 'mainwp_opts_showhide_sections', $opts );
1126 - die( 'ok' );
1127 - }
1128 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1129 - die( 'failed' );
1130 - }
1103 + echo wp_json_encode( $ret );
1104 + exit;
1105 + }
1131 1106
1132 - /**
1133 - * Method mainwp_saving_status()
1134 - *
1135 - * MainWP Saving Status.
1136 - */
1137 - public function mainwp_saving_status() {
1138 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1139 - if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1140 - die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1141 - }
1142 - $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1143 - if ( ! empty( $saving_status ) ) {
1144 - $current_options = get_option( 'mainwp_opts_saving_status' );
1145 - if ( ! is_array( $current_options ) ) {
1146 - $current_options = array();
1147 - }
1148 - if ( isset( $_POST['value'] ) ) {
1149 - $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1150 - }
1151 - update_option( 'mainwp_opts_saving_status', $current_options );
1152 - }
1153 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1154 - die( 'ok' );
1155 - }
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 + }
1156 1125
1157 - /**
1158 - * Method ajax_recheck_http()
1159 - *
1160 - * Recheck Child Site http status code & message.
1161 - *
1162 - * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1163 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1164 - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1165 - */
1166 - public function ajax_recheck_http() {
1167 - $this->check_security( 'mainwp_recheck_http' );
1168 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1169 - if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1170 - die( -1 );
1171 - }
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 + }
1172 1138
1173 - $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1174 - if ( empty( $website ) ) {
1175 - die( -1 );
1176 - }
1177 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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 + }
1178 1151
1179 - $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1180 - $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1181 - $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
1182 - die(
1183 - wp_json_encode(
1184 - array(
1185 - 'httpcode' => esc_html( $http_code ),
1186 - 'status' => $check_result ? 1 : 0,
1187 - )
1188 - )
1189 - );
1190 - }
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
1191 1166
1192 - /**
1193 - * Method mainwp_ignore_http_response()
1194 - *
1195 - * Ignore Child Site https response.
1196 - *
1197 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1198 - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1199 - */
1200 - public function mainwp_ignore_http_response() {
1201 - $this->check_security( 'mainwp_ignore_http_response' );
1202 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1203 - $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1204 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1205 - if ( empty( $siteid ) ) {
1206 - die( -1 );
1207 - }
1167 + if ( empty( $clientid ) ) {
1168 + wp_die( 'Error - empty client id!' );
1169 + }
1208 1170
1209 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1210 - if ( empty( $website ) ) {
1211 - die( -1 );
1212 - }
1171 + $params = array(
1172 + 'client_id' => $clientid,
1173 + 'suspended' => $suspended,
1174 + );
1213 1175
1214 - MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1215 - die( wp_json_encode( array( 'ok' => 1 ) ) );
1216 - }
1176 + MainWP_DB_Client::instance()->update_client( $params );
1217 1177
1218 - /**
1219 - * Method mainwp_autoupdate_and_trust_child()
1220 - *
1221 - * Set MainWP Child Plugin to Trusted & AutoUpdate.
1222 - *
1223 - * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1224 - */
1225 - public function mainwp_autoupdate_and_trust_child() {
1226 - $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1227 - if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1228 - update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1229 - }
1230 - MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1231 - die( 'ok' );
1232 - }
1178 + $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
1233 1179
1234 - /**
1235 - * Method mainwp_force_destroy_sessions()
1236 - *
1237 - * Force destroy sessions.
1238 - *
1239 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1240 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1241 - *
1242 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1243 - */
1244 - public function mainwp_force_destroy_sessions() {
1245 - $this->secure_request( 'mainwp_force_destroy_sessions' );
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 );
1246 1189
1247 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1248 - $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1249 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1250 - if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1251 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1252 - }
1190 + MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1253 1191
1254 - $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1255 - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1256 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1257 - }
1192 + wp_die( 'success' );
1193 + }
1258 1194
1259 - try {
1260 - $information = MainWP_Connect::fetch_url_authed(
1261 - $website,
1262 - 'settings_tools',
1263 - array(
1264 - 'action' => 'force_destroy_sessions',
1265 - )
1266 - );
1267 - } catch ( \Exception $e ) {
1268 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1269 - }
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 + }
1270 1213
1271 - wp_send_json( $information );
1272 - }
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 + }
1273 1262
1274 - /**
1275 - * Method ajax_refresh_icon()
1276 - */
1277 - public function ajax_refresh_icon() {
1278 - $this->secure_request( 'mainwp_refresh_icon' );
1279 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1280 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1281 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1282 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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 );
1283 1269
1284 - if ( empty( $slug ) ) {
1285 - wp_die( 'failed' );
1286 - }
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.
1287 1280
1288 - $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
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 + }
1289 1300
1290 - if ( ! empty( $fet_icon ) ) {
1291 - wp_die( 'success' );
1292 - } else {
1293 - wp_die( 'failed' );
1294 - }
1295 - }
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() {
1296 1310
1297 - /**
1298 - * Method ajax_upload_custom_icon()
1299 - */
1300 - public function ajax_upload_custom_icon() {
1301 - $this->secure_request( 'mainwp_upload_custom_icon' );
1302 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1303 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1304 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1305 - $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1311 + $this->secure_request( 'mainwp_syncerrors_dismiss' );
1306 1312
1307 - if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1308 - wp_die( 'invalid data!' );
1309 - }
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 + }
1310 1319
1311 - $sub_folder = '';
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 + }
1312 1354
1313 - if ( 'plugin' === $type ) {
1314 - $sub_folder = 'plugin-icons';
1315 - } elseif ( 'theme' === $type ) {
1316 - $sub_folder = 'theme-icons';
1317 - } else {
1318 - wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1319 - }
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 + }
1320 1374
1321 - if ( $delete ) {
1322 - MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1323 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1324 - }
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 + }
1325 1399
1326 - $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1327 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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 + }
1328 1415
1329 - $uploaded_icon = 'NOTCHANGE';
1330 - if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1331 - $uploaded_icon = $output['filename'];
1332 - }
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
1333 1421
1334 - if ( 'NOTCHANGE' !== $uploaded_icon ) {
1335 - MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1336 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1337 - } else {
1338 - wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1339 - }
1340 - }
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 );
1341 1425
1342 - /**
1343 - * Method ajax_select_custom_theme()
1344 - */
1345 - public function ajax_select_custom_theme() {
1346 - $this->secure_request( 'mainwp_select_custom_theme' );
1347 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1348 - $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1349 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1350 - if ( empty( $theme ) ) {
1351 - wp_die( 'failed' );
1352 - }
1426 + if ( is_array( $result ) && isset( $result['new_uptime_status'] ) ) {
1427 + $check_result = $result['new_uptime_status'];
1428 + }
1353 1429
1354 - $user = wp_get_current_user();
1355 - if ( empty( $user ) || empty( $user->ID ) ) {
1356 - wp_die( 'failed' );
1357 - }
1430 + die(
1431 + wp_json_encode(
1432 + array(
1433 + 'httpcode' => esc_html( $http_code ),
1434 + 'status' => $check_result ? 1 : 0,
1435 + )
1436 + )
1437 + );
1438 + }
1358 1439
1359 - update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1360 - wp_die( 'success' );
1361 - }
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 + }
1362 1456
1457 + $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1458 + if ( empty( $website ) ) {
1459 + die( -1 );
1460 + }
1363 1461
1364 - /**
1365 - * Method ajax_site_actions_dismiss()
1366 - */
1367 - public function ajax_site_actions_dismiss() {
1368 - $this->secure_request( 'mainwp_site_actions_dismiss' );
1369 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1370 - $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1371 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1462 + MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1463 + die( wp_json_encode( array( 'ok' => 1 ) ) );
1464 + }
1372 1465
1373 - if ( empty( $action_id ) ) {
1374 - wp_die( 'failed' );
1375 - }
1376 - $update = array(
1377 - 'dismiss' => 1,
1378 - );
1379 - MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1380 - wp_die( 'success' );
1381 - }
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 + }
1382 1481
1383 - /**
1384 - * Method ajax_site_actions_dismiss()
1385 - */
1386 - public function ajax_delete_non_mainwp_actions() {
1387 - $this->secure_request( 'mainwp_delete_non_mainwp_actions' );
1388 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1389 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
1390 - if ( empty( $siteid ) ) {
1391 - wp_die( wp_json_encode( array( 'error' => 'Empty site ID' ) ) );
1392 - }
1393 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1394 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1395 - $success = false;
1396 - $error = '';
1397 - try {
1398 - $response = MainWP_Connect::fetch_url_authed( $website, 'delete_actions', array( 'del' => 'act' ) );
1399 - if ( is_array( $response ) ) {
1400 - if ( isset( $response['success'] ) ) {
1401 - $success = true;
1402 - } elseif ( isset( $response['error'] ) ) {
1403 - $error = $response['error'];
1404 - }
1405 - }
1406 - } catch ( \Exception $e ) {
1407 - // ok!
1408 - }
1409 - if ( $success ) {
1410 - MainWP_DB_Site_Actions::instance()->delete_action_by( 'wpid', $siteid );
1411 - wp_die( wp_json_encode( array( 'success' => 'ok' ) ) );
1412 - }
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' );
1413 1494
1414 - if ( empty( $error ) ) {
1415 - $error = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1416 - }
1417 - wp_die( wp_json_encode( array( 'error' => $error ) ) );
1418 - }
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 + }
1419 1501
1420 - /**
1421 - * Method ajax_import_demo_data().
1422 - */
1423 - public function ajax_import_demo_data() {
1424 - $this->secure_request( 'mainwp_import_demo_data' );
1425 - $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1426 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1427 - wp_die( wp_json_encode( $data ) );
1428 - }
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 + }
1429 1506
1430 - /**
1431 - * Method ajax_delete_demo_data().
1432 - */
1433 - public function ajax_delete_demo_data() {
1434 - $this->secure_request( 'mainwp_delete_demo_data' );
1435 - $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1436 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1437 - wp_die( wp_json_encode( $data ) );
1438 - }
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 + }
1518 +
1519 + wp_send_json( $information );
1520 + }
1521 +
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
1531 +
1532 + if ( empty( $slug ) ) {
1533 + wp_die( 'failed' );
1534 + }
1535 +
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 + }
1439 2135 }