Skip to content

Commit f3ca90b

Browse files
authored
Use static closures where possible (#2641)
1 parent 023b9f2 commit f3ca90b

31 files changed

+57
-57
lines changed

build/followers/render.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/reactions/render.php

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-activitypub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static function register_user_meta() {
225225
'description' => 'The user description.',
226226
'single' => true,
227227
'default' => '',
228-
'sanitize_callback' => function ( $value ) {
228+
'sanitize_callback' => static function ( $value ) {
229229
return wp_kses( $value, 'user_description' );
230230
},
231231
)
@@ -336,7 +336,7 @@ public static function register_user_meta() {
336336
'description' => 'User-specific blocked ActivityPub domains.',
337337
'single' => true,
338338
'default' => array(),
339-
'sanitize_callback' => function ( $value ) {
339+
'sanitize_callback' => static function ( $value ) {
340340
return \array_unique( \array_map( array( Sanitize::class, 'host_list' ), $value ) );
341341
},
342342
)
@@ -350,7 +350,7 @@ public static function register_user_meta() {
350350
'description' => 'User-specific blocked ActivityPub keywords.',
351351
'single' => true,
352352
'default' => array(),
353-
'sanitize_callback' => function ( $value ) {
353+
'sanitize_callback' => static function ( $value ) {
354354
return \array_map( 'sanitize_text_field', $value );
355355
},
356356
)

includes/class-blocks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function register_rest_fields() {
116116
* @param \WP_REST_Request $request The request object.
117117
* @return int The number of published posts.
118118
*/
119-
'get_callback' => function ( $response, $field_name, $request ) {
119+
'get_callback' => static function ( $response, $field_name, $request ) {
120120
return (int) count_user_posts( $request->get_param( 'id' ), 'post', true );
121121
},
122122
'schema' => array(
@@ -300,7 +300,7 @@ public static function filter_import_mastodon_post_data( $data, $post ) {
300300
// Convert paragraphs to blocks.
301301
\preg_match_all( '#<p>.*?</p>#is', $data['post_content'], $matches );
302302
$blocks = \array_map(
303-
function ( $paragraph ) {
303+
static function ( $paragraph ) {
304304
return '<!-- wp:paragraph -->' . PHP_EOL . $paragraph . PHP_EOL . '<!-- /wp:paragraph -->' . PHP_EOL;
305305
},
306306
$matches[0] ?? array()

includes/class-mailer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static function new_follower( $activity, $user_ids, $success ) {
207207
\load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/emails/new-follower.php', false, $template_args );
208208
$html_message = \ob_get_clean();
209209

210-
$alt_function = function ( $mailer ) use ( $actor, $admin_url ) {
210+
$alt_function = static function ( $mailer ) use ( $actor, $admin_url ) {
211211
/* translators: 1: Follower name */
212212
$message = \sprintf( \__( 'New Follower: %1$s.', 'activitypub' ), $actor['name'] ) . "\r\n\r\n";
213213
/* translators: Follower URL */
@@ -295,7 +295,7 @@ public static function direct_message( $activity, $user_ids ) {
295295
\load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/emails/new-dm.php', false, $template_args );
296296
$html_message = \ob_get_clean();
297297

298-
$alt_function = function ( $mailer ) use ( $actor, $activity ) {
298+
$alt_function = static function ( $mailer ) use ( $actor, $activity ) {
299299
$content = \html_entity_decode(
300300
\wp_strip_all_tags(
301301
str_replace( '</p>', PHP_EOL . PHP_EOL, $activity['object']['content'] )
@@ -395,7 +395,7 @@ public static function mention( $activity, $user_ids ) {
395395
\load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/emails/new-mention.php', false, $template_args );
396396
$html_message = \ob_get_clean();
397397

398-
$alt_function = function ( $mailer ) use ( $actor, $activity ) {
398+
$alt_function = static function ( $mailer ) use ( $actor, $activity ) {
399399
$content = \html_entity_decode(
400400
\wp_strip_all_tags(
401401
str_replace( '</p>', PHP_EOL . PHP_EOL, $activity['object']['content'] )

includes/class-options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static function register_settings() {
7676
'type' => 'integer',
7777
'description' => 'Number of images to attach to posts.',
7878
'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
79-
'sanitize_callback' => function ( $value ) {
79+
'sanitize_callback' => static function ( $value ) {
8080
return \is_numeric( $value ) ? \absint( $value ) : ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS;
8181
},
8282
)

includes/class-post-types.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static function register_inbox_post_type() {
143143
'description' => 'The type of the activity',
144144
'single' => true,
145145
'show_in_rest' => true,
146-
'sanitize_callback' => function ( $value ) {
146+
'sanitize_callback' => static function ( $value ) {
147147
$schema = array(
148148
'type' => 'string',
149149
'enum' => Activity::TYPES,
@@ -177,7 +177,7 @@ public static function register_inbox_post_type() {
177177
'type' => 'string',
178178
'single' => true,
179179
'show_in_rest' => true,
180-
'sanitize_callback' => function ( $value ) {
180+
'sanitize_callback' => static function ( $value ) {
181181
$schema = array(
182182
'type' => 'string',
183183
'enum' => array( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE, ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ),
@@ -246,7 +246,7 @@ public static function register_outbox_post_type() {
246246
'description' => 'The type of the activity',
247247
'single' => true,
248248
'show_in_rest' => true,
249-
'sanitize_callback' => function ( $value ) {
249+
'sanitize_callback' => static function ( $value ) {
250250
$schema = array(
251251
'type' => 'string',
252252
'enum' => Activity::TYPES,
@@ -269,7 +269,7 @@ public static function register_outbox_post_type() {
269269
'type' => 'string',
270270
'single' => true,
271271
'show_in_rest' => true,
272-
'sanitize_callback' => function ( $value ) {
272+
'sanitize_callback' => static function ( $value ) {
273273
$schema = array(
274274
'type' => 'string',
275275
'enum' => array( 'application', 'blog', 'user' ),
@@ -315,7 +315,7 @@ public static function register_outbox_post_type() {
315315
'type' => 'string',
316316
'single' => true,
317317
'show_in_rest' => true,
318-
'sanitize_callback' => function ( $value ) {
318+
'sanitize_callback' => static function ( $value ) {
319319
$schema = array(
320320
'type' => 'string',
321321
'enum' => array( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE, ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ),
@@ -470,7 +470,7 @@ public static function register_activitypub_post_meta() {
470470
'type' => 'string',
471471
'single' => true,
472472
'show_in_rest' => true,
473-
'sanitize_callback' => function ( $value ) {
473+
'sanitize_callback' => static function ( $value ) {
474474
$schema = array(
475475
'type' => 'string',
476476
'enum' => array( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE, ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ),
@@ -505,7 +505,7 @@ public static function register_activitypub_post_meta() {
505505
'type' => 'string',
506506
'single' => true,
507507
'show_in_rest' => true,
508-
'sanitize_callback' => function ( $value ) {
508+
'sanitize_callback' => static function ( $value ) {
509509
$schema = array(
510510
'type' => 'string',
511511
'enum' => array( ACTIVITYPUB_INTERACTION_POLICY_ANYONE, ACTIVITYPUB_INTERACTION_POLICY_FOLLOWERS, ACTIVITYPUB_INTERACTION_POLICY_ME ),
@@ -528,7 +528,7 @@ public static function register_activitypub_post_meta() {
528528
'type' => 'string',
529529
'single' => true,
530530
'show_in_rest' => true,
531-
'sanitize_callback' => function ( $value ) {
531+
'sanitize_callback' => static function ( $value ) {
532532
$schema = array(
533533
'type' => 'string',
534534
'enum' => array( 'pending', 'federated', 'failed' ),
@@ -560,7 +560,7 @@ public static function register_ap_actor_rest_field() {
560560
* @param array $response Prepared response array.
561561
* @return string The raw post content.
562562
*/
563-
'get_callback' => function ( $response ) {
563+
'get_callback' => static function ( $response ) {
564564
return \get_post_field( 'post_content', $response['id'] );
565565
},
566566
'schema' => array(

includes/class-router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static function add_headers() {
158158

159159
add_action(
160160
'wp_head',
161-
function () use ( $id ) {
161+
static function () use ( $id ) {
162162
echo PHP_EOL . '<link rel="alternate" title="ActivityPub (JSON)" type="application/activity+json" href="' . esc_url( $id ) . '" />' . PHP_EOL;
163163
}
164164
);

includes/class-sanitize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function identifier_list( $value ) {
8686
public static function host_list( $value ) {
8787
$value = \explode( PHP_EOL, (string) $value );
8888
$value = \array_map(
89-
function ( $host ) {
89+
static function ( $host ) {
9090
$host = \trim( $host );
9191
$host = \strtolower( $host );
9292
$host = \set_url_scheme( $host );

includes/collection/class-actors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public static function get_all() {
405405
// Filter out any WP_Error instances.
406406
return array_filter(
407407
$actors,
408-
function ( $actor ) {
408+
static function ( $actor ) {
409409
return ! \is_wp_error( $actor );
410410
}
411411
);

0 commit comments

Comments
 (0)