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