3
3
4
4
use WP_User_Query ;
5
5
use Activitypub \Model \Blog ;
6
+ use Activitypub \Activitypub ;
6
7
use Activitypub \Collection \Users ;
7
8
8
9
use function Activitypub \count_followers ;
9
10
use function Activitypub \is_user_disabled ;
10
11
use function Activitypub \was_comment_received ;
11
12
use function Activitypub \is_comment_federatable ;
13
+ use function Activitypub \add_default_actor_extra_fields ;
12
14
13
15
/**
14
16
* ActivityPub Admin Class
@@ -23,16 +25,21 @@ public static function init() {
23
25
\add_action ( 'admin_menu ' , array ( self ::class, 'admin_menu ' ) );
24
26
\add_action ( 'admin_init ' , array ( self ::class, 'register_settings ' ) );
25
27
\add_action ( 'load-comment.php ' , array ( self ::class, 'edit_comment ' ) );
28
+ \add_action ( 'load-post.php ' , array ( self ::class, 'edit_post ' ) );
29
+ \add_action ( 'load-edit.php ' , array ( self ::class, 'list_posts ' ) );
26
30
\add_action ( 'personal_options_update ' , array ( self ::class, 'save_user_description ' ) );
27
31
\add_action ( 'admin_enqueue_scripts ' , array ( self ::class, 'enqueue_scripts ' ) );
28
32
\add_action ( 'admin_notices ' , array ( self ::class, 'admin_notices ' ) );
29
33
30
34
\add_filter ( 'comment_row_actions ' , array ( self ::class, 'comment_row_actions ' ), 10 , 2 );
31
35
\add_filter ( 'manage_edit-comments_columns ' , array ( static ::class, 'manage_comment_columns ' ) );
32
- \add_filter ( 'manage_comments_custom_column ' , array ( static ::class, 'manage_comments_custom_column ' ), 9 , 2 );
36
+ \add_action ( 'manage_comments_custom_column ' , array ( static ::class, 'manage_comments_custom_column ' ), 9 , 2 );
37
+
38
+ \add_filter ( 'manage_posts_columns ' , array ( static ::class, 'manage_post_columns ' ), 10 , 2 );
39
+ \add_action ( 'manage_posts_custom_column ' , array ( self ::class, 'manage_posts_custom_column ' ), 10 , 2 );
33
40
34
41
\add_filter ( 'manage_users_columns ' , array ( self ::class, 'manage_users_columns ' ), 10 , 1 );
35
- \add_filter ( 'manage_users_custom_column ' , array ( self ::class, 'manage_users_custom_column ' ), 10 , 3 );
42
+ \add_action ( 'manage_users_custom_column ' , array ( self ::class, 'manage_users_custom_column ' ), 10 , 3 );
36
43
\add_filter ( 'bulk_actions-users ' , array ( self ::class, 'user_bulk_options ' ) );
37
44
\add_filter ( 'handle_bulk_actions-users ' , array ( self ::class, 'handle_bulk_request ' ), 10 , 3 );
38
45
@@ -62,6 +69,8 @@ public static function admin_menu() {
62
69
$ followers_list_page = \add_users_page ( \__ ( 'Followers ' , 'activitypub ' ), \__ ( 'Followers ' , 'activitypub ' ), 'read ' , 'activitypub-followers-list ' , array ( self ::class, 'followers_list_page ' ) );
63
70
64
71
\add_action ( 'load- ' . $ followers_list_page , array ( self ::class, 'add_followers_list_help_tab ' ) );
72
+
73
+ \add_users_page ( \__ ( 'Extra Fields ' , 'activitypub ' ), \__ ( 'Extra Fields ' , 'activitypub ' ), 'read ' , esc_url ( admin_url ( '/edit.php?post_type=ap_extrafield ' ) ) );
65
74
}
66
75
}
67
76
@@ -76,6 +85,16 @@ public static function admin_notices() {
76
85
$ admin_notice = \__ ( 'You are using the ActivityPub plugin with a permalink structure of "plain". This will prevent ActivityPub from working. Please go to "Settings" / "Permalinks" and choose a permalink structure other than "plain". ' , 'activitypub ' );
77
86
self ::show_admin_notice ( $ admin_notice , 'error ' );
78
87
}
88
+
89
+ $ current_screen = get_current_screen ();
90
+
91
+ if ( isset ( $ current_screen ->id ) && 'edit-ap_extrafield ' === $ current_screen ->id ) {
92
+ ?>
93
+ <div class="notice" style="margin: 0; background: none; border: none; box-shadow: none; padding: 15px 0 0 0; font-size: 14px;">
94
+ <?php esc_html_e ( 'These are extra fields that are used for your ActivityPub profile. You can use your homepage, social profiles, pronouns, age, anything you want. ' , 'activitypub ' ); ?>
95
+ </div>
96
+ <?php
97
+ }
79
98
}
80
99
81
100
/**
@@ -353,6 +372,68 @@ function ( $allcaps, $caps, $arg ) {
353
372
);
354
373
}
355
374
375
+ public static function edit_post () {
376
+ // Disable the edit_post capability for federated posts.
377
+ \add_filter (
378
+ 'user_has_cap ' ,
379
+ function ( $ allcaps , $ caps , $ arg ) {
380
+ if ( 'edit_post ' !== $ arg [0 ] ) {
381
+ return $ allcaps ;
382
+ }
383
+
384
+ $ post = get_post ( $ arg [2 ] );
385
+
386
+ if ( 'ap_extrafield ' !== $ post ->post_type ) {
387
+ return $ allcaps ;
388
+ }
389
+
390
+ if ( (int ) get_current_user_id () !== (int ) $ post ->post_author ) {
391
+ return false ;
392
+ }
393
+
394
+ return $ allcaps ;
395
+ },
396
+ 1 ,
397
+ 3
398
+ );
399
+ }
400
+
401
+ /**
402
+ * Add ActivityPub specific actions/filters to the post list view
403
+ *
404
+ * @return void
405
+ */
406
+ public static function list_posts () {
407
+ // Show only the user's extra fields.
408
+ \add_action (
409
+ 'pre_get_posts ' ,
410
+ function ( $ query ) {
411
+ if ( $ query ->get ( 'post_type ' ) === 'ap_extrafield ' ) {
412
+ $ query ->set ( 'author ' , get_current_user_id () );
413
+ }
414
+ }
415
+ );
416
+
417
+ // Remove all views for the extra fields.
418
+ $ screen_id = get_current_screen ()->id ;
419
+
420
+ add_filter (
421
+ "views_ {$ screen_id }" ,
422
+ function ( $ views ) {
423
+ if ( 'ap_extrafield ' === get_post_type () ) {
424
+ return array ();
425
+ }
426
+
427
+ return $ views ;
428
+ }
429
+ );
430
+
431
+ // Set defaults for new extra fields.
432
+ if ( 'edit-ap_extrafield ' === $ screen_id ) {
433
+ Activitypub::default_actor_extra_fields ( array (), get_current_user_id () );
434
+ }
435
+ }
436
+
356
437
public static function comment_row_actions ( $ actions , $ comment ) {
357
438
if ( was_comment_received ( $ comment ) ) {
358
439
unset( $ actions ['edit ' ] );
@@ -382,12 +463,28 @@ public static function manage_users_columns( $columns ) {
382
463
* @param array $columns the list of column names
383
464
*/
384
465
public static function manage_comment_columns ( $ columns ) {
385
- $ columns ['comment_type ' ] = esc_attr__ ( 'Comment-Type ' , 'activitypub ' );
466
+ $ columns ['comment_type ' ] = esc_attr__ ( 'Comment-Type ' , 'activitypub ' );
386
467
$ columns ['comment_protocol ' ] = esc_attr__ ( 'Protocol ' , 'activitypub ' );
387
468
388
469
return $ columns ;
389
470
}
390
471
472
+ /**
473
+ * Add "post_content" as column for Extra-Fields in WP-Admin
474
+ *
475
+ * @param array $columns Tthe list of column names.
476
+ * @param string $post_type The post type.
477
+ */
478
+ public static function manage_post_columns ( $ columns , $ post_type ) {
479
+ if ( 'ap_extrafield ' === $ post_type ) {
480
+ $ after_key = 'title ' ;
481
+ $ index = array_search ( $ after_key , array_keys ( $ columns ), true );
482
+ $ columns = array_slice ( $ columns , 0 , $ index + 1 ) + array ( 'extra_field_content ' => esc_attr__ ( 'Content ' , 'activitypub ' ) ) + $ columns ;
483
+ }
484
+
485
+ return $ columns ;
486
+ }
487
+
391
488
/**
392
489
* Add "comment-type" and "protocol" as column in WP-Admin
393
490
*
@@ -429,6 +526,25 @@ public static function manage_users_custom_column( $output, $column_name, $user_
429
526
}
430
527
}
431
528
529
+ /**
530
+ * Add a column "extra_field_content" to the post list view
531
+ *
532
+ * @param string $column_name The column name.
533
+ * @param int $post_id The post ID.
534
+ *
535
+ * @return void
536
+ */
537
+ public static function manage_posts_custom_column ( $ column_name , $ post_id ) {
538
+ $ post = get_post ( $ post_id );
539
+
540
+ if ( 'extra_field_content ' === $ column_name ) {
541
+ $ post = get_post ( $ post_id );
542
+ if ( 'ap_extrafield ' === $ post ->post_type ) {
543
+ echo esc_attr ( wp_strip_all_tags ( $ post ->post_content ) );
544
+ }
545
+ }
546
+ }
547
+
432
548
/**
433
549
* Add options to the Bulk dropdown on the users page
434
550
*
0 commit comments