isset( $_POST['mainwp_edit_monitor_active'] ) ? intval( $_POST['mainwp_edit_monitor_active'] ) : 0, 'keyword' => isset( $_POST['mainwp_edit_monitor_keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_edit_monitor_keyword'] ) ) : '', 'interval' => isset( $_POST['mainwp_edit_monitor_interval_hidden'] ) ? intval( $_POST['mainwp_edit_monitor_interval_hidden'] ) : 60, 'maxretries' => isset( $_POST['mainwp_edit_monitor_maxretries'] ) ? intval( $_POST['mainwp_edit_monitor_maxretries'] ) : 0, 'up_status_codes' => $up_status_codes, 'type' => isset( $_POST['mainwp_edit_monitor_type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['mainwp_edit_monitor_type'] ) ) ) : 'http', 'method' => isset( $_POST['mainwp_edit_monitor_method'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['mainwp_edit_monitor_method'] ) ) ) : 'get', 'timeout' => isset( $_POST['mainwp_edit_monitor_timeout_number'] ) ? intval( $_POST['mainwp_edit_monitor_timeout_number'] ) : 60, ); $individual = ! empty( $_POST['mainwp_edit_monitor_individual_settings'] ) ? 1 : 0; if ( $individual ) { $site_id = isset( $_REQUEST['monitor_wpid'] ) ? intval( $_REQUEST['monitor_wpid'] ) : 0; if ( empty( $site_id ) && isset( $_REQUEST['id'] ) ) { $site_id = (int) $_REQUEST['id']; } $update['wpid'] = $site_id; $current = false; $sub_editing = false; // create or update sub monitor. if ( ! empty( $_POST['update_submonitor'] ) ) { $sub_editing = true; if ( ! empty( $_POST['edit_sub_monitor_id'] ) ) { // edit sub monitor. $update['monitor_id'] = intval( $_POST['edit_sub_monitor_id'] ); } $redirect_sub_monitor = ! empty( $update['monitor_id'] ) ? '&monitor_id=' . intval( $update['monitor_id'] ) : '&action=add_submonitor'; $update['suburl'] = isset( $_POST['mainwp_edit_monitor_sub_url'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_edit_monitor_sub_url'] ) ) : ''; if ( empty( $update['suburl'] ) ) { wp_safe_redirect( 'admin.php?page=managesites&id=' . $site_id . '&monitor_wpid=' . $site_id . $redirect_sub_monitor . '&message=5' ); exit(); } $update['suburl'] = ltrim( trim( $update['suburl'] ), '/' ); // remove starting '/', if present. if ( ! empty( $_POST['edit_sub_monitor_id'] ) ) { // edit sub monitor. $current = MainWP_DB_Uptime_Monitoring::instance()->get_monitor_by( $site_id, 'suburl', $update['suburl'], array(), ARRAY_A ); // existed suburl in use. if ( $current && ( (int) $current['monitor_id'] !== $update['monitor_id'] ) ) { wp_safe_redirect( 'admin.php?page=managesites&id=' . $site_id . '&monitor_wpid=' . $site_id . $redirect_sub_monitor . '&message=3' ); exit(); } } else { $params = array(); // add new sub monitor. $current = MainWP_DB_Uptime_Monitoring::instance()->get_monitor_by( $site_id, 'suburl', $update['suburl'], $params, ARRAY_A ); // suburl in use. if ( $current ) { wp_safe_redirect( 'admin.php?page=managesites&id=' . $site_id . '&monitor_wpid=' . $site_id . $redirect_sub_monitor . '&message=4' ); exit(); } } $update['issub'] = ! empty( $_POST['monitor_edit_is_sub_url'] ) ? 1 : 0; if ( ! empty( $_POST['edit_sub_monitor_id'] ) ) { $update['monitor_id'] = intval( $_POST['edit_sub_monitor_id'] ); // edit sub monitor. } if ( empty( $update['suburl'] ) || empty( $update['issub'] ) ) { wp_safe_redirect( 'admin.php?page=managesites&id=' . $site_id . '&monitor_wpid=' . $site_id . $redirect_sub_monitor . '&message=2' ); exit(); } } elseif ( ! empty( $_POST['mainwp_edit_monitor_id'] ) ) { $update['monitor_id'] = intval( $_POST['mainwp_edit_monitor_id'] ); // update monitor or sub monitor. } if ( ! empty( $update['monitor_id'] ) ) { $allowed_methods = static::get_allowed_methods(); if ( $current ) { // fix invalid data. if ( $current['method'] || ! isset( $allowed_methods[ $current['method'] ] ) ) { $update['method'] = 'get'; } $update['issub'] = ! empty( $update['suburl'] ) ? 1 : 0; } } $update = apply_filters( 'mainwp_uptime_monitoring_update_monitor_data', $update, $site_id ); MainWP_DB_Uptime_Monitoring::instance()->update_wp_monitor( $update ); MainWP_Uptime_Monitoring_Schedule::instance()->check_to_disable_schedule_individual_uptime_monitoring(); // required a check to sync the settings. if ( $sub_editing ) { wp_safe_redirect( 'admin.php?page=managesites&id=' . $site_id . '&monitor_wpid=' . $site_id . '&message=1' ); exit(); } } else { MainWP_Uptime_Monitoring_Handle::update_uptime_global_settings( $update ); } } } /** * Method is_enable_global_monitoring * * @return int */ public static function is_enable_global_monitoring() { $global_settings = MainWP_Uptime_Monitoring_Handle::get_global_monitoring_settings(); $glo_active = 0; if ( isset( $global_settings['active'] ) ) { $glo_active = 1 === (int) $global_settings['active'] ? 1 : 0; } return 1 === $glo_active ? true : false; } /** * Method render_monitor_settings * * @param mixed $site_id site id. * @param bool $individual Individual settings. * @return void */ public function render_monitor_settings( $site_id = false, $individual = false ) { //phpcs:ignore -- NOSONAR - complexity. $title = __( 'Site Monitoring Settings', 'mainwp' ); $sub_header = __( 'Adjust monitoring preferences for this site to override global settings if needed.', 'mainwp' ); $is_editing_monitor_or_sub_monitor = true; $default = MainWP_Uptime_Monitoring_Handle::get_default_monitoring_settings( $individual ); $edit_sub_monitor = false; $show_in_modal = false; $is_sub_url = 0; $sub_monitor_id = 0; $mo_settings = array(); if ( $individual ) { if ( empty( $site_id ) ) { ?>
get_monitor_by( $site_id, 'monitor_id', $_GET['sub_monitor_id'], array(), ARRAY_A ); //phpcs:ignore -- NOSONAR -ok. if ( empty( $mo_settings ) ) { ?>
get_monitor_by( $site_id, 'issub', 0, array(), ARRAY_A ); // if not found main site monitor. if ( empty( $mo_settings ) ) { // get site to create new main monitor. $mo_settings = MainWP_DB::instance()->get_website_by_id_params( $site_id, array(), ARRAY_A ); } } // add new main monitor. if ( empty( $mo_settings['monitor_id'] ) ) { if ( empty( $mo_settings ) || ! is_array( $mo_settings ) ) { $mo_settings = array(); } $mo_settings = array_merge( $mo_settings, $default ); $title = __( 'Add a New Monitor', 'mainwp' ); $is_editing_monitor_or_sub_monitor = false; } } else { $mo_settings = get_option( 'mainwp_global_uptime_monitoring_settings', false ); } if ( isset( $_GET['action'] ) && 'add_submonitor' === $_GET['action'] ) { //phpcs:ignore -- ok. $title = __( 'Add New Sub Monitor', 'mainwp' ); $edit_sub_monitor = true; $is_sub_url = 1; $is_editing_monitor_or_sub_monitor = false; } if ( empty( $mo_settings ) ) { $mo_settings = $default; } $hide_style = 'style="display:none"'; if ( $individual ) { $disableGeneralSitesMonitoring = false; } else { $disableGeneralSitesMonitoring = empty( $mo_settings['active'] ) ? true : false; } $disabled_methods_individual = false; if ( $individual && ( 'ping' === $mo_settings['type'] || 'keyword' === $mo_settings['type'] ) ) { $disabled_methods_individual = true; } ?>

render_add_edit_sub_page_monitor_begin_form_in_modal( $title ); } ?>
/>
hide-element="uptime-monitoring">
hide-element="uptime-monitoring">
hide-element="monitor-type" >
hide-element="uptime-monitoring">
hide-element="uptime-monitoring">
hide-element="uptime-monitoring">
hide-element="uptime-monitoring">
1, 'wpid' => $site_id, ); $sub_monitors = MainWP_DB_Uptime_Monitoring::instance()->get_monitors( $_params, ARRAY_A ); ?>
render_sub_urls_monitoring( $mo_settings, $sub_monitors ); ?>
render_add_edit_sub_page_monitor_end_form_in_modal( $site_id, $is_editing_monitor_or_sub_monitor ); ?>
esc_html__( 'Use global settings', 'mainwp' ), 'head' => 'HEAD', 'get' => 'GET', 'post' => 'POST', 'push' => 'PUSH', 'patch' => 'PATCH', 'delete' => 'DELETE', ) ); if ( ! $individual && isset( $methods['useglobal'] ) ) { unset( $methods['useglobal'] ); } return $methods; } /** * Method get_interval_values * * @param mixed $individual individual. * @param mixed $flip_values flip values. * @return array */ public static function get_interval_values( $individual = true, $flip_values = false ) { $values = array( -1 => 'Use global setting', 5 => '5m', 10 => '10m', 15 => '15m', 30 => '30m', 45 => '45m', ); if ( ! $individual ) { unset( $values[-1] ); } for ( $i = 1;$i <= 24;$i++ ) { $values[ $i * 60 ] = $i . 'h'; } if ( $flip_values ) { $values = array_flip( $values ); } return apply_filters( 'mainwp_uptime_monitoring_interval_values', $values, $flip_values ); } /** * Method get_timeout_values * * @param mixed $individual individual. * @param mixed $flip_values flip values. * @return array */ public static function get_timeout_values( $individual = true, $flip_values = false ) { $values = array( -1 => 'Use global setting', 30 => '30s', 45 => '45s', 60 => '60s', 90 => '90s', ); if ( ! $individual ) { unset( $values[-1] ); } $step = 60; $val = 60; for ( $i = 1;$i < 10;$i++ ) { $val += $step; $values[ $val ] = ( $i + 1 ) . 'min'; } $values[ 15 * 60 ] = '15min'; $values[ 30 * 60 ] = '30min'; $values[ 45 * 60 ] = '45min'; $values[ 60 * 60 ] = '60min'; $values[ 90 * 60 ] = '90min'; $values[0] = 'No limit'; if ( $flip_values ) { $values = array_flip( $values ); } return apply_filters( 'mainwp_uptime_monitoring_timeout_values', $values, $flip_values ); } /** * Method render_add_edit_sub_page_monitor_begin_form_in_modal(). * * Renders Modal. * * @param mixed $title title. * @return void */ public function render_add_edit_sub_page_monitor_begin_form_in_modal( $title ) { ?>