Skip to content

Commit 0dc7e04

Browse files
kraftbjanomiex
andauthored
Various: Fix PHP 8.1 warnings/errors (#35551)
* Fix various PHP 8.1 warnings/errors --------- Co-authored-by: Brad Jorsch <[email protected]>
1 parent 562a99f commit 0dc7e04

11 files changed

+34
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Fixed various PHP warnings in PHP 8.1+

projects/packages/videopress/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@automattic/jetpack-videopress",
4-
"version": "0.23.0",
4+
"version": "0.23.1-alpha",
55
"description": "VideoPress package",
66
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/videopress/#readme",
77
"bugs": {

projects/packages/videopress/src/class-package-version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* The Package_Version class.
1212
*/
1313
class Package_Version {
14-
const PACKAGE_VERSION = '0.23.0';
14+
const PACKAGE_VERSION = '0.23.1-alpha';
1515

1616
const PACKAGE_SLUG = 'videopress';
1717

projects/packages/videopress/src/class-wpcom-rest-api-v2-attachment-field-videopress.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function get( $attachment, $request ) { // phpcs:ignore VariableAnalysis.
125125
* @return string
126126
*/
127127
public function get_videopress_guid( $attachment_id, $blog_id ) {
128-
return video_get_info_by_blogpostid( $blog_id, $attachment_id )->guid;
128+
return video_get_info_by_blogpostid( $blog_id, $attachment_id )->guid ?? '';
129129
}
130130

131131
/**

projects/packages/videopress/src/class-wpcom-rest-api-v2-attachment-videopress-data.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function get( $attachment, $request ) { // phpcs:ignore VariableAnalysis.
202202
* @param int $attachment_id Attachment ID.
203203
* @param int $blog_id Blog ID.
204204
*
205-
* @return string
205+
* @return array
206206
*/
207207
public function get_videopress_data( $attachment_id, $blog_id ) {
208208
$info = video_get_info_by_blogpostid( $blog_id, $attachment_id );
@@ -233,8 +233,8 @@ public function get_videopress_data( $attachment_id, $blog_id ) {
233233
'title' => $title,
234234
'description' => $description,
235235
'caption' => $caption,
236-
'guid' => $info->guid,
237-
'rating' => $info->rating,
236+
'guid' => $info->guid ?? null,
237+
'rating' => $info->rating ?? null,
238238
'allow_download' =>
239239
isset( $info->allow_download ) && $info->allow_download ? 1 : 0,
240240
'display_embed' =>

projects/plugins/jetpack/_inc/lib/class.media-summary.php

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ public static function get( $post_id, $blog_id = 0, $args = array() ) {
146146
break;
147147
case 'youtube':
148148
if ( 0 === $return['count']['video'] ) {
149+
if ( ! isset( $extract['shortcode']['youtube']['id'][0] ) ) {
150+
break;
151+
}
149152
$return['type'] = 'video';
150153
$return['video'] = esc_url_raw( 'http://www.youtube.com/watch?feature=player_embedded&v=' . $extract['shortcode']['youtube']['id'][0] );
151154
$return['image'] = self::get_video_poster( 'youtube', $extract['shortcode']['youtube']['id'][0] );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
Fixed various PHP warnings for PHP 8.1+

projects/plugins/jetpack/class.json-api-endpoints.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1297,18 +1297,18 @@ public function user_can_view_post( $post_id ) {
12971297

12981298
if ( 'inherit' === $post->post_status ) {
12991299
$parent_post = get_post( $post->post_parent );
1300-
$post_status_obj = get_post_status_object( $parent_post->post_status );
1300+
$post_status_obj = get_post_status_object( $parent_post->post_status ?? $post->post_status );
13011301
} else {
13021302
$post_status_obj = get_post_status_object( $post->post_status );
13031303
}
13041304

1305-
if ( ! $post_status_obj->public ) {
1305+
if ( empty( $post_status_obj->public ) ) {
13061306
if ( is_user_logged_in() ) {
1307-
if ( $post_status_obj->protected ) {
1307+
if ( ! empty( $post_status_obj->protected ) ) {
13081308
if ( ! current_user_can( 'edit_post', $post->ID ) ) {
13091309
return new WP_Error( 'unauthorized', 'User cannot view post', 403 );
13101310
}
1311-
} elseif ( $post_status_obj->private ) {
1311+
} elseif ( ! empty( $post_status_obj->private ) ) {
13121312
if ( ! current_user_can( 'read_post', $post->ID ) ) {
13131313
return new WP_Error( 'unauthorized', 'User cannot view post', 403 );
13141314
}

projects/plugins/jetpack/class.json-api.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function setup_inputs( $method = null, $url = null, $post_body = null ) {
313313
$this->content_type = filter_var( wp_unslash( $_SERVER['HTTP_CONTENT_TYPE'] ) );
314314
} elseif ( ! empty( $_SERVER['CONTENT_TYPE'] ) ) {
315315
$this->content_type = filter_var( wp_unslash( $_SERVER['CONTENT_TYPE'] ) );
316-
} elseif ( '{' === $this->post_body[0] ) {
316+
} elseif ( isset( $this->post_body[0] ) && '{' === $this->post_body[0] ) {
317317
$this->content_type = 'application/json';
318318
} else {
319319
$this->content_type = 'application/x-www-form-urlencoded';
@@ -424,9 +424,10 @@ public function serve( $exit = true ) {
424424

425425
// Normalize path and extract API version.
426426
$this->path = untrailingslashit( $this->path );
427-
preg_match( '#^/rest/v(\d+(\.\d+)*)#', $this->path, $matches );
428-
$this->path = substr( $this->path, strlen( $matches[0] ) );
429-
$this->version = $matches[1];
427+
if ( preg_match( '#^/rest/v(\d+(\.\d+)*)#', $this->path, $matches ) ) {
428+
$this->path = substr( $this->path, strlen( $matches[0] ) );
429+
$this->version = $matches[1];
430+
}
430431

431432
$allowed_methods = array( 'GET', 'POST' );
432433
$four_oh_five = false;
@@ -741,7 +742,7 @@ public static function serializable_error( $error ) {
741742

742743
$status_code = $error->get_error_data();
743744

744-
if ( is_array( $status_code ) ) {
745+
if ( is_array( $status_code ) && isset( $status_code['status_code'] ) ) {
745746
$status_code = $status_code['status_code'];
746747
}
747748

projects/plugins/jetpack/modules/masterbar/admin-menu/class-wpcom-admin-menu.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ public function get_upsell_nudge() {
245245
'content' => $message->content['message'],
246246
'cta' => $message->CTA['message'], // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
247247
'link' => $message->CTA['link'], // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
248-
'tracks_impression_event_name' => $message->tracks['display']['name'],
249-
'tracks_impression_cta_name' => $message->tracks['display']['props']['cta_name'],
250-
'tracks_click_event_name' => $message->tracks['click']['name'],
251-
'tracks_click_cta_name' => $message->tracks['click']['props']['cta_name'],
248+
'tracks_impression_event_name' => $message->tracks['display']['name'] ?? null,
249+
'tracks_impression_cta_name' => $message->tracks['display']['props']['cta_name'] ?? null,
250+
'tracks_click_event_name' => $message->tracks['click']['name'] ?? null,
251+
'tracks_click_cta_name' => $message->tracks['click']['props']['cta_name'] ?? null,
252252
'dismissible' => $message->is_dismissible,
253253
'feature_class' => $message->feature_class,
254254
'id' => $message->id,

projects/plugins/jetpack/sal/class.json-api-token.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,15 @@ public static function for_anonymous_user() {
115115
*/
116116
public static function from_rest_token( $token ) {
117117
$user_id = isset( $token['user_id'] ) ? $token['user_id'] : get_current_user_id();
118-
$scope = isset( $token['scope'] ) ? $token['scope'][0] : null;
118+
$scope = isset( $token['scope'][0] ) ? $token['scope'][0] : null;
119119
$client_id = isset( $token['client_id'] ) ? $token['client_id'] : null;
120120
$external_user_id = isset( $token['external_user_id'] ) ? $token['external_user_id'] : null;
121121
$external_user_code = isset( $token['external_user_code'] ) ? $token['external_user_code'] : null;
122122
$auth = isset( $token['auth'] ) ? $token['auth'] : null;
123+
$blog_id = isset( $token['blog_id'] ) ? $token['blog_id'] : null;
123124

124125
return new SAL_Token(
125-
$token['blog_id'],
126+
$blog_id,
126127
$user_id,
127128
$scope, // there's only ever one scope in our current API implementation, auth or global.
128129
$client_id,

0 commit comments

Comments
 (0)