-
Notifications
You must be signed in to change notification settings - Fork 135
Description
In unit tests, when we create a post using the WordPress Tests Library factory, but the current user account does not have the rights to see the edit link, the EF_Notifications::notification_status_change callback on transition_post_status throws this deprecation notice:
htmlspecialchars_decode(): Passing null to parameter #1 ($string) of type string is deprecated
This causes the test to fail.
The issue happens when get_edit_post_link returns null in this call:
$edit_link = htmlspecialchars_decode( get_edit_post_link( $post_id ) );In most cases we can get around this by setting an active user with wp_set_current_user before we create the post. But it would be helpful if the callback guarded against the possibility that get_edit_post_link does not return a URL. Suggested patch below.
Index: modules/notifications/notifications.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/modules/notifications/notifications.php b/modules/notifications/notifications.php
--- a/modules/notifications/notifications.php (revision 780790ec5d82cd4cbccd924cde9d63f99b6fae4f)
+++ b/modules/notifications/notifications.php (date 1762942919184)
@@ -666,13 +666,29 @@
/* translators: 1: author name, 2: author email */
$body .= sprintf( __( 'Author: %1$s (%2$s)', 'edit-flow' ), $post_author->display_name, $post_author->user_email ) . "\r\n";
}
-
- $edit_link = htmlspecialchars_decode( get_edit_post_link( $post_id ) );
+
+ $edit_post_link = get_edit_post_link( $post_id );
+ if ( is_null( $edit_post_link ) ) {
+ return;
+ }
+
+ $edit_link = htmlspecialchars_decode( $edit_post_link );
+
if ( $new_status != 'publish' ) {
$view_link = add_query_arg( array( 'preview' => 'true' ), wp_get_shortlink( $post_id ) );
} else {
- $view_link = htmlspecialchars_decode( get_permalink( $post_id ) );
+ $permalink = get_permalink( $post_id );
+ if ( is_null( $permalink ) ) {
+ return;
+ }
+
+ $view_link = htmlspecialchars_decode( $permalink );
}
+
$body .= "\r\n";
$body .= __( '== Actions ==', 'edit-flow' ) . "\r\n";
$body .= sprintf( __( 'Add editorial comment: %s', 'edit-flow' ), $edit_link . '#editorialcomments/add' ) . "\r\n";
@@ -751,8 +767,19 @@
$body .= esc_html__( 'Notified', 'edit-flow' ) . ": " . esc_html( $notification_list ) . "\n";
}
- $edit_link = htmlspecialchars_decode( get_edit_post_link( $post_id ) );
- $view_link = htmlspecialchars_decode( get_permalink( $post_id ) );
+ $edit_post_link = get_edit_post_link( $post_id );
+ if ( is_null( $edit_post_link ) ) {
+ return;
+ }
+
+ $edit_link = htmlspecialchars_decode( $edit_post_link );
+
+ $permalink = get_permalink( $post_id );
+ if ( is_null( $permalink ) ) {
+ return;
+ }
+
+ $view_link = htmlspecialchars_decode( $permalink );
$body .= "\r\n";
$body .= __( '== Actions ==', 'edit-flow' ) . "\r\n";Metadata
Metadata
Assignees
Labels
No labels