$new_site['name'], 'site_url' => $new_site['url'], 'site_id' => $new_site['id'], 'mainwp_dash' => true, ) ); Settings_Helper::delete_option_value( 'wsal-child-sites' ); } } /** * MainWP Site Removed * * Site removed from MainWP dashboard. * * @param stdClass $website – Removed website. * * @since 5.0.0 */ public static function site_removed( $website ) { if ( empty( $website ) ) { return; } if ( isset( $website->name ) ) { Alert_Manager::trigger_event( 7701, array( 'friendly_name' => $website->name, 'site_url' => $website->url, 'site_id' => $website->id, 'mainwp_dash' => true, ) ); Settings_Helper::delete_option_value( 'wsal-child-sites' ); } } /** * MainWP Site Edited * * Site edited from MainWP dashboard. * * @param int $site_id – Site id. * * @since 5.0.0 */ public static function site_edited( $site_id ) { if ( empty( $site_id ) ) { return; } // Get MainWP child sites. $mwp_sites = MainWP_Settings::get_mwp_child_sites(); // Search for the site data. $key = array_search( $site_id, array_column( $mwp_sites, 'id' ), false ); if ( false !== $key && isset( $mwp_sites[ $key ] ) ) { Alert_Manager::trigger_event( 7702, array( 'friendly_name' => $mwp_sites[ $key ]['name'], 'site_url' => $mwp_sites[ $key ]['url'], 'site_id' => $mwp_sites[ $key ]['id'], 'mainwp_dash' => true, ) ); } } /** * MainWP Site Synced * * Site synced from MainWP dashboard. * * @param stdClass $website – Removed website. * * @since 5.0.0 */ public static function site_synced( $website ) { if ( empty( $website ) ) { return; } $is_global_sync = isset( $_POST['isGlobalSync'] ) ? sanitize_text_field( wp_unslash( $_POST['isGlobalSync'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( property_exists( $website, 'id' ) ) { MainWP_Helper::sync_site( (int) $website->id ); } if ( 'true' === $is_global_sync ) { // Check if not global sync. return; } if ( isset( $website->name ) ) { Alert_Manager::trigger_event( 7703, array( 'friendly_name' => $website->name, 'site_url' => $website->url, 'SiteID' => $website->id, 'mainwp_dash' => true, ) ); } } /** * MainWP Sites Synced * * Log event when MainWP sites are synced altogether. * * @since 5.0.0 */ public static function synced_all_sites() { // @codingStandardsIgnoreStart $is_global_sync = isset( $_POST['isGlobalSync'] ) ? sanitize_text_field( wp_unslash( $_POST['isGlobalSync'] ) ) : false; // @codingStandardsIgnoreEnd // make sure this is global sync. if ( ! in_array( $is_global_sync, array( 'true', '1' ) ) ) { return; } MainWP_Helper::retrieve_events_manually(); // Trigger global sync event. Alert_Manager::trigger_event( 7704, array( 'mainwp_dash' => true ) ); } /** * MainWP Extension Added * * MainWP extension added to menu. * * @param string $slug – Extension slug. * * @since 5.0.0 */ public static function added_extension_menu( $slug ) { self::extension_menu_edited( $slug, 'Added' ); } /** * MainWP Extension Removed * * MainWP extension removed from menu. * * @param string $slug – Extension slug. * * @since 5.0.0 */ public static function removed_extension_menu( $slug ) { self::extension_menu_edited( $slug, 'Removed' ); } /** * MainWP Menu Edited * * Extension added/removed from MainWP menu. * * @param string $slug – Slug of the extension. * @param string $action – Added or Removed action. * * @since 5.0.0 */ public static function extension_menu_edited( $slug, $action ) { // Check if the slug is not empty and it is active. if ( ! empty( $slug ) && \is_plugin_active( $slug ) ) { Alert_Manager::trigger_event( 7709, array( 'mainwp_dash' => true, 'extension' => $slug, 'action' => $action, 'option' => 'Added' === $action ? 'to' : 'from', 'EventType' => $action, ) ); } } /** * MainWP Extension Activated * * @param bool $response Installation response. * @param array $hook_extra Extra arguments passed to hooked filters. * @param array $result Installation result data. * * @since 5.0.0 */ public static function mwp_extension_installed( $response, $hook_extra, $result ) { self::extension_log_event( 7705, $result['destination_name'] ); } /** * MainWP Extension Activated * * @param string $extension – Extension file path. * * @since 5.0.0 */ public static function mwp_extension_activated( $extension ) { self::extension_log_event( 7706, $extension ); } /** * MainWP Extension Deactivated * * @param string $extension - Extension file path. * * @since 5.0.0 */ public static function mwp_extension_deactivated( $extension ) { self::extension_log_event( 7707, $extension ); } /** * MainWP Extension Deleted * * @param string $extension - Extension file path. * * @since 5.0.0 */ public static function mwp_extension_deleted( $extension ) { self::extension_log_event( 7708, $extension ); } /** * Add Extension Event * * @param string $event – Event ID. * @param string $extension – Name of extension. * * @since 5.0.0 */ private static function extension_log_event( $event, $extension ) { $extension_dir = explode( '/', $extension ); $extension_dir = isset( $extension_dir[0] ) ? $extension_dir[0] : false; if ( ! $extension_dir ) { return; } // Get MainWP extensions data. $mwp_extensions = \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions( 'all' ); $extension_ids = array_keys( $mwp_extensions ); if ( ! in_array( $extension_dir, $extension_ids, true ) ) { return; } if ( $event ) { // Event data. $event_data = array(); if ( 7708 === $event ) { // Get extension data. $plugin_file = trailingslashit( WP_PLUGIN_DIR ) . $extension; $event_data = array( 'mainwp_dash' => true, 'extension_name' => isset( $mwp_extensions[ $extension_dir ]['title'] ) ? $mwp_extensions[ $extension_dir ]['title'] : false, 'PluginFile' => $plugin_file, 'PluginData' => (object) array( 'Name' => isset( $mwp_extensions[ $extension_dir ]['title'] ) ? $mwp_extensions[ $extension_dir ]['title'] : false, ), ); } else { // Get extension data. $plugin_file = trailingslashit( WP_PLUGIN_DIR ) . $extension; $plugin_data = get_plugin_data( $plugin_file ); $event_data = array( 'mainwp_dash' => true, 'extension_name' => isset( $mwp_extensions[ $extension_dir ]['title'] ) ? $mwp_extensions[ $extension_dir ]['title'] : false, 'Plugin' => (object) array( 'Name' => $plugin_data['Name'], 'PluginURI' => $plugin_data['PluginURI'], 'Version' => $plugin_data['Version'], 'Author' => $plugin_data['Author'], 'Network' => $plugin_data['Network'] ? 'True' : 'False', 'plugin_dir_path' => $plugin_file, ), ); } // Log the event. Alert_Manager::trigger_event( $event, $event_data ); } } /** * Advanced Uptime Monitor Created. * * @param array $monitor_site – Monitor Site data array. * * @since 5.0.0 */ public static function aum_monitor_created( $monitor_site ) { // Get monitor site url. $site_url = isset( $monitor_site['url_address'] ) ? trailingslashit( $monitor_site['url_address'] ) : ( isset( $monitor_site['url_friendly_name'] ) ? trailingslashit( $monitor_site['url_friendly_name'] ) : false ); // Report event. self::report_aum_monitor_event( 7750, $site_url ); } /** * Advanced Uptime Monitor Deleted. * * @param object $monitor_site – Monitor site object. * * @since 5.0.0 */ public static function aum_monitor_deleted( $monitor_site ) { // Get monitor site url. $site_url = isset( $monitor_site->url_address ) ? trailingslashit( $monitor_site->url_address ) : ( isset( $monitor_site->url_friendly_name ) ? trailingslashit( $monitor_site->url_friendly_name ) : false ); // Report event. self::report_aum_monitor_event( 7751, $site_url ); } /** * Advanced Uptime Monitor Started. * * @param object $monitor_site – Monitor site object. * * @since 5.0.0 */ public static function aum_monitor_started( $monitor_site ) { // Get monitor site url. $site_url = isset( $monitor_site->url_address ) ? trailingslashit( $monitor_site->url_address ) : ( isset( $monitor_site->url_friendly_name ) ? trailingslashit( $monitor_site->url_friendly_name ) : false ); // Report event. self::report_aum_monitor_event( 7752, $site_url ); } /** * Advanced Uptime Monitor Paused. * * @param object $monitor_site – Monitor site object. * * @since 5.0.0 */ public static function aum_monitor_paused( $monitor_site ) { // Get monitor site url. $site_url = isset( $monitor_site->url_address ) ? trailingslashit( $monitor_site->url_address ) : ( isset( $monitor_site->url_friendly_name ) ? trailingslashit( $monitor_site->url_friendly_name ) : false ); // Report event. self::report_aum_monitor_event( 7753, $site_url ); } /** * Report Advanced Uptime Monitor Event. * * @param integer $event_id – Event ID. * @param string $site_url – Site URL. * * @since 5.0.0 */ public static function report_aum_monitor_event( $event_id, $site_url ) { if ( ! empty( $event_id ) && ! empty( $site_url ) ) { // Search for site in MainWP sites. $site = MainWP_Settings::get_mwp_site_by( $site_url, 'url' ); // If site is found then report it as MainWP child site. if ( false !== $site ) { Alert_Manager::trigger_event( $event_id, array( 'friendly_name' => $site['name'], 'site_url' => $site['url'], 'site_id' => $site['id'], 'mainwp_dash' => true, ) ); } else { // Else report as other site. Alert_Manager::trigger_event( $event_id, array( 'friendly_name' => $site_url, 'site_url' => $site_url, 'mainwp_dash' => true, ) ); } } } /** * Report Advanced Uptime Monitor Auto Add Sites. * * @since 5.0.0 */ public static function aum_monitor_auto_add() { Alert_Manager::trigger_event( 7754, array( 'mainwp_dash' => true ) ); } } }