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.3 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 All 156 releases
← All changes | includes/rest-api/controller/version2/class-mainwp-rest-sites-controller.php +49 -5 6.2 → 6.2.1 View file →
@@ -2389,9 +2389,9 @@
2389 2389 'arg_options' => array(
2390 2390 'sanitize_callback' => 'sanitize_text_field',
2391 2391 ),
2392 2392 ),
2393 - 'tags' => array( // response as tags.
2393 + 'tags' => array(
2394 2394 'type' => 'string',
2395 2395 'description' => __( 'Site tags.', 'mainwp' ),
2396 2396 'context' => array( 'view' ),
2397 2397 ),
@@ -2682,8 +2682,15 @@
2682 2682 'arg_options' => array(
2683 2683 'sanitize_callback' => 'absint',
2684 2684 ),
2685 2685 ),
2686 + // groupids is validated and sanitized in the database save function
2687 + // before updating the group associations.
2688 + 'groupids' => array(
2689 + 'type' => 'string',
2690 + 'description' => __( 'Site tag/group IDs as a comma-separated string.', 'mainwp' ),
2691 + 'context' => array( 'edit' ),
2692 + ),
2686 2693
2687 2694 ),
2688 2695 );
2689 2696 }
@@ -3294,12 +3301,22 @@
3294 3301 public function create_item( $request ) { //phpcs:ignore -- NOSONAR - complex.
3295 3302 $resp_data = array();
3296 3303 $resp_data['success'] = 0;
3297 3304 $site_id = 0;
3298 - $url = '';
3299 3305 $data = array(); //phpcs:ignore -- NOSONAR - not used data.
3300 3306 $found_id = 0;
3301 3307 try {
3308 +
3309 + if ( $request->has_param( 'groupids' ) && ! empty( $request['groupids'] ) && false === MainWP_DB_Common::instance()->validate_site_group_ids( $request['groupids'] ) ) {
3310 + return new \WP_Error(
3311 + 'rest_invalid_param',
3312 + __( 'The groupids parameter must be a comma-separated string of positive integers.', 'mainwp' ),
3313 + array(
3314 + 'status' => 400,
3315 + )
3316 + );
3317 + }
3318 +
3302 3319 $item = $this->prepare_object_for_database( $request );
3303 3320
3304 3321 if ( empty( $item['name'] ) && ! empty( $item['url'] ) ) {
3305 3322 $item['name'] = MainWP_Utility::remove_http_prefix( $item['url'], true );
@@ -3305,10 +3322,9 @@
3305 3322 $item['name'] = MainWP_Utility::remove_http_prefix( $item['url'], true );
3306 3323 $item['name'] = rtrim( $item['name'], '/' );
3307 3324 }
3308 3325
3309 - $url = $item['url'];
3310 - $website = MainWP_DB::instance()->get_websites_by_url( $item['url'] );
3326 + $website = MainWP_DB::instance()->get_websites_by_url( $item['url'] );
3311 3327 list( $message, $error, $site_id, $found_id ) = MainWP_Manage_Sites_View::add_wp_site( $website, $item );
3312 3328
3313 3329 if ( ! empty( $site_id ) ) {
3314 3330 $site = MainWP_DB::instance()->get_website_by_id( $site_id );
@@ -3345,13 +3361,41 @@
3345 3361 $website = $this->get_request_item( $request );
3346 3362 if ( is_wp_error( $website ) ) {
3347 3363 return $website;
3348 3364 }
3365 +
3366 + if ( $request->has_param( 'tags' ) ) {
3367 + return new \WP_Error(
3368 + 'rest_invalid_param',
3369 + __( 'The "tags" parameter is not supported for this endpoint.', 'mainwp' ),
3370 + array(
3371 + 'status' => 400,
3372 + )
3373 + );
3374 + }
3375 +
3376 + if ( $request->has_param( 'groupids' ) && ! is_string( $request['groupids'] ) ) {
3377 + return new \WP_Error(
3378 + 'rest_invalid_param',
3379 + __( 'The groupids parameter must be a string.', 'mainwp' ),
3380 + array(
3381 + 'status' => 400,
3382 + )
3383 + );
3384 + }
3385 +
3349 3386 $resp_data = array();
3350 3387 $resp_data['success'] = 0;
3351 3388 try {
3352 3389 $item = $this->prepare_object_for_update( $request );
3353 3390 $result = MainWP_DB_Common::instance()->rest_api_update_website( $website->id, $item );
3391 + if ( is_array( $result ) ) {
3392 + foreach ( array( 'group_updated', 'group_message', 'message' ) as $field ) {
3393 + if ( array_key_exists( $field, $result ) ) {
3394 + $resp_data[ $field ] = $result[ $field ];
3395 + }
3396 + }
3397 + }
3354 3398 if ( is_array( $result ) && ! empty( $result['success'] ) ) {
3355 3399 $resp_data['success'] = 1;
3356 3400 $params = array(
3357 3401 'full_data' => true,
@@ -3361,9 +3405,9 @@
3361 3405 );
3362 3406 $websites = MainWP_DB::instance()->get_websites_for_current_user( $params );
3363 3407 $data = $websites ? current( $websites ) : array();
3364 3408 $resp_data['data'] = $this->prepare_site_item_for_response_context( $data, $request, 'view' );
3365 - } else {
3409 + } elseif ( empty( $resp_data['group_message'] ) && empty( $resp_data['message'] ) ) {
3366 3410 $resp_data['error'] = esc_html__( 'Update site failed. Please try again.', 'mainwp' );
3367 3411 }
3368 3412 } catch ( \Exception $e ) {
3369 3413 $resp_data['error'] = $e->getMessage();