Enqueue reply assets only if there is anything to reply to on the page (#706)

This commit is contained in:
Kaspars Dambis 2024-03-12 19:57:07 +02:00 committed by GitHub
parent e4ea69ca6f
commit 343a3b5c67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,6 +13,14 @@ use function Activitypub\is_user_disabled;
* methods that are used to handle comments. * methods that are used to handle comments.
*/ */
class Comment { class Comment {
/**
* Enqueue reply assets only if the reply feature is needed
* for the current request.
*
* @var bool
*/
private static $remote_reply_assets_needed = false;
/** /**
* Initialize the class, registering WordPress hooks * Initialize the class, registering WordPress hooks
*/ */
@ -40,6 +48,8 @@ class Comment {
return $link; return $link;
} }
self::$remote_reply_assets_needed = true; // Request script and styles for remote reply feature.
$attrs = array( $attrs = array(
'selectedComment' => self::generate_id( $comment ), 'selectedComment' => self::generate_id( $comment ),
'commentId' => $comment->comment_ID, 'commentId' => $comment->comment_ID,
@ -351,7 +361,11 @@ class Comment {
* Enqueue scripts for remote comments * Enqueue scripts for remote comments
*/ */
public static function enqueue_scripts() { public static function enqueue_scripts() {
if ( ! is_singular() ) { $assets_needed = \apply_filters(
'activitypub_remote_reply_assets_needed',
self::$remote_reply_assets_needed
);
if ( ! $assets_needed ) {
return; return;
} }
$handle = 'activitypub-remote-reply'; $handle = 'activitypub-remote-reply';