PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | includes/rest-api/controller/version2/class-mainwp-rest-settings-controller.php +159 -63 6.1.6 → 6.2.1 View file →
@@ -24,8 +24,9 @@
24 24 use MainWP\Dashboard\MainWP_Sync;
25 25 use MainWP\Dashboard\MainWP_Manage_Sites_View;
26 26 use MainWP\Dashboard\MainWP_Uptime_Monitoring_Handle;
27 27 use MainWP\Dashboard\MainWP_Uptime_Monitoring_Edit;
28 +use MainWP\Dashboard\MainWP_Credential_Render;
28 29
29 30 // Exit if accessed directly.
30 31 if ( ! defined( 'ABSPATH' ) ) {
31 32 exit;
@@ -530,9 +531,9 @@
530 531 if ( array_key_exists( $key, $body ) ) {
531 532 $val = $body[ $key ];
532 533 $val = $this->cast_field_value( $val, $cast );
533 534 if ( 'mainwp_widgets' === $key ) {
534 - $show_widgets = get_user_option( 'mainwp_settings_show_widgets', array() );
535 + $show_widgets = get_user_option( 'mainwp_settings_show_widgets' );
535 536 $val = array_replace( $show_widgets, (array) $val );
536 537 }
537 538 update_user_option( $user_id, $option_name, $val, true );
538 539 }
@@ -582,8 +583,9 @@
582 583 do_action( 'mainwp_debug_log', 'Update general settings error: ' . $e->getMessage() );
583 584 return new WP_Error(
584 585 'rest_invalid_param',
585 586 /* translators: %s: Error message */ sprintf( __( 'Update general settings error: %s', 'mainwp' ), $e->getMessage() ),
587 + array( 'status' => 500 )
586 588 );
587 589 }
588 590
589 591 return rest_ensure_response(
@@ -683,8 +685,9 @@
683 685 do_action( 'mainwp_debug_log', 'Update advanced settings error: ' . $e->getMessage() );
684 686 return new WP_Error(
685 687 'rest_invalid_param',
686 688 /* translators: %s: Error message */ sprintf( __( 'Update advanced settings error: %s', 'mainwp' ), $e->getMessage() ),
689 + array( 'status' => 500 )
687 690 );
688 691 }
689 692
690 693 return rest_ensure_response(
@@ -787,8 +790,12 @@
787 790 if ( isset( $body['mainwp_uptime_monitoring_type'] ) ) {
788 791 $updated_settings['type'] = $body['mainwp_uptime_monitoring_type'];
789 792 }
790 793
794 + if ( isset( $body['mainwp_uptime_monitoring_bypass_cache'] ) ) {
795 + $updated_settings['bypass_cache'] = $body['mainwp_uptime_monitoring_bypass_cache'] ? 1 : 0;
796 + }
797 +
791 798 // Save monitoring the updated settings.
792 799 $updated_settings = apply_filters( 'mainwp_uptime_monitoring_update_global_settings', $updated_settings );
793 800 MainWP_Uptime_Monitoring_Handle::update_uptime_global_settings( $updated_settings );
794 801
@@ -876,14 +883,14 @@
876 883
877 884 // Get mail type.
878 885 $setting = $request->get_param( 'mail_type' );
879 886 if ( empty( $setting ) ) {
880 - return new WP_Error( 'invalid_mail_type', __( 'Mail type is not exist.', 'mainwp' ) );
887 + return new WP_Error( 'invalid_mail_type', __( 'Mail type is not exist.', 'mainwp' ), array( 'status' => 400 ) );
881 888 }
882 889
883 890 $type = $setting['type'] ?? '';
884 891 if ( empty( $type ) ) {
885 - return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ) );
892 + return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ), array( 'status' => 400 ) );
886 893 }
887 894
888 895 // Get email settings.
889 896 $emails_settings = get_option( 'mainwp_settings_notification_emails' );
@@ -1055,9 +1062,9 @@
1055 1062 $custom_product_types = $this->safe_json_decode( $all_opts['custom_product_types'] ?? '' );
1056 1063
1057 1064 // Check if product type duplicated.
1058 1065 if ( isset( $custom_product_types[ $slug ] ) ) {
1059 - return new WP_Error( 'duplicate_title', __( 'Duplicate product type. Please choose another one.', 'mainwp' ) );
1066 + return new WP_Error( 'duplicate_title', __( 'Duplicate product type. Please choose another one.', 'mainwp' ), array( 'status' => 400 ) );
1060 1067 }
1061 1068 // Map product type.
1062 1069 $custom_product_types[ $slug ] = $title;
1063 1070 $all_opts['custom_product_types'] = wp_json_encode( $custom_product_types );
@@ -1113,9 +1120,9 @@
1113 1120 }
1114 1121
1115 1122 $slug = $request->get_param( 'slug' );
1116 1123 if ( empty( $slug ) ) {
1117 - return new WP_Error( 'invalid_slug', __( 'Invalid product type slug.', 'mainwp' ) );
1124 + return new WP_Error( 'invalid_slug', __( 'Invalid product type slug.', 'mainwp' ), array( 'status' => 400 ) );
1118 1125 }
1119 1126
1120 1127 // Default Product Type.
1121 1128 $default_product_types = Cost_Tracker_Admin::get_default_product_types();
@@ -1126,9 +1133,9 @@
1126 1133 $icon = ! empty( $body['icon'] ) ? $body['icon'] : 'deficon:folder open';
1127 1134
1128 1135 // Cannot change title if it's a default product type.
1129 1136 if ( array_key_exists( $slug, $default_product_types ) && $title !== $default_product_types[ $slug ] ) {
1130 - return new WP_Error( 'invalid_title', __( 'Cannot change title of default product type.', 'mainwp' ) );
1137 + return new WP_Error( 'invalid_title', __( 'Cannot change title of default product type.', 'mainwp' ), array( 'status' => 400 ) );
1131 1138 }
1132 1139
1133 1140 // Map product type.
1134 1141 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -1176,9 +1183,9 @@
1176 1183 public function delete_cost_tracker_product_type( $request ) { // phpcs:ignore -- NOSONAR - complex.
1177 1184 $slug = $request->get_param( 'slug' );
1178 1185
1179 1186 if ( empty( $slug ) ) {
1180 - return new WP_Error( 'invalid_slug', __( 'Invalid product type slug.', 'mainwp' ) );
1187 + return new WP_Error( 'invalid_slug', __( 'Invalid product type slug.', 'mainwp' ), array( 'status' => 400 ) );
1181 1188 }
1182 1189
1183 1190 // Default Product Type.
1184 1191 $default_product_types = Cost_Tracker_Admin::get_default_product_types();
@@ -1183,9 +1190,9 @@
1183 1190 // Default Product Type.
1184 1191 $default_product_types = Cost_Tracker_Admin::get_default_product_types();
1185 1192 // Cannot delete a default product type.
1186 1193 if ( array_key_exists( $slug, $default_product_types ) ) {
1187 - return new WP_Error( 'invalid_title', __( 'Cannot delete of default product type.', 'mainwp' ) );
1194 + return new WP_Error( 'invalid_title', __( 'Cannot delete of default product type.', 'mainwp' ), array( 'status' => 400 ) );
1188 1195 }
1189 1196
1190 1197 // Get all options.
1191 1198 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -1194,9 +1201,9 @@
1194 1201 $product_types_icons = $this->safe_json_decode( $all_opts['product_types_icons'] ?? '' );
1195 1202
1196 1203 // Check if product type exists.
1197 1204 if ( ! isset( $custom_product_types[ $slug ] ) ) {
1198 - return new WP_Error( 'invalid_slug', __( 'Product type does not exist.', 'mainwp' ) );
1205 + return new WP_Error( 'invalid_slug', __( 'Product type does not exist.', 'mainwp' ), array( 'status' => 404 ) );
1199 1206 }
1200 1207
1201 1208 // Delete product type.
1202 1209 unset( $custom_product_types[ $slug ] );
@@ -1244,9 +1251,9 @@
1244 1251 // Get payment methods.
1245 1252 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
1246 1253
1247 1254 if ( isset( $payment_methods[ $slug ] ) ) {
1248 - return new WP_Error( 'duplicate_title', __( 'Duplicate payment method. Please choose another one.', 'mainwp' ) );
1255 + return new WP_Error( 'duplicate_title', __( 'Duplicate payment method. Please choose another one.', 'mainwp' ), array( 'status' => 400 ) );
1249 1256 }
1250 1257
1251 1258 // Save payment method.
1252 1259 $payment_methods[ $slug ] = $title;
@@ -1295,9 +1302,9 @@
1295 1302 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
1296 1303 // Get payment methods.
1297 1304 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
1298 1305 if ( ! isset( $payment_methods[ $slug ] ) ) {
1299 - return new WP_Error( 'invalid_slug', __( 'Invalid payment method slug.', 'mainwp' ) );
1306 + return new WP_Error( 'invalid_slug', __( 'Invalid payment method slug.', 'mainwp' ), array( 'status' => 404 ) );
1300 1307 }
1301 1308
1302 1309 $payment_methods[ $slug ] = $body['title'];
1303 1310 $all_opts['custom_payment_methods'] = wp_json_encode( $payment_methods );
@@ -1331,9 +1338,9 @@
1331 1338 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
1332 1339 // Get payment methods.
1333 1340 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
1334 1341 if ( ! isset( $payment_methods[ $slug ] ) ) {
1335 - return new WP_Error( 'invalid_slug', __( 'Invalid payment method slug.', 'mainwp' ) );
1342 + return new WP_Error( 'invalid_slug', __( 'Invalid payment method slug.', 'mainwp' ), array( 'status' => 404 ) );
1336 1343 }
1337 1344
1338 1345 unset( $payment_methods[ $slug ] );
1339 1346 $all_opts['custom_payment_methods'] = wp_json_encode( $payment_methods );
@@ -1489,9 +1496,9 @@
1489 1496
1490 1497 // Get API slug data.
1491 1498 $api = $request->get_param( 'api_slug' );
1492 1499 if ( empty( $api ) ) {
1493 - return new WP_Error( 'invalid_api_slug', __( 'API backup not exists.', 'mainwp' ) );
1500 + return new WP_Error( 'invalid_api_slug', __( 'API backup not exists.', 'mainwp' ), array( 'status' => 400 ) );
1494 1501 }
1495 1502
1496 1503 $updated = array();
1497 1504 // Update option if present.
@@ -1504,10 +1511,10 @@
1504 1511 };
1505 1512
1506 1513 // Update secrets if present.
1507 1514 $update_secrets_api = function ( $slug, $value, $name = 'api_key' ) use ( &$updated ) { // phpcs:ignore -- NOSONAR - complex.
1508 - if ( ! empty( $slug ) && ! empty( $value ) ) {
1509 - Api_Backups_Utility::get_instance()->update_api_key( $slug, $value );
1515 + $success = Api_Backups_Utility::get_instance()->update_api_key( $slug, $value );
1516 + if ( $success ) {
1510 1517 $updated[ $name ] = $value;
1511 1518 }
1512 1519 };
1513 1520
@@ -1519,11 +1526,32 @@
1519 1526 $update_if_present( 'username', $api['options']['username'] ?? '' );
1520 1527 $update_if_present( 'company_id', $api['options']['company_id'] ?? '' );
1521 1528
1522 1529 // Update api key or password.
1523 - $update_secrets_api( $api['slug'] ?? '', $body['secrets']['api_key'] ?? '', 'api_key' );
1524 - $update_secrets_api( $api['slug'] ?? '', $body['password'] ?? '', 'password' );
1530 + if ( ! empty( $api['slug'] ) ) {
1531 + if ( isset( $body['secrets']['api_key'] ) ) {
1532 + $update_secrets_api( $api['slug'] ?? '', $body['secrets']['api_key'] ?? '', 'api_key' );
1533 + }
1534 + if ( isset( $body['password'] ) ) {
1535 + $update_secrets_api( $api['slug'] ?? '', $body['password'] ?? '', 'password' );
1536 + }
1537 + }
1525 1538
1539 + if ( ! empty( $api['slug'] ) && 'cloudways' === $api['slug'] && isset( $body['secrets']['access_token'] ) ) {
1540 + $success = Api_Backups_Utility::get_instance()->update_api_key( 'cloudways', $body['secrets']['access_token'], 'access_token' );
1541 + if ( $success ) {
1542 + $updated['access_token'] = $body['secrets']['access_token'];
1543 + }
1544 + }
1545 +
1546 + // Get secrets key.
1547 + $secrets = array( 'api_key', 'access_token', 'password' );
1548 + foreach ( $secrets as $secret_key ) {
1549 + if ( isset( $updated[ $secret_key ] ) ) {
1550 + $updated[ $secret_key ] = MainWP_Credential_Render::value_for_input( false );
1551 + }
1552 + }
1553 +
1526 1554 return rest_ensure_response(
1527 1555 array(
1528 1556 'success' => 1,
1529 1557 'message' => __( 'API backup settings updated successfully.', 'mainwp' ),
@@ -1660,9 +1688,10 @@
1660 1688 $destroy_id = $request->get_param( 'destroy_id' ); // Get id from url.
1661 1689 if ( empty( $destroy_id ) ) {
1662 1690 return new WP_Error(
1663 1691 'missing_destroy_id',
1664 - __( 'Destroy ID is required.', 'mainwp' )
1692 + __( 'Destroy ID is required.', 'mainwp' ),
1693 + array( 'status' => 400 )
1665 1694 );
1666 1695 }
1667 1696
1668 1697 $destroy_data = get_transient( "mainwp_tool_destroy_job_{$destroy_id}" );
@@ -1668,9 +1697,10 @@
1668 1697 $destroy_data = get_transient( "mainwp_tool_destroy_job_{$destroy_id}" );
1669 1698 if ( ! $destroy_data ) {
1670 1699 return new WP_Error(
1671 1700 'destroy_session_job_not_found',
1672 - __( 'Destroy session job not found.', 'mainwp' )
1701 + __( 'Destroy session job not found.', 'mainwp' ),
1702 + array( 'status' => 404 )
1673 1703 );
1674 1704 }
1675 1705
1676 1706 return rest_ensure_response(
@@ -1817,9 +1847,10 @@
1817 1847
1818 1848 if ( empty( $renew_id ) ) {
1819 1849 return new WP_Error(
1820 1850 'missing_renew_id',
1821 - __( 'Renew ID is required.', 'mainwp' )
1851 + __( 'Renew ID is required.', 'mainwp' ),
1852 + array( 'status' => 400 )
1822 1853 );
1823 1854 }
1824 1855
1825 1856 // Get disconnect data.
@@ -1827,9 +1858,10 @@
1827 1858
1828 1859 if ( ! $renew_data ) {
1829 1860 return new WP_Error(
1830 1861 'renew_connection_job_not_found',
1831 - __( 'Renew connection job not found.', 'mainwp' )
1862 + __( 'Renew connection job not found.', 'mainwp' ),
1863 + array( 'status' => 404 )
1832 1864 );
1833 1865 }
1834 1866
1835 1867 return rest_ensure_response(
@@ -2064,9 +2096,10 @@
2064 2096
2065 2097 if ( empty( $disconnect_id ) ) {
2066 2098 return new WP_Error(
2067 2099 'missing_disconnect_id',
2068 - __( 'Disconnect ID is required.', 'mainwp' )
2100 + __( 'Disconnect ID is required.', 'mainwp' ),
2101 + array( 'status' => 400 )
2069 2102 );
2070 2103 }
2071 2104
2072 2105 // Get disconnect data.
@@ -2074,9 +2107,10 @@
2074 2107
2075 2108 if ( ! $disconnect_data ) {
2076 2109 return new WP_Error(
2077 2110 'disconnect_job_not_found',
2078 - __( 'Job not found.', 'mainwp' )
2111 + __( 'Job not found.', 'mainwp' ),
2112 + array( 'status' => 404 )
2079 2113 );
2080 2114 }
2081 2115
2082 2116 return rest_ensure_response(
@@ -2259,9 +2293,10 @@
2259 2293 ),
2260 2294 'plugin_automatic_daily_update' => array(
2261 2295 'required' => false,
2262 2296 'description' => __( 'Plugin automatic daily update.', 'mainwp' ),
2263 - 'type' => 'boolean',
2297 + 'type' => 'integer',
2298 + 'enum' => $val_bool,
2264 2299 'sanitize_callback' => $this->make_enum_sanitizer( $val_bool ),
2265 2300 'validate_callback' => $this->make_enum_validator( $val_bool ),
2266 2301 ),
2267 2302 'theme_automatic_daily_update' => array(
@@ -2266,9 +2301,10 @@
2266 2301 ),
2267 2302 'theme_automatic_daily_update' => array(
2268 2303 'required' => false,
2269 2304 'description' => __( 'Theme automatic daily update.', 'mainwp' ),
2270 - 'type' => 'boolean',
2305 + 'type' => 'integer',
2306 + 'enum' => $val_bool,
2271 2307 'sanitize_callback' => $this->make_enum_sanitizer( $val_bool ),
2272 2308 'validate_callback' => $this->make_enum_validator( $val_bool ),
2273 2309 ),
2274 2310 'trans_automatic_daily_update' => array(
@@ -2630,8 +2666,14 @@
2630 2666 'description' => __( 'Uptime monitoring keyword.', 'mainwp' ),
2631 2667 'type' => 'string',
2632 2668 'sanitize_callback' => 'sanitize_text_field',
2633 2669 ),
2670 + 'mainwp_uptime_monitoring_bypass_cache' => array(
2671 + 'required' => false,
2672 + 'description' => __( 'Uptime monitoring attempt to bypass page cache.', 'mainwp' ),
2673 + 'type' => 'integer',
2674 + 'sanitize_callback' => 'intval',
2675 + ),
2634 2676 'mainwp_uptime_monitoring_up_status_codes' => array(
2635 2677 'required' => false,
2636 2678 'description' => __( 'Uptime monitoring up status codes.', 'mainwp' ),
2637 2679 'type' => 'array',
@@ -2684,8 +2726,9 @@
2684 2726 if ( ! is_email( $value ) ) {
2685 2727 return new WP_Error(
2686 2728 'invalid_email',
2687 2729 /* translators: %s: Email address */ sprintf( __( 'Invalid email address: %s.', 'mainwp' ), $value ),
2730 + array( 'status' => 400 )
2688 2731 );
2689 2732 }
2690 2733 return true;
2691 2734 },
@@ -2944,14 +2987,20 @@
2944 2987 'type' => 'object',
2945 2988 'required' => false,
2946 2989 'description' => __( 'Secrets (Cpanel not used).', 'mainwp' ),
2947 2990 'properties' => array(
2948 - 'api_key' => array(
2991 + 'api_key' => array(
2949 2992 'type' => 'string',
2950 - 'required' => true,
2993 + 'required' => false,
2951 2994 'description' => __( 'API key (for kinsta).', 'mainwp' ),
2952 2995 'sanitize_callback' => 'sanitize_text_field',
2953 2996 ),
2997 + 'access_token' => array(
2998 + 'type' => 'string',
2999 + 'required' => false,
3000 + 'description' => __( 'Access token (for Cloudways).', 'mainwp' ),
3001 + 'sanitize_callback' => 'sanitize_text_field',
3002 + ),
2954 3003 ),
2955 3004 ),
2956 3005 );
2957 3006 }
@@ -2999,13 +3048,13 @@
2999 3048 * Sanitize API slug.
3000 3049 *
3001 3050 * @param string $value API slug.
3002 3051 *
3003 - * @return string
3052 + * @return array|WP_Error The API backup definition the slug names, with the slug added to it, or WP_Error for a slug with no definition.
3004 3053 */
3005 3054 public function sanitize_api_slug( $value ) {
3006 3055 if ( empty( $value ) ) {
3007 - return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ) );
3056 + return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ), array( 'status' => 400 ) );
3008 3057 }
3009 3058
3010 3059 // Sanitize field.
3011 3060 $value = $this->sanitize_field( $value );
@@ -3010,9 +3059,9 @@
3010 3059 // Sanitize field.
3011 3060 $value = $this->sanitize_field( $value );
3012 3061 $api_backups = $this->get_api_backup_definitions(); // Get API backup definitions.
3013 3062 if ( ! array_key_exists( $value, $api_backups ) ) {
3014 - return new WP_Error( 'invalid_slug', __( 'API slug not exists.', 'mainwp' ) );
3063 + return new WP_Error( 'invalid_slug', __( 'API slug not exists.', 'mainwp' ), array( 'status' => 400 ) );
3015 3064 }
3016 3065 $api_backups[ $value ]['slug'] = $value; // Add slug to API backup definition.
3017 3066 return $api_backups[ $value ];
3018 3067 }
@@ -3026,9 +3075,9 @@
3026 3075 * @return bool|WP_Error
3027 3076 */
3028 3077 public function validate_api_slug( $value, $request ) {
3029 3078 if ( empty( $value ) ) {
3030 - return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ) );
3079 + return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ), array( 'status' => 400 ) );
3031 3080 }
3032 3081
3033 3082 $value = $this->sanitize_field( $value );
3034 3083
@@ -3034,9 +3083,9 @@
3034 3083
3035 3084 // Check if API slug exists.
3036 3085 $api_backups = $this->get_api_backup_definitions();
3037 3086 if ( ! array_key_exists( $value, $api_backups ) ) {
3038 - return new WP_Error( 'invalid_slug', __( 'API slug not exists.', 'mainwp' ) );
3087 + return new WP_Error( 'invalid_slug', __( 'API slug not exists.', 'mainwp' ), array( 'status' => 400 ) );
3039 3088 }
3040 3089
3041 3090 return true;
3042 3091 }
@@ -3058,9 +3107,9 @@
3058 3107
3059 3108 $value = $this->sanitize_field( $value ); // Sanitize field.
3060 3109 $symbol = Cost_Tracker_Utility::get_currency_symbol( $value ); // Get currency symbol.
3061 3110 if ( empty( $symbol ) ) {
3062 - return new WP_Error( 'invalid_currency', __( 'Invalid currency.', 'mainwp' ) );
3111 + return new WP_Error( 'invalid_currency', __( 'Invalid currency.', 'mainwp' ), array( 'status' => 400 ) );
3063 3112 }
3064 3113 return true;
3065 3114 }
3066 3115 /**
@@ -3077,9 +3126,9 @@
3077 3126 }
3078 3127
3079 3128 $value = $this->sanitize_field( $value );
3080 3129 if ( ! preg_match( '/^#([A-Fa-f0-9]{6})$/', $value ) ) {
3081 - return new WP_Error( 'invalid_color', __( 'Invalid color. Color must be in the format "#RRGGBB".', 'mainwp' ) );
3130 + return new WP_Error( 'invalid_color', __( 'Invalid color. Color must be in the format "#RRGGBB".', 'mainwp' ), array( 'status' => 400 ) );
3082 3131 }
3083 3132 return true;
3084 3133 }
3085 3134
@@ -3099,9 +3148,10 @@
3099 3148 $value = $this->sanitize_field( $value );
3100 3149 if ( ! preg_match( '/^[a-z0-9_\-]+:[a-z0-9_\-\s]+$/i', $value ) ) {
3101 3150 return new WP_Error(
3102 3151 'invalid_icon',
3103 - __( 'Invalid icon. Icon must be in the format "icon_type:icon_name".', 'mainwp' )
3152 + __( 'Invalid icon. Icon must be in the format "icon_type:icon_name".', 'mainwp' ),
3153 + array( 'status' => 400 )
3104 3154 );
3105 3155 }
3106 3156 return true;
3107 3157 }
@@ -3118,9 +3168,9 @@
3118 3168 * @return bool|WP_Error
3119 3169 */
3120 3170 public function validate_product_type_slug( $value, $request ) {
3121 3171 if ( empty( $value ) ) {
3122 - return new WP_Error( 'invalid_slug', __( 'Invalid product type slug.', 'mainwp' ) );
3172 + return new WP_Error( 'invalid_slug', __( 'Invalid product type slug.', 'mainwp' ), array( 'status' => 400 ) );
3123 3173 }
3124 3174
3125 3175 $value = $this->sanitize_field( $value );
3126 3176 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -3131,9 +3181,9 @@
3131 3181 $product_types = array_merge( $product_types, Cost_Tracker_Admin::get_default_product_types() );
3132 3182 }
3133 3183
3134 3184 if ( ! isset( $product_types[ $value ] ) ) {
3135 - return new WP_Error( 'invalid_slug', __( 'Product type does not exist.', 'mainwp' ) );
3185 + return new WP_Error( 'invalid_slug', __( 'Product type does not exist.', 'mainwp' ), array( 'status' => 400 ) );
3136 3186 }
3137 3187
3138 3188 return true;
3139 3189 }
@@ -3149,9 +3199,9 @@
3149 3199 * @return bool|WP_Error
3150 3200 */
3151 3201 public function validate_payment_method_slug( $value, $request ) { // phpcs:ignore -- NOSONAR - long method.
3152 3202 if ( empty( $value ) ) {
3153 - return new WP_Error( 'invalid_slug', __( 'Invalid payment method slug.', 'mainwp' ) );
3203 + return new WP_Error( 'invalid_slug', __( 'Invalid payment method slug.', 'mainwp' ), array( 'status' => 400 ) );
3154 3204 }
3155 3205
3156 3206 $value = $this->sanitize_field( $value );
3157 3207 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -3156,9 +3206,9 @@
3156 3206 $value = $this->sanitize_field( $value );
3157 3207 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
3158 3208 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
3159 3209 if ( ! isset( $payment_methods[ $value ] ) ) {
3160 - return new WP_Error( 'invalid_slug', __( 'Payment method does not exist.', 'mainwp' ) );
3210 + return new WP_Error( 'invalid_slug', __( 'Payment method does not exist.', 'mainwp' ), array( 'status' => 400 ) );
3161 3211 }
3162 3212
3163 3213 return true;
3164 3214 }
@@ -3173,9 +3223,9 @@
3173 3223 * @return string|WP_Error
3174 3224 */
3175 3225 public function sanitize_email_type( $value ) { // phpcs:ignore -- NOSONAR - long method.
3176 3226 if ( empty( $value ) ) {
3177 - return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ) );
3227 + return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ), array( 'status' => 400 ) );
3178 3228 }
3179 3229
3180 3230 // Sanitize email type.
3181 3231 $value = $this->sanitize_field( $value );
@@ -3182,9 +3232,9 @@
3182 3232
3183 3233 // Get default email settings.
3184 3234 $email_setting = MainWP_Notification_Settings::get_default_emails_fields( $value, '', true );
3185 3235 if ( empty( $email_setting ) ) {
3186 - return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ) );
3236 + return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ), array( 'status' => 400 ) );
3187 3237 }
3188 3238
3189 3239 return array_merge( $email_setting, array( 'type' => $value ) );
3190 3240 }
@@ -3200,9 +3250,9 @@
3200 3250 * @return bool|WP_Error
3201 3251 */
3202 3252 public function validate_email_type( $value, $request ) { // phpcs:ignore -- NOSONAR - long method.
3203 3253 if ( empty( $value ) ) {
3204 - return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ) );
3254 + return new WP_Error( 'invalid_mail_type', __( 'Invalid email type.', 'mainwp' ), array( 'status' => 400 ) );
3205 3255 }
3206 3256
3207 3257 $value = $this->sanitize_field( $value );
3208 3258 // Get notification email types.
@@ -3208,9 +3258,9 @@
3208 3258 // Get notification email types.
3209 3259 $notification_emails = MainWP_Notification_Settings::get_notification_types();
3210 3260
3211 3261 if ( ! array_key_exists( $value, $notification_emails ) ) {
3212 - return new WP_Error( 'invalid_mail_type', __( 'Email type does not exist.', 'mainwp' ) );
3262 + return new WP_Error( 'invalid_mail_type', __( 'Email type does not exist.', 'mainwp' ), array( 'status' => 400 ) );
3213 3263 }
3214 3264
3215 3265 return true;
3216 3266 }
@@ -3229,9 +3279,9 @@
3229 3279 }
3230 3280
3231 3281 $int_value = (int) $this->sanitize_field( $value );
3232 3282 if ( $int_value < 1 || $int_value > 12 ) {
3233 - return new WP_Error( 'invalid_frequency_daily_update', __( 'Invalid frequency daily update. Use 1-12.', 'mainwp' ) );
3283 + return new WP_Error( 'invalid_frequency_daily_update', __( 'Invalid frequency daily update. Use 1-12.', 'mainwp' ), array( 'status' => 400 ) );
3234 3284 }
3235 3285 return true;
3236 3286 }
3237 3287
@@ -3253,8 +3303,9 @@
3253 3303 if ( preg_match( '/\d/', $value ) ) {
3254 3304 return new WP_Error(
3255 3305 'invalid_date_format_numeric',
3256 3306 __( 'Invalid date format: should not contain digits. Use format characters like F j, Y.', 'mainwp' ),
3307 + array( 'status' => 400 )
3257 3308 );
3258 3309 }
3259 3310
3260 3311 // Allows only valid PHP date() format characters and some basic separators.
@@ -3261,8 +3312,9 @@
3261 3312 if ( ! preg_match( '/^[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU\-\.,:\/\s\\\\]+$/', $value ) ) {
3262 3313 return new WP_Error(
3263 3314 'invalid_date_format',
3264 3315 __( 'Invalid date format. Use valid PHP date format characters like F j, Y.', 'mainwp' ),
3316 + array( 'status' => 400 )
3265 3317 );
3266 3318 }
3267 3319
3268 3320 // Check rendering works.
@@ -3270,8 +3322,9 @@
3270 3322 if ( false === $date || '' === $date ) {
3271 3323 return new WP_Error(
3272 3324 'invalid_date_format_render',
3273 3325 __( 'Invalid or unsupported date format.', 'mainwp' ),
3326 + array( 'status' => 400 )
3274 3327 );
3275 3328 }
3276 3329
3277 3330 return true;
@@ -3294,8 +3347,9 @@
3294 3347 if ( preg_match( '/\d/', $value ) ) {
3295 3348 return new WP_Error(
3296 3349 'invalid_time_format_numeric',
3297 3350 __( 'Invalid time format: should not contain digits. Use format characters like g:i a.', 'mainwp' ),
3351 + array( 'status' => 400 )
3298 3352 );
3299 3353 }
3300 3354
3301 3355 // Allows only valid PHP date() format characters and some basic separators.
@@ -3302,8 +3356,9 @@
3302 3356 if ( ! preg_match( '/^[gGhHisAa\-\.,:\/\s\\\\]+$/', $value ) ) {
3303 3357 return new WP_Error(
3304 3358 'invalid_time_format',
3305 3359 __( 'Invalid time format. Use valid PHP time format characters like g:i a or H:i.', 'mainwp' ),
3360 + array( 'status' => 400 )
3306 3361 );
3307 3362 }
3308 3363
3309 3364 // Check rendering works.
@@ -3311,8 +3366,9 @@
3311 3366 if ( false === $time || '' === $time ) {
3312 3367 return new WP_Error(
3313 3368 'invalid_time_format_render',
3314 3369 __( 'Invalid or unsupported time format.', 'mainwp' ),
3370 + array( 'status' => 400 )
3315 3371 );
3316 3372 }
3317 3373
3318 3374 return true;
@@ -3350,8 +3406,9 @@
3350 3406 } catch ( Exception $e ) {
3351 3407 return new WP_Error(
3352 3408 'invalid_timezone_string',
3353 3409 __( 'Invalid timezone. Use a valid format like "UTC+0" or its equivalent name, e.g. "Europe/London".', 'mainwp' ),
3410 + array( 'status' => 400 )
3354 3411 );
3355 3412 }
3356 3413
3357 3414 // Convert to UTC offset.
@@ -3366,8 +3423,9 @@
3366 3423
3367 3424 return new WP_Error(
3368 3425 'invalid_timezone_string',
3369 3426 __( 'Invalid timezone. Use a valid format like "UTC+0" or its equivalent name, e.g. "Europe/London".', 'mainwp' ),
3427 + array( 'status' => 400 )
3370 3428 );
3371 3429 }
3372 3430
3373 3431 /**
@@ -3400,8 +3458,9 @@
3400 3458
3401 3459 return new WP_Error(
3402 3460 'invalid_timezone_string',
3403 3461 __( 'Invalid timezone. Use a valid format like UTC+0 or its equivalent name, e.g. "Europe/London".', 'mainwp' ),
3462 + array( 'status' => 400 )
3404 3463 );
3405 3464 }
3406 3465
3407 3466 /**
@@ -3414,13 +3473,14 @@
3414 3473 public function sanitize_mainwp_widgets( $value ) { // phpcs:ignore -- NOSONAR - complex.
3415 3474 if ( ! is_array( $value ) ) {
3416 3475 return new WP_Error(
3417 3476 'invalid_mainwp_widgets_type',
3418 - __( 'mainwp_widgets must be an object.', 'mainwp' )
3477 + __( 'mainwp_widgets must be an object.', 'mainwp' ),
3478 + array( 'status' => 400 )
3419 3479 );
3420 3480 }
3421 3481
3422 - $existing = get_user_option( 'mainwp_settings_show_widgets', array() );
3482 + $existing = get_user_option( 'mainwp_settings_show_widgets' );
3423 3483 if ( ! is_array( $existing ) ) {
3424 3484 $existing = array();
3425 3485 }
3426 3486
@@ -3452,8 +3512,9 @@
3452 3512 if ( ! is_array( $value ) ) {
3453 3513 return new WP_Error(
3454 3514 'invalid_mainwp_widgets_type',
3455 3515 __( 'mainwp_widgets must be an object.', 'mainwp' ),
3516 + array( 'status' => 400 )
3456 3517 );
3457 3518 }
3458 3519
3459 3520 // Sanitize field data.
@@ -3458,9 +3519,9 @@
3458 3519
3459 3520 // Sanitize field data.
3460 3521 $values = array_map( 'sanitize_text_field', wp_unslash( $value ) );
3461 3522
3462 - $widgets = get_user_option( 'mainwp_settings_show_widgets', array() );
3523 + $widgets = get_user_option( 'mainwp_settings_show_widgets' );
3463 3524 $allowed = array_keys( $widgets );
3464 3525 $keys = array_keys( $values );
3465 3526
3466 3527 $invalid_keys = array_values( array_diff( $keys, $allowed ) );
@@ -3473,8 +3534,9 @@
3473 3534 __( 'Invalid widget keys: %1$s. Allowed keys: %2$s.', 'mainwp' ),
3474 3535 esc_html( implode( ', ', $invalid_keys ) ),
3475 3536 esc_html( implode( ', ', $allowed ) )
3476 3537 ),
3538 + array( 'status' => 400 )
3477 3539 );
3478 3540 }
3479 3541
3480 3542 foreach ( $values as $k => $v ) {
@@ -3481,8 +3543,9 @@
3481 3543 if ( is_array( $v ) || is_object( $v ) ) {
3482 3544 return new WP_Error(
3483 3545 'invalid_mainwp_widgets_value_type',
3484 3546 /* translators: %s: Widget key name */ sprintf( __( 'Value for "%s" must be 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3547 + array( 'status' => 400 )
3485 3548 );
3486 3549 }
3487 3550 $int = (int) $v;
3488 3551 if ( 0 !== $int && 1 !== $int ) {
@@ -3488,8 +3551,9 @@
3488 3551 if ( 0 !== $int && 1 !== $int ) {
3489 3552 return new WP_Error(
3490 3553 'invalid_mainwp_widgets_value',
3491 3554 /* translators: %s: Widget key name */ sprintf( __( 'Invalid value for "%s". Allowed: 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3555 + array( 'status' => 400 )
3492 3556 );
3493 3557 }
3494 3558 }
3495 3559
@@ -3510,9 +3574,10 @@
3510 3574
3511 3575 if ( ! is_array( $value ) ) {
3512 3576 return new WP_Error(
3513 3577 'invalid_status_codes_type',
3514 - __( 'Status codes must be an array.', 'mainwp' )
3578 + __( 'Status codes must be an array.', 'mainwp' ),
3579 + array( 'status' => 400 )
3515 3580 );
3516 3581 }
3517 3582
3518 3583 // Parse ID list to ensure all values are integers.
@@ -3580,9 +3645,10 @@
3580 3645 public function sanitize_sync_data( $value ) { // phpcs:ignore -- NOSONAR - complex.
3581 3646 if ( ! is_array( $value ) ) {
3582 3647 return new WP_Error(
3583 3648 'invalid_sync_data_type',
3584 - __( 'Sync data must be an object.', 'mainwp' )
3649 + __( 'Sync data must be an object.', 'mainwp' ),
3650 + array( 'status' => 400 )
3585 3651 );
3586 3652 }
3587 3653
3588 3654 $values = array_map( 'sanitize_text_field', wp_unslash( $value ) );
@@ -3617,9 +3683,10 @@
3617 3683
3618 3684 if ( ! is_array( $value ) ) {
3619 3685 return new WP_Error(
3620 3686 'invalid_sync_data_type',
3621 - __( 'Sync data must be an object.', 'mainwp' )
3687 + __( 'Sync data must be an object.', 'mainwp' ),
3688 + array( 'status' => 400 )
3622 3689 );
3623 3690 }
3624 3691 // Sanitize field data.
3625 3692 $values = array_map( 'sanitize_text_field', wp_unslash( $value ) );
@@ -3638,8 +3705,9 @@
3638 3705 __( 'Invalid sync data keys: %1$s. Allowed keys: %2$s.', 'mainwp' ),
3639 3706 esc_html( implode( ', ', $invalid_keys ) ),
3640 3707 esc_html( implode( ', ', $allowed ) )
3641 3708 ),
3709 + array( 'status' => 400 )
3642 3710 );
3643 3711 }
3644 3712
3645 3713 foreach ( $values as $k => $v ) {
@@ -3646,8 +3714,9 @@
3646 3714 if ( is_array( $v ) || is_object( $v ) ) {
3647 3715 return new WP_Error(
3648 3716 'invalid_sync_data_type',
3649 3717 /* translators: %s: Sync data key name */ sprintf( __( 'Value for "%s" must be 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3718 + array( 'status' => 400 )
3650 3719 );
3651 3720 }
3652 3721 $int = (int) $v;
3653 3722 if ( 0 !== $int && 1 !== $int ) {
@@ -3653,8 +3722,9 @@
3653 3722 if ( 0 !== $int && 1 !== $int ) {
3654 3723 return new WP_Error(
3655 3724 'invalid_sync_data_type',
3656 3725 /* translators: %s: Sync data key name */ sprintf( __( 'Invalid value for "%s". Allowed: 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3726 + array( 'status' => 400 )
3657 3727 );
3658 3728 }
3659 3729 }
3660 3730
@@ -3677,8 +3747,9 @@
3677 3747 if ( ! preg_match( '/^(?:[01]?\d|2[0-3]):[0-5]\d$/', $value ) ) {
3678 3748 return new WP_Error(
3679 3749 'invalid_time_update',
3680 3750 __( 'Invalid time. Use whole hours in 24h format like 0:00, 9:00, 23:00, etc...', 'mainwp' ),
3751 + array( 'status' => 400 )
3681 3752 );
3682 3753 }
3683 3754
3684 3755 return $value;
@@ -3704,8 +3775,9 @@
3704 3775
3705 3776 return new WP_Error(
3706 3777 'invalid_time_update',
3707 3778 __( 'Invalid time. Use whole hours in 24h format like 0:00, 9:00, 23:00, etc...', 'mainwp' ),
3779 + array( 'status' => 400 )
3708 3780 );
3709 3781 }
3710 3782
3711 3783 /**
@@ -3737,15 +3809,17 @@
3737 3809 if ( 'module-api-backups' === $primary_backup_value && ( null !== $backup_feature && '0' !== (string) $backup_feature && 0 !== (int) $backup_feature ) ) {
3738 3810 // When primary backup is module-api-backups, legacy feature must be 0.
3739 3811 return new WP_Error(
3740 3812 'invalid_backup_config',
3741 - __( 'When mainwp_primary_backup is "module-api-backups", mainwp_enable_legacy_backup_feature must be disabled (0).', 'mainwp' )
3813 + __( 'When mainwp_primary_backup is "module-api-backups", mainwp_enable_legacy_backup_feature must be disabled (0).', 'mainwp' ),
3814 + array( 'status' => 400 )
3742 3815 );
3743 3816 } elseif ( '' === $primary_backup_value && ( null !== $backup_feature && '1' !== (string) $backup_feature && 1 !== (int) $backup_feature ) ) {
3744 3817 // When primary backup is not module-api-backups, legacy feature must be 1.
3745 3818 return new WP_Error(
3746 3819 'invalid_backup_config',
3747 - __( 'When mainwp_primary_backup is not "module-api-backups", mainwp_enable_legacy_backup_feature must be enabled (1).', 'mainwp' )
3820 + __( 'When mainwp_primary_backup is not "module-api-backups", mainwp_enable_legacy_backup_feature must be enabled (1).', 'mainwp' ),
3821 + array( 'status' => 400 )
3748 3822 );
3749 3823 }
3750 3824 }
3751 3825
@@ -3783,8 +3857,9 @@
3783 3857 // Return error.
3784 3858 return new WP_Error(
3785 3859 'empty_body',
3786 3860 __( 'Request body is empty.', 'mainwp' ),
3861 + array( 'status' => 400 )
3787 3862 );
3788 3863 }
3789 3864
3790 3865 /**
@@ -3798,8 +3873,9 @@
3798 3873 if ( 'application/json' !== $content_type ) {
3799 3874 return new WP_Error(
3800 3875 'invalid_content_type',
3801 3876 __( 'Invalid content type. Expected application/json.', 'mainwp' ),
3877 + array( 'status' => 400 )
3802 3878 );
3803 3879 }
3804 3880 return true;
3805 3881 }
@@ -3833,9 +3909,10 @@
3833 3909 $websites = MainWP_DB::instance()->get_sites();
3834 3910 if ( empty( $websites ) ) {
3835 3911 return new WP_Error(
3836 3912 'no_website_found',
3837 - __( 'No website found.', 'mainwp' )
3913 + __( 'No website found.', 'mainwp' ),
3914 + array( 'status' => 404 )
3838 3915 );
3839 3916 }
3840 3917 return $websites;
3841 3918 }
@@ -3876,8 +3953,9 @@
3876 3953 if ( empty( $user_id ) ) {
3877 3954 return new WP_Error(
3878 3955 'invalid_user',
3879 3956 __( 'User not authenticated.', 'mainwp' ),
3957 + array( 'status' => 401 )
3880 3958 );
3881 3959 }
3882 3960 return $user_id;
3883 3961 }
@@ -3929,9 +4007,9 @@
3929 4007 MainWP_Utility::update_option( $option_name, $val );
3930 4008 return true;
3931 4009 }
3932 4010 // translators: %s: Missing key.
3933 - return new WP_Error( 'missing_key', sprintf( __( 'Missing key %s.', 'mainwp' ), esc_html( $key ) ), );
4011 + return new WP_Error( 'missing_key', sprintf( __( 'Missing key %s.', 'mainwp' ), esc_html( $key ) ), array( 'status' => 400 ) );
3934 4012 }
3935 4013
3936 4014 /**
3937 4015 * Format date.
@@ -3987,9 +4065,10 @@
3987 4065 'options' => array(
3988 4066 'account_email' => 'mainwp_cloudways_api_account_email',
3989 4067 ),
3990 4068 'secrets' => array(
3991 - 'api_key' => array( Api_Backups_3rd_Party::class, 'get_cloudways_api_key' ),
4069 + 'api_key' => array( Api_Backups_3rd_Party::class, 'get_cloudways_api_key' ),
4070 + 'access_token' => array( Api_Backups_3rd_Party::class, 'get_cloudways_access_token' ),
3992 4071 ),
3993 4072 ),
3994 4073 'gridpane' => array(
3995 4074 'label' => 'GridPane',
@@ -4077,10 +4156,14 @@
4077 4156 */
4078 4157 protected function get_general_settings_data() {
4079 4158 // Default Setting.
4080 4159 $default_setting = MainWP_Settings_Indicator::get_defaults_value();
4081 - $show_widgets = get_user_option( 'mainwp_settings_show_widgets', array() );
4160 + $show_widgets = get_user_option( 'mainwp_settings_show_widgets' );
4082 4161
4162 + if ( ! is_array( $show_widgets ) ) {
4163 + $show_widgets = array();
4164 + }
4165 +
4083 4166 // Map settings.
4084 4167 $gmt_offset = (float) get_option( 'gmt_offset', 0 );
4085 4168 $tz_sign = $gmt_offset >= 0 ? '+' : '-';
4086 4169 $tz_value = (string) abs( $gmt_offset );
@@ -4113,8 +4196,15 @@
4113 4196 );
4114 4197 }
4115 4198
4116 4199 $enable_legacy_backup = get_option( 'mainwp_enableLegacyBackupFeature' );
4200 +
4201 + // get_user_option()'s second argument is a user id, not a default, and the defaults array keys this on the option name rather than the response field name.
4202 + $sidebar_position = get_user_option( 'mainwp_sidebarPosition' );
4203 + if ( false === $sidebar_position ) {
4204 + $sidebar_position = $default_setting['mainwp_sidebarPosition'];
4205 + }
4206 +
4117 4207 return array(
4118 4208 // General settings.
4119 4209 'time_daily_update' => get_option( 'mainwp_timeDailyUpdate', $default_setting['mainwp_timeDailyUpdate'] ),
4120 4210 'frequency_daily_update' => (int) get_option( 'mainwp_frequencyDailyUpdate', $default_setting['mainwp_frequencyDailyUpdate'] ),
@@ -4120,9 +4210,9 @@
4120 4210 'frequency_daily_update' => (int) get_option( 'mainwp_frequencyDailyUpdate', $default_setting['mainwp_frequencyDailyUpdate'] ),
4121 4211 'date_format' => get_option( 'date_format', $default_setting['date_format'] ),
4122 4212 'time_format' => get_option( 'time_format', $default_setting['time_format'] ),
4123 4213 'timezone_string' => $tz_string,
4124 - 'sidebar_position' => get_user_option( ' mainwp_sidebarPosition', $default_setting['sidebar_position'] ),
4214 + 'sidebar_position' => (int) $sidebar_position,
4125 4215 'hide_update_everything' => get_option( 'mainwp_hide_update_everything', $default_setting['mainwp_hide_update_everything'] ),
4126 4216 'mainwp_widgets' => $show_widgets,
4127 4217 'plugin_automatic_daily_update' => (int) get_option( 'mainwp_pluginAutomaticDailyUpdate', $default_setting['mainwp_pluginAutomaticDailyUpdate'] ),
4128 4218 'theme_automatic_daily_update' => (int) get_option( 'mainwp_themeAutomaticDailyUpdate', $default_setting['mainwp_themeAutomaticDailyUpdate'] ),
@@ -4201,16 +4291,16 @@
4201 4291 protected function get_monitoring_settings_data() {
4202 4292 $monitoring_settings = MainWP_Uptime_Monitoring_Handle::get_global_monitoring_settings();
4203 4293
4204 4294 // Get interval values.
4205 - $interval_values = MainWP_Uptime_Monitoring_Edit::get_interval_values( false );
4206 - $interval = $monitoring_settings['interval'] ?? 60;
4207 - $interval = isset( $interval_values[ $interval ] ) ? $interval_values[ $interval ] : $interval_values[60];
4295 + $interval_values = MainWP_Uptime_Monitoring_Edit::get_interval_values( false );
4296 + $interval = $monitoring_settings['interval'] ?? 60;
4297 + $interval = isset( $interval_values[ $interval ] ) ? $interval_values[ $interval ] : $interval_values[60];
4208 4298
4209 4299 // Get timeout values.
4210 - $timeout_values = MainWP_Uptime_Monitoring_Edit::get_timeout_values( false );
4211 - $timeout = $monitoring_settings['timeout'] ?? 60;
4212 - $timeout = isset( $timeout_values[ $timeout ] ) ? $timeout_values[ $timeout ] : $timeout_values[60];
4300 + $timeout_values = MainWP_Uptime_Monitoring_Edit::get_timeout_values( false );
4301 + $timeout = $monitoring_settings['timeout'] ?? 60;
4302 + $timeout = isset( $timeout_values[ $timeout ] ) ? $timeout_values[ $timeout ] : $timeout_values[60];
4213 4303
4214 4304 return array(
4215 4305 'mainwp_uptime_monitoring_active' => (int) $monitoring_settings['active'] ?? 0,
4216 4306 'mainwp_uptime_monitoring_interval' => $interval,
@@ -4219,8 +4309,9 @@
4219 4309 'mainwp_uptime_monitoring_type' => $monitoring_settings['type'] ?? 'http',
4220 4310 'mainwp_uptime_monitoring_up_status_codes' => explode( ',', $monitoring_settings['up_status_codes'] ) ?? array(),
4221 4311 'mainwp_uptime_monitoring_down_confirmation_check' => (int) $monitoring_settings['maxretries'] ?? 1,
4222 4312 'mainwp_uptime_monitoring_keyword' => $monitoring_settings['keyword'] ?? '',
4313 + 'mainwp_uptime_monitoring_bypass_cache' => (int) ( $monitoring_settings['bypass_cache'] ?? 0 ),
4223 4314 'mainwp_disable_sites_health_monitoring' => (int) get_option( 'mainwp_disableSitesHealthMonitoring', 1 ),
4224 4315 'mainwp_sitehealth_threshold' => (int) get_option( 'mainwp_sitehealthThreshold', 80 ),
4225 4316 );
4226 4317 }
@@ -4589,8 +4680,13 @@
4589 4680 ),
4590 4681 'mainwp_uptime_monitoring_keyword' => array(
4591 4682 'type' => 'string',
4592 4683 'description' => __( 'Uptime monitoring keyword.', 'mainwp' ),
4684 + 'context' => array( 'monitoring_view' ),
4685 + ),
4686 + 'mainwp_uptime_monitoring_bypass_cache' => array(
4687 + 'type' => 'integer',
4688 + 'description' => __( 'Uptime monitoring attempt to bypass page cache.', 'mainwp' ),
4593 4689 'context' => array( 'monitoring_view' ),
4594 4690 ),
4595 4691 'mainwp_primary_backup' => array(
4596 4692 'type' => 'object',