PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
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 +191 -75 6.1.3 → 6.2.2 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(
@@ -752,10 +755,18 @@
752 755 if ( isset( $body['mainwp_uptime_monitoring_up_status_codes'] ) ) {
753 756 $updated_settings['up_status_codes'] = implode( ',', $body['mainwp_uptime_monitoring_up_status_codes'] );
754 757 }
755 758 if ( isset( $body['mainwp_uptime_monitoring_interval'] ) ) {
756 - $interval_values = MainWP_Uptime_Monitoring_Edit::get_interval_values( false );
757 - $interval = array_search( $body['mainwp_uptime_monitoring_interval'], $interval_values, true );
759 + $interval_values = MainWP_Uptime_Monitoring_Edit::get_interval_values( false );
760 + $interval = array_search( $body['mainwp_uptime_monitoring_interval'], $interval_values, true );
761 + // An empty string passes the enum validator, so an unmatched label has to be rejected here, before anything is saved.
762 + if ( false === $interval ) {
763 + return new WP_Error(
764 + 'rest_invalid_param',
765 + __( 'Invalid mainwp_uptime_monitoring_interval value.', 'mainwp' ),
766 + array( 'status' => 400 )
767 + );
768 + }
758 769 $updated_settings['interval'] = $interval;
759 770 }
760 771 if ( isset( $body['mainwp_uptime_monitoring_keyword'] ) ) {
761 772 $updated_settings['keyword'] = $body['mainwp_uptime_monitoring_keyword'];
@@ -763,10 +774,18 @@
763 774 if ( isset( $body['mainwp_uptime_monitoring_method'] ) ) {
764 775 $updated_settings['method'] = $body['mainwp_uptime_monitoring_method'];
765 776 }
766 777 if ( isset( $body['mainwp_uptime_monitoring_timeout'] ) ) {
767 - $timeout_values = MainWP_Uptime_Monitoring_Edit::get_timeout_values( false );
768 - $timeout = array_search( $body['mainwp_uptime_monitoring_timeout'], $timeout_values, true );
778 + $timeout_values = MainWP_Uptime_Monitoring_Edit::get_timeout_values( false );
779 + $timeout = array_search( $body['mainwp_uptime_monitoring_timeout'], $timeout_values, true );
780 + // An empty string passes the enum validator, so an unmatched label has to be rejected here, before anything is saved.
781 + if ( false === $timeout ) {
782 + return new WP_Error(
783 + 'rest_invalid_param',
784 + __( 'Invalid mainwp_uptime_monitoring_timeout value.', 'mainwp' ),
785 + array( 'status' => 400 )
786 + );
787 + }
769 788 $updated_settings['timeout'] = $timeout;
770 789 }
771 790 if ( isset( $body['mainwp_uptime_monitoring_type'] ) ) {
772 791 $updated_settings['type'] = $body['mainwp_uptime_monitoring_type'];
@@ -771,8 +790,12 @@
771 790 if ( isset( $body['mainwp_uptime_monitoring_type'] ) ) {
772 791 $updated_settings['type'] = $body['mainwp_uptime_monitoring_type'];
773 792 }
774 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 +
775 798 // Save monitoring the updated settings.
776 799 $updated_settings = apply_filters( 'mainwp_uptime_monitoring_update_global_settings', $updated_settings );
777 800 MainWP_Uptime_Monitoring_Handle::update_uptime_global_settings( $updated_settings );
778 801
@@ -860,14 +883,14 @@
860 883
861 884 // Get mail type.
862 885 $setting = $request->get_param( 'mail_type' );
863 886 if ( empty( $setting ) ) {
864 - 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 ) );
865 888 }
866 889
867 890 $type = $setting['type'] ?? '';
868 891 if ( empty( $type ) ) {
869 - 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 ) );
870 893 }
871 894
872 895 // Get email settings.
873 896 $emails_settings = get_option( 'mainwp_settings_notification_emails' );
@@ -1039,9 +1062,9 @@
1039 1062 $custom_product_types = $this->safe_json_decode( $all_opts['custom_product_types'] ?? '' );
1040 1063
1041 1064 // Check if product type duplicated.
1042 1065 if ( isset( $custom_product_types[ $slug ] ) ) {
1043 - 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 ) );
1044 1067 }
1045 1068 // Map product type.
1046 1069 $custom_product_types[ $slug ] = $title;
1047 1070 $all_opts['custom_product_types'] = wp_json_encode( $custom_product_types );
@@ -1097,9 +1120,9 @@
1097 1120 }
1098 1121
1099 1122 $slug = $request->get_param( 'slug' );
1100 1123 if ( empty( $slug ) ) {
1101 - 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 ) );
1102 1125 }
1103 1126
1104 1127 // Default Product Type.
1105 1128 $default_product_types = Cost_Tracker_Admin::get_default_product_types();
@@ -1110,9 +1133,9 @@
1110 1133 $icon = ! empty( $body['icon'] ) ? $body['icon'] : 'deficon:folder open';
1111 1134
1112 1135 // Cannot change title if it's a default product type.
1113 1136 if ( array_key_exists( $slug, $default_product_types ) && $title !== $default_product_types[ $slug ] ) {
1114 - 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 ) );
1115 1138 }
1116 1139
1117 1140 // Map product type.
1118 1141 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -1160,9 +1183,9 @@
1160 1183 public function delete_cost_tracker_product_type( $request ) { // phpcs:ignore -- NOSONAR - complex.
1161 1184 $slug = $request->get_param( 'slug' );
1162 1185
1163 1186 if ( empty( $slug ) ) {
1164 - 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 ) );
1165 1188 }
1166 1189
1167 1190 // Default Product Type.
1168 1191 $default_product_types = Cost_Tracker_Admin::get_default_product_types();
@@ -1167,9 +1190,9 @@
1167 1190 // Default Product Type.
1168 1191 $default_product_types = Cost_Tracker_Admin::get_default_product_types();
1169 1192 // Cannot delete a default product type.
1170 1193 if ( array_key_exists( $slug, $default_product_types ) ) {
1171 - 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 ) );
1172 1195 }
1173 1196
1174 1197 // Get all options.
1175 1198 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -1178,9 +1201,9 @@
1178 1201 $product_types_icons = $this->safe_json_decode( $all_opts['product_types_icons'] ?? '' );
1179 1202
1180 1203 // Check if product type exists.
1181 1204 if ( ! isset( $custom_product_types[ $slug ] ) ) {
1182 - 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 ) );
1183 1206 }
1184 1207
1185 1208 // Delete product type.
1186 1209 unset( $custom_product_types[ $slug ] );
@@ -1228,9 +1251,9 @@
1228 1251 // Get payment methods.
1229 1252 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
1230 1253
1231 1254 if ( isset( $payment_methods[ $slug ] ) ) {
1232 - 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 ) );
1233 1256 }
1234 1257
1235 1258 // Save payment method.
1236 1259 $payment_methods[ $slug ] = $title;
@@ -1279,9 +1302,9 @@
1279 1302 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
1280 1303 // Get payment methods.
1281 1304 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
1282 1305 if ( ! isset( $payment_methods[ $slug ] ) ) {
1283 - 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 ) );
1284 1307 }
1285 1308
1286 1309 $payment_methods[ $slug ] = $body['title'];
1287 1310 $all_opts['custom_payment_methods'] = wp_json_encode( $payment_methods );
@@ -1315,9 +1338,9 @@
1315 1338 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
1316 1339 // Get payment methods.
1317 1340 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
1318 1341 if ( ! isset( $payment_methods[ $slug ] ) ) {
1319 - 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 ) );
1320 1343 }
1321 1344
1322 1345 unset( $payment_methods[ $slug ] );
1323 1346 $all_opts['custom_payment_methods'] = wp_json_encode( $payment_methods );
@@ -1473,9 +1496,9 @@
1473 1496
1474 1497 // Get API slug data.
1475 1498 $api = $request->get_param( 'api_slug' );
1476 1499 if ( empty( $api ) ) {
1477 - 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 ) );
1478 1501 }
1479 1502
1480 1503 $updated = array();
1481 1504 // Update option if present.
@@ -1488,10 +1511,10 @@
1488 1511 };
1489 1512
1490 1513 // Update secrets if present.
1491 1514 $update_secrets_api = function ( $slug, $value, $name = 'api_key' ) use ( &$updated ) { // phpcs:ignore -- NOSONAR - complex.
1492 - if ( ! empty( $slug ) && ! empty( $value ) ) {
1493 - 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 ) {
1494 1517 $updated[ $name ] = $value;
1495 1518 }
1496 1519 };
1497 1520
@@ -1503,11 +1526,32 @@
1503 1526 $update_if_present( 'username', $api['options']['username'] ?? '' );
1504 1527 $update_if_present( 'company_id', $api['options']['company_id'] ?? '' );
1505 1528
1506 1529 // Update api key or password.
1507 - $update_secrets_api( $api['slug'] ?? '', $body['secrets']['api_key'] ?? '', 'api_key' );
1508 - $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 + }
1509 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 +
1510 1554 return rest_ensure_response(
1511 1555 array(
1512 1556 'success' => 1,
1513 1557 'message' => __( 'API backup settings updated successfully.', 'mainwp' ),
@@ -1644,9 +1688,10 @@
1644 1688 $destroy_id = $request->get_param( 'destroy_id' ); // Get id from url.
1645 1689 if ( empty( $destroy_id ) ) {
1646 1690 return new WP_Error(
1647 1691 'missing_destroy_id',
1648 - __( 'Destroy ID is required.', 'mainwp' )
1692 + __( 'Destroy ID is required.', 'mainwp' ),
1693 + array( 'status' => 400 )
1649 1694 );
1650 1695 }
1651 1696
1652 1697 $destroy_data = get_transient( "mainwp_tool_destroy_job_{$destroy_id}" );
@@ -1652,9 +1697,10 @@
1652 1697 $destroy_data = get_transient( "mainwp_tool_destroy_job_{$destroy_id}" );
1653 1698 if ( ! $destroy_data ) {
1654 1699 return new WP_Error(
1655 1700 'destroy_session_job_not_found',
1656 - __( 'Destroy session job not found.', 'mainwp' )
1701 + __( 'Destroy session job not found.', 'mainwp' ),
1702 + array( 'status' => 404 )
1657 1703 );
1658 1704 }
1659 1705
1660 1706 return rest_ensure_response(
@@ -1801,9 +1847,10 @@
1801 1847
1802 1848 if ( empty( $renew_id ) ) {
1803 1849 return new WP_Error(
1804 1850 'missing_renew_id',
1805 - __( 'Renew ID is required.', 'mainwp' )
1851 + __( 'Renew ID is required.', 'mainwp' ),
1852 + array( 'status' => 400 )
1806 1853 );
1807 1854 }
1808 1855
1809 1856 // Get disconnect data.
@@ -1811,9 +1858,10 @@
1811 1858
1812 1859 if ( ! $renew_data ) {
1813 1860 return new WP_Error(
1814 1861 'renew_connection_job_not_found',
1815 - __( 'Renew connection job not found.', 'mainwp' )
1862 + __( 'Renew connection job not found.', 'mainwp' ),
1863 + array( 'status' => 404 )
1816 1864 );
1817 1865 }
1818 1866
1819 1867 return rest_ensure_response(
@@ -2048,9 +2096,10 @@
2048 2096
2049 2097 if ( empty( $disconnect_id ) ) {
2050 2098 return new WP_Error(
2051 2099 'missing_disconnect_id',
2052 - __( 'Disconnect ID is required.', 'mainwp' )
2100 + __( 'Disconnect ID is required.', 'mainwp' ),
2101 + array( 'status' => 400 )
2053 2102 );
2054 2103 }
2055 2104
2056 2105 // Get disconnect data.
@@ -2058,9 +2107,10 @@
2058 2107
2059 2108 if ( ! $disconnect_data ) {
2060 2109 return new WP_Error(
2061 2110 'disconnect_job_not_found',
2062 - __( 'Job not found.', 'mainwp' )
2111 + __( 'Job not found.', 'mainwp' ),
2112 + array( 'status' => 404 )
2063 2113 );
2064 2114 }
2065 2115
2066 2116 return rest_ensure_response(
@@ -2243,9 +2293,10 @@
2243 2293 ),
2244 2294 'plugin_automatic_daily_update' => array(
2245 2295 'required' => false,
2246 2296 'description' => __( 'Plugin automatic daily update.', 'mainwp' ),
2247 - 'type' => 'boolean',
2297 + 'type' => 'integer',
2298 + 'enum' => $val_bool,
2248 2299 'sanitize_callback' => $this->make_enum_sanitizer( $val_bool ),
2249 2300 'validate_callback' => $this->make_enum_validator( $val_bool ),
2250 2301 ),
2251 2302 'theme_automatic_daily_update' => array(
@@ -2250,23 +2301,26 @@
2250 2301 ),
2251 2302 'theme_automatic_daily_update' => array(
2252 2303 'required' => false,
2253 2304 'description' => __( 'Theme automatic daily update.', 'mainwp' ),
2254 - 'type' => 'boolean',
2305 + 'type' => 'integer',
2306 + 'enum' => $val_bool,
2255 2307 'sanitize_callback' => $this->make_enum_sanitizer( $val_bool ),
2256 2308 'validate_callback' => $this->make_enum_validator( $val_bool ),
2257 2309 ),
2258 2310 'trans_automatic_daily_update' => array(
2259 2311 'required' => false,
2260 - 'description' => __( 'Translation automatic daily update.', 'mainwp' ),
2261 - 'type' => 'array',
2312 + 'description' => __( 'Translation automatic daily update enabled.', 'mainwp' ),
2313 + 'type' => 'integer',
2314 + 'enum' => $val_bool,
2262 2315 'sanitize_callback' => $this->make_enum_sanitizer( $val_bool ),
2263 2316 'validate_callback' => $this->make_enum_validator( $val_bool ),
2264 2317 ),
2265 2318 'automatic_daily_update' => array(
2266 2319 'required' => false,
2267 - 'description' => __( 'Plugin automatic daily update.', 'mainwp' ),
2268 - 'type' => 'array',
2320 + 'description' => __( 'Automatic daily update enabled.', 'mainwp' ),
2321 + 'type' => 'integer',
2322 + 'enum' => $val_bool,
2269 2323 'sanitize_callback' => $this->make_enum_sanitizer( $val_bool ),
2270 2324 'validate_callback' => $this->make_enum_validator( $val_bool ),
2271 2325 ),
2272 2326 'frequency_auto_update' => array(
@@ -2593,9 +2647,10 @@
2593 2647 ),
2594 2648 'mainwp_uptime_monitoring_timeout' => array(
2595 2649 'required' => false,
2596 2650 'description' => __( 'Uptime monitoring timeout.', 'mainwp' ),
2597 - 'type' => 'integer',
2651 + 'type' => 'string',
2652 + 'enum' => $timeout_values,
2598 2653 'sanitize_callback' => $this->make_enum_sanitizer( $timeout_values, 'string' ),
2599 2654 'validate_callback' => $this->make_enum_validator( $timeout_values, 'string' ),
2600 2655 ),
2601 2656 'mainwp_uptime_monitoring_interval' => array(
@@ -2600,9 +2655,10 @@
2600 2655 ),
2601 2656 'mainwp_uptime_monitoring_interval' => array(
2602 2657 'required' => false,
2603 2658 'description' => __( 'Uptime monitoring interval.', 'mainwp' ),
2604 - 'type' => 'integer',
2659 + 'type' => 'string',
2660 + 'enum' => $interval_values,
2605 2661 'sanitize_callback' => $this->make_enum_sanitizer( $interval_values, 'string' ),
2606 2662 'validate_callback' => $this->make_enum_validator( $interval_values, 'string' ),
2607 2663 ),
2608 2664 'mainwp_uptime_monitoring_keyword' => array(
@@ -2610,8 +2666,14 @@
2610 2666 'description' => __( 'Uptime monitoring keyword.', 'mainwp' ),
2611 2667 'type' => 'string',
2612 2668 'sanitize_callback' => 'sanitize_text_field',
2613 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 + ),
2614 2676 'mainwp_uptime_monitoring_up_status_codes' => array(
2615 2677 'required' => false,
2616 2678 'description' => __( 'Uptime monitoring up status codes.', 'mainwp' ),
2617 2679 'type' => 'array',
@@ -2664,8 +2726,9 @@
2664 2726 if ( ! is_email( $value ) ) {
2665 2727 return new WP_Error(
2666 2728 'invalid_email',
2667 2729 /* translators: %s: Email address */ sprintf( __( 'Invalid email address: %s.', 'mainwp' ), $value ),
2730 + array( 'status' => 400 )
2668 2731 );
2669 2732 }
2670 2733 return true;
2671 2734 },
@@ -2924,14 +2987,20 @@
2924 2987 'type' => 'object',
2925 2988 'required' => false,
2926 2989 'description' => __( 'Secrets (Cpanel not used).', 'mainwp' ),
2927 2990 'properties' => array(
2928 - 'api_key' => array(
2991 + 'api_key' => array(
2929 2992 'type' => 'string',
2930 - 'required' => true,
2993 + 'required' => false,
2931 2994 'description' => __( 'API key (for kinsta).', 'mainwp' ),
2932 2995 'sanitize_callback' => 'sanitize_text_field',
2933 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 + ),
2934 3003 ),
2935 3004 ),
2936 3005 );
2937 3006 }
@@ -2979,13 +3048,13 @@
2979 3048 * Sanitize API slug.
2980 3049 *
2981 3050 * @param string $value API slug.
2982 3051 *
2983 - * @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.
2984 3053 */
2985 3054 public function sanitize_api_slug( $value ) {
2986 3055 if ( empty( $value ) ) {
2987 - return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ) );
3056 + return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ), array( 'status' => 400 ) );
2988 3057 }
2989 3058
2990 3059 // Sanitize field.
2991 3060 $value = $this->sanitize_field( $value );
@@ -2990,9 +3059,9 @@
2990 3059 // Sanitize field.
2991 3060 $value = $this->sanitize_field( $value );
2992 3061 $api_backups = $this->get_api_backup_definitions(); // Get API backup definitions.
2993 3062 if ( ! array_key_exists( $value, $api_backups ) ) {
2994 - 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 ) );
2995 3064 }
2996 3065 $api_backups[ $value ]['slug'] = $value; // Add slug to API backup definition.
2997 3066 return $api_backups[ $value ];
2998 3067 }
@@ -3006,9 +3075,9 @@
3006 3075 * @return bool|WP_Error
3007 3076 */
3008 3077 public function validate_api_slug( $value, $request ) {
3009 3078 if ( empty( $value ) ) {
3010 - return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ) );
3079 + return new WP_Error( 'invalid_slug', __( 'Invalid API slug.', 'mainwp' ), array( 'status' => 400 ) );
3011 3080 }
3012 3081
3013 3082 $value = $this->sanitize_field( $value );
3014 3083
@@ -3014,9 +3083,9 @@
3014 3083
3015 3084 // Check if API slug exists.
3016 3085 $api_backups = $this->get_api_backup_definitions();
3017 3086 if ( ! array_key_exists( $value, $api_backups ) ) {
3018 - 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 ) );
3019 3088 }
3020 3089
3021 3090 return true;
3022 3091 }
@@ -3038,9 +3107,9 @@
3038 3107
3039 3108 $value = $this->sanitize_field( $value ); // Sanitize field.
3040 3109 $symbol = Cost_Tracker_Utility::get_currency_symbol( $value ); // Get currency symbol.
3041 3110 if ( empty( $symbol ) ) {
3042 - return new WP_Error( 'invalid_currency', __( 'Invalid currency.', 'mainwp' ) );
3111 + return new WP_Error( 'invalid_currency', __( 'Invalid currency.', 'mainwp' ), array( 'status' => 400 ) );
3043 3112 }
3044 3113 return true;
3045 3114 }
3046 3115 /**
@@ -3057,9 +3126,9 @@
3057 3126 }
3058 3127
3059 3128 $value = $this->sanitize_field( $value );
3060 3129 if ( ! preg_match( '/^#([A-Fa-f0-9]{6})$/', $value ) ) {
3061 - 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 ) );
3062 3131 }
3063 3132 return true;
3064 3133 }
3065 3134
@@ -3079,9 +3148,10 @@
3079 3148 $value = $this->sanitize_field( $value );
3080 3149 if ( ! preg_match( '/^[a-z0-9_\-]+:[a-z0-9_\-\s]+$/i', $value ) ) {
3081 3150 return new WP_Error(
3082 3151 'invalid_icon',
3083 - __( '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 )
3084 3154 );
3085 3155 }
3086 3156 return true;
3087 3157 }
@@ -3098,9 +3168,9 @@
3098 3168 * @return bool|WP_Error
3099 3169 */
3100 3170 public function validate_product_type_slug( $value, $request ) {
3101 3171 if ( empty( $value ) ) {
3102 - 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 ) );
3103 3173 }
3104 3174
3105 3175 $value = $this->sanitize_field( $value );
3106 3176 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -3111,9 +3181,9 @@
3111 3181 $product_types = array_merge( $product_types, Cost_Tracker_Admin::get_default_product_types() );
3112 3182 }
3113 3183
3114 3184 if ( ! isset( $product_types[ $value ] ) ) {
3115 - 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 ) );
3116 3186 }
3117 3187
3118 3188 return true;
3119 3189 }
@@ -3129,9 +3199,9 @@
3129 3199 * @return bool|WP_Error
3130 3200 */
3131 3201 public function validate_payment_method_slug( $value, $request ) { // phpcs:ignore -- NOSONAR - long method.
3132 3202 if ( empty( $value ) ) {
3133 - 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 ) );
3134 3204 }
3135 3205
3136 3206 $value = $this->sanitize_field( $value );
3137 3207 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
@@ -3136,9 +3206,9 @@
3136 3206 $value = $this->sanitize_field( $value );
3137 3207 $all_opts = Cost_Tracker_Utility::get_instance()->get_all_options();
3138 3208 $payment_methods = $this->safe_json_decode( $all_opts['custom_payment_methods'] ?? '' );
3139 3209 if ( ! isset( $payment_methods[ $value ] ) ) {
3140 - 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 ) );
3141 3211 }
3142 3212
3143 3213 return true;
3144 3214 }
@@ -3153,9 +3223,9 @@
3153 3223 * @return string|WP_Error
3154 3224 */
3155 3225 public function sanitize_email_type( $value ) { // phpcs:ignore -- NOSONAR - long method.
3156 3226 if ( empty( $value ) ) {
3157 - 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 ) );
3158 3228 }
3159 3229
3160 3230 // Sanitize email type.
3161 3231 $value = $this->sanitize_field( $value );
@@ -3162,9 +3232,9 @@
3162 3232
3163 3233 // Get default email settings.
3164 3234 $email_setting = MainWP_Notification_Settings::get_default_emails_fields( $value, '', true );
3165 3235 if ( empty( $email_setting ) ) {
3166 - 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 ) );
3167 3237 }
3168 3238
3169 3239 return array_merge( $email_setting, array( 'type' => $value ) );
3170 3240 }
@@ -3180,9 +3250,9 @@
3180 3250 * @return bool|WP_Error
3181 3251 */
3182 3252 public function validate_email_type( $value, $request ) { // phpcs:ignore -- NOSONAR - long method.
3183 3253 if ( empty( $value ) ) {
3184 - 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 ) );
3185 3255 }
3186 3256
3187 3257 $value = $this->sanitize_field( $value );
3188 3258 // Get notification email types.
@@ -3188,9 +3258,9 @@
3188 3258 // Get notification email types.
3189 3259 $notification_emails = MainWP_Notification_Settings::get_notification_types();
3190 3260
3191 3261 if ( ! array_key_exists( $value, $notification_emails ) ) {
3192 - 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 ) );
3193 3263 }
3194 3264
3195 3265 return true;
3196 3266 }
@@ -3209,9 +3279,9 @@
3209 3279 }
3210 3280
3211 3281 $int_value = (int) $this->sanitize_field( $value );
3212 3282 if ( $int_value < 1 || $int_value > 12 ) {
3213 - 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 ) );
3214 3284 }
3215 3285 return true;
3216 3286 }
3217 3287
@@ -3233,8 +3303,9 @@
3233 3303 if ( preg_match( '/\d/', $value ) ) {
3234 3304 return new WP_Error(
3235 3305 'invalid_date_format_numeric',
3236 3306 __( 'Invalid date format: should not contain digits. Use format characters like F j, Y.', 'mainwp' ),
3307 + array( 'status' => 400 )
3237 3308 );
3238 3309 }
3239 3310
3240 3311 // Allows only valid PHP date() format characters and some basic separators.
@@ -3241,8 +3312,9 @@
3241 3312 if ( ! preg_match( '/^[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU\-\.,:\/\s\\\\]+$/', $value ) ) {
3242 3313 return new WP_Error(
3243 3314 'invalid_date_format',
3244 3315 __( 'Invalid date format. Use valid PHP date format characters like F j, Y.', 'mainwp' ),
3316 + array( 'status' => 400 )
3245 3317 );
3246 3318 }
3247 3319
3248 3320 // Check rendering works.
@@ -3250,8 +3322,9 @@
3250 3322 if ( false === $date || '' === $date ) {
3251 3323 return new WP_Error(
3252 3324 'invalid_date_format_render',
3253 3325 __( 'Invalid or unsupported date format.', 'mainwp' ),
3326 + array( 'status' => 400 )
3254 3327 );
3255 3328 }
3256 3329
3257 3330 return true;
@@ -3274,8 +3347,9 @@
3274 3347 if ( preg_match( '/\d/', $value ) ) {
3275 3348 return new WP_Error(
3276 3349 'invalid_time_format_numeric',
3277 3350 __( 'Invalid time format: should not contain digits. Use format characters like g:i a.', 'mainwp' ),
3351 + array( 'status' => 400 )
3278 3352 );
3279 3353 }
3280 3354
3281 3355 // Allows only valid PHP date() format characters and some basic separators.
@@ -3282,8 +3356,9 @@
3282 3356 if ( ! preg_match( '/^[gGhHisAa\-\.,:\/\s\\\\]+$/', $value ) ) {
3283 3357 return new WP_Error(
3284 3358 'invalid_time_format',
3285 3359 __( 'Invalid time format. Use valid PHP time format characters like g:i a or H:i.', 'mainwp' ),
3360 + array( 'status' => 400 )
3286 3361 );
3287 3362 }
3288 3363
3289 3364 // Check rendering works.
@@ -3291,8 +3366,9 @@
3291 3366 if ( false === $time || '' === $time ) {
3292 3367 return new WP_Error(
3293 3368 'invalid_time_format_render',
3294 3369 __( 'Invalid or unsupported time format.', 'mainwp' ),
3370 + array( 'status' => 400 )
3295 3371 );
3296 3372 }
3297 3373
3298 3374 return true;
@@ -3330,8 +3406,9 @@
3330 3406 } catch ( Exception $e ) {
3331 3407 return new WP_Error(
3332 3408 'invalid_timezone_string',
3333 3409 __( 'Invalid timezone. Use a valid format like "UTC+0" or its equivalent name, e.g. "Europe/London".', 'mainwp' ),
3410 + array( 'status' => 400 )
3334 3411 );
3335 3412 }
3336 3413
3337 3414 // Convert to UTC offset.
@@ -3346,8 +3423,9 @@
3346 3423
3347 3424 return new WP_Error(
3348 3425 'invalid_timezone_string',
3349 3426 __( 'Invalid timezone. Use a valid format like "UTC+0" or its equivalent name, e.g. "Europe/London".', 'mainwp' ),
3427 + array( 'status' => 400 )
3350 3428 );
3351 3429 }
3352 3430
3353 3431 /**
@@ -3380,8 +3458,9 @@
3380 3458
3381 3459 return new WP_Error(
3382 3460 'invalid_timezone_string',
3383 3461 __( 'Invalid timezone. Use a valid format like UTC+0 or its equivalent name, e.g. "Europe/London".', 'mainwp' ),
3462 + array( 'status' => 400 )
3384 3463 );
3385 3464 }
3386 3465
3387 3466 /**
@@ -3394,13 +3473,14 @@
3394 3473 public function sanitize_mainwp_widgets( $value ) { // phpcs:ignore -- NOSONAR - complex.
3395 3474 if ( ! is_array( $value ) ) {
3396 3475 return new WP_Error(
3397 3476 'invalid_mainwp_widgets_type',
3398 - __( 'mainwp_widgets must be an object.', 'mainwp' )
3477 + __( 'mainwp_widgets must be an object.', 'mainwp' ),
3478 + array( 'status' => 400 )
3399 3479 );
3400 3480 }
3401 3481
3402 - $existing = get_user_option( 'mainwp_settings_show_widgets', array() );
3482 + $existing = get_user_option( 'mainwp_settings_show_widgets' );
3403 3483 if ( ! is_array( $existing ) ) {
3404 3484 $existing = array();
3405 3485 }
3406 3486
@@ -3432,8 +3512,9 @@
3432 3512 if ( ! is_array( $value ) ) {
3433 3513 return new WP_Error(
3434 3514 'invalid_mainwp_widgets_type',
3435 3515 __( 'mainwp_widgets must be an object.', 'mainwp' ),
3516 + array( 'status' => 400 )
3436 3517 );
3437 3518 }
3438 3519
3439 3520 // Sanitize field data.
@@ -3438,9 +3519,9 @@
3438 3519
3439 3520 // Sanitize field data.
3440 3521 $values = array_map( 'sanitize_text_field', wp_unslash( $value ) );
3441 3522
3442 - $widgets = get_user_option( 'mainwp_settings_show_widgets', array() );
3523 + $widgets = get_user_option( 'mainwp_settings_show_widgets' );
3443 3524 $allowed = array_keys( $widgets );
3444 3525 $keys = array_keys( $values );
3445 3526
3446 3527 $invalid_keys = array_values( array_diff( $keys, $allowed ) );
@@ -3453,8 +3534,9 @@
3453 3534 __( 'Invalid widget keys: %1$s. Allowed keys: %2$s.', 'mainwp' ),
3454 3535 esc_html( implode( ', ', $invalid_keys ) ),
3455 3536 esc_html( implode( ', ', $allowed ) )
3456 3537 ),
3538 + array( 'status' => 400 )
3457 3539 );
3458 3540 }
3459 3541
3460 3542 foreach ( $values as $k => $v ) {
@@ -3461,8 +3543,9 @@
3461 3543 if ( is_array( $v ) || is_object( $v ) ) {
3462 3544 return new WP_Error(
3463 3545 'invalid_mainwp_widgets_value_type',
3464 3546 /* translators: %s: Widget key name */ sprintf( __( 'Value for "%s" must be 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3547 + array( 'status' => 400 )
3465 3548 );
3466 3549 }
3467 3550 $int = (int) $v;
3468 3551 if ( 0 !== $int && 1 !== $int ) {
@@ -3468,8 +3551,9 @@
3468 3551 if ( 0 !== $int && 1 !== $int ) {
3469 3552 return new WP_Error(
3470 3553 'invalid_mainwp_widgets_value',
3471 3554 /* translators: %s: Widget key name */ sprintf( __( 'Invalid value for "%s". Allowed: 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3555 + array( 'status' => 400 )
3472 3556 );
3473 3557 }
3474 3558 }
3475 3559
@@ -3490,9 +3574,10 @@
3490 3574
3491 3575 if ( ! is_array( $value ) ) {
3492 3576 return new WP_Error(
3493 3577 'invalid_status_codes_type',
3494 - __( 'Status codes must be an array.', 'mainwp' )
3578 + __( 'Status codes must be an array.', 'mainwp' ),
3579 + array( 'status' => 400 )
3495 3580 );
3496 3581 }
3497 3582
3498 3583 // Parse ID list to ensure all values are integers.
@@ -3560,9 +3645,10 @@
3560 3645 public function sanitize_sync_data( $value ) { // phpcs:ignore -- NOSONAR - complex.
3561 3646 if ( ! is_array( $value ) ) {
3562 3647 return new WP_Error(
3563 3648 'invalid_sync_data_type',
3564 - __( 'Sync data must be an object.', 'mainwp' )
3649 + __( 'Sync data must be an object.', 'mainwp' ),
3650 + array( 'status' => 400 )
3565 3651 );
3566 3652 }
3567 3653
3568 3654 $values = array_map( 'sanitize_text_field', wp_unslash( $value ) );
@@ -3597,9 +3683,10 @@
3597 3683
3598 3684 if ( ! is_array( $value ) ) {
3599 3685 return new WP_Error(
3600 3686 'invalid_sync_data_type',
3601 - __( 'Sync data must be an object.', 'mainwp' )
3687 + __( 'Sync data must be an object.', 'mainwp' ),
3688 + array( 'status' => 400 )
3602 3689 );
3603 3690 }
3604 3691 // Sanitize field data.
3605 3692 $values = array_map( 'sanitize_text_field', wp_unslash( $value ) );
@@ -3618,8 +3705,9 @@
3618 3705 __( 'Invalid sync data keys: %1$s. Allowed keys: %2$s.', 'mainwp' ),
3619 3706 esc_html( implode( ', ', $invalid_keys ) ),
3620 3707 esc_html( implode( ', ', $allowed ) )
3621 3708 ),
3709 + array( 'status' => 400 )
3622 3710 );
3623 3711 }
3624 3712
3625 3713 foreach ( $values as $k => $v ) {
@@ -3626,8 +3714,9 @@
3626 3714 if ( is_array( $v ) || is_object( $v ) ) {
3627 3715 return new WP_Error(
3628 3716 'invalid_sync_data_type',
3629 3717 /* translators: %s: Sync data key name */ sprintf( __( 'Value for "%s" must be 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3718 + array( 'status' => 400 )
3630 3719 );
3631 3720 }
3632 3721 $int = (int) $v;
3633 3722 if ( 0 !== $int && 1 !== $int ) {
@@ -3633,8 +3722,9 @@
3633 3722 if ( 0 !== $int && 1 !== $int ) {
3634 3723 return new WP_Error(
3635 3724 'invalid_sync_data_type',
3636 3725 /* translators: %s: Sync data key name */ sprintf( __( 'Invalid value for "%s". Allowed: 0 or 1.', 'mainwp' ), esc_html( $k ) ),
3726 + array( 'status' => 400 )
3637 3727 );
3638 3728 }
3639 3729 }
3640 3730
@@ -3657,8 +3747,9 @@
3657 3747 if ( ! preg_match( '/^(?:[01]?\d|2[0-3]):[0-5]\d$/', $value ) ) {
3658 3748 return new WP_Error(
3659 3749 'invalid_time_update',
3660 3750 __( 'Invalid time. Use whole hours in 24h format like 0:00, 9:00, 23:00, etc...', 'mainwp' ),
3751 + array( 'status' => 400 )
3661 3752 );
3662 3753 }
3663 3754
3664 3755 return $value;
@@ -3684,8 +3775,9 @@
3684 3775
3685 3776 return new WP_Error(
3686 3777 'invalid_time_update',
3687 3778 __( 'Invalid time. Use whole hours in 24h format like 0:00, 9:00, 23:00, etc...', 'mainwp' ),
3779 + array( 'status' => 400 )
3688 3780 );
3689 3781 }
3690 3782
3691 3783 /**
@@ -3717,15 +3809,17 @@
3717 3809 if ( 'module-api-backups' === $primary_backup_value && ( null !== $backup_feature && '0' !== (string) $backup_feature && 0 !== (int) $backup_feature ) ) {
3718 3810 // When primary backup is module-api-backups, legacy feature must be 0.
3719 3811 return new WP_Error(
3720 3812 'invalid_backup_config',
3721 - __( '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 )
3722 3815 );
3723 3816 } elseif ( '' === $primary_backup_value && ( null !== $backup_feature && '1' !== (string) $backup_feature && 1 !== (int) $backup_feature ) ) {
3724 3817 // When primary backup is not module-api-backups, legacy feature must be 1.
3725 3818 return new WP_Error(
3726 3819 'invalid_backup_config',
3727 - __( '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 )
3728 3822 );
3729 3823 }
3730 3824 }
3731 3825
@@ -3763,8 +3857,9 @@
3763 3857 // Return error.
3764 3858 return new WP_Error(
3765 3859 'empty_body',
3766 3860 __( 'Request body is empty.', 'mainwp' ),
3861 + array( 'status' => 400 )
3767 3862 );
3768 3863 }
3769 3864
3770 3865 /**
@@ -3778,8 +3873,9 @@
3778 3873 if ( 'application/json' !== $content_type ) {
3779 3874 return new WP_Error(
3780 3875 'invalid_content_type',
3781 3876 __( 'Invalid content type. Expected application/json.', 'mainwp' ),
3877 + array( 'status' => 400 )
3782 3878 );
3783 3879 }
3784 3880 return true;
3785 3881 }
@@ -3813,9 +3909,10 @@
3813 3909 $websites = MainWP_DB::instance()->get_sites();
3814 3910 if ( empty( $websites ) ) {
3815 3911 return new WP_Error(
3816 3912 'no_website_found',
3817 - __( 'No website found.', 'mainwp' )
3913 + __( 'No website found.', 'mainwp' ),
3914 + array( 'status' => 404 )
3818 3915 );
3819 3916 }
3820 3917 return $websites;
3821 3918 }
@@ -3856,8 +3953,9 @@
3856 3953 if ( empty( $user_id ) ) {
3857 3954 return new WP_Error(
3858 3955 'invalid_user',
3859 3956 __( 'User not authenticated.', 'mainwp' ),
3957 + array( 'status' => 401 )
3860 3958 );
3861 3959 }
3862 3960 return $user_id;
3863 3961 }
@@ -3909,9 +4007,9 @@
3909 4007 MainWP_Utility::update_option( $option_name, $val );
3910 4008 return true;
3911 4009 }
3912 4010 // translators: %s: Missing key.
3913 - 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 ) );
3914 4012 }
3915 4013
3916 4014 /**
3917 4015 * Format date.
@@ -3967,9 +4065,10 @@
3967 4065 'options' => array(
3968 4066 'account_email' => 'mainwp_cloudways_api_account_email',
3969 4067 ),
3970 4068 'secrets' => array(
3971 - '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' ),
3972 4071 ),
3973 4072 ),
3974 4073 'gridpane' => array(
3975 4074 'label' => 'GridPane',
@@ -4057,10 +4156,14 @@
4057 4156 */
4058 4157 protected function get_general_settings_data() {
4059 4158 // Default Setting.
4060 4159 $default_setting = MainWP_Settings_Indicator::get_defaults_value();
4061 - $show_widgets = get_user_option( 'mainwp_settings_show_widgets', array() );
4160 + $show_widgets = get_user_option( 'mainwp_settings_show_widgets' );
4062 4161
4162 + if ( ! is_array( $show_widgets ) ) {
4163 + $show_widgets = array();
4164 + }
4165 +
4063 4166 // Map settings.
4064 4167 $gmt_offset = (float) get_option( 'gmt_offset', 0 );
4065 4168 $tz_sign = $gmt_offset >= 0 ? '+' : '-';
4066 4169 $tz_value = (string) abs( $gmt_offset );
@@ -4093,8 +4196,15 @@
4093 4196 );
4094 4197 }
4095 4198
4096 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 +
4097 4207 return array(
4098 4208 // General settings.
4099 4209 'time_daily_update' => get_option( 'mainwp_timeDailyUpdate', $default_setting['mainwp_timeDailyUpdate'] ),
4100 4210 'frequency_daily_update' => (int) get_option( 'mainwp_frequencyDailyUpdate', $default_setting['mainwp_frequencyDailyUpdate'] ),
@@ -4100,9 +4210,9 @@
4100 4210 'frequency_daily_update' => (int) get_option( 'mainwp_frequencyDailyUpdate', $default_setting['mainwp_frequencyDailyUpdate'] ),
4101 4211 'date_format' => get_option( 'date_format', $default_setting['date_format'] ),
4102 4212 'time_format' => get_option( 'time_format', $default_setting['time_format'] ),
4103 4213 'timezone_string' => $tz_string,
4104 - 'sidebar_position' => get_user_option( ' mainwp_sidebarPosition', $default_setting['sidebar_position'] ),
4214 + 'sidebar_position' => (int) $sidebar_position,
4105 4215 'hide_update_everything' => get_option( 'mainwp_hide_update_everything', $default_setting['mainwp_hide_update_everything'] ),
4106 4216 'mainwp_widgets' => $show_widgets,
4107 4217 'plugin_automatic_daily_update' => (int) get_option( 'mainwp_pluginAutomaticDailyUpdate', $default_setting['mainwp_pluginAutomaticDailyUpdate'] ),
4108 4218 'theme_automatic_daily_update' => (int) get_option( 'mainwp_themeAutomaticDailyUpdate', $default_setting['mainwp_themeAutomaticDailyUpdate'] ),
@@ -4181,16 +4291,16 @@
4181 4291 protected function get_monitoring_settings_data() {
4182 4292 $monitoring_settings = MainWP_Uptime_Monitoring_Handle::get_global_monitoring_settings();
4183 4293
4184 4294 // Get interval values.
4185 - $interval_values = MainWP_Uptime_Monitoring_Edit::get_interval_values( false );
4186 - $interval = $monitoring_settings['interval'] ?? 60;
4187 - $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];
4188 4298
4189 4299 // Get timeout values.
4190 - $timeout_values = MainWP_Uptime_Monitoring_Edit::get_timeout_values( false );
4191 - $timeout = $monitoring_settings['timeout'] ?? 60;
4192 - $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];
4193 4303
4194 4304 return array(
4195 4305 'mainwp_uptime_monitoring_active' => (int) $monitoring_settings['active'] ?? 0,
4196 4306 'mainwp_uptime_monitoring_interval' => $interval,
@@ -4199,8 +4309,9 @@
4199 4309 'mainwp_uptime_monitoring_type' => $monitoring_settings['type'] ?? 'http',
4200 4310 'mainwp_uptime_monitoring_up_status_codes' => explode( ',', $monitoring_settings['up_status_codes'] ) ?? array(),
4201 4311 'mainwp_uptime_monitoring_down_confirmation_check' => (int) $monitoring_settings['maxretries'] ?? 1,
4202 4312 'mainwp_uptime_monitoring_keyword' => $monitoring_settings['keyword'] ?? '',
4313 + 'mainwp_uptime_monitoring_bypass_cache' => (int) ( $monitoring_settings['bypass_cache'] ?? 0 ),
4203 4314 'mainwp_disable_sites_health_monitoring' => (int) get_option( 'mainwp_disableSitesHealthMonitoring', 1 ),
4204 4315 'mainwp_sitehealth_threshold' => (int) get_option( 'mainwp_sitehealthThreshold', 80 ),
4205 4316 );
4206 4317 }
@@ -4537,9 +4648,9 @@
4537 4648 'description' => __( 'Uptime monitoring active.', 'mainwp' ),
4538 4649 'context' => array( 'monitoring_view' ),
4539 4650 ),
4540 4651 'mainwp_uptime_monitoring_interval' => array(
4541 - 'type' => 'integer',
4652 + 'type' => 'string',
4542 4653 'description' => __( 'Uptime monitoring interval.', 'mainwp' ),
4543 4654 'context' => array( 'monitoring_view' ),
4544 4655 ),
4545 4656 'mainwp_uptime_monitoring_method' => array(
@@ -4547,9 +4658,9 @@
4547 4658 'description' => __( 'Uptime monitoring method.', 'mainwp' ),
4548 4659 'context' => array( 'monitoring_view' ),
4549 4660 ),
4550 4661 'mainwp_uptime_monitoring_timeout' => array(
4551 - 'type' => 'integer',
4662 + 'type' => 'string',
4552 4663 'description' => __( 'Uptime monitoring timeout.', 'mainwp' ),
4553 4664 'context' => array( 'monitoring_view' ),
4554 4665 ),
4555 4666 'mainwp_uptime_monitoring_type' => array(
@@ -4569,8 +4680,13 @@
4569 4680 ),
4570 4681 'mainwp_uptime_monitoring_keyword' => array(
4571 4682 'type' => 'string',
4572 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' ),
4573 4689 'context' => array( 'monitoring_view' ),
4574 4690 ),
4575 4691 'mainwp_primary_backup' => array(
4576 4692 'type' => 'object',