Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more PHP 8.1 compatibility issues #1494

Merged
merged 19 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alerts/class-alert-type-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function alert( $record_id, $recordarr, $alert ) {
$user = get_user_by( 'id', $user_id );

// translators: Placeholder refers to a username (e.g. "administrator").
$message .= sprintf( __( "User:\t%s", 'stream' ), $user->user_login ) . "\n";
$message .= sprintf( __( "User:\t%s", 'stream' ), ! empty( $user->user_login ) ? $user->user_login : __( 'unknown', 'stream' ) ) . "\n";

if ( ! empty( $alert->alert_meta['trigger_context'] ) ) {
$context = $this->plugin->alerts->alert_triggers['context']->get_display_value( 'list_table', $alert );
Expand Down
30 changes: 17 additions & 13 deletions alerts/class-alert-type-ifttt.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,24 @@ public function notify_ifttt( $alert, $recordarr ) {
)
);

$user_id = $recordarr['user_id'];
$user = get_user_by( 'id', $user_id );
$user_id = ! empty( $recordarr['user_id'] ) ? $recordarr['user_id'] : 0;
$user = get_user_by( 'id', $user_id );
$user_value = '';

/**
* Filter User data field
*
* Defaults to 'user_login'.
*
* @param object $alert The Alert.
* @param array $recordarray The Record's data.
* @return string
*/
$user_field = apply_filters( 'wp_stream_alert_ifttt_user_data_value', 'user_login', $alert, $recordarr );
$user_value = ! empty( $user->$user_field ) ? $user->$user_field : $user->user_login;
if ( $user instanceof \WP_User ) {
/**
* Filter User data field.
*
* Defaults to 'user_login'.
*
* @param object $alert The Alert object.
* @param array $recordarr Array of Record data.
*
* @return string
*/
$user_field = apply_filters( 'wp_stream_alert_ifttt_user_data_value', 'user_login', $alert, $recordarr );
$user_value = ! empty( $user->$user_field ) ? $user->$user_field : $user->user_login;
}

$created = $recordarr['created'];
/**
Expand Down
88 changes: 47 additions & 41 deletions classes/class-date-interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

namespace WP_Stream;

// Load Carbon to Handle dates much easier.
if ( ! class_exists( 'Carbon\Carbon' ) ) {
require_once wp_stream_get_instance()->locations['inc_dir'] . 'lib/Carbon.php';
}
use Carbon\Carbon;
bartoszgadomski marked this conversation as resolved.
Show resolved Hide resolved

/**
* Class - Date_Interval
*/
Expand Down Expand Up @@ -43,86 +37,98 @@ public function get_predefined_intervals() {

if ( empty( $timezone ) ) {
$gmt_offset = (int) get_option( 'gmt_offset' );
$timezone = timezone_name_from_abbr( null, $gmt_offset * 3600, true );
if ( false === $timezone ) {
$timezone = timezone_name_from_abbr( null, $gmt_offset * 3600, false );
}
$timezone = timezone_name_from_abbr( '', $gmt_offset * 3600, true );
if ( false === $timezone ) {
$timezone = null;
$timezone = timezone_name_from_abbr( '', $gmt_offset * 3600, false );
}
}

return apply_filters(
'wp_stream_predefined_date_intervals',
array(
try {
$timezone_object = $timezone ? new \DateTimeZone( $timezone ) : null;
} catch ( \Exception $e ) {
$timezone_object = null;
}

try {
$today = new \DateTimeImmutable( 'today', $timezone_object );
$date_intervals = array(
tharsheblows marked this conversation as resolved.
Show resolved Hide resolved
'today' => array(
'label' => esc_html__( 'Today', 'stream' ),
'start' => Carbon::today( $timezone )->startOfDay(),
'end' => Carbon::today( $timezone )->endOfDay(),
'start' => $today,
'end' => $today->modify( '+1 day -1 microsecond' ),
),
'yesterday' => array(
'label' => esc_html__( 'Yesterday', 'stream' ),
'start' => Carbon::today( $timezone )->startOfDay()->subDay(),
'end' => Carbon::today( $timezone )->startOfDay()->subSecond(),
'start' => $today->modify( '-1 day' ),
'end' => $today->modify( '-1 microsecond' ),
),
'last-7-days' => array(
/* translators: %d: number of days (e.g. "7") */
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 7 ),
'start' => Carbon::today( $timezone )->subDays( 7 ),
'end' => Carbon::today( $timezone ),
'start' => $today->modify( '-7 days' ),
'end' => $today,
),
'last-14-days' => array(
/* translators: %d: number of days (e.g. "7") */
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 14 ),
'start' => Carbon::today( $timezone )->subDays( 14 ),
'end' => Carbon::today( $timezone ),
'start' => $today->modify( '-14 days' ),
'end' => $today,
),
'last-30-days' => array(
/* translators: %d: number of days (e.g. "7") */
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 30 ),
'start' => Carbon::today( $timezone )->subDays( 30 ),
'end' => Carbon::today( $timezone ),
'start' => $today->modify( '-30 days' ),
'end' => $today,
),
'this-month' => array(
'label' => esc_html__( 'This Month', 'stream' ),
'start' => Carbon::today( $timezone )->startOfMonth(),
'end' => Carbon::today( $timezone )->endOfMonth(),
'start' => $today->modify( 'first day of this month' ),
'end' => $today->modify( 'last day of this month' )->modify( '+1 day -1 microsecond' ),
),
'last-month' => array(
'label' => esc_html__( 'Last Month', 'stream' ),
'start' => Carbon::today( $timezone )->startOfMonth()->subMonth(),
'end' => Carbon::today( $timezone )->startOfMonth()->subSecond(),
'start' => $today->modify( 'first day of last month' ),
'end' => $today->modify( 'last day of last month' )->modify( '+1 day -1 microsecond' ),
),
'last-3-months' => array(
/* translators: %d: number of months (e.g. "3") */
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 3 ),
'start' => Carbon::today( $timezone )->subMonths( 3 ),
'end' => Carbon::today( $timezone ),
'start' => $today->modify( '-3 months' ),
'end' => $today,
),
'last-6-months' => array(
/* translators: %d: number of months (e.g. "3") */
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 6 ),
'start' => Carbon::today( $timezone )->subMonths( 6 ),
'end' => Carbon::today( $timezone ),
'start' => $today->modify( '-6 months' ),
'end' => $today,
),
'last-12-months' => array(
/* translators: %d: number of months (e.g. "3") */
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 12 ),
'start' => Carbon::today( $timezone )->subMonths( 12 ),
'end' => Carbon::today( $timezone ),
'start' => $today->modify( '-12 months' ),
'end' => $today,
),
'this-year' => array(
'label' => esc_html__( 'This Year', 'stream' ),
'start' => Carbon::today( $timezone )->startOfYear(),
'end' => Carbon::today( $timezone )->endOfYear(),
'start' => $today->modify( 'first day of January' ),
'end' => $today->modify( 'last day of December' )->modify( '+1 day -1 microsecond' ),
),
'last-year' => array(
'label' => esc_html__( 'Last Year', 'stream' ),
'start' => Carbon::today( $timezone )->startOfYear()->subYear(),
'end' => Carbon::today( $timezone )->startOfYear()->subSecond(),
'start' => $today->modify( 'first day of January' )->modify( '-1 year' ),
'end' => $today->modify( 'first day of January' )->modify( '-1 microsecond' ),
),
),
$timezone
);
);
} catch ( \Exception $e ) {
$date_intervals = array();
}

/**
* Allow other plugins to filter the predefined date intervals.
*
* @param array $date_intervals Date intervals array.
* @param string $timezone Timezone.
*/
return apply_filters( 'wp_stream_predefined_date_intervals', $date_intervals, $timezone );
delawski marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"automattic/vipwpcs": "^2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
"humanmade/mercator": "^1.0",
"johnbillion/query-monitor": "^3.16",
"johnpbloch/wordpress": "^6.3",
"php-coveralls/php-coveralls": "^2.5",
"phpcompatibility/php-compatibility": "dev-develop as 9.99.99",
Expand Down
73 changes: 72 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connectors/class-connector-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public function check_meta_values( $type, $action, $meta_id, $object_id, $key, $
/* translators: %1$s: a field label, %2$s: an object title, %3$s: an object type (e.g. "Message", "Hello World", "post") */
esc_html_x( '"%1$s" of "%2$s" %3$s updated', 'acf', 'stream' ),
array(
'field_label' => $cache['field']['label'],
'field_label' => ! empty( $cache['field']['label'] ) ? $cache['field']['label'] : __( 'unknown', 'stream' ),
'title' => $title,
'singular_name' => $type_name,
'meta_value' => $value,
Expand Down
19 changes: 10 additions & 9 deletions connectors/class-connector-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,17 @@ public function callback_jetpack_log_entry( array $entry ) {
$user_id = get_current_user_id();
}

$user = new \WP_User( $user_id );
$user_email = $user->user_email;
$user_login = $user->user_login;
$context = 'users';
$action = $method;
$meta = compact( 'user_id', 'user_email', 'user_login' );
$message = sprintf(
/* translators: %1$s: a user display name, %2$s: a status and the connection either "from" or "to" (e.g. "Jane Doe", "unlinked from") */
$user = new \WP_User( $user_id );
$user_email = ! empty( $user->user_email ) ? $user->user_email : '';
$user_login = ! empty( $user->user_login ) ? $user->user_login : '';
$user_display_name = ! empty( $user->display_name ) ? $user->display_name : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓question
Could a user without a display name be something involving the $user_id here? Like 'Unknown user, user_id: 21'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I follow. Can you elaborate on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delawski If there's no user, like the user has been deleted, then it'd be nice to have the display name be shown as something like "Unknown user {$user_id}"? I think we did this somewhere else too, it's the same sort of thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I get it, thank you for explaining :) I've addressed it in 080e85f.

$context = 'users';
$action = $method;
$meta = compact( 'user_id', 'user_email', 'user_login' );
$message = sprintf(
/* translators: %1$s: a user display name, %2$s: a status and the connection either "from" or "to" (e.g. "Jane Doe", "unlinked from") */
__( '%1$s\'s account %2$s Jetpack', 'stream' ),
$user->display_name,
$user_display_name,
( 'unlink' === $action ) ? esc_html__( 'unlinked from', 'stream' ) : esc_html__( 'linked to', 'stream' )
);
} elseif ( in_array( $method, array( 'register', 'disconnect', 'subsiteregister', 'subsitedisconnect' ), true ) ) {
Expand Down
Loading
Loading