Skip to content

Commit 147b526

Browse files
committed
FIX: PR feedbacks
1 parent b493e75 commit 147b526

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

.stylelintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"**/*.php",
77
"**/*.svg"
88
],
9-
"rules": {}
9+
"rules": {
10+
"selector-class-pattern": null
11+
}
1012
}

inc/Modules/MediaSharing/MediaActions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function remove_sync_meta( int $attachment_id ): void {
136136
}
137137

138138
// Make POST request to delete attachment on brand sites.
139-
$response = wp_remote_post(
139+
$response = wp_safe_remote_post(
140140
$site_url . '/wp-json/' . Abstract_REST_Controller::NAMESPACE . '/delete-media-metadata',
141141
[
142142
'body' => wp_json_encode(
@@ -350,7 +350,7 @@ public function update_sync_attachments( int $attachment_id ): void {
350350
$attachment_data['terms'] = $attachment_terms;
351351

352352
// Make POST request to update existing attachment on brand sites.
353-
wp_remote_post(
353+
wp_safe_remote_post(
354354
$site_url . $post_request_suffix,
355355
[
356356
'body' => [

inc/Modules/Rest/Media_Sharing_Controller.php

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ public function sync_media_files( \WP_REST_Request $request ): \WP_Error|\WP_RES
746746

747747
// Share the attachment metadata with the brand sites.
748748
// Get attachment metadata.
749-
$attachment_data = wp_get_attachment_metadata( $media['id'] );
749+
$attachment_data = wp_get_attachment_metadata( $media['id'] ?? 0 );
750750

751751
// Get attachment title, alt text, caption and description.
752752
$attachment_data['post_title'] = $media['title'];
@@ -767,6 +767,9 @@ public function sync_media_files( \WP_REST_Request $request ): \WP_Error|\WP_RES
767767
// Get all registered brand sites to compare endpoint and get API token before sharing media.
768768
$all_brand_sites = Settings::get_shared_sites();
769769

770+
// Success response.
771+
$success_response = [];
772+
770773
foreach ( $brand_sites as $site ) {
771774
$site_url = $site;
772775

@@ -776,15 +779,13 @@ public function sync_media_files( \WP_REST_Request $request ): \WP_Error|\WP_RES
776779

777780
if ( empty( $site_url ) ) {
778781
$failed_sites[] = [
779-
'site' => $site,
780-
'message' => sprintf(
782+
'site' => $site,
783+
'message' => sprintf(
781784
/* translators: %s: site URL */
782785
__( 'Invalid site URL: %s', 'onemedia' ),
783786
$site_url . $brand_site_prefix
784787
),
785-
'site_url' => $site_url . $brand_site_prefix,
786-
'token' => $site_token,
787-
'child_key' => Settings::get_api_key(),
788+
'site_url' => $site_url . $brand_site_prefix,
788789
];
789790
continue;
790791
}
@@ -800,11 +801,8 @@ public function sync_media_files( \WP_REST_Request $request ): \WP_Error|\WP_RES
800801
}
801802
}
802803

803-
// Success response.
804-
$success_response = [];
805-
806804
// Prepare the request to the brand site.
807-
$response = wp_remote_post(
805+
$response = wp_safe_remote_post(
808806
$site_url . $brand_site_prefix,
809807
[
810808
'headers' => [
@@ -838,8 +836,6 @@ public function sync_media_files( \WP_REST_Request $request ): \WP_Error|\WP_RES
838836
'message' => $response_body['message'] ?? __( 'Failed to sync media files.', 'onemedia' ),
839837
'errors' => $errors,
840838
'site_url' => $site_url . $brand_site_prefix,
841-
'token' => $site_token,
842-
'child_key' => Settings::get_api_key(),
843839
'is_mime_type_error' => $is_mime_type_error,
844840
];
845841
}
@@ -911,8 +907,6 @@ public function sync_media_files( \WP_REST_Request $request ): \WP_Error|\WP_RES
911907
'site' => $site,
912908
'message' => __( 'Failed to update synced media.', 'onemedia' ),
913909
'site_url' => $site_url . $brand_site_prefix,
914-
'token' => $site_token,
915-
'child_key' => Settings::get_api_key(),
916910
];
917911
}
918912
}
@@ -1353,8 +1347,6 @@ public function update_existing_attachment( \WP_REST_Request $request ): \WP_Err
13531347
'site' => $site,
13541348
'message' => __( 'Invalid site URL.', 'onemedia' ),
13551349
'site_url' => $site_url . $brand_site_prefix,
1356-
'token' => $site_token,
1357-
'child_key' => Settings::get_api_key(),
13581350
];
13591351
continue;
13601352
}
@@ -1376,8 +1368,6 @@ public function update_existing_attachment( \WP_REST_Request $request ): \WP_Err
13761368
'site' => $site,
13771369
'message' => __( 'Invalid child ID data.', 'onemedia' ),
13781370
'site_url' => $site_url . $brand_site_prefix,
1379-
'token' => $site_token,
1380-
'child_key' => Settings::get_api_key(),
13811371
];
13821372
continue;
13831373
}
@@ -1407,7 +1397,7 @@ public function update_existing_attachment( \WP_REST_Request $request ): \WP_Err
14071397
];
14081398

14091399
// Prepare the request to the brand site.
1410-
$response = wp_remote_post(
1400+
$response = wp_safe_remote_post(
14111401
$site_url . $brand_site_prefix,
14121402
[
14131403
'headers' => [
@@ -1443,8 +1433,6 @@ public function update_existing_attachment( \WP_REST_Request $request ): \WP_Err
14431433
'message' => $response_body['message'] ?? __( 'Failed to sync media files.', 'onemedia' ),
14441434
'errors' => $errors,
14451435
'site_url' => $site_url . $brand_site_prefix,
1446-
'token' => $site_token,
1447-
'child_key' => Settings::get_api_key(),
14481436
'is_mime_type_error' => $is_mime_type_error,
14491437
];
14501438
}
@@ -1498,8 +1486,6 @@ public function update_existing_attachment( \WP_REST_Request $request ): \WP_Err
14981486
'site' => $site,
14991487
'message' => __( 'Failed to update synced media.', 'onemedia' ),
15001488
'site_url' => $site_url . $brand_site_prefix,
1501-
'token' => $site_token,
1502-
'child_key' => Settings::get_api_key(),
15031489
];
15041490
continue;
15051491
}

0 commit comments

Comments
 (0)