| @@ -6,18 +6,8 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace MainWP\Dashboard; |
| 9 | 9 | |
| 10 | -use MainWP\Dashboard\Module\Log\Log_DB_Helper; | |
| 11 | -use MainWP\Dashboard\Module\Log\Log_Changes_Logs_Helper; | |
| 12 | - | |
| 13 | -// Exit if accessed directly. | |
| 14 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | - exit; | |
| 16 | -} | |
| 17 | - | |
| 18 | -// phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity. | |
| 19 | - | |
| 20 | 10 | /** |
| 21 | 11 | * Class MainWP_Post_Handler |
| 22 | 12 | * |
| 23 | 13 | * @package MainWP\Dashboard |
| @@ -23,2082 +13,1103 @@ | ||
| 23 | 13 | * @package MainWP\Dashboard |
| 24 | 14 | * |
| 25 | 15 | * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler |
| 26 | 16 | */ |
| 27 | -class MainWP_Post_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore -- NOSONAR - Complex. | |
| 17 | +class MainWP_Post_Handler extends MainWP_Post_Base_Handler { | |
| 18 | + // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated. | |
| 28 | 19 | |
| 29 | - /** | |
| 30 | - * Private static variable to hold the single instance of the class. | |
| 31 | - * | |
| 32 | - * @static | |
| 33 | - * | |
| 34 | - * @var mixed Default null | |
| 35 | - */ | |
| 36 | - private static $instance = null; | |
| 20 | + /** | |
| 21 | + * Private static variable to hold the single instance of the class. | |
| 22 | + * | |
| 23 | + * @static | |
| 24 | + * | |
| 25 | + * @var mixed Default null | |
| 26 | + */ | |
| 27 | + private static $instance = null; | |
| 37 | 28 | |
| 38 | - /** | |
| 39 | - * Method instance() | |
| 40 | - * | |
| 41 | - * Create a public static instance. | |
| 42 | - * | |
| 43 | - * @static | |
| 44 | - * @return MainWP_Post_Handler | |
| 45 | - */ | |
| 46 | - public static function instance() { | |
| 47 | - if ( null === static::$instance ) { | |
| 48 | - static::$instance = new self(); | |
| 49 | - } | |
| 50 | - return static::$instance; | |
| 51 | - } | |
| 29 | + /** | |
| 30 | + * Method instance() | |
| 31 | + * | |
| 32 | + * Create a public static instance. | |
| 33 | + * | |
| 34 | + * @static | |
| 35 | + * @return MainWP_Post_Handler | |
| 36 | + */ | |
| 37 | + public static function instance() { | |
| 38 | + if ( null == self::$instance ) { | |
| 39 | + self::$instance = new self(); | |
| 40 | + } | |
| 41 | + return self::$instance; | |
| 42 | + } | |
| 52 | 43 | |
| 53 | - /** | |
| 54 | - * Initiate all actions. | |
| 55 | - * | |
| 56 | - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name() | |
| 57 | - */ | |
| 58 | - public function init() { | |
| 59 | - // Page: ManageSites. | |
| 60 | - $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) ); | |
| 44 | + /** | |
| 45 | + * Initiate all actions. | |
| 46 | + * | |
| 47 | + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name() | |
| 48 | + */ | |
| 49 | + public function init() { | |
| 50 | + // Page: ManageSites. | |
| 51 | + $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) ); | |
| 61 | 52 | |
| 62 | - // Page: BulkAddUser. | |
| 63 | - $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) ); | |
| 64 | - $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) ); | |
| 53 | + // Page: BulkAddUser. | |
| 54 | + $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) ); | |
| 55 | + $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) ); | |
| 65 | 56 | |
| 66 | - // Widget: RightNow. | |
| 67 | - $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) ); | |
| 57 | + // Widget: RightNow. | |
| 58 | + $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) ); | |
| 68 | 59 | |
| 69 | - if ( \mainwp_current_user_can( 'dashboard', 'manage_security_issues' ) ) { | |
| 70 | - // Page: SecurityIssues. | |
| 71 | - $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) ); | |
| 72 | - $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) ); | |
| 73 | - $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) ); | |
| 74 | - } | |
| 60 | + if ( mainwp_current_user_have_right( 'dashboard', 'manage_security_issues' ) ) { | |
| 61 | + // Page: SecurityIssues. | |
| 62 | + $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) ); | |
| 63 | + $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) ); | |
| 64 | + $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) ); | |
| 65 | + } | |
| 75 | 66 | |
| 76 | - $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) ); | |
| 77 | - $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) ); | |
| 78 | - $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) ); | |
| 79 | - $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) ); | |
| 80 | - $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) ); | |
| 81 | - $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) ); | |
| 82 | - $this->add_action( 'mainwp_guided_tours_option_update', array( &$this, 'ajax_guided_tours_option_update' ) ); | |
| 83 | - $this->add_action( 'mainwp_help_modal_content_update', array( &$this, 'ajax_mainwp_help_modal_content_update' ) ); | |
| 67 | + $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) ); | |
| 68 | + $this->add_action( 'mainwp_dismiss_twit', array( &$this, 'mainwp_dismiss_twit' ) ); | |
| 69 | + $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) ); | |
| 70 | + $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) ); | |
| 71 | + $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) ); | |
| 72 | + $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) ); | |
| 73 | + $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) ); | |
| 84 | 74 | |
| 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' ) ); | |
| 75 | + $this->add_action( 'mainwp_twitter_dashboard_action', array( &$this, 'mainwp_twitter_dashboard_action' ) ); | |
| 108 | 76 | |
| 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' ) ); | |
| 77 | + // Page: Recent Posts. | |
| 78 | + if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) { | |
| 79 | + $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) ); | |
| 80 | + $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) ); | |
| 81 | + $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) ); | |
| 82 | + $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) ); | |
| 83 | + $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) ); | |
| 84 | + $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) ); | |
| 85 | + } | |
| 86 | + $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) ); | |
| 87 | + // Page: Pages. | |
| 88 | + if ( mainwp_current_user_have_right( 'dashboard', 'manage_pages' ) ) { | |
| 89 | + $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) ); | |
| 90 | + $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) ); | |
| 91 | + $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) ); | |
| 92 | + $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) ); | |
| 93 | + $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) ); | |
| 94 | + } | |
| 95 | + // Page: Users. | |
| 96 | + $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) ); | |
| 97 | + $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) ); | |
| 98 | + $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) ); | |
| 99 | + $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) ); | |
| 115 | 100 | |
| 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' ) ); | |
| 101 | + // Page: Posts. | |
| 102 | + $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) ); | |
| 103 | + $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) ); | |
| 104 | + $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) ); | |
| 105 | + $this->add_action( 'mainwp_post_postingbulk', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_posting_posts' ) ); | |
| 106 | + $this->add_action( 'mainwp_get_sites_of_groups', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_get_sites_of_groups' ) ); | |
| 120 | 107 | |
| 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' ) ); | |
| 108 | + // Page: Pages. | |
| 109 | + $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) ); | |
| 110 | + // Page: User. | |
| 111 | + $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) ); | |
| 132 | 112 | |
| 133 | - $this->add_action_nonce( 'mainwp-common-nonce' ); | |
| 113 | + $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) ); | |
| 114 | + $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) ); | |
| 115 | + $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) ); | |
| 116 | + $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) ); | |
| 117 | + $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) ); | |
| 118 | + $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) ); | |
| 119 | + $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) ); | |
| 120 | + $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) ); | |
| 121 | + $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) ); | |
| 122 | + $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) ); | |
| 123 | + $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) ); | |
| 134 | 124 | |
| 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' ) ); | |
| 125 | + $this->add_action_nonce( 'mainwp-common-nonce' ); | |
| 126 | + } | |
| 138 | 127 | |
| 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' ) ); | |
| 128 | + /** | |
| 129 | + * Method add_post_action() | |
| 130 | + * | |
| 131 | + * Add ajax action. | |
| 132 | + * | |
| 133 | + * @param string $action Action to perform. | |
| 134 | + * @param string $callback Callback to perform. | |
| 135 | + */ | |
| 136 | + public function add_post_action( $action, $callback ) { | |
| 137 | + $this->add_action( $action, $callback ); | |
| 138 | + } | |
| 152 | 139 | |
| 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' ) ); | |
| 140 | + /** | |
| 141 | + * Method mainwp_installation_warning_hide() | |
| 142 | + * | |
| 143 | + * Hide the installation warning. | |
| 144 | + */ | |
| 145 | + public function mainwp_installation_warning_hide() { | |
| 146 | + $this->secure_request( 'mainwp_installation_warning_hide' ); | |
| 155 | 147 | |
| 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' ) ); | |
| 148 | + update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' ); | |
| 149 | + die( 'ok' ); | |
| 150 | + } | |
| 161 | 151 | |
| 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' ) ); | |
| 152 | + /** | |
| 153 | + * Method mainwp_users_search() | |
| 154 | + * | |
| 155 | + * Search Post handler, | |
| 156 | + * Page: User. | |
| 157 | + * | |
| 158 | + * @uses \MainWP\Dashboard\MainWP_Cache::init_session() | |
| 159 | + * @uses \MainWP\Dashboard\MainWP_User::render_table() | |
| 160 | + */ | |
| 161 | + public function mainwp_users_search() { | |
| 162 | + $this->secure_request( 'mainwp_users_search' ); | |
| 163 | + MainWP_Cache::init_session(); | |
| 166 | 164 | |
| 167 | - $this->add_action( 'mainwp_changes_logs_get_item_changes', array( &$this, 'ajax_get_item_changes_logs' ) ); | |
| 168 | - } | |
| 165 | + $role = isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : ''; | |
| 166 | + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : ''; | |
| 167 | + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : ''; | |
| 168 | + $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : ''; | |
| 169 | 169 | |
| 170 | - /** | |
| 171 | - * Method 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 | - } | |
| 170 | + MainWP_User::render_table( false, $role, $groups, $sites, $search ); | |
| 171 | + die(); | |
| 172 | + } | |
| 181 | 173 | |
| 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' ); | |
| 174 | + /** | |
| 175 | + * Method mainwp_posts_search() | |
| 176 | + * | |
| 177 | + * Search Post handler, | |
| 178 | + * Page: Posts. | |
| 179 | + * | |
| 180 | + * @uses \MainWP\Dashboard\MainWP_Cache::init_session() | |
| 181 | + * @uses \MainWP\Dashboard\MainWP_Post::render_table() | |
| 182 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 183 | + */ | |
| 184 | + public function mainwp_posts_search() { | |
| 185 | + $this->secure_request( 'mainwp_posts_search' ); | |
| 186 | + $post_type = ( isset( $_POST['post_type'] ) && 0 < strlen( sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' ); | |
| 187 | + if ( isset( $_POST['maximum'] ) ) { | |
| 188 | + MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 ); | |
| 189 | + } | |
| 189 | 190 | |
| 190 | - update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' ); | |
| 191 | - die( 'ok' ); | |
| 192 | - } | |
| 191 | + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : ''; | |
| 192 | + $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( trim( $_POST['dtsstart'] ) ) ) : ''; | |
| 193 | + $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( trim( $_POST['dtsstop'] ) ) ) : ''; | |
| 194 | + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : ''; | |
| 195 | + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : ''; | |
| 196 | + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : ''; | |
| 197 | + $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : ''; | |
| 198 | + $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : ''; | |
| 199 | + $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : ''; | |
| 200 | + $table_content_only = isset( $_POST['table_content'] ) && $_POST['table_content'] ? true : false; | |
| 193 | 201 | |
| 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(); | |
| 202 | + MainWP_Cache::init_session(); | |
| 203 | + if ( $table_content_only ) { | |
| 204 | + MainWP_Post::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, true ); | |
| 205 | + } else { | |
| 206 | + MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on ); | |
| 207 | + } | |
| 208 | + die(); | |
| 209 | + } | |
| 210 | + /** | |
| 211 | + * Method mainwp_pages_search() | |
| 212 | + * | |
| 213 | + * Search Post handler, | |
| 214 | + * Page: Pages. | |
| 215 | + * | |
| 216 | + * @uses \MainWP\Dashboard\MainWP_Cache::init_session() | |
| 217 | + * @uses \MainWP\Dashboard\MainWP_Page::render_table() | |
| 218 | + * | |
| 219 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 220 | + */ | |
| 221 | + public function mainwp_pages_search() { | |
| 222 | + $this->secure_request( 'mainwp_pages_search' ); | |
| 223 | + if ( isset( $_POST['maximum'] ) ) { | |
| 224 | + MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 ); | |
| 225 | + } | |
| 206 | 226 | |
| 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 | - } | |
| 227 | + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : ''; | |
| 228 | + $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : ''; | |
| 229 | + $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : ''; | |
| 230 | + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : ''; | |
| 231 | + $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : ''; | |
| 232 | + $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : ''; | |
| 233 | + $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : ''; | |
| 218 | 234 | |
| 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 | |
| 235 | + MainWP_Cache::init_session(); | |
| 236 | + MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $search_on ); | |
| 237 | + die(); | |
| 238 | + } | |
| 248 | 239 | |
| 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(); | |
| 240 | + /** | |
| 241 | + * Method mainwp_get_categories() | |
| 242 | + * | |
| 243 | + * Get post/page categories. | |
| 244 | + * | |
| 245 | + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories() | |
| 246 | + */ | |
| 247 | + public function mainwp_get_categories() { | |
| 248 | + $this->secure_request( 'mainwp_get_categories' ); | |
| 249 | + MainWP_Post_Page_Handler::get_categories(); | |
| 250 | + die(); | |
| 251 | + } | |
| 293 | 252 | |
| 294 | - $params = array( | |
| 295 | - 'groups' => $groups, | |
| 296 | - 'sites' => $sites, | |
| 297 | - 'search_on' => $search_on, | |
| 298 | - 'clients' => $clients, | |
| 299 | - ); | |
| 253 | + /** | |
| 254 | + * Method mainwp_post_get_edit() | |
| 255 | + * | |
| 256 | + * Get post to edit. | |
| 257 | + * | |
| 258 | + * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post() | |
| 259 | + */ | |
| 260 | + public function mainwp_post_get_edit() { | |
| 261 | + $this->secure_request( 'mainwp_post_get_edit' ); | |
| 262 | + MainWP_Post_Page_Handler::get_post(); | |
| 263 | + die(); | |
| 264 | + } | |
| 300 | 265 | |
| 301 | - MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params ); | |
| 302 | - die(); | |
| 303 | - } | |
| 266 | + /** | |
| 267 | + * Method mainwp_user_delete() | |
| 268 | + * | |
| 269 | + * Delete User from Child Site, | |
| 270 | + * Page: Users. | |
| 271 | + * | |
| 272 | + * @uses \MainWP\Dashboard\MainWP_User::delete() | |
| 273 | + */ | |
| 274 | + public function mainwp_user_delete() { | |
| 275 | + $this->secure_request( 'mainwp_user_delete' ); | |
| 276 | + MainWP_User::delete(); | |
| 277 | + } | |
| 304 | 278 | |
| 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 | - } | |
| 279 | + /** | |
| 280 | + * Method mainwp_user_edit() | |
| 281 | + * | |
| 282 | + * Edit User from Child Site, | |
| 283 | + * Page: Users. | |
| 284 | + * | |
| 285 | + * @uses \MainWP\Dashboard\MainWP_User::edit() | |
| 286 | + */ | |
| 287 | + public function mainwp_user_edit() { | |
| 288 | + $this->secure_request( 'mainwp_user_edit' ); | |
| 289 | + MainWP_User::edit(); | |
| 290 | + } | |
| 317 | 291 | |
| 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 | - } | |
| 292 | + /** | |
| 293 | + * Method mainwp_user_update_password( | |
| 294 | + * | |
| 295 | + * Update User password from Child Site, | |
| 296 | + * Page: Users. | |
| 297 | + * | |
| 298 | + * @uses \MainWP\Dashboard\MainWP_User::update_password() | |
| 299 | + */ | |
| 300 | + public function mainwp_user_update_password() { | |
| 301 | + $this->secure_request( 'mainwp_user_update_password' ); | |
| 302 | + MainWP_User::update_password(); | |
| 303 | + } | |
| 330 | 304 | |
| 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 | - } | |
| 305 | + /** | |
| 306 | + * Method mainwp_user_update_user() | |
| 307 | + * | |
| 308 | + * Update User from Child Site, | |
| 309 | + * Page: Users. | |
| 310 | + * | |
| 311 | + * @uses \MainWP\Dashboard\MainWP_User::update_user() | |
| 312 | + */ | |
| 313 | + public function mainwp_user_update_user() { | |
| 314 | + $this->secure_request( 'mainwp_user_update_user' ); | |
| 315 | + MainWP_User::update_user(); | |
| 316 | + } | |
| 343 | 317 | |
| 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 | - } | |
| 318 | + /** | |
| 319 | + * Method mainwp_post_unpublish() | |
| 320 | + * | |
| 321 | + * Unpublish post from Child Site, | |
| 322 | + * Page: Recent Posts. | |
| 323 | + * | |
| 324 | + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish() | |
| 325 | + */ | |
| 326 | + public function mainwp_post_unpublish() { | |
| 327 | + $this->secure_request( 'mainwp_post_unpublish' ); | |
| 328 | + MainWP_Recent_Posts::unpublish(); | |
| 329 | + } | |
| 356 | 330 | |
| 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 | - } | |
| 331 | + /** | |
| 332 | + * Method mainwp_post_publish() | |
| 333 | + * | |
| 334 | + * Publish post on Child Site, | |
| 335 | + * Page: Recent Posts. | |
| 336 | + * | |
| 337 | + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish() | |
| 338 | + */ | |
| 339 | + public function mainwp_post_publish() { | |
| 340 | + $this->secure_request( 'mainwp_post_publish' ); | |
| 341 | + MainWP_Recent_Posts::publish(); | |
| 342 | + } | |
| 369 | 343 | |
| 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 | - } | |
| 344 | + /** | |
| 345 | + * Method mainwp_post_approve() | |
| 346 | + * | |
| 347 | + * Approve post on Child Site, | |
| 348 | + * Page: Recent Posts. | |
| 349 | + * | |
| 350 | + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve() | |
| 351 | + */ | |
| 352 | + public function mainwp_post_approve() { | |
| 353 | + $this->secure_request( 'mainwp_post_approve' ); | |
| 354 | + MainWP_Recent_Posts::approve(); | |
| 355 | + } | |
| 382 | 356 | |
| 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 | - } | |
| 357 | + /** | |
| 358 | + * Method mainwp_post_trash() | |
| 359 | + * | |
| 360 | + * Trash post on Child Site, | |
| 361 | + * Page: Recent Posts. | |
| 362 | + * | |
| 363 | + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash() | |
| 364 | + */ | |
| 365 | + public function mainwp_post_trash() { | |
| 366 | + $this->secure_request( 'mainwp_post_trash' ); | |
| 395 | 367 | |
| 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 | - } | |
| 368 | + MainWP_Recent_Posts::trash(); | |
| 369 | + } | |
| 408 | 370 | |
| 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 | - } | |
| 371 | + /** | |
| 372 | + * Method mainwp_post_delete() | |
| 373 | + * | |
| 374 | + * Delete post on Child Site, | |
| 375 | + * Page: Recent Posts. | |
| 376 | + * | |
| 377 | + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete() | |
| 378 | + */ | |
| 379 | + public function mainwp_post_delete() { | |
| 380 | + $this->secure_request( 'mainwp_post_delete' ); | |
| 421 | 381 | |
| 422 | - /** | |
| 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' ); | |
| 382 | + MainWP_Recent_Posts::delete(); | |
| 383 | + } | |
| 432 | 384 | |
| 433 | - MainWP_Recent_Posts::trash(); | |
| 434 | - } | |
| 385 | + /** | |
| 386 | + * Method mainwp_post_restore() | |
| 387 | + * | |
| 388 | + * Restore post, | |
| 389 | + * Page: Recent Posts. | |
| 390 | + * | |
| 391 | + * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore() | |
| 392 | + */ | |
| 393 | + public function mainwp_post_restore() { | |
| 394 | + $this->secure_request( 'mainwp_post_restore' ); | |
| 435 | 395 | |
| 436 | - /** | |
| 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' ); | |
| 396 | + MainWP_Recent_Posts::restore(); | |
| 397 | + } | |
| 446 | 398 | |
| 447 | - MainWP_Recent_Posts::delete(); | |
| 448 | - } | |
| 399 | + /** | |
| 400 | + * Method mainwp_page_unpublish() | |
| 401 | + * | |
| 402 | + * Unpublish page, | |
| 403 | + * Page: Recent Pages. | |
| 404 | + * | |
| 405 | + * @uses \MainWP\Dashboard\MainWP_Page::unpublish() | |
| 406 | + */ | |
| 407 | + public function mainwp_page_unpublish() { | |
| 408 | + $this->secure_request( 'mainwp_page_unpublish' ); | |
| 409 | + MainWP_Page::unpublish(); | |
| 410 | + } | |
| 449 | 411 | |
| 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' ); | |
| 412 | + /** | |
| 413 | + * Method mainwp_page_publish() | |
| 414 | + * | |
| 415 | + * Publish page, | |
| 416 | + * Page: Recent Pages. | |
| 417 | + * | |
| 418 | + * @uses \MainWP\Dashboard\MainWP_Page::publish() | |
| 419 | + */ | |
| 420 | + public function mainwp_page_publish() { | |
| 421 | + $this->secure_request( 'mainwp_page_publish' ); | |
| 422 | + MainWP_Page::publish(); | |
| 423 | + } | |
| 460 | 424 | |
| 461 | - MainWP_Recent_Posts::restore(); | |
| 462 | - } | |
| 425 | + /** | |
| 426 | + * Method mainwp_page_trash() | |
| 427 | + * | |
| 428 | + * Trash page, | |
| 429 | + * Page: Recent Pages. | |
| 430 | + * | |
| 431 | + * @uses \MainWP\Dashboard\MainWP_Page::trash() | |
| 432 | + */ | |
| 433 | + public function mainwp_page_trash() { | |
| 434 | + $this->secure_request( 'mainwp_page_trash' ); | |
| 435 | + MainWP_Page::trash(); | |
| 436 | + } | |
| 463 | 437 | |
| 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 | - } | |
| 438 | + /** | |
| 439 | + * Method mainwp_page_delete() | |
| 440 | + * | |
| 441 | + * Delete page, | |
| 442 | + * Page: Recent Pages. | |
| 443 | + * | |
| 444 | + * @uses \MainWP\Dashboard\MainWP_Page::delete() | |
| 445 | + */ | |
| 446 | + public function mainwp_page_delete() { | |
| 447 | + $this->secure_request( 'mainwp_page_delete' ); | |
| 448 | + MainWP_Page::delete(); | |
| 449 | + } | |
| 476 | 450 | |
| 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 | - } | |
| 451 | + /** | |
| 452 | + * Method mainwp_page_restor() | |
| 453 | + * | |
| 454 | + * Restore page, | |
| 455 | + * Page: Recent Pages. | |
| 456 | + * | |
| 457 | + * @uses \MainWP\Dashboard\MainWP_Page::restore() | |
| 458 | + */ | |
| 459 | + public function mainwp_page_restore() { | |
| 460 | + $this->secure_request( 'mainwp_page_restore' ); | |
| 461 | + MainWP_Page::restore(); | |
| 462 | + } | |
| 489 | 463 | |
| 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 | - } | |
| 464 | + /** | |
| 465 | + * Method mainwp_notice_status_update() | |
| 466 | + * | |
| 467 | + * Hide after installation notices, | |
| 468 | + * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning). | |
| 469 | + * | |
| 470 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 471 | + */ | |
| 472 | + public function mainwp_notice_status_update() { | |
| 473 | + $this->secure_request( 'mainwp_notice_status_update' ); | |
| 502 | 474 | |
| 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 | - } | |
| 475 | + $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false; | |
| 476 | + if ( 'mail_failed' === $no_id ) { | |
| 477 | + MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' ); | |
| 478 | + die( 'ok' ); | |
| 479 | + } | |
| 515 | 480 | |
| 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 | - } | |
| 481 | + /** | |
| 482 | + * Current user global. | |
| 483 | + * | |
| 484 | + * @global string | |
| 485 | + */ | |
| 486 | + global $current_user; | |
| 487 | + $user_id = $current_user->ID; | |
| 488 | + if ( $user_id ) { | |
| 489 | + $status = get_user_option( 'mainwp_notice_saved_status' ); | |
| 490 | + if ( ! is_array( $status ) ) { | |
| 491 | + $status = array(); | |
| 492 | + } | |
| 493 | + if ( ! empty( $no_id ) ) { | |
| 494 | + $status[ $no_id ] = 1; | |
| 495 | + update_user_option( $user_id, 'mainwp_notice_saved_status', $status ); | |
| 496 | + } | |
| 497 | + } | |
| 498 | + die( 1 ); | |
| 499 | + } | |
| 528 | 500 | |
| 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' ); | |
| 501 | + /** | |
| 502 | + * Method mainwp_status_saving() | |
| 503 | + * | |
| 504 | + * Save last_sync_sites time() or mainwp_status_saved_values. | |
| 505 | + */ | |
| 506 | + public function mainwp_status_saving() { | |
| 507 | + $this->secure_request( 'mainwp_status_saving' ); | |
| 508 | + $values = get_option( 'mainwp_status_saved_values' ); | |
| 539 | 509 | |
| 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 | - } | |
| 510 | + if ( ! isset( $_POST['status'] ) ) { | |
| 511 | + die( -1 ); | |
| 512 | + } | |
| 546 | 513 | |
| 547 | - if ( 'phpver_8_0' === $no_id ) { | |
| 548 | - MainWP_Utility::update_user_option( 'lasttime_hidden_phpver_8_0', time() ); | |
| 549 | - } | |
| 514 | + if ( 'last_sync_sites' === $_POST['status'] ) { | |
| 515 | + if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) { | |
| 516 | + update_option( 'mainwp_last_synced_all_sites', time() ); | |
| 550 | 517 | |
| 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 | - } | |
| 518 | + /** | |
| 519 | + * Action: mainwp_synced_all_sites | |
| 520 | + * | |
| 521 | + * Fires upon successfull synchronization process. | |
| 522 | + * | |
| 523 | + * @since 3.5.1 | |
| 524 | + */ | |
| 525 | + do_action( 'mainwp_synced_all_sites' ); | |
| 526 | + } | |
| 527 | + die( 'ok' ); | |
| 528 | + } | |
| 556 | 529 | |
| 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 | - } | |
| 530 | + $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : ''; | |
| 531 | + $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : ''; | |
| 595 | 532 | |
| 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' ); | |
| 533 | + if ( ! empty( $status ) ) { | |
| 534 | + if ( empty( $value ) ) { | |
| 535 | + if ( isset( $values[ $status ] ) ) { | |
| 536 | + unset( $values[ $status ] ); | |
| 537 | + } | |
| 538 | + } else { | |
| 539 | + $values[ $status ] = $value; | |
| 540 | + } | |
| 541 | + update_option( 'mainwp_status_saved_values', $values ); | |
| 542 | + } | |
| 604 | 543 | |
| 605 | - if ( ! is_array( $values ) ) { | |
| 606 | - $values = array(); | |
| 607 | - } | |
| 544 | + die( 'ok' ); | |
| 545 | + } | |
| 608 | 546 | |
| 609 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 610 | - if ( ! isset( $_POST['status'] ) ) { | |
| 611 | - die( -1 ); | |
| 612 | - } | |
| 547 | + /** | |
| 548 | + * Method ajax_widget_order() | |
| 549 | + * | |
| 550 | + * Update saved widget order. | |
| 551 | + */ | |
| 552 | + public function ajax_widgets_order() { | |
| 613 | 553 | |
| 614 | - if ( 'last_sync_sites' === $_POST['status'] ) { | |
| 615 | - if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) { | |
| 616 | - update_option( 'mainwp_last_synced_all_sites', time() ); | |
| 554 | + $this->secure_request( 'mainwp_widgets_order' ); | |
| 555 | + $user = wp_get_current_user(); | |
| 556 | + if ( $user && ! empty( $_POST['page'] ) ) { | |
| 557 | + $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : ''; | |
| 558 | + $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : ''; | |
| 559 | + update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, $order, true ); | |
| 560 | + die( 'ok' ); | |
| 561 | + } | |
| 562 | + die( -1 ); | |
| 563 | + } | |
| 617 | 564 | |
| 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 | - } | |
| 565 | + /** | |
| 566 | + * Method ajax_mainwp_save_settings() | |
| 567 | + * | |
| 568 | + * Update saved MainWP Settings. | |
| 569 | + * | |
| 570 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 571 | + */ | |
| 572 | + public function ajax_mainwp_save_settings() { | |
| 573 | + $this->secure_request( 'mainwp_save_settings' ); | |
| 574 | + $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; | |
| 575 | + if ( ! empty( $name ) ) { | |
| 576 | + $option_name = 'mainwp_' . $name; | |
| 577 | + $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : ''; | |
| 578 | + MainWP_Utility::update_option( $option_name, $val ); | |
| 579 | + } | |
| 580 | + die( 'ok' ); | |
| 581 | + } | |
| 629 | 582 | |
| 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 | |
| 583 | + /** | |
| 584 | + * Method mainwp_leftmenu_filter_group() | |
| 585 | + * | |
| 586 | + * MainWP left menu filter by group. | |
| 587 | + * | |
| 588 | + * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 589 | + * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id() | |
| 590 | + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 591 | + * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 592 | + */ | |
| 593 | + public function mainwp_leftmenu_filter_group() { | |
| 594 | + $this->secure_request( 'mainwp_leftmenu_filter_group' ); | |
| 633 | 595 | |
| 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 | - } | |
| 596 | + $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false; | |
| 644 | 597 | |
| 645 | - die( 'ok' ); | |
| 646 | - } | |
| 598 | + if ( ! empty( $gid ) ) { | |
| 599 | + $ids = ''; | |
| 600 | + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) ); | |
| 601 | + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 602 | + $ids .= $website->id . ','; | |
| 603 | + } | |
| 604 | + MainWP_DB::free_result( $websites ); | |
| 605 | + $ids = rtrim( $ids, ',' ); | |
| 606 | + die( $ids ); | |
| 607 | + } | |
| 608 | + die( '' ); | |
| 609 | + } | |
| 647 | 610 | |
| 648 | - /** | |
| 649 | - * Method ajax_widget_order() | |
| 650 | - * | |
| 651 | - * Update saved widget order. | |
| 652 | - */ | |
| 653 | - public function ajax_widgets_order() { //phpcs:ignore -- NOSONAR - complex. | |
| 611 | + /** | |
| 612 | + * Method mainwp_dismiss_twit() | |
| 613 | + * | |
| 614 | + * Dismiss the twitter bragger. | |
| 615 | + * | |
| 616 | + * @uses \MainWP\Dashboard\MainWP_Twitter::clear_twitter_info() | |
| 617 | + */ | |
| 618 | + public function mainwp_dismiss_twit() { | |
| 619 | + $this->secure_request( 'mainwp_dismiss_twit' ); | |
| 654 | 620 | |
| 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'] ) ) : ''; | |
| 621 | + /** | |
| 622 | + * Current user global. | |
| 623 | + * | |
| 624 | + * @global string | |
| 625 | + */ | |
| 626 | + global $current_user; | |
| 663 | 627 | |
| 664 | - $wgs_orders = array(); | |
| 628 | + $user_id = $current_user->ID; | |
| 629 | + if ( $user_id && isset( $_POST['twitId'] ) && ! empty( $_POST['twitId'] ) && isset( $_POST['what'] ) && ! empty( $_POST['what'] ) ) { | |
| 630 | + MainWP_Twitter::clear_twitter_info( sanitize_text_field( wp_unslash( $_POST['what'] ) ), sanitize_text_field( wp_unslash( $_POST['twitId'] ) ) ); | |
| 631 | + } | |
| 632 | + die( 1 ); | |
| 633 | + } | |
| 665 | 634 | |
| 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 | - } | |
| 635 | + /** | |
| 636 | + * Method dismiss_activate_notice() | |
| 637 | + * | |
| 638 | + * Dismiss activate notice. | |
| 639 | + */ | |
| 640 | + public function dismiss_activate_notice() { | |
| 641 | + $this->secure_request( 'mainwp_dismiss_activate_notice' ); | |
| 681 | 642 | |
| 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 | - } | |
| 643 | + /** | |
| 644 | + * Current user global. | |
| 645 | + * | |
| 646 | + * @global string | |
| 647 | + */ | |
| 648 | + global $current_user; | |
| 702 | 649 | |
| 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 | - } | |
| 650 | + $user_id = $current_user->ID; | |
| 651 | + $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 652 | + if ( $user_id && ! empty( $slug ) ) { | |
| 653 | + $activate_notices = get_user_option( 'mainwp_hide_activate_notices' ); | |
| 654 | + if ( ! is_array( $activate_notices ) ) { | |
| 655 | + $activate_notices = array(); | |
| 656 | + } | |
| 722 | 657 | |
| 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 | - } | |
| 658 | + $activate_notices[ $slug ] = time(); | |
| 659 | + update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices ); | |
| 660 | + } | |
| 661 | + die( 1 ); | |
| 662 | + } | |
| 738 | 663 | |
| 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 | - } | |
| 664 | + /** | |
| 665 | + * Method mainwp_twitter_dashboard_action() | |
| 666 | + * | |
| 667 | + * Post handler for twitter bragger. | |
| 668 | + * | |
| 669 | + * @return mixed $html|$success | |
| 670 | + * | |
| 671 | + * @uses \MainWP\Dashboard\MainWP_Twitter | |
| 672 | + * @uses \MainWP\Dashboard\MainWP_Twitter::update_twitter_info() | |
| 673 | + * @uses \MainWP\Dashboard\MainWP_Twitter::enabled_twitter_messages() | |
| 674 | + * @uses \MainWP\Dashboard\MainWP_Twitter::get_twitter_notice() | |
| 675 | + * @uses \MainWP\Dashboard\MainWP_Twitter::get_twit_to_send() | |
| 676 | + */ | |
| 677 | + public function mainwp_twitter_dashboard_action() { | |
| 678 | + $this->secure_request( 'mainwp_twitter_dashboard_action' ); | |
| 753 | 679 | |
| 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' ); | |
| 680 | + $success = false; | |
| 681 | + $actionName = isset( $_POST['actionName'] ) ? sanitize_text_field( wp_unslash( $_POST['actionName'] ) ) : ''; | |
| 682 | + $countSites = isset( $_POST['countSites'] ) ? intval( $_POST['countSites'] ) : 0; | |
| 683 | + $countRealItems = isset( $_POST['countRealItems'] ) ? intval( $_POST['countRealItems'] ) : 0; | |
| 684 | + $countItems = isset( $_POST['countItems'] ) ? intval( $_POST['countItems'] ) : 0; | |
| 685 | + $countSeconds = isset( $_POST['countSeconds'] ) ? intval( $_POST['countSeconds'] ) : 0; | |
| 766 | 686 | |
| 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 | |
| 687 | + if ( ! empty( $actionName ) && ! empty( $countSites ) ) { | |
| 688 | + $success = MainWP_Twitter::update_twitter_info( $actionName, $countSites, $countSeconds, $countRealItems, time(), $countItems ); | |
| 689 | + } | |
| 770 | 690 | |
| 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 | - } | |
| 691 | + if ( ! empty( $_POST['showNotice'] ) ) { | |
| 692 | + if ( MainWP_Twitter::enabled_twitter_messages() ) { | |
| 693 | + $twitters = MainWP_Twitter::get_twitter_notice( $actionName ); | |
| 694 | + $html = ''; | |
| 695 | + if ( is_array( $twitters ) ) { | |
| 696 | + foreach ( $twitters as $timeid => $twit_mess ) { | |
| 697 | + if ( ! empty( $twit_mess ) ) { | |
| 698 | + $sendText = MainWP_Twitter::get_twit_to_send( $actionName, $timeid ); | |
| 699 | + $html .= '<div class="mainwp-tips mainwp-notice mainwp-notice-blue twitter"><span class="mainwp-tip" twit-what="' . esc_attr( $actionName ) . '" twit-id="' . $timeid . '">' . $twit_mess . '</span> ' . MainWP_Twitter::gen_twitter_button( $sendText, false ) . '<span><a href="#" class="mainwp-dismiss-twit mainwp-right" ><i class="fa fa-times-circle"></i> ' . __( 'Dismiss', 'mainwp' ) . '</a></span></div>'; | |
| 700 | + } | |
| 701 | + } | |
| 702 | + } | |
| 703 | + die( $html ); | |
| 704 | + } | |
| 705 | + } elseif ( $success ) { | |
| 706 | + die( 'ok' ); | |
| 707 | + } | |
| 783 | 708 | |
| 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' ); | |
| 709 | + die( '' ); | |
| 710 | + } | |
| 791 | 711 | |
| 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 | - } | |
| 712 | + /** | |
| 713 | + * Method mainwp_security_issues_request() | |
| 714 | + * | |
| 715 | + * Post handler for, | |
| 716 | + * Page: SecurityIssues. | |
| 717 | + * | |
| 718 | + * @uses \MainWP\Dashboard\MainWP_Exception | |
| 719 | + * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues() | |
| 720 | + */ | |
| 721 | + public function mainwp_security_issues_request() { | |
| 722 | + $this->secure_request( 'mainwp_security_issues_request' ); | |
| 806 | 723 | |
| 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 | - } | |
| 724 | + try { | |
| 725 | + wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) ); | |
| 726 | + } catch ( MainWP_Exception $e ) { | |
| 727 | + die( | |
| 728 | + wp_json_encode( | |
| 729 | + array( | |
| 730 | + 'error' => array( | |
| 731 | + 'message' => $e->getMessage(), | |
| 732 | + 'extra' => $e->get_message_extra(), | |
| 733 | + ), | |
| 734 | + ) | |
| 735 | + ) | |
| 736 | + ); | |
| 737 | + } | |
| 738 | + } | |
| 813 | 739 | |
| 740 | + /** | |
| 741 | + * Method mainwp_security_issues_fix() | |
| 742 | + * | |
| 743 | + * Post handler for 'fix issues', | |
| 744 | + * Page: SecurityIssues. | |
| 745 | + * | |
| 746 | + * @uses \MainWP\Dashboard\MainWP_Exception | |
| 747 | + * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue() | |
| 748 | + */ | |
| 749 | + public function mainwp_security_issues_fix() { | |
| 750 | + $this->secure_request( 'mainwp_security_issues_fix' ); | |
| 814 | 751 | |
| 752 | + try { | |
| 753 | + wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) ); | |
| 754 | + } catch ( MainWP_Exception $e ) { | |
| 755 | + die( | |
| 756 | + wp_json_encode( | |
| 757 | + array( | |
| 758 | + 'error' => array( | |
| 759 | + 'message' => $e->getMessage(), | |
| 760 | + 'extra' => $e->get_message_extra(), | |
| 761 | + ), | |
| 762 | + ) | |
| 763 | + ) | |
| 764 | + ); | |
| 765 | + } | |
| 766 | + } | |
| 815 | 767 | |
| 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' ); | |
| 768 | + /** | |
| 769 | + * Method mainwp_security_issues_unfix() | |
| 770 | + * | |
| 771 | + * Post handler for 'unfix issues', | |
| 772 | + * Page: SecurityIssues. | |
| 773 | + * | |
| 774 | + * @uses \MainWP\Dashboard\MainWP_Exception | |
| 775 | + * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue() | |
| 776 | + */ | |
| 777 | + public function mainwp_security_issues_unfix() { | |
| 778 | + $this->secure_request( 'mainwp_security_issues_unfix' ); | |
| 827 | 779 | |
| 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 | - } | |
| 780 | + try { | |
| 781 | + wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) ); | |
| 782 | + } catch ( MainWP_Exception $e ) { | |
| 783 | + die( | |
| 784 | + wp_json_encode( | |
| 785 | + array( | |
| 786 | + 'error' => array( | |
| 787 | + 'message' => $e->getMessage(), | |
| 788 | + 'extra' => $e->get_message_extra(), | |
| 789 | + ), | |
| 790 | + ) | |
| 791 | + ) | |
| 792 | + ); | |
| 793 | + } | |
| 794 | + } | |
| 843 | 795 | |
| 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' ); | |
| 796 | + /** | |
| 797 | + * Method ajax_disconnect_site() | |
| 798 | + * | |
| 799 | + * Disconnect Child Site. | |
| 800 | + * | |
| 801 | + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 802 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 803 | + */ | |
| 804 | + public function ajax_disconnect_site() { | |
| 805 | + $this->secure_request( 'mainwp_disconnect_site' ); | |
| 855 | 806 | |
| 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 | - } | |
| 807 | + $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0; | |
| 871 | 808 | |
| 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' ); | |
| 809 | + if ( empty( $siteid ) ) { | |
| 810 | + die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) ); | |
| 811 | + } | |
| 883 | 812 | |
| 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 | - } | |
| 813 | + $website = MainWP_DB::instance()->get_website_by_id( $siteid ); | |
| 899 | 814 | |
| 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 | |
| 815 | + if ( ! $website ) { | |
| 816 | + die( wp_json_encode( array( 'error' => 'Not found site' ) ) ); | |
| 817 | + } | |
| 913 | 818 | |
| 914 | - if ( empty( $siteid ) ) { | |
| 915 | - die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) ); | |
| 916 | - } | |
| 819 | + try { | |
| 820 | + $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' ); | |
| 821 | + } catch ( \Exception $e ) { | |
| 822 | + $information = array( 'error' => __( 'fetch_url_authed exception', 'mainwp' ) ); | |
| 823 | + } | |
| 917 | 824 | |
| 918 | - $website = MainWP_DB::instance()->get_website_by_id( $siteid ); | |
| 825 | + wp_send_json( $information ); | |
| 826 | + } | |
| 919 | 827 | |
| 920 | - if ( ! $website ) { | |
| 921 | - die( wp_json_encode( array( 'error' => 'Not found site' ) ) ); | |
| 922 | - } | |
| 828 | + /** | |
| 829 | + * Method ajax_sites_display_rows() | |
| 830 | + * | |
| 831 | + * Display rows via ajax, | |
| 832 | + * Page: Manage Sites. | |
| 833 | + * | |
| 834 | + * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows() | |
| 835 | + */ | |
| 836 | + public function ajax_sites_display_rows() { | |
| 837 | + $this->secure_request( 'mainwp_manage_sites_display_rows' ); | |
| 838 | + MainWP_Manage_Sites::ajax_optimize_display_rows(); | |
| 839 | + } | |
| 923 | 840 | |
| 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 | - } | |
| 841 | + /** | |
| 842 | + * Method ajax_sites_display_rows() | |
| 843 | + * | |
| 844 | + * Display rows via ajax, | |
| 845 | + * Page: Monitoring Sites. | |
| 846 | + * | |
| 847 | + * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows() | |
| 848 | + */ | |
| 849 | + public function ajax_monitoring_display_rows() { | |
| 850 | + $this->secure_request( 'mainwp_monitoring_sites_display_rows' ); | |
| 851 | + MainWP_Monitoring::ajax_optimize_display_rows(); | |
| 852 | + } | |
| 929 | 853 | |
| 930 | - wp_send_json( $information ); | |
| 931 | - } | |
| 932 | 854 | |
| 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 | - } | |
| 855 | + /** | |
| 856 | + * Method mainwp_bulkadduser() | |
| 857 | + * | |
| 858 | + * Bulk Add User for, | |
| 859 | + * Page: BulkAddUser. | |
| 860 | + * | |
| 861 | + * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add() | |
| 862 | + */ | |
| 863 | + public function mainwp_bulkadduser() { | |
| 864 | + $this->check_security( 'mainwp_bulkadduser' ); | |
| 865 | + MainWP_User::do_bulk_add(); | |
| 866 | + die(); | |
| 867 | + } | |
| 945 | 868 | |
| 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 | - } | |
| 869 | + /** | |
| 870 | + * Method mainwp_importuser() | |
| 871 | + * | |
| 872 | + * Import user. | |
| 873 | + * | |
| 874 | + * @uses \MainWP\Dashboard\MainWP_User::do_import() | |
| 875 | + */ | |
| 876 | + public function mainwp_importuser() { | |
| 877 | + $this->secure_request( 'mainwp_importuser' ); | |
| 878 | + MainWP_User::do_import(); | |
| 879 | + } | |
| 958 | 880 | |
| 881 | + /** | |
| 882 | + * Method mainwp_notes_save() | |
| 883 | + * | |
| 884 | + * Post handler for save notes on, | |
| 885 | + * Page: Manage Sites. | |
| 886 | + * | |
| 887 | + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note() | |
| 888 | + */ | |
| 889 | + public function mainwp_notes_save() { | |
| 890 | + $this->secure_request( 'mainwp_notes_save' ); | |
| 891 | + MainWP_Manage_Sites_Handler::save_note(); | |
| 892 | + } | |
| 959 | 893 | |
| 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 | - } | |
| 894 | + /** | |
| 895 | + * Method mainwp_syncerrors_dismiss() | |
| 896 | + * | |
| 897 | + * Dismiss Sync errors for, | |
| 898 | + * Widget: RightNow. | |
| 899 | + * | |
| 900 | + * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors() | |
| 901 | + */ | |
| 902 | + public function mainwp_syncerrors_dismiss() { | |
| 973 | 903 | |
| 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 | - } | |
| 904 | + $this->secure_request( 'mainwp_syncerrors_dismiss' ); | |
| 985 | 905 | |
| 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 | - } | |
| 906 | + try { | |
| 907 | + die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) ); | |
| 908 | + } catch ( \Exception $e ) { | |
| 909 | + die( wp_json_encode( array( 'error' => $e->getMessage() ) ) ); | |
| 910 | + } | |
| 911 | + } | |
| 997 | 912 | |
| 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 | - } | |
| 913 | + /** | |
| 914 | + * Method mainwp_events_notice_hide() | |
| 915 | + * | |
| 916 | + * Hide events notice. | |
| 917 | + */ | |
| 918 | + public function mainwp_events_notice_hide() { | |
| 919 | + $this->secure_request( 'mainwp_events_notice_hide' ); | |
| 1018 | 920 | |
| 1019 | - echo wp_json_encode( $ret ); | |
| 1020 | - exit; | |
| 1021 | - } | |
| 921 | + if ( isset( $_POST['notice'] ) ) { | |
| 922 | + $current_options = get_option( 'mainwp_showhide_events_notice' ); | |
| 923 | + if ( ! is_array( $current_options ) ) { | |
| 924 | + $current_options = array(); | |
| 925 | + } | |
| 926 | + if ( 'first_site' === $_POST['notice'] ) { | |
| 927 | + update_option( 'mainwp_first_site_events_notice', '' ); | |
| 928 | + } elseif ( 'request_reviews1' === $_POST['notice'] ) { | |
| 929 | + $current_options['request_reviews1'] = 15; | |
| 930 | + $current_options['request_reviews1_starttime'] = time(); | |
| 931 | + } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) { | |
| 932 | + $current_options['request_reviews1'] = 'forever'; | |
| 933 | + $current_options['request_reviews2'] = 'forever'; | |
| 934 | + } elseif ( 'request_reviews2' === $_POST['notice'] ) { | |
| 935 | + $current_options['request_reviews2'] = 15; | |
| 936 | + $current_options['request_reviews2_starttime'] = time(); | |
| 937 | + } elseif ( 'trust_child' === $_POST['notice'] ) { | |
| 938 | + $current_options['trust_child'] = 1; | |
| 939 | + } elseif ( 'multi_site' === $_POST['notice'] ) { | |
| 940 | + $current_options['hide_multi_site_notice'] = 1; | |
| 941 | + } | |
| 942 | + update_option( 'mainwp_showhide_events_notice', $current_options ); | |
| 943 | + } | |
| 944 | + die( 'ok' ); | |
| 945 | + } | |
| 1022 | 946 | |
| 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 | - } | |
| 947 | + /** | |
| 948 | + * Method mainwp_showhide_sections() | |
| 949 | + * | |
| 950 | + * Show/Hide sections. | |
| 951 | + */ | |
| 952 | + public function mainwp_showhide_sections() { | |
| 953 | + if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) { | |
| 954 | + $opts = get_option( 'mainwp_opts_showhide_sections' ); | |
| 955 | + if ( ! is_array( $opts ) ) { | |
| 956 | + $opts = array(); | |
| 957 | + } | |
| 958 | + $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) ); | |
| 959 | + update_option( 'mainwp_opts_showhide_sections', $opts ); | |
| 960 | + die( 'ok' ); | |
| 961 | + } | |
| 962 | + die( 'failed' ); | |
| 963 | + } | |
| 1034 | 964 | |
| 965 | + /** | |
| 966 | + * Method mainwp_saving_status() | |
| 967 | + * | |
| 968 | + * MainWP Saving Status. | |
| 969 | + */ | |
| 970 | + public function mainwp_saving_status() { | |
| 971 | + if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) { | |
| 972 | + die( __( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) ); | |
| 973 | + } | |
| 974 | + $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false; | |
| 975 | + if ( ! empty( $saving_status ) ) { | |
| 976 | + $current_options = get_option( 'mainwp_opts_saving_status' ); | |
| 977 | + if ( ! is_array( $current_options ) ) { | |
| 978 | + $current_options = array(); | |
| 979 | + } | |
| 980 | + if ( isset( $_POST['value'] ) ) { | |
| 981 | + $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) ); | |
| 982 | + } | |
| 983 | + update_option( 'mainwp_opts_saving_status', $current_options ); | |
| 984 | + } | |
| 985 | + die( 'ok' ); | |
| 986 | + } | |
| 1035 | 987 | |
| 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 | - } | |
| 988 | + /** | |
| 989 | + * Method ajax_recheck_http() | |
| 990 | + * | |
| 991 | + * Recheck Child Site http status code & message. | |
| 992 | + * | |
| 993 | + * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code() | |
| 994 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 995 | + * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website() | |
| 996 | + */ | |
| 997 | + public function ajax_recheck_http() { | |
| 998 | + $this->check_security( 'mainwp_recheck_http' ); | |
| 1055 | 999 | |
| 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 | |
| 1000 | + if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) { | |
| 1001 | + die( -1 ); | |
| 1002 | + } | |
| 1067 | 1003 | |
| 1068 | - if ( empty( $field_ids ) ) { | |
| 1069 | - $ret['data'] = array( 'message' => __( 'No fields selected.', 'mainwp' ) ); | |
| 1070 | - echo wp_json_encode( $ret ); | |
| 1071 | - exit; | |
| 1072 | - } | |
| 1004 | + $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) ); | |
| 1005 | + if ( empty( $website ) ) { | |
| 1006 | + die( -1 ); | |
| 1007 | + } | |
| 1073 | 1008 | |
| 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 | - } | |
| 1009 | + $result = MainWP_Monitoring_Handler::handle_check_website( $website ); | |
| 1010 | + $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0; | |
| 1011 | + $check_result = MainWP_Connect::check_ignored_http_code( $http_code ); | |
| 1012 | + die( | |
| 1013 | + wp_json_encode( | |
| 1014 | + array( | |
| 1015 | + 'httpcode' => esc_html( $http_code ), | |
| 1016 | + 'status' => $check_result ? 1 : 0, | |
| 1017 | + ) | |
| 1018 | + ) | |
| 1019 | + ); | |
| 1020 | + } | |
| 1081 | 1021 | |
| 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 | - } | |
| 1022 | + /** | |
| 1023 | + * Method mainwp_ignore_http_response() | |
| 1024 | + * | |
| 1025 | + * Ignore Child Site https response. | |
| 1026 | + * | |
| 1027 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 1028 | + * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() | |
| 1029 | + */ | |
| 1030 | + public function mainwp_ignore_http_response() { | |
| 1031 | + $this->check_security( 'mainwp_ignore_http_response' ); | |
| 1032 | + $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false; | |
| 1088 | 1033 | |
| 1089 | - echo wp_json_encode( $ret ); | |
| 1090 | - exit; | |
| 1091 | - } | |
| 1034 | + if ( empty( $siteid ) ) { | |
| 1035 | + die( -1 ); | |
| 1036 | + } | |
| 1092 | 1037 | |
| 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 | - } | |
| 1038 | + $website = MainWP_DB::instance()->get_website_by_id( $siteid ); | |
| 1039 | + if ( empty( $website ) ) { | |
| 1040 | + die( -1 ); | |
| 1041 | + } | |
| 1111 | 1042 | |
| 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 | - } | |
| 1043 | + MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) ); | |
| 1044 | + die( wp_json_encode( array( 'ok' => 1 ) ) ); | |
| 1045 | + } | |
| 1124 | 1046 | |
| 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 | - } | |
| 1047 | + /** | |
| 1048 | + * Method mainwp_autoupdate_and_trust_child() | |
| 1049 | + * | |
| 1050 | + * Set MainWP Child Plugin to Trusted & AutoUpdate. | |
| 1051 | + * | |
| 1052 | + * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin() | |
| 1053 | + */ | |
| 1054 | + public function mainwp_autoupdate_and_trust_child() { | |
| 1055 | + $this->secure_request( 'mainwp_autoupdate_and_trust_child' ); | |
| 1056 | + if ( get_option( 'mainwp_automaticDailyUpdate' ) != 1 ) { | |
| 1057 | + update_option( 'mainwp_automaticDailyUpdate', 1 ); | |
| 1058 | + } | |
| 1059 | + MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' ); | |
| 1060 | + die( 'ok' ); | |
| 1061 | + } | |
| 1137 | 1062 | |
| 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 | |
| 1063 | + /** | |
| 1064 | + * Method mainwp_force_destroy_sessions() | |
| 1065 | + * | |
| 1066 | + * Force destroy sessions. | |
| 1067 | + * | |
| 1068 | + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 1069 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 1070 | + * | |
| 1071 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 1072 | + */ | |
| 1073 | + public function mainwp_force_destroy_sessions() { | |
| 1074 | + $this->secure_request( 'mainwp_force_destroy_sessions' ); | |
| 1152 | 1075 | |
| 1153 | - if ( empty( $clientid ) ) { | |
| 1154 | - wp_die( 'Error - empty client id!' ); | |
| 1155 | - } | |
| 1076 | + $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 ); | |
| 1156 | 1077 | |
| 1157 | - $params = array( | |
| 1158 | - 'client_id' => $clientid, | |
| 1159 | - 'suspended' => $suspended, | |
| 1160 | - ); | |
| 1078 | + if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) { | |
| 1079 | + die( wp_json_encode( array( 'error' => array( 'message' => __( 'This website does not exist.', 'mainwp' ) ) ) ) ); | |
| 1080 | + } | |
| 1161 | 1081 | |
| 1162 | - MainWP_DB_Client::instance()->update_client( $params ); | |
| 1082 | + $website = MainWP_DB::instance()->get_website_by_id( $website_id ); | |
| 1083 | + if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 1084 | + die( wp_json_encode( array( 'error' => array( 'message' => __( 'You cannot edit this website.', 'mainwp' ) ) ) ) ); | |
| 1085 | + } | |
| 1163 | 1086 | |
| 1164 | - $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid ); | |
| 1087 | + try { | |
| 1088 | + $information = MainWP_Connect::fetch_url_authed( | |
| 1089 | + $website, | |
| 1090 | + 'settings_tools', | |
| 1091 | + array( | |
| 1092 | + 'action' => 'force_destroy_sessions', | |
| 1093 | + ) | |
| 1094 | + ); | |
| 1165 | 1095 | |
| 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 ); | |
| 1096 | + /** | |
| 1097 | + * MainWP information array. | |
| 1098 | + * | |
| 1099 | + * @global object $mainWP | |
| 1100 | + */ | |
| 1101 | + global $mainWP; | |
| 1175 | 1102 | |
| 1176 | - MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended ); | |
| 1103 | + if ( ( '2.0.22' === $mainWP->get_version() ) || ( '2.0.23' === $mainWP->get_version() ) ) { | |
| 1104 | + if ( 1 != get_option( 'mainwp_fixed_security_2022' ) ) { | |
| 1105 | + update_option( 'mainwp_fixed_security_2022', 1 ); | |
| 1106 | + } | |
| 1107 | + } | |
| 1108 | + } catch ( \Exception $e ) { | |
| 1109 | + $information = array( 'error' => __( 'fetch_url_authed exception', 'mainwp' ) ); | |
| 1110 | + } | |
| 1177 | 1111 | |
| 1178 | - wp_die( 'success' ); | |
| 1179 | - } | |
| 1112 | + wp_send_json( $information ); | |
| 1113 | + } | |
| 1180 | 1114 | |
| 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 | 1115 | } |