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