PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
← All changes | class/class-mainwp-post-handler.php +1197 -1296 5.24.3 View file →
@@ -13,1446 +13,1347 @@
13 13 * @package MainWP\Dashboard
14 14 *
15 15 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
16 16 */
17 -class MainWP_Post_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
17 +class MainWP_Post_Handler extends MainWP_Post_Base_Handler {
18 + // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated.
18 19
19 - // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated.
20 + /**
21 + * Private static variable to hold the single instance of the class.
22 + *
23 + * @static
24 + *
25 + * @var mixed Default null
26 + */
27 + private static $instance = null;
20 28
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;
29 + /**
30 + * Method instance()
31 + *
32 + * Create a public static instance.
33 + *
34 + * @static
35 + * @return MainWP_Post_Handler
36 + */
37 + public static function instance() {
38 + if ( null == self::$instance ) {
39 + self::$instance = new self();
40 + }
41 + return self::$instance;
42 + }
29 43
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 === static::$instance ) {
40 - static::$instance = new self();
41 - }
42 - return static::$instance;
43 - }
44 + /**
45 + * Initiate all actions.
46 + *
47 + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name()
48 + */
49 + public function init() {
50 + // Page: ManageSites.
51 + $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
44 52
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' ) );
53 + // Page: BulkAddUser.
54 + $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
55 + $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
53 56
54 - // Page: BulkAddUser.
55 - $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
56 - $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
57 + // Widget: RightNow.
58 + $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
57 59
58 - // Widget: RightNow.
59 - $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
60 + if ( mainwp_current_user_have_right( 'dashboard', 'manage_security_issues' ) ) {
61 + // Page: SecurityIssues.
62 + $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) );
63 + $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) );
64 + $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) );
65 + }
60 66
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 - }
67 + $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
68 + $this->add_action( 'mainwp_dismiss_twit', array( &$this, 'mainwp_dismiss_twit' ) );
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' ) );
67 74
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' ) );
75 + $this->add_action( 'mainwp_twitter_dashboard_action', array( &$this, 'mainwp_twitter_dashboard_action' ) );
75 76
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' ) );
77 + // Page: Recent Posts.
78 + if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
79 + $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
80 + $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
81 + $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
82 + $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
83 + $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
84 + $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
85 + }
86 + $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) );
87 + // Page: Pages.
88 + if ( mainwp_current_user_have_right( 'dashboard', 'manage_pages' ) ) {
89 + $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
90 + $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
91 + $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
92 + $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
93 + $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
94 + }
95 + // Page: Users.
96 + $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
97 + $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
98 + $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
99 + $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
99 100
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' ) );
101 + // Page: Posts.
102 + $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) );
103 + $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) );
104 + $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
105 + $this->add_action( 'mainwp_post_postingbulk', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_posting_posts' ) );
106 + $this->add_action( 'mainwp_get_sites_of_groups', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_get_sites_of_groups' ) );
106 107
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' ) );
108 + // Page: Pages.
109 + $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) );
110 + // Page: User.
111 + $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
111 112
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' ) );
113 + $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
114 + $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
115 + $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
116 + $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
117 + $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
118 + $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
119 + $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) );
120 + $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
121 + $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
122 + $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) );
123 + $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) );
123 124
124 - $this->add_action_nonce( 'mainwp-common-nonce' );
125 + $this->add_action_nonce( 'mainwp-common-nonce' );
125 126
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' ) );
127 + // Page: Clients.
128 + $this->add_action( 'mainwp_clients_add_client', array( &$this, 'mainwp_clients_add_client' ) );
129 + $this->add_action( 'mainwp_clients_delete_client', array( &$this, 'mainwp_clients_delete_client' ) );
129 130
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 - }
131 + $this->add_action( 'mainwp_clients_save_field', array( &$this, 'mainwp_clients_save_field' ) );
132 + $this->add_action( 'mainwp_clients_delete_general_field', array( &$this, 'mainwp_clients_delete_general_field' ) );
133 + $this->add_action( 'mainwp_clients_delete_field', array( &$this, 'mainwp_clients_delete_field' ) );
134 + $this->add_action( 'mainwp_clients_notes_save', array( &$this, 'mainwp_clients_notes_save' ) );
135 + $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
136 + $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
137 + $this->add_action( 'mainwp_upload_custom_icon', array( &$this, 'ajax_upload_custom_icon' ) );
138 + $this->add_action( 'mainwp_select_custom_theme', array( &$this, 'ajax_select_custom_theme' ) );
139 + $this->add_action( 'mainwp_site_actions_dismiss', array( &$this, 'ajax_site_actions_dismiss' ) );
140 + }
145 141
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 - }
142 + /**
143 + * Method add_post_action()
144 + *
145 + * Add ajax action.
146 + *
147 + * @param string $action Action to perform.
148 + * @param string $callback Callback to perform.
149 + */
150 + public function add_post_action( $action, $callback ) {
151 + $this->add_action( $action, $callback );
152 + }
157 153
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' );
154 + /**
155 + * Method mainwp_installation_warning_hide()
156 + *
157 + * Hide the installation warning.
158 + */
159 + public function mainwp_installation_warning_hide() {
160 + $this->secure_request( 'mainwp_installation_warning_hide' );
165 161
166 - update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
167 - die( 'ok' );
168 - }
162 + update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
163 + die( 'ok' );
164 + }
169 165
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();
166 + /**
167 + * Method mainwp_users_search()
168 + *
169 + * Search Post handler,
170 + * Page: User.
171 + *
172 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
173 + * @uses \MainWP\Dashboard\MainWP_User::render_table()
174 + */
175 + public function mainwp_users_search() {
176 + $this->secure_request( 'mainwp_users_search' );
177 + MainWP_Cache::init_session();
182 178
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 - }
179 + $role = isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : '';
180 + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
181 + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
182 + $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
183 + $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
193 184
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 -- NOSONAR - 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
185 + MainWP_User::render_table( false, $role, $groups, $sites, $search, $clients );
186 + die();
187 + }
223 188
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 - $params = array(
229 - 'groups' => $groups,
230 - 'sites' => $sites,
231 - 'postId' => $postId,
232 - 'userId' => $userId,
233 - 'post_type' => $post_type,
234 - 'search_on' => $search_on,
235 - 'clients' => $clients,
236 - );
237 - MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
238 - }
239 - die();
240 - }
241 - /**
242 - * Method mainwp_pages_search()
243 - *
244 - * Search Post handler,
245 - * Page: Pages.
246 - *
247 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
248 - * @uses \MainWP\Dashboard\MainWP_Page::render_table()
249 - *
250 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
251 - */
252 - public function mainwp_pages_search() {
253 - $this->secure_request( 'mainwp_pages_search' );
254 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
255 - if ( isset( $_POST['maximum'] ) ) {
256 - MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
257 - }
258 - $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
259 - $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
260 - $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
261 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
262 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
263 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
264 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
265 - $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
266 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
267 - MainWP_Cache::init_session();
189 + /**
190 + * Method mainwp_posts_search()
191 + *
192 + * Search Post handler,
193 + * Page: Posts.
194 + *
195 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
196 + * @uses \MainWP\Dashboard\MainWP_Post::render_table()
197 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
198 + */
199 + public function mainwp_posts_search() {
200 + $this->secure_request( 'mainwp_posts_search' );
201 + $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' );
202 + if ( isset( $_POST['maximum'] ) ) {
203 + MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
204 + }
268 205
269 - $params = array(
270 - 'groups' => $groups,
271 - 'sites' => $sites,
272 - 'search_on' => $search_on,
273 - 'clients' => $clients,
274 - );
206 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
207 + $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( trim( $_POST['dtsstart'] ) ) ) : '';
208 + $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( trim( $_POST['dtsstop'] ) ) ) : '';
209 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
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 + $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : '';
214 + $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : '';
215 + $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
216 + $table_content_only = isset( $_POST['table_content'] ) && $_POST['table_content'] ? true : false;
275 217
276 - MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
277 - die();
278 - }
218 + MainWP_Cache::init_session();
219 + if ( $table_content_only ) {
220 + MainWP_Post::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, true, $clients );
221 + } else {
222 + MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, $clients );
223 + }
224 + die();
225 + }
226 + /**
227 + * Method mainwp_pages_search()
228 + *
229 + * Search Post handler,
230 + * Page: Pages.
231 + *
232 + * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
233 + * @uses \MainWP\Dashboard\MainWP_Page::render_table()
234 + *
235 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
236 + */
237 + public function mainwp_pages_search() {
238 + $this->secure_request( 'mainwp_pages_search' );
239 + if ( isset( $_POST['maximum'] ) ) {
240 + MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
241 + }
279 242
280 - /**
281 - * Method mainwp_get_categories()
282 - *
283 - * Get post/page categories.
284 - *
285 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories()
286 - */
287 - public function mainwp_get_categories() {
288 - $this->secure_request( 'mainwp_get_categories' );
289 - MainWP_Post_Page_Handler::ajax_handle_get_categories();
290 - die();
291 - }
243 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
244 + $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
245 + $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
246 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
247 + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
248 + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
249 + $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
250 + $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
292 251
293 - /**
294 - * Method mainwp_post_get_edit()
295 - *
296 - * Get post to edit.
297 - *
298 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
299 - */
300 - public function mainwp_post_get_edit() {
301 - $this->secure_request( 'mainwp_post_get_edit' );
302 - MainWP_Post_Page_Handler::get_post();
303 - die();
304 - }
252 + MainWP_Cache::init_session();
253 + MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $search_on, $clients );
254 + die();
255 + }
305 256
306 - /**
307 - * Method mainwp_user_delete()
308 - *
309 - * Delete User from Child Site,
310 - * Page: Users.
311 - *
312 - * @uses \MainWP\Dashboard\MainWP_User::delete()
313 - */
314 - public function mainwp_user_delete() {
315 - $this->secure_request( 'mainwp_user_delete' );
316 - MainWP_User::delete();
317 - }
257 + /**
258 + * Method mainwp_get_categories()
259 + *
260 + * Get post/page categories.
261 + *
262 + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories()
263 + */
264 + public function mainwp_get_categories() {
265 + $this->secure_request( 'mainwp_get_categories' );
266 + MainWP_Post_Page_Handler::get_categories();
267 + die();
268 + }
318 269
319 - /**
320 - * Method mainwp_user_edit()
321 - *
322 - * Edit User from Child Site,
323 - * Page: Users.
324 - *
325 - * @uses \MainWP\Dashboard\MainWP_User::edit()
326 - */
327 - public function mainwp_user_edit() {
328 - $this->secure_request( 'mainwp_user_edit' );
329 - MainWP_User::edit();
330 - }
270 + /**
271 + * Method mainwp_post_get_edit()
272 + *
273 + * Get post to edit.
274 + *
275 + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
276 + */
277 + public function mainwp_post_get_edit() {
278 + $this->secure_request( 'mainwp_post_get_edit' );
279 + MainWP_Post_Page_Handler::get_post();
280 + die();
281 + }
331 282
332 - /**
333 - * Method mainwp_user_update_password(
334 - *
335 - * Update User password from Child Site,
336 - * Page: Users.
337 - *
338 - * @uses \MainWP\Dashboard\MainWP_User::update_password()
339 - */
340 - public function mainwp_user_update_password() {
341 - $this->secure_request( 'mainwp_user_update_password' );
342 - MainWP_User::update_password();
343 - }
283 + /**
284 + * Method mainwp_user_delete()
285 + *
286 + * Delete User from Child Site,
287 + * Page: Users.
288 + *
289 + * @uses \MainWP\Dashboard\MainWP_User::delete()
290 + */
291 + public function mainwp_user_delete() {
292 + $this->secure_request( 'mainwp_user_delete' );
293 + MainWP_User::delete();
294 + }
344 295
345 - /**
346 - * Method mainwp_user_update_user()
347 - *
348 - * Update User from Child Site,
349 - * Page: Users.
350 - *
351 - * @uses \MainWP\Dashboard\MainWP_User::update_user()
352 - */
353 - public function mainwp_user_update_user() {
354 - $this->secure_request( 'mainwp_user_update_user' );
355 - MainWP_User::update_user();
356 - }
296 + /**
297 + * Method mainwp_user_edit()
298 + *
299 + * Edit User from Child Site,
300 + * Page: Users.
301 + *
302 + * @uses \MainWP\Dashboard\MainWP_User::edit()
303 + */
304 + public function mainwp_user_edit() {
305 + $this->secure_request( 'mainwp_user_edit' );
306 + MainWP_User::edit();
307 + }
357 308
358 - /**
359 - * Method mainwp_post_unpublish()
360 - *
361 - * Unpublish post from Child Site,
362 - * Page: Recent Posts.
363 - *
364 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish()
365 - */
366 - public function mainwp_post_unpublish() {
367 - $this->secure_request( 'mainwp_post_unpublish' );
368 - MainWP_Recent_Posts::unpublish();
369 - }
309 + /**
310 + * Method mainwp_user_update_password(
311 + *
312 + * Update User password from Child Site,
313 + * Page: Users.
314 + *
315 + * @uses \MainWP\Dashboard\MainWP_User::update_password()
316 + */
317 + public function mainwp_user_update_password() {
318 + $this->secure_request( 'mainwp_user_update_password' );
319 + MainWP_User::update_password();
320 + }
370 321
371 - /**
372 - * Method mainwp_post_publish()
373 - *
374 - * Publish post on Child Site,
375 - * Page: Recent Posts.
376 - *
377 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish()
378 - */
379 - public function mainwp_post_publish() {
380 - $this->secure_request( 'mainwp_post_publish' );
381 - MainWP_Recent_Posts::publish();
382 - }
322 + /**
323 + * Method mainwp_user_update_user()
324 + *
325 + * Update User from Child Site,
326 + * Page: Users.
327 + *
328 + * @uses \MainWP\Dashboard\MainWP_User::update_user()
329 + */
330 + public function mainwp_user_update_user() {
331 + $this->secure_request( 'mainwp_user_update_user' );
332 + MainWP_User::update_user();
333 + }
383 334
384 - /**
385 - * Method mainwp_post_approve()
386 - *
387 - * Approve post on Child Site,
388 - * Page: Recent Posts.
389 - *
390 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve()
391 - */
392 - public function mainwp_post_approve() {
393 - $this->secure_request( 'mainwp_post_approve' );
394 - MainWP_Recent_Posts::approve();
395 - }
335 + /**
336 + * Method mainwp_post_unpublish()
337 + *
338 + * Unpublish post from Child Site,
339 + * Page: Recent Posts.
340 + *
341 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish()
342 + */
343 + public function mainwp_post_unpublish() {
344 + $this->secure_request( 'mainwp_post_unpublish' );
345 + MainWP_Recent_Posts::unpublish();
346 + }
396 347
397 - /**
398 - * Method mainwp_post_trash()
399 - *
400 - * Trash post on Child Site,
401 - * Page: Recent Posts.
402 - *
403 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash()
404 - */
405 - public function mainwp_post_trash() {
406 - $this->secure_request( 'mainwp_post_trash' );
348 + /**
349 + * Method mainwp_post_publish()
350 + *
351 + * Publish post on Child Site,
352 + * Page: Recent Posts.
353 + *
354 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish()
355 + */
356 + public function mainwp_post_publish() {
357 + $this->secure_request( 'mainwp_post_publish' );
358 + MainWP_Recent_Posts::publish();
359 + }
407 360
408 - MainWP_Recent_Posts::trash();
409 - }
361 + /**
362 + * Method mainwp_post_approve()
363 + *
364 + * Approve post on Child Site,
365 + * Page: Recent Posts.
366 + *
367 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve()
368 + */
369 + public function mainwp_post_approve() {
370 + $this->secure_request( 'mainwp_post_approve' );
371 + MainWP_Recent_Posts::approve();
372 + }
410 373
411 - /**
412 - * Method mainwp_post_delete()
413 - *
414 - * Delete post on Child Site,
415 - * Page: Recent Posts.
416 - *
417 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete()
418 - */
419 - public function mainwp_post_delete() {
420 - $this->secure_request( 'mainwp_post_delete' );
374 + /**
375 + * Method mainwp_post_trash()
376 + *
377 + * Trash post on Child Site,
378 + * Page: Recent Posts.
379 + *
380 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash()
381 + */
382 + public function mainwp_post_trash() {
383 + $this->secure_request( 'mainwp_post_trash' );
421 384
422 - MainWP_Recent_Posts::delete();
423 - }
385 + MainWP_Recent_Posts::trash();
386 + }
424 387
425 - /**
426 - * Method mainwp_post_restore()
427 - *
428 - * Restore post,
429 - * Page: Recent Posts.
430 - *
431 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore()
432 - */
433 - public function mainwp_post_restore() {
434 - $this->secure_request( 'mainwp_post_restore' );
388 + /**
389 + * Method mainwp_post_delete()
390 + *
391 + * Delete post on Child Site,
392 + * Page: Recent Posts.
393 + *
394 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete()
395 + */
396 + public function mainwp_post_delete() {
397 + $this->secure_request( 'mainwp_post_delete' );
435 398
436 - MainWP_Recent_Posts::restore();
437 - }
399 + MainWP_Recent_Posts::delete();
400 + }
438 401
439 - /**
440 - * Method mainwp_page_unpublish()
441 - *
442 - * Unpublish page,
443 - * Page: Recent Pages.
444 - *
445 - * @uses \MainWP\Dashboard\MainWP_Page::unpublish()
446 - */
447 - public function mainwp_page_unpublish() {
448 - $this->secure_request( 'mainwp_page_unpublish' );
449 - MainWP_Page::unpublish();
450 - }
402 + /**
403 + * Method mainwp_post_restore()
404 + *
405 + * Restore post,
406 + * Page: Recent Posts.
407 + *
408 + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore()
409 + */
410 + public function mainwp_post_restore() {
411 + $this->secure_request( 'mainwp_post_restore' );
451 412
452 - /**
453 - * Method mainwp_page_publish()
454 - *
455 - * Publish page,
456 - * Page: Recent Pages.
457 - *
458 - * @uses \MainWP\Dashboard\MainWP_Page::publish()
459 - */
460 - public function mainwp_page_publish() {
461 - $this->secure_request( 'mainwp_page_publish' );
462 - MainWP_Page::publish();
463 - }
413 + MainWP_Recent_Posts::restore();
414 + }
464 415
465 - /**
466 - * Method mainwp_page_trash()
467 - *
468 - * Trash page,
469 - * Page: Recent Pages.
470 - *
471 - * @uses \MainWP\Dashboard\MainWP_Page::trash()
472 - */
473 - public function mainwp_page_trash() {
474 - $this->secure_request( 'mainwp_page_trash' );
475 - MainWP_Page::trash();
476 - }
416 + /**
417 + * Method mainwp_page_unpublish()
418 + *
419 + * Unpublish page,
420 + * Page: Recent Pages.
421 + *
422 + * @uses \MainWP\Dashboard\MainWP_Page::unpublish()
423 + */
424 + public function mainwp_page_unpublish() {
425 + $this->secure_request( 'mainwp_page_unpublish' );
426 + MainWP_Page::unpublish();
427 + }
477 428
478 - /**
479 - * Method mainwp_page_delete()
480 - *
481 - * Delete page,
482 - * Page: Recent Pages.
483 - *
484 - * @uses \MainWP\Dashboard\MainWP_Page::delete()
485 - */
486 - public function mainwp_page_delete() {
487 - $this->secure_request( 'mainwp_page_delete' );
488 - MainWP_Page::delete();
489 - }
429 + /**
430 + * Method mainwp_page_publish()
431 + *
432 + * Publish page,
433 + * Page: Recent Pages.
434 + *
435 + * @uses \MainWP\Dashboard\MainWP_Page::publish()
436 + */
437 + public function mainwp_page_publish() {
438 + $this->secure_request( 'mainwp_page_publish' );
439 + MainWP_Page::publish();
440 + }
490 441
491 - /**
492 - * Method mainwp_page_restor()
493 - *
494 - * Restore page,
495 - * Page: Recent Pages.
496 - *
497 - * @uses \MainWP\Dashboard\MainWP_Page::restore()
498 - */
499 - public function mainwp_page_restore() {
500 - $this->secure_request( 'mainwp_page_restore' );
501 - MainWP_Page::restore();
502 - }
442 + /**
443 + * Method mainwp_page_trash()
444 + *
445 + * Trash page,
446 + * Page: Recent Pages.
447 + *
448 + * @uses \MainWP\Dashboard\MainWP_Page::trash()
449 + */
450 + public function mainwp_page_trash() {
451 + $this->secure_request( 'mainwp_page_trash' );
452 + MainWP_Page::trash();
453 + }
503 454
504 - /**
505 - * Method mainwp_notice_status_update()
506 - *
507 - * Hide after installation notices,
508 - * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
509 - *
510 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
511 - */
512 - public function mainwp_notice_status_update() {
513 - $this->secure_request( 'mainwp_notice_status_update' );
455 + /**
456 + * Method mainwp_page_delete()
457 + *
458 + * Delete page,
459 + * Page: Recent Pages.
460 + *
461 + * @uses \MainWP\Dashboard\MainWP_Page::delete()
462 + */
463 + public function mainwp_page_delete() {
464 + $this->secure_request( 'mainwp_page_delete' );
465 + MainWP_Page::delete();
466 + }
514 467
515 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
516 - $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
517 - if ( 'mail_failed' === $no_id ) {
518 - MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
519 - die( 'ok' );
520 - }
468 + /**
469 + * Method mainwp_page_restor()
470 + *
471 + * Restore page,
472 + * Page: Recent Pages.
473 + *
474 + * @uses \MainWP\Dashboard\MainWP_Page::restore()
475 + */
476 + public function mainwp_page_restore() {
477 + $this->secure_request( 'mainwp_page_restore' );
478 + MainWP_Page::restore();
479 + }
521 480
522 - /**
523 - * Current user global.
524 - *
525 - * @global string
526 - */
527 - global $current_user;
528 - $user_id = $current_user->ID;
529 - if ( $user_id ) {
530 - $status = get_user_option( 'mainwp_notice_saved_status' );
531 - if ( ! is_array( $status ) ) {
532 - $status = array();
533 - }
534 - if ( ! empty( $no_id ) ) {
535 - $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
536 - if ( $time_set ) {
537 - $status[ $no_id ] = time();
538 - } else {
539 - $status[ $no_id ] = 1;
540 - }
541 - update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
542 - }
543 - }
544 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
545 - die( 1 );
546 - }
481 + /**
482 + * Method mainwp_notice_status_update()
483 + *
484 + * Hide after installation notices,
485 + * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
486 + *
487 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
488 + */
489 + public function mainwp_notice_status_update() {
490 + $this->secure_request( 'mainwp_notice_status_update' );
547 491
548 - /**
549 - * Method mainwp_status_saving()
550 - *
551 - * Save last_sync_sites time().
552 - */
553 - public function mainwp_status_saving() { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
554 - $this->secure_request( 'mainwp_status_saving' );
555 - $values = get_option( 'mainwp_status_saved_values' );
492 + $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
493 + if ( 'mail_failed' === $no_id ) {
494 + MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
495 + die( 'ok' );
496 + }
556 497
557 - if ( ! is_array( $values ) ) {
558 - $values = array();
559 - }
498 + /**
499 + * Current user global.
500 + *
501 + * @global string
502 + */
503 + global $current_user;
504 + $user_id = $current_user->ID;
505 + if ( $user_id ) {
506 + $status = get_user_option( 'mainwp_notice_saved_status' );
507 + if ( ! is_array( $status ) ) {
508 + $status = array();
509 + }
510 + if ( ! empty( $no_id ) ) {
511 + $status[ $no_id ] = 1;
512 + update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
513 + }
514 + }
515 + die( 1 );
516 + }
560 517
561 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
562 - if ( ! isset( $_POST['status'] ) ) {
563 - die( -1 );
564 - }
518 + /**
519 + * Method mainwp_status_saving()
520 + *
521 + * Save last_sync_sites time() or mainwp_status_saved_values.
522 + */
523 + public function mainwp_status_saving() {
524 + $this->secure_request( 'mainwp_status_saving' );
525 + $values = get_option( 'mainwp_status_saved_values' );
565 526
566 - if ( 'last_sync_sites' === $_POST['status'] ) {
567 - if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
568 - update_option( 'mainwp_last_synced_all_sites', time() );
527 + if ( ! isset( $_POST['status'] ) ) {
528 + die( -1 );
529 + }
569 530
570 - /**
571 - * Action: mainwp_synced_all_sites
572 - *
573 - * Fires upon successfull synchronization process.
574 - *
575 - * @since 3.5.1
576 - */
577 - do_action( 'mainwp_synced_all_sites' );
578 - }
579 - die( 'ok' );
580 - }
531 + if ( 'last_sync_sites' === $_POST['status'] ) {
532 + if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
533 + update_option( 'mainwp_last_synced_all_sites', time() );
581 534
582 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
583 - $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
584 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
535 + /**
536 + * Action: mainwp_synced_all_sites
537 + *
538 + * Fires upon successfull synchronization process.
539 + *
540 + * @since 3.5.1
541 + */
542 + do_action( 'mainwp_synced_all_sites' );
543 + }
544 + die( 'ok' );
545 + }
585 546
586 - if ( ! empty( $status ) ) {
587 - if ( empty( $value ) ) {
588 - if ( isset( $values[ $status ] ) ) {
589 - unset( $values[ $status ] );
590 - }
591 - } else {
592 - $values[ $status ] = $value;
593 - }
594 - update_option( 'mainwp_status_saved_values', $values );
595 - }
547 + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
548 + $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
596 549
597 - die( 'ok' );
598 - }
550 + if ( ! empty( $status ) ) {
551 + if ( empty( $value ) ) {
552 + if ( isset( $values[ $status ] ) ) {
553 + unset( $values[ $status ] );
554 + }
555 + } else {
556 + $values[ $status ] = $value;
557 + }
558 + update_option( 'mainwp_status_saved_values', $values );
559 + }
599 560
600 - /**
601 - * Method ajax_widget_order()
602 - *
603 - * Update saved widget order.
604 - */
605 - public function ajax_widgets_order() { //phpcs:ignore -- NOSONAR - complex.
561 + die( 'ok' );
562 + }
606 563
607 - $this->secure_request( 'mainwp_widgets_order' );
608 - $user = wp_get_current_user();
609 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
610 - if ( $user && ! empty( $_POST['page'] ) ) {
611 - $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
612 - $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
613 - $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
564 + /**
565 + * Method ajax_widget_order()
566 + *
567 + * Update saved widget order.
568 + */
569 + public function ajax_widgets_order() {
614 570
615 - $wgs_orders = array();
571 + $this->secure_request( 'mainwp_widgets_order' );
572 + $user = wp_get_current_user();
573 + if ( $user && ! empty( $_POST['page'] ) ) {
574 + $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
575 + $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
576 + update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, $order, true );
577 + die( 'ok' );
578 + }
579 + die( -1 );
580 + }
616 581
617 - if ( ! empty( $wgids ) ) {
618 - $wgids = json_decode( $wgids, true );
619 - $order = json_decode( $order, true );
620 - if ( is_array( $wgids ) && is_array( $order ) ) {
621 - foreach ( $wgids as $idx => $wgid ) {
622 - if ( isset( $order[ $idx ] ) ) {
623 - $pre = 'widget-';
624 - if ( 0 === strpos( $wgid, $pre ) ) {
625 - $wgid = substr( $wgid, strlen( $pre ) );
626 - }
627 - $wgs_orders[ $wgid ] = $order[ $idx ];
628 - }
629 - }
630 - }
631 - }
582 + /**
583 + * Method ajax_mainwp_save_settings()
584 + *
585 + * Update saved MainWP Settings.
586 + *
587 + * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
588 + */
589 + public function ajax_mainwp_save_settings() {
590 + $this->secure_request( 'mainwp_save_settings' );
591 + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
592 + if ( ! empty( $name ) ) {
593 + $option_name = 'mainwp_' . $name;
594 + $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
595 + MainWP_Utility::update_option( $option_name, $val );
596 + }
597 + die( 'ok' );
598 + }
632 599
633 - if ( 'mainwp_page_manageclients' === $page ) {
634 - $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
635 - $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
636 - if ( ! empty( $sorted_array ) ) {
637 - $sorted_array = json_decode( $sorted_array, true );
638 - }
639 - if ( ! is_array( $sorted_array ) ) {
640 - $sorted_array = array();
641 - }
642 - $sorted_array[ $item_id ] = $wgs_orders;
643 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
644 - } else {
645 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
646 - }
647 - die( 'ok' );
648 - }
649 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
650 - die( -1 );
651 - }
600 + /**
601 + * Method mainwp_leftmenu_filter_group()
602 + *
603 + * MainWP left menu filter by group.
604 + *
605 + * @uses \MainWP\Dashboard\MainWP_DB::query()
606 + * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
607 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
608 + * @uses \MainWP\Dashboard\MainWP_DB::free_result()
609 + */
610 + public function mainwp_leftmenu_filter_group() {
611 + $this->secure_request( 'mainwp_leftmenu_filter_group' );
652 612
653 - /**
654 - * Method ajax_mainwp_save_settings()
655 - *
656 - * Update saved MainWP Settings.
657 - *
658 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
659 - */
660 - public function ajax_mainwp_save_settings() {
661 - $this->secure_request( 'mainwp_save_settings' );
662 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
663 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
664 - if ( ! empty( $name ) ) {
665 - $option_name = 'mainwp_' . $name;
666 - $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
667 - MainWP_Utility::update_option( $option_name, $val );
668 - }
669 - // phpcs:enable
670 - die( 'ok' );
671 - }
613 + $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
672 614
673 - /**
674 - * Method ajax_guided_tours_option_update()
675 - *
676 - * Update saved MainWP Settings.
677 - *
678 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
679 - */
680 - public function ajax_guided_tours_option_update() {
681 - $this->secure_request( 'mainwp_guided_tours_option_update' );
682 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
683 - $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
684 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
685 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
686 - die( 'ok ' . intval( $enable ) );
687 - }
615 + if ( ! empty( $gid ) ) {
616 + $ids = '';
617 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
618 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
619 + $ids .= $website->id . ',';
620 + }
621 + MainWP_DB::free_result( $websites );
622 + $ids = rtrim( $ids, ',' );
623 + die( $ids );
624 + }
625 + die( '' );
626 + }
688 627
689 - /**
690 - * Method mainwp_leftmenu_filter_group()
691 - *
692 - * MainWP left menu filter by group.
693 - *
694 - * @uses \MainWP\Dashboard\MainWP_DB::query()
695 - * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
696 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
697 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
698 - */
699 - public function mainwp_leftmenu_filter_group() {
700 - $this->secure_request( 'mainwp_leftmenu_filter_group' );
628 + /**
629 + * Method mainwp_dismiss_twit()
630 + *
631 + * Dismiss the twitter bragger.
632 + *
633 + * @uses \MainWP\Dashboard\MainWP_Twitter::clear_twitter_info()
634 + */
635 + public function mainwp_dismiss_twit() {
636 + $this->secure_request( 'mainwp_dismiss_twit' );
701 637
702 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
703 - $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
704 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
638 + /**
639 + * Current user global.
640 + *
641 + * @global string
642 + */
643 + global $current_user;
705 644
706 - if ( ! empty( $gid ) ) {
707 - $ids = '';
708 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
709 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
710 - $ids .= $website->id . ',';
711 - }
712 - MainWP_DB::free_result( $websites );
713 - $ids = rtrim( $ids, ',' );
714 - die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
715 - }
716 - die( '' );
717 - }
645 + $user_id = $current_user->ID;
646 + if ( $user_id && isset( $_POST['twitId'] ) && ! empty( $_POST['twitId'] ) && isset( $_POST['what'] ) && ! empty( $_POST['what'] ) ) {
647 + MainWP_Twitter::clear_twitter_info( sanitize_text_field( wp_unslash( $_POST['what'] ) ), sanitize_text_field( wp_unslash( $_POST['twitId'] ) ) );
648 + }
649 + die( 1 );
650 + }
718 651
719 - /**
720 - * Method dismiss_activate_notice()
721 - *
722 - * Dismiss activate notice.
723 - */
724 - public function dismiss_activate_notice() {
725 - $this->secure_request( 'mainwp_dismiss_activate_notice' );
652 + /**
653 + * Method dismiss_activate_notice()
654 + *
655 + * Dismiss activate notice.
656 + */
657 + public function dismiss_activate_notice() {
658 + $this->secure_request( 'mainwp_dismiss_activate_notice' );
726 659
727 - /**
728 - * Current user global.
729 - *
730 - * @global string
731 - */
732 - global $current_user;
733 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
734 - $user_id = $current_user->ID;
735 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
736 - if ( $user_id && ! empty( $slug ) ) {
737 - $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
738 - if ( ! is_array( $activate_notices ) ) {
739 - $activate_notices = array();
740 - }
660 + /**
661 + * Current user global.
662 + *
663 + * @global string
664 + */
665 + global $current_user;
741 666
742 - $activate_notices[ $slug ] = time();
743 - update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
744 - }
745 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
746 - die( 1 );
747 - }
667 + $user_id = $current_user->ID;
668 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
669 + if ( $user_id && ! empty( $slug ) ) {
670 + $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
671 + if ( ! is_array( $activate_notices ) ) {
672 + $activate_notices = array();
673 + }
748 674
675 + $activate_notices[ $slug ] = time();
676 + update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
677 + }
678 + die( 1 );
679 + }
749 680
681 + /**
682 + * Method mainwp_twitter_dashboard_action()
683 + *
684 + * Post handler for twitter bragger.
685 + *
686 + * @return mixed $html|$success
687 + *
688 + * @uses \MainWP\Dashboard\MainWP_Twitter
689 + * @uses \MainWP\Dashboard\MainWP_Twitter::update_twitter_info()
690 + * @uses \MainWP\Dashboard\MainWP_Twitter::enabled_twitter_messages()
691 + * @uses \MainWP\Dashboard\MainWP_Twitter::get_twitter_notice()
692 + * @uses \MainWP\Dashboard\MainWP_Twitter::get_twit_to_send()
693 + */
694 + public function mainwp_twitter_dashboard_action() {
695 + $this->secure_request( 'mainwp_twitter_dashboard_action' );
750 696
751 - /**
752 - * Method mainwp_security_issues_request()
753 - *
754 - * Post handler for,
755 - * Page: SecurityIssues.
756 - *
757 - * @uses \MainWP\Dashboard\MainWP_Exception
758 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
759 - */
760 - public function mainwp_security_issues_request() {
761 - $this->secure_request( 'mainwp_security_issues_request' );
697 + $success = false;
698 + $actionName = isset( $_POST['actionName'] ) ? sanitize_text_field( wp_unslash( $_POST['actionName'] ) ) : '';
699 + $countSites = isset( $_POST['countSites'] ) ? intval( $_POST['countSites'] ) : 0;
700 + $countRealItems = isset( $_POST['countRealItems'] ) ? intval( $_POST['countRealItems'] ) : 0;
701 + $countItems = isset( $_POST['countItems'] ) ? intval( $_POST['countItems'] ) : 0;
702 + $countSeconds = isset( $_POST['countSeconds'] ) ? intval( $_POST['countSeconds'] ) : 0;
762 703
763 - try {
764 - wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
765 - } catch ( MainWP_Exception $e ) {
766 - die(
767 - wp_json_encode(
768 - array(
769 - 'error' => array(
770 - 'message' => $e->getMessage(),
771 - 'extra' => $e->get_message_extra(),
772 - ),
773 - )
774 - )
775 - );
776 - }
777 - }
704 + if ( ! empty( $actionName ) && ! empty( $countSites ) ) {
705 + $success = MainWP_Twitter::update_twitter_info( $actionName, $countSites, $countSeconds, $countRealItems, time(), $countItems );
706 + }
778 707
779 - /**
780 - * Method mainwp_security_issues_fix()
781 - *
782 - * Post handler for 'fix issues',
783 - * Page: SecurityIssues.
784 - *
785 - * @uses \MainWP\Dashboard\MainWP_Exception
786 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
787 - */
788 - public function mainwp_security_issues_fix() {
789 - $this->secure_request( 'mainwp_security_issues_fix' );
708 + if ( ! empty( $_POST['showNotice'] ) ) {
709 + if ( MainWP_Twitter::enabled_twitter_messages() ) {
710 + $twitters = MainWP_Twitter::get_twitter_notice( $actionName );
711 + $html = '';
712 + if ( is_array( $twitters ) ) {
713 + foreach ( $twitters as $timeid => $twit_mess ) {
714 + if ( ! empty( $twit_mess ) ) {
715 + $sendText = MainWP_Twitter::get_twit_to_send( $actionName, $timeid );
716 + $html .= '<div class="mainwp-tips mainwp-notice mainwp-notice-blue twitter"><span class="mainwp-tip" twit-what="' . esc_attr( $actionName ) . '" twit-id="' . $timeid . '">' . $twit_mess . '</span>&nbsp;' . MainWP_Twitter::gen_twitter_button( $sendText, false ) . '<span><a href="#" class="mainwp-dismiss-twit mainwp-right" ><i class="fa fa-times-circle"></i> ' . __( 'Dismiss', 'mainwp' ) . '</a></span></div>';
717 + }
718 + }
719 + }
720 + die( $html );
721 + }
722 + } elseif ( $success ) {
723 + die( 'ok' );
724 + }
790 725
791 - try {
792 - wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
793 - } catch ( MainWP_Exception $e ) {
794 - die(
795 - wp_json_encode(
796 - array(
797 - 'error' => array(
798 - 'message' => $e->getMessage(),
799 - 'extra' => $e->get_message_extra(),
800 - ),
801 - )
802 - )
803 - );
804 - }
805 - }
726 + die( '' );
727 + }
806 728
807 - /**
808 - * Method mainwp_security_issues_unfix()
809 - *
810 - * Post handler for 'unfix issues',
811 - * Page: SecurityIssues.
812 - *
813 - * @uses \MainWP\Dashboard\MainWP_Exception
814 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
815 - */
816 - public function mainwp_security_issues_unfix() {
817 - $this->secure_request( 'mainwp_security_issues_unfix' );
729 + /**
730 + * Method mainwp_security_issues_request()
731 + *
732 + * Post handler for,
733 + * Page: SecurityIssues.
734 + *
735 + * @uses \MainWP\Dashboard\MainWP_Exception
736 + * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
737 + */
738 + public function mainwp_security_issues_request() {
739 + $this->secure_request( 'mainwp_security_issues_request' );
818 740
819 - try {
820 - wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
821 - } catch ( MainWP_Exception $e ) {
822 - die(
823 - wp_json_encode(
824 - array(
825 - 'error' => array(
826 - 'message' => $e->getMessage(),
827 - 'extra' => $e->get_message_extra(),
828 - ),
829 - )
830 - )
831 - );
832 - }
833 - }
741 + try {
742 + wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
743 + } catch ( MainWP_Exception $e ) {
744 + die(
745 + wp_json_encode(
746 + array(
747 + 'error' => array(
748 + 'message' => $e->getMessage(),
749 + 'extra' => $e->get_message_extra(),
750 + ),
751 + )
752 + )
753 + );
754 + }
755 + }
834 756
835 - /**
836 - * Method ajax_disconnect_site()
837 - *
838 - * Disconnect Child Site.
839 - *
840 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
841 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
842 - */
843 - public function ajax_disconnect_site() {
844 - $this->secure_request( 'mainwp_disconnect_site' );
845 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
846 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
847 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
757 + /**
758 + * Method mainwp_security_issues_fix()
759 + *
760 + * Post handler for 'fix issues',
761 + * Page: SecurityIssues.
762 + *
763 + * @uses \MainWP\Dashboard\MainWP_Exception
764 + * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
765 + */
766 + public function mainwp_security_issues_fix() {
767 + $this->secure_request( 'mainwp_security_issues_fix' );
848 768
849 - if ( empty( $siteid ) ) {
850 - die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
851 - }
769 + try {
770 + wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
771 + } catch ( MainWP_Exception $e ) {
772 + die(
773 + wp_json_encode(
774 + array(
775 + 'error' => array(
776 + 'message' => $e->getMessage(),
777 + 'extra' => $e->get_message_extra(),
778 + ),
779 + )
780 + )
781 + );
782 + }
783 + }
852 784
853 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
785 + /**
786 + * Method mainwp_security_issues_unfix()
787 + *
788 + * Post handler for 'unfix issues',
789 + * Page: SecurityIssues.
790 + *
791 + * @uses \MainWP\Dashboard\MainWP_Exception
792 + * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
793 + */
794 + public function mainwp_security_issues_unfix() {
795 + $this->secure_request( 'mainwp_security_issues_unfix' );
854 796
855 - if ( ! $website ) {
856 - die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
857 - }
797 + try {
798 + wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
799 + } catch ( MainWP_Exception $e ) {
800 + die(
801 + wp_json_encode(
802 + array(
803 + 'error' => array(
804 + 'message' => $e->getMessage(),
805 + 'extra' => $e->get_message_extra(),
806 + ),
807 + )
808 + )
809 + );
810 + }
811 + }
858 812
859 - try {
860 - $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
861 - } catch ( \Exception $e ) {
862 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
863 - }
813 + /**
814 + * Method ajax_disconnect_site()
815 + *
816 + * Disconnect Child Site.
817 + *
818 + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
819 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
820 + */
821 + public function ajax_disconnect_site() {
822 + $this->secure_request( 'mainwp_disconnect_site' );
864 823
865 - wp_send_json( $information );
866 - }
824 + $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
867 825
868 - /**
869 - * Method ajax_sites_display_rows()
870 - *
871 - * Display rows via ajax,
872 - * Page: Manage Sites.
873 - *
874 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
875 - */
876 - public function ajax_sites_display_rows() {
877 - $this->secure_request( 'mainwp_manage_sites_display_rows' );
878 - MainWP_Manage_Sites::ajax_optimize_display_rows();
879 - }
826 + if ( empty( $siteid ) ) {
827 + die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
828 + }
880 829
881 - /**
882 - * Method ajax_monitoring_display_rows()
883 - *
884 - * Display rows via ajax,
885 - * Page: Monitoring Sites.
886 - *
887 - * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
888 - */
889 - public function ajax_monitoring_display_rows() {
890 - $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
891 - MainWP_Monitoring::ajax_optimize_display_rows();
892 - }
830 + $website = MainWP_DB::instance()->get_website_by_id( $siteid );
893 831
832 + if ( ! $website ) {
833 + die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
834 + }
894 835
895 - /**
896 - * Method mainwp_bulkadduser()
897 - *
898 - * Bulk Add User for,
899 - * Page: BulkAddUser.
900 - *
901 - * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
902 - */
903 - public function mainwp_bulkadduser() {
904 - $this->check_security( 'mainwp_bulkadduser' );
905 - MainWP_User::do_bulk_add();
906 - die();
907 - }
836 + try {
837 + $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
838 + } catch ( \Exception $e ) {
839 + $information = array( 'error' => __( 'fetch_url_authed exception', 'mainwp' ) );
840 + }
908 841
909 - /**
910 - * Method mainwp_importuser()
911 - *
912 - * Import user.
913 - *
914 - * @uses \MainWP\Dashboard\MainWP_User::do_import()
915 - */
916 - public function mainwp_importuser() {
917 - $this->secure_request( 'mainwp_importuser' );
918 - MainWP_User::do_import();
919 - }
842 + wp_send_json( $information );
843 + }
920 844
921 - /**
922 - * Method mainwp_clients_add_client()
923 - *
924 - * Add Client for,
925 - * Page: BulkAddClient.
926 - */
927 - public function mainwp_clients_add_client() {
928 - $this->check_security( 'mainwp_clients_add_client' );
929 - MainWP_Client::add_client();
930 - die();
931 - }
845 + /**
846 + * Method ajax_sites_display_rows()
847 + *
848 + * Display rows via ajax,
849 + * Page: Manage Sites.
850 + *
851 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
852 + */
853 + public function ajax_sites_display_rows() {
854 + $this->secure_request( 'mainwp_manage_sites_display_rows' );
855 + MainWP_Manage_Sites::ajax_optimize_display_rows();
856 + }
932 857
933 - /**
934 - * Method mainwp_clients_delete_client()
935 - *
936 - * Add Client for,
937 - * Page: BulkAddClient.
938 - */
939 - public function mainwp_clients_delete_client() {
940 - $this->check_security( 'mainwp_clients_delete_client' );
941 - $ret = array( 'success' => false );
942 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
943 - $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
944 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
945 - if ( $client_id ) {
946 - MainWP_DB_Client::instance()->delete_client( $client_id );
947 - $ret['success'] = 'SUCCESS';
948 - $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
949 - } else {
950 - $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
951 - }
858 + /**
859 + * Method ajax_monitoring_display_rows()
860 + *
861 + * Display rows via ajax,
862 + * Page: Monitoring Sites.
863 + *
864 + * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
865 + */
866 + public function ajax_monitoring_display_rows() {
867 + $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
868 + MainWP_Monitoring::ajax_optimize_display_rows();
869 + }
952 870
953 - echo wp_json_encode( $ret );
954 - exit;
955 - }
956 871
957 - /**
958 - * Method mainwp_clients_save_field()
959 - *
960 - * Save client custom fields.
961 - */
962 - public function mainwp_clients_save_field() {
963 - $this->check_security( 'mainwp_clients_save_field' );
964 - MainWP_Client::save_client_field();
965 - die();
966 - }
872 + /**
873 + * Method mainwp_bulkadduser()
874 + *
875 + * Bulk Add User for,
876 + * Page: BulkAddUser.
877 + *
878 + * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
879 + */
880 + public function mainwp_bulkadduser() {
881 + $this->check_security( 'mainwp_bulkadduser' );
882 + MainWP_User::do_bulk_add();
883 + die();
884 + }
967 885
886 + /**
887 + * Method mainwp_importuser()
888 + *
889 + * Import user.
890 + *
891 + * @uses \MainWP\Dashboard\MainWP_User::do_import()
892 + */
893 + public function mainwp_importuser() {
894 + $this->secure_request( 'mainwp_importuser' );
895 + MainWP_User::do_import();
896 + }
968 897
969 - /**
970 - * Method mainwp_clients_delete_general_field()
971 - *
972 - * Delete client general fields.
973 - */
974 - public function mainwp_clients_delete_general_field() {
975 - $this->check_security( 'mainwp_clients_delete_general_field' );
976 - $ret = array( 'success' => false );
977 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
978 - $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
979 - $client_id = 0; // 0 general fields.
980 - if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
981 - $ret['success'] = true;
982 - }
983 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
984 - echo wp_json_encode( $ret );
985 - exit;
986 - }
898 + /**
899 + * Method mainwp_clients_add_client()
900 + *
901 + * Add Client for,
902 + * Page: BulkAddClient.
903 + */
904 + public function mainwp_clients_add_client() {
905 + $this->check_security( 'mainwp_clients_add_client' );
906 + MainWP_Client::add_client();
907 + die();
908 + }
987 909
910 + /**
911 + * Method mainwp_clients_delete_client()
912 + *
913 + * Add Client for,
914 + * Page: BulkAddClient.
915 + */
916 + public function mainwp_clients_delete_client() {
917 + $this->check_security( 'mainwp_clients_delete_client' );
918 + $ret = array( 'success' => false );
919 + $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
988 920
989 - /**
990 - * Method mainwp_clients_delete_field()
991 - *
992 - * Delete client custom fields.
993 - */
994 - public function mainwp_clients_delete_field() {
995 - $this->check_security( 'mainwp_clients_delete_field' );
996 - $ret = array( 'success' => false );
997 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
998 - $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
999 - $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
1000 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1001 - if ( $client_id && MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1002 - $ret['success'] = true;
1003 - }
1004 - echo wp_json_encode( $ret );
1005 - exit;
1006 - }
921 + if ( $client_id ) {
922 + MainWP_DB_Client::instance()->delete_client( $client_id );
923 + $ret['success'] = 'SUCCESS';
924 + $ret['result'] = __( 'Client removed successfully.', 'mainwp' );
925 + } else {
926 + $ret['result'] = __( 'Client ID empty.', 'mainwp' );
927 + }
1007 928
1008 - /**
1009 - * Method mainwp_notes_save()
1010 - *
1011 - * Post handler for save notes on,
1012 - * Page: Manage Sites.
1013 - *
1014 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1015 - */
1016 - public function mainwp_notes_save() {
1017 - $this->secure_request( 'mainwp_notes_save' );
1018 - MainWP_Manage_Sites_Handler::save_note();
1019 - }
929 + echo wp_json_encode( $ret );
930 + exit;
931 + }
1020 932
1021 - /**
1022 - * Method mainwp_clients_notes_save()
1023 - *
1024 - * Post handler for save notes on,
1025 - * Page: Manage Sites.
1026 - *
1027 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1028 - */
1029 - public function mainwp_clients_notes_save() {
1030 - $this->secure_request( 'mainwp_clients_notes_save' );
1031 - MainWP_Client::save_note();
1032 - }
933 + /**
934 + * Method mainwp_clients_save_field()
935 + *
936 + * Save client custom fields.
937 + */
938 + public function mainwp_clients_save_field() {
939 + $this->check_security( 'mainwp_clients_save_field' );
940 + MainWP_Client::save_client_field();
941 + die();
942 + }
1033 943
1034 - /**
1035 - * Method mainwp_clients_suspend_client()
1036 - *
1037 - * Post handler for suspend client,
1038 - * Page: Manage Sites.
1039 - *
1040 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1041 - */
1042 - public function mainwp_clients_suspend_client() {
1043 - $this->secure_request( 'mainwp_clients_suspend_client' );
1044 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1045 - $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1046 - $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1047 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1048 944
1049 - if ( empty( $clientid ) ) {
1050 - wp_die( 'Error - empty client id!' );
1051 - }
945 + /**
946 + * Method mainwp_clients_delete_general_field()
947 + *
948 + * Delete client general fields.
949 + */
950 + public function mainwp_clients_delete_general_field() {
951 + $this->check_security( 'mainwp_clients_delete_field' );
952 + $ret = array( 'success' => false );
953 + $field_id = intval( $_POST['field_id'] );
954 + $client_id = 0; // 0 general fields.
955 + if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
956 + $ret['success'] = true;
957 + }
958 + echo wp_json_encode( $ret );
959 + exit;
960 + }
1052 961
1053 - $params = array(
1054 - 'client_id' => $clientid,
1055 - 'suspended' => $suspended,
1056 - );
1057 962
1058 - MainWP_DB_Client::instance()->update_client( $params );
963 + /**
964 + * Method mainwp_clients_delete_field()
965 + *
966 + * Delete client custom fields.
967 + */
968 + public function mainwp_clients_delete_field() {
969 + $this->check_security( 'mainwp_clients_delete_field' );
970 + $ret = array( 'success' => false );
971 + $field_id = intval( $_POST['field_id'] );
972 + $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
973 + if ( $client_id ) {
974 + if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
975 + $ret['success'] = true;
976 + }
977 + }
978 + echo wp_json_encode( $ret );
979 + exit;
980 + }
1059 981
1060 - $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
982 + /**
983 + * Method mainwp_notes_save()
984 + *
985 + * Post handler for save notes on,
986 + * Page: Manage Sites.
987 + *
988 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
989 + */
990 + public function mainwp_notes_save() {
991 + $this->secure_request( 'mainwp_notes_save' );
992 + MainWP_Manage_Sites_Handler::save_note();
993 + }
1061 994
1062 - /**
1063 - * Fires immediately after update client suspend/unsuspend.
1064 - *
1065 - * @since 4.5.1.1
1066 - *
1067 - * @param object $client client data.
1068 - * @param bool $suspended true|false.
1069 - */
1070 - do_action( 'mainwp_client_suspend', $client, $suspended );
995 + /**
996 + * Method mainwp_clients_notes_save()
997 + *
998 + * Post handler for save notes on,
999 + * Page: Manage Sites.
1000 + *
1001 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1002 + */
1003 + public function mainwp_clients_notes_save() {
1004 + $this->secure_request( 'mainwp_clients_notes_save' );
1005 + MainWP_Client::save_note();
1006 + }
1071 1007
1072 - MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1008 + /**
1009 + * Method mainwp_clients_suspend_client()
1010 + *
1011 + * Post handler for suspend client,
1012 + * Page: Manage Sites.
1013 + *
1014 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1015 + */
1016 + public function mainwp_clients_suspend_client() {
1017 + $this->secure_request( 'mainwp_clients_suspend_client' );
1018 + $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1019 + $suspended = isset( $_POST['suspend_status'] ) && $_POST['suspend_status'] ? 1 : 0;
1073 1020
1074 - wp_die( 'success' );
1075 - }
1021 + if ( empty( $clientid ) ) {
1022 + wp_die( 'Error - empty client id!' );
1023 + }
1076 1024
1077 - /**
1078 - * Method mainwp_syncerrors_dismiss()
1079 - *
1080 - * Dismiss Sync errors for,
1081 - * Widget: RightNow.
1082 - *
1083 - * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1084 - */
1085 - public function mainwp_syncerrors_dismiss() {
1025 + $params = array(
1026 + 'client_id' => $clientid,
1027 + 'suspended' => $suspended,
1028 + );
1086 1029
1087 - $this->secure_request( 'mainwp_syncerrors_dismiss' );
1030 + MainWP_DB_Client::instance()->update_client( $params );
1088 1031
1089 - try {
1090 - die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1091 - } catch ( \Exception $e ) {
1092 - die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
1093 - }
1094 - }
1032 + MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
1095 1033
1096 - /**
1097 - * Method mainwp_events_notice_hide()
1098 - *
1099 - * Hide events notice.
1100 - */
1101 - public function mainwp_events_notice_hide() {
1102 - $this->secure_request( 'mainwp_events_notice_hide' );
1103 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1104 - if ( isset( $_POST['notice'] ) ) {
1105 - $current_options = get_option( 'mainwp_showhide_events_notice' );
1106 - if ( ! is_array( $current_options ) ) {
1107 - $current_options = array();
1108 - }
1109 - if ( 'first_site' === $_POST['notice'] ) {
1110 - update_option( 'mainwp_first_site_events_notice', '' );
1111 - } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1112 - $current_options['request_reviews1'] = 15;
1113 - $current_options['request_reviews1_starttime'] = time();
1114 - } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1115 - $current_options['request_reviews1'] = 'forever';
1116 - $current_options['request_reviews2'] = 'forever';
1117 - } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1118 - $current_options['request_reviews2'] = 15;
1119 - $current_options['request_reviews2_starttime'] = time();
1120 - } elseif ( 'trust_child' === $_POST['notice'] ) {
1121 - $current_options['trust_child'] = 1;
1122 - } elseif ( 'multi_site' === $_POST['notice'] ) {
1123 - $current_options['hide_multi_site_notice'] = 1;
1124 - }
1125 - update_option( 'mainwp_showhide_events_notice', $current_options );
1126 - }
1127 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1128 - die( 'ok' );
1129 - }
1034 + wp_die( 'success' );
1035 + }
1130 1036
1131 - /**
1132 - * Method mainwp_showhide_sections()
1133 - *
1134 - * Show/Hide sections.
1135 - */
1136 - public function mainwp_showhide_sections() {
1137 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1138 - if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1139 - $opts = get_option( 'mainwp_opts_showhide_sections' );
1140 - if ( ! is_array( $opts ) ) {
1141 - $opts = array();
1142 - }
1143 - $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1144 - update_option( 'mainwp_opts_showhide_sections', $opts );
1145 - die( 'ok' );
1146 - }
1147 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1148 - die( 'failed' );
1149 - }
1037 + /**
1038 + * Method mainwp_syncerrors_dismiss()
1039 + *
1040 + * Dismiss Sync errors for,
1041 + * Widget: RightNow.
1042 + *
1043 + * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1044 + */
1045 + public function mainwp_syncerrors_dismiss() {
1150 1046
1151 - /**
1152 - * Method mainwp_saving_status()
1153 - *
1154 - * MainWP Saving Status.
1155 - */
1156 - public function mainwp_saving_status() {
1157 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1158 - if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1159 - die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1160 - }
1161 - $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1162 - if ( ! empty( $saving_status ) ) {
1163 - $current_options = get_option( 'mainwp_opts_saving_status' );
1164 - if ( ! is_array( $current_options ) ) {
1165 - $current_options = array();
1166 - }
1167 - if ( isset( $_POST['value'] ) ) {
1168 - $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1169 - }
1170 - update_option( 'mainwp_opts_saving_status', $current_options );
1171 - }
1172 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1173 - die( 'ok' );
1174 - }
1047 + $this->secure_request( 'mainwp_syncerrors_dismiss' );
1175 1048
1176 - /**
1177 - * Method ajax_recheck_http()
1178 - *
1179 - * Recheck Child Site http status code & message.
1180 - *
1181 - * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1182 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1183 - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1184 - */
1185 - public function ajax_recheck_http() {
1186 - $this->check_security( 'mainwp_recheck_http' );
1187 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1188 - if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1189 - die( -1 );
1190 - }
1049 + try {
1050 + die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1051 + } catch ( \Exception $e ) {
1052 + die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
1053 + }
1054 + }
1191 1055
1192 - $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1193 - if ( empty( $website ) ) {
1194 - die( -1 );
1195 - }
1196 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1056 + /**
1057 + * Method mainwp_events_notice_hide()
1058 + *
1059 + * Hide events notice.
1060 + */
1061 + public function mainwp_events_notice_hide() {
1062 + $this->secure_request( 'mainwp_events_notice_hide' );
1197 1063
1198 - $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1199 - $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1200 - $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
1201 - die(
1202 - wp_json_encode(
1203 - array(
1204 - 'httpcode' => esc_html( $http_code ),
1205 - 'status' => $check_result ? 1 : 0,
1206 - )
1207 - )
1208 - );
1209 - }
1064 + if ( isset( $_POST['notice'] ) ) {
1065 + $current_options = get_option( 'mainwp_showhide_events_notice' );
1066 + if ( ! is_array( $current_options ) ) {
1067 + $current_options = array();
1068 + }
1069 + if ( 'first_site' === $_POST['notice'] ) {
1070 + update_option( 'mainwp_first_site_events_notice', '' );
1071 + } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1072 + $current_options['request_reviews1'] = 15;
1073 + $current_options['request_reviews1_starttime'] = time();
1074 + } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1075 + $current_options['request_reviews1'] = 'forever';
1076 + $current_options['request_reviews2'] = 'forever';
1077 + } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1078 + $current_options['request_reviews2'] = 15;
1079 + $current_options['request_reviews2_starttime'] = time();
1080 + } elseif ( 'trust_child' === $_POST['notice'] ) {
1081 + $current_options['trust_child'] = 1;
1082 + } elseif ( 'multi_site' === $_POST['notice'] ) {
1083 + $current_options['hide_multi_site_notice'] = 1;
1084 + }
1085 + update_option( 'mainwp_showhide_events_notice', $current_options );
1086 + }
1087 + die( 'ok' );
1088 + }
1210 1089
1211 - /**
1212 - * Method mainwp_ignore_http_response()
1213 - *
1214 - * Ignore Child Site https response.
1215 - *
1216 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1217 - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1218 - */
1219 - public function mainwp_ignore_http_response() {
1220 - $this->check_security( 'mainwp_ignore_http_response' );
1221 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1222 - $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1223 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1224 - if ( empty( $siteid ) ) {
1225 - die( -1 );
1226 - }
1090 + /**
1091 + * Method mainwp_showhide_sections()
1092 + *
1093 + * Show/Hide sections.
1094 + */
1095 + public function mainwp_showhide_sections() {
1096 + if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1097 + $opts = get_option( 'mainwp_opts_showhide_sections' );
1098 + if ( ! is_array( $opts ) ) {
1099 + $opts = array();
1100 + }
1101 + $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1102 + update_option( 'mainwp_opts_showhide_sections', $opts );
1103 + die( 'ok' );
1104 + }
1105 + die( 'failed' );
1106 + }
1227 1107
1228 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1229 - if ( empty( $website ) ) {
1230 - die( -1 );
1231 - }
1108 + /**
1109 + * Method mainwp_saving_status()
1110 + *
1111 + * MainWP Saving Status.
1112 + */
1113 + public function mainwp_saving_status() {
1114 + if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1115 + die( __( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1116 + }
1117 + $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1118 + if ( ! empty( $saving_status ) ) {
1119 + $current_options = get_option( 'mainwp_opts_saving_status' );
1120 + if ( ! is_array( $current_options ) ) {
1121 + $current_options = array();
1122 + }
1123 + if ( isset( $_POST['value'] ) ) {
1124 + $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1125 + }
1126 + update_option( 'mainwp_opts_saving_status', $current_options );
1127 + }
1128 + die( 'ok' );
1129 + }
1232 1130
1233 - MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1234 - die( wp_json_encode( array( 'ok' => 1 ) ) );
1235 - }
1131 + /**
1132 + * Method ajax_recheck_http()
1133 + *
1134 + * Recheck Child Site http status code & message.
1135 + *
1136 + * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1137 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1138 + * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1139 + */
1140 + public function ajax_recheck_http() {
1141 + $this->check_security( 'mainwp_recheck_http' );
1236 1142
1237 - /**
1238 - * Method mainwp_autoupdate_and_trust_child()
1239 - *
1240 - * Set MainWP Child Plugin to Trusted & AutoUpdate.
1241 - *
1242 - * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1243 - */
1244 - public function mainwp_autoupdate_and_trust_child() {
1245 - $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1246 - if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1247 - update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1248 - }
1249 - MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1250 - die( 'ok' );
1251 - }
1143 + if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1144 + die( -1 );
1145 + }
1252 1146
1253 - /**
1254 - * Method mainwp_force_destroy_sessions()
1255 - *
1256 - * Force destroy sessions.
1257 - *
1258 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1259 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1260 - *
1261 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1262 - */
1263 - public function mainwp_force_destroy_sessions() {
1264 - $this->secure_request( 'mainwp_force_destroy_sessions' );
1147 + $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1148 + if ( empty( $website ) ) {
1149 + die( -1 );
1150 + }
1265 1151
1266 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1267 - $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1268 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1269 - if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1270 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1271 - }
1152 + $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1153 + $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1154 + $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
1155 + die(
1156 + wp_json_encode(
1157 + array(
1158 + 'httpcode' => esc_html( $http_code ),
1159 + 'status' => $check_result ? 1 : 0,
1160 + )
1161 + )
1162 + );
1163 + }
1272 1164
1273 - $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1274 - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1275 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1276 - }
1165 + /**
1166 + * Method mainwp_ignore_http_response()
1167 + *
1168 + * Ignore Child Site https response.
1169 + *
1170 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1171 + * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1172 + */
1173 + public function mainwp_ignore_http_response() {
1174 + $this->check_security( 'mainwp_ignore_http_response' );
1175 + $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1277 1176
1278 - try {
1279 - $information = MainWP_Connect::fetch_url_authed(
1280 - $website,
1281 - 'settings_tools',
1282 - array(
1283 - 'action' => 'force_destroy_sessions',
1284 - )
1285 - );
1286 - } catch ( \Exception $e ) {
1287 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1288 - }
1177 + if ( empty( $siteid ) ) {
1178 + die( -1 );
1179 + }
1289 1180
1290 - wp_send_json( $information );
1291 - }
1181 + $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1182 + if ( empty( $website ) ) {
1183 + die( -1 );
1184 + }
1292 1185
1293 - /**
1294 - * Method ajax_refresh_icon()
1295 - */
1296 - public function ajax_refresh_icon() {
1297 - $this->secure_request( 'mainwp_refresh_icon' );
1298 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1299 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1300 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1301 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1186 + MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1187 + die( wp_json_encode( array( 'ok' => 1 ) ) );
1188 + }
1302 1189
1303 - if ( empty( $slug ) ) {
1304 - wp_die( 'failed' );
1305 - }
1190 + /**
1191 + * Method mainwp_autoupdate_and_trust_child()
1192 + *
1193 + * Set MainWP Child Plugin to Trusted & AutoUpdate.
1194 + *
1195 + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1196 + */
1197 + public function mainwp_autoupdate_and_trust_child() {
1198 + $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1199 + if ( get_option( 'mainwp_automaticDailyUpdate' ) != 1 ) {
1200 + update_option( 'mainwp_automaticDailyUpdate', 1 );
1201 + }
1202 + MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1203 + die( 'ok' );
1204 + }
1306 1205
1307 - $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1206 + /**
1207 + * Method mainwp_force_destroy_sessions()
1208 + *
1209 + * Force destroy sessions.
1210 + *
1211 + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1212 + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1213 + *
1214 + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1215 + */
1216 + public function mainwp_force_destroy_sessions() {
1217 + $this->secure_request( 'mainwp_force_destroy_sessions' );
1308 1218
1309 - if ( ! empty( $fet_icon ) ) {
1310 - wp_die( 'success' );
1311 - } else {
1312 - wp_die( 'failed' );
1313 - }
1314 - }
1219 + $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1315 1220
1316 - /**
1317 - * Method ajax_upload_custom_icon()
1318 - */
1319 - public function ajax_upload_custom_icon() {
1320 - $this->secure_request( 'mainwp_upload_custom_icon' );
1321 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1322 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1323 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1324 - $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1221 + if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1222 + die( wp_json_encode( array( 'error' => array( 'message' => __( 'This website does not exist.', 'mainwp' ) ) ) ) );
1223 + }
1325 1224
1326 - if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1327 - wp_die( 'invalid data!' );
1328 - }
1225 + $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1226 + if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1227 + die( wp_json_encode( array( 'error' => array( 'message' => __( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1228 + }
1329 1229
1330 - $sub_folder = '';
1230 + try {
1231 + $information = MainWP_Connect::fetch_url_authed(
1232 + $website,
1233 + 'settings_tools',
1234 + array(
1235 + 'action' => 'force_destroy_sessions',
1236 + )
1237 + );
1331 1238
1332 - if ( 'plugin' === $type ) {
1333 - $sub_folder = 'plugin-icons';
1334 - } elseif ( 'theme' === $type ) {
1335 - $sub_folder = 'theme-icons';
1336 - } else {
1337 - wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1338 - }
1239 + /**
1240 + * MainWP information array.
1241 + *
1242 + * @global object $mainWP
1243 + */
1244 + global $mainWP;
1339 1245
1340 - if ( $delete ) {
1341 - MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1342 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1343 - }
1246 + if ( ( '2.0.22' === $mainWP->get_version() ) || ( '2.0.23' === $mainWP->get_version() ) ) {
1247 + if ( 1 != get_option( 'mainwp_fixed_security_2022' ) ) {
1248 + update_option( 'mainwp_fixed_security_2022', 1 );
1249 + }
1250 + }
1251 + } catch ( \Exception $e ) {
1252 + $information = array( 'error' => __( 'fetch_url_authed exception', 'mainwp' ) );
1253 + }
1344 1254
1345 - $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1346 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1255 + wp_send_json( $information );
1256 + }
1347 1257
1348 - $uploaded_icon = 'NOTCHANGE';
1349 - if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1350 - $uploaded_icon = $output['filename'];
1351 - }
1258 + /**
1259 + * Method ajax_refresh_icon()
1260 + */
1261 + public function ajax_refresh_icon() {
1262 + $this->secure_request( 'mainwp_refresh_icon' );
1263 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1264 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1352 1265
1353 - if ( 'NOTCHANGE' !== $uploaded_icon ) {
1354 - MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1355 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1356 - } else {
1357 - wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1358 - }
1359 - }
1266 + if ( empty( $slug ) ) {
1267 + wp_die( 'failed' );
1268 + }
1360 1269
1361 - /**
1362 - * Method ajax_select_custom_theme()
1363 - */
1364 - public function ajax_select_custom_theme() {
1365 - $this->secure_request( 'mainwp_select_custom_theme' );
1366 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1367 - $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1368 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1369 - if ( empty( $theme ) ) {
1370 - wp_die( 'failed' );
1371 - }
1270 + $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1372 1271
1373 - $user = wp_get_current_user();
1374 - if ( empty( $user ) || empty( $user->ID ) ) {
1375 - wp_die( 'failed' );
1376 - }
1272 + if ( ! empty( $fet_icon ) ) {
1273 + wp_die( 'success' );
1274 + } else {
1275 + wp_die( 'failed' );
1276 + }
1277 + }
1377 1278
1378 - update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1379 - wp_die( 'success' );
1380 - }
1279 + /**
1280 + * Method ajax_upload_custom_icon()
1281 + */
1282 + public function ajax_upload_custom_icon() {
1283 + $this->secure_request( 'mainwp_upload_custom_icon' );
1284 + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1285 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1286 + $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1381 1287
1288 + if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1289 + wp_die( 'failed' );
1290 + }
1382 1291
1383 - /**
1384 - * Method ajax_site_actions_dismiss()
1385 - */
1386 - public function ajax_site_actions_dismiss() {
1387 - $this->secure_request( 'mainwp_site_actions_dismiss' );
1388 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1389 - $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1390 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1292 + $sub_folder = '';
1391 1293
1392 - if ( empty( $action_id ) ) {
1393 - wp_die( 'failed' );
1394 - }
1395 - $update = array(
1396 - 'dismiss' => 1,
1397 - );
1398 - MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1399 - wp_die( 'success' );
1400 - }
1294 + if ( 'plugin' === $type ) {
1295 + $sub_folder = 'plugin-icons';
1296 + } elseif ( 'theme' === $type ) {
1297 + $sub_folder = 'theme-icons';
1298 + } else {
1299 + wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1300 + }
1401 1301
1402 - /**
1403 - * Method ajax_site_actions_dismiss()
1404 - */
1405 - public function ajax_delete_non_mainwp_actions() {
1406 - $this->secure_request( 'mainwp_delete_non_mainwp_actions' );
1407 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1408 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
1409 - if ( empty( $siteid ) ) {
1410 - wp_die( wp_json_encode( array( 'error' => 'Empty site ID' ) ) );
1411 - }
1412 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1413 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1414 - $success = false;
1415 - $error = '';
1416 - try {
1417 - $response = MainWP_Connect::fetch_url_authed( $website, 'delete_actions', array( 'del' => 'act' ) );
1418 - if ( is_array( $response ) ) {
1419 - if ( isset( $response['success'] ) ) {
1420 - $success = true;
1421 - } elseif ( isset( $response['error'] ) ) {
1422 - $error = $response['error'];
1423 - }
1424 - }
1425 - } catch ( \Exception $e ) {
1426 - // ok!
1427 - }
1428 - if ( $success ) {
1429 - MainWP_DB_Site_Actions::instance()->delete_action_by( 'wpid', $siteid );
1430 - wp_die( wp_json_encode( array( 'success' => 'ok' ) ) );
1431 - }
1302 + if ( $delete ) {
1303 + MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1304 + wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1305 + }
1432 1306
1433 - if ( empty( $error ) ) {
1434 - $error = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1435 - }
1436 - wp_die( wp_json_encode( array( 'error' => $error ) ) );
1437 - }
1307 + $output = MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 );
1438 1308
1439 - /**
1440 - * Method ajax_import_demo_data().
1441 - */
1442 - public function ajax_import_demo_data() {
1443 - $this->secure_request( 'mainwp_import_demo_data' );
1444 - $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1445 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1446 - wp_die( wp_json_encode( $data ) );
1447 - }
1309 + $uploaded_icon = 'NOTCHANGE';
1310 + if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1311 + $uploaded_icon = $output['filename'];
1312 + }
1448 1313
1449 - /**
1450 - * Method ajax_delete_demo_data().
1451 - */
1452 - public function ajax_delete_demo_data() {
1453 - $this->secure_request( 'mainwp_delete_demo_data' );
1454 - $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1455 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1456 - wp_die( wp_json_encode( $data ) );
1457 - }
1314 + if ( 'NOTCHANGE' !== $uploaded_icon ) {
1315 + MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1316 + wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1317 + } else {
1318 + wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1319 + }
1320 + }
1321 +
1322 + /**
1323 + * Method ajax_select_custom_theme()
1324 + */
1325 + public function ajax_select_custom_theme() {
1326 + $this->secure_request( 'mainwp_select_custom_theme' );
1327 + $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1328 + if ( empty( $theme ) ) {
1329 + wp_die( 'failed' );
1330 + }
1331 +
1332 + $user = wp_get_current_user();
1333 + if ( empty( $user ) || empty( $user->ID ) ) {
1334 + wp_die( 'failed' );
1335 + }
1336 +
1337 + update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1338 + wp_die( 'success' );
1339 + }
1340 +
1341 +
1342 + /**
1343 + * Method ajax_site_actions_dismiss()
1344 + */
1345 + public function ajax_site_actions_dismiss() {
1346 + $this->secure_request( 'mainwp_site_actions_dismiss' );
1347 + $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1348 + if ( empty( $action_id ) ) {
1349 + wp_die( 'failed' );
1350 + }
1351 + $update = array(
1352 + 'dismiss' => 1,
1353 + );
1354 + MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1355 + wp_die( 'success' );
1356 + }
1357 +
1358 +
1458 1359 }