PluginProbe
ActivityPub / 2.6.0
ActivityPub v2.6.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-admin.php +307 -8 2.1.02.6.0 View file →
@@ -1,13 +1,17 @@
1 1 <?php
2 2 namespace Activitypub;
3 3
4 4 use WP_User_Query;
5 -use Activitypub\Model\Blog_User;
5 +use Activitypub\Model\Blog;
6 +use Activitypub\Activitypub;
7 +use Activitypub\Collection\Users;
6 8
9 +use function Activitypub\count_followers;
7 10 use function Activitypub\is_user_disabled;
8 11 use function Activitypub\was_comment_received;
9 12 use function Activitypub\is_comment_federatable;
13 +use function Activitypub\add_default_actor_extra_fields;
10 14
11 15 /**
12 16 * ActivityPub Admin Class
13 17 *
@@ -20,16 +24,31 @@
20 24 public static function init() {
21 25 \add_action( 'admin_menu', array( self::class, 'admin_menu' ) );
22 26 \add_action( 'admin_init', array( self::class, 'register_settings' ) );
23 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' ) );
24 30 \add_action( 'personal_options_update', array( self::class, 'save_user_description' ) );
25 31 \add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) );
26 32 \add_action( 'admin_notices', array( self::class, 'admin_notices' ) );
33 +
27 34 \add_filter( 'comment_row_actions', array( self::class, 'comment_row_actions' ), 10, 2 );
35 + \add_filter( 'manage_edit-comments_columns', array( static::class, 'manage_comment_columns' ) );
36 + \add_action( 'manage_comments_custom_column', array( static::class, 'manage_comments_custom_column' ), 9, 2 );
28 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 );
40 +
41 + \add_filter( 'manage_users_columns', array( self::class, 'manage_users_columns' ), 10, 1 );
42 + \add_action( 'manage_users_custom_column', array( self::class, 'manage_users_custom_column' ), 10, 3 );
43 + \add_filter( 'bulk_actions-users', array( self::class, 'user_bulk_options' ) );
44 + \add_filter( 'handle_bulk_actions-users', array( self::class, 'handle_bulk_request' ), 10, 3 );
45 +
29 46 if ( ! is_user_disabled( get_current_user_id() ) ) {
30 47 \add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
31 48 }
49 +
50 + \add_filter( 'dashboard_glance_items', array( self::class, 'dashboard_glance_items' ) );
32 51 }
33 52
34 53 /**
35 54 * Add admin menu entry
@@ -49,8 +68,10 @@
49 68 if ( ! is_user_disabled( get_current_user_id() ) ) {
50 69 $followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers', 'activitypub' ), 'read', 'activitypub-followers-list', array( self::class, 'followers_list_page' ) );
51 70
52 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' ) ) );
53 74 }
54 75 }
55 76
56 77 /**
@@ -60,11 +81,21 @@
60 81 */
61 82 public static function admin_notices() {
62 83 $permalink_structure = \get_option( 'permalink_structure' );
63 84 if ( empty( $permalink_structure ) ) {
64 - $admin_notice = \__( 'You are using the ActivityPub plugin without setting a permalink structure. This will prevent ActivityPub from working. Please set a permalink structure.', 'activitypub' );
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' );
65 86 self::show_admin_notice( $admin_notice, 'error' );
66 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 + }
67 98 }
68 99
69 100 /**
70 101 * Display one admin menu notice about configuration problems or conflicts.
@@ -174,9 +205,8 @@
174 205 'show_in_rest' => array(
175 206 'schema' => array(
176 207 'enum' => array(
177 208 'note',
178 - 'article',
179 209 'wordpress-post-format',
180 210 ),
181 211 ),
182 212 ),
@@ -208,9 +238,9 @@
208 238 array(
209 239 'type' => 'string',
210 240 'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ),
211 241 'show_in_rest' => true,
212 - 'default' => Blog_User::get_default_username(),
242 + 'default' => Blog::get_default_username(),
213 243 'sanitize_callback' => function ( $value ) {
214 244 // hack to allow dots in the username
215 245 $parts = explode( '.', $value );
216 246 $sanitized = array();
@@ -239,9 +269,9 @@
239 269 \esc_html__( 'You cannot use an existing author\'s name for the blog profile ID.', 'activitypub' ),
240 270 'error'
241 271 );
242 272
243 - return Blog_User::get_default_username();
273 + return Blog::get_default_username();
244 274 }
245 275
246 276 return $sanitized;
247 277 },
@@ -305,11 +335,15 @@
305 335 }
306 336
307 337 public static function enqueue_scripts( $hook_suffix ) {
308 338 if ( false !== strpos( $hook_suffix, 'activitypub' ) ) {
309 - wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), '1.0.0' );
310 - wp_enqueue_script( 'activitypub-admin-styles', plugins_url( 'assets/js/activitypub-admin.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', false );
339 + wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), get_plugin_version() );
340 + wp_enqueue_script( 'activitypub-admin-script', plugins_url( 'assets/js/activitypub-admin.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), get_plugin_version(), false );
311 341 }
342 +
343 + if ( 'index.php' === $hook_suffix ) {
344 + wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), get_plugin_version() );
345 + }
312 346 }
313 347
314 348 /**
315 349 * Hook into the edit_comment functionality
@@ -337,14 +371,279 @@
337 371 3
338 372 );
339 373 }
340 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 +
341 437 public static function comment_row_actions( $actions, $comment ) {
342 438 if ( was_comment_received( $comment ) ) {
343 439 unset( $actions['edit'] );
344 - unset( $actions['reply'] );
345 440 unset( $actions['quickedit'] );
346 441 }
347 442
348 443 return $actions;
444 + }
445 +
446 + /**
447 + * Add a column "activitypub"
448 + *
449 + * This column shows if the user has the capability to use ActivityPub.
450 + *
451 + * @param array $columns The columns.
452 + *
453 + * @return array The columns extended by the activitypub.
454 + */
455 + public static function manage_users_columns( $columns ) {
456 + $columns['activitypub'] = __( 'ActivityPub', 'activitypub' );
457 + return $columns;
458 + }
459 +
460 + /**
461 + * Add "comment-type" and "protocol" as column in WP-Admin
462 + *
463 + * @param array $columns the list of column names
464 + */
465 + public static function manage_comment_columns( $columns ) {
466 + $columns['comment_type'] = esc_attr__( 'Comment-Type', 'activitypub' );
467 + $columns['comment_protocol'] = esc_attr__( 'Protocol', 'activitypub' );
468 +
469 + return $columns;
470 + }
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 +
488 + /**
489 + * Add "comment-type" and "protocol" as column in WP-Admin
490 + *
491 + * @param array $column The column to implement
492 + * @param int $comment_id The comment id
493 + */
494 + public static function manage_comments_custom_column( $column, $comment_id ) {
495 + if ( 'comment_type' === $column && ! defined( 'WEBMENTION_PLUGIN_DIR' ) ) {
496 + echo esc_attr( ucfirst( get_comment_type( $comment_id ) ) );
497 + } elseif ( 'comment_protocol' === $column ) {
498 + $protocol = get_comment_meta( $comment_id, 'protocol', true );
499 +
500 + if ( $protocol ) {
501 + echo esc_attr( ucfirst( str_replace( 'activitypub', 'ActivityPub', $protocol ) ) );
502 + } else {
503 + esc_attr_e( 'Local', 'activitypub' );
504 + }
505 + }
506 + }
507 +
508 + /**
509 + * Return the results for the activitypub column.
510 + *
511 + * @param string $output Custom column output. Default empty.
512 + * @param string $column_name Column name.
513 + * @param int $user_id ID of the currently-listed user.
514 + *
515 + * @return string The column contents.
516 + */
517 + public static function manage_users_custom_column( $output, $column_name, $user_id ) {
518 + if ( 'activitypub' !== $column_name ) {
519 + return $output;
520 + }
521 +
522 + if ( \user_can( $user_id, 'activitypub' ) ) {
523 + return '<span aria-hidden="true">&#x2713;</span><span class="screen-reader-text">' . esc_html__( 'ActivityPub enabled for this author', 'activitypub' ) . '</span>';
524 + } else {
525 + return '<span aria-hidden="true">&#x2717;</span><span class="screen-reader-text">' . esc_html__( 'ActivityPub disabled for this author', 'activitypub' ) . '</span>';
526 + }
527 + }
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 +
548 + /**
549 + * Add options to the Bulk dropdown on the users page
550 + *
551 + * @param array $actions The existing bulk options.
552 + *
553 + * @return array The extended bulk options.
554 + */
555 + public static function user_bulk_options( $actions ) {
556 + $actions['add_activitypub_cap'] = __( 'Enable for ActivityPub', 'activitypub' );
557 + $actions['remove_activitypub_cap'] = __( 'Disable for ActivityPub', 'activitypub' );
558 +
559 + return $actions;
560 + }
561 +
562 + /**
563 + * Handle bulk activitypub requests
564 + *
565 + * * `add_activitypub_cap` - Add the activitypub capability to the selected users.
566 + * * `remove_activitypub_cap` - Remove the activitypub capability from the selected users.
567 + *
568 + * @param string $sendback The URL to send the user back to.
569 + * @param string $action The requested action.
570 + * @param array $users The selected users.
571 + *
572 + * @return string The URL to send the user back to.
573 + */
574 + public static function handle_bulk_request( $sendback, $action, $users ) {
575 + if (
576 + 'remove_activitypub_cap' !== $action &&
577 + 'add_activitypub_cap' !== $action
578 + ) {
579 + return $sendback;
580 + }
581 +
582 + foreach ( $users as $user_id ) {
583 + $user = new \WP_User( $user_id );
584 + if (
585 + 'add_activitypub_cap' === $action &&
586 + user_can( $user_id, 'publish_posts' )
587 + ) {
588 + $user->add_cap( 'activitypub' );
589 + } elseif ( 'remove_activitypub_cap' === $action ) {
590 + $user->remove_cap( 'activitypub' );
591 + }
592 + }
593 +
594 + return $sendback;
595 + }
596 +
597 + /**
598 + * Add ActivityPub infos to the dashboard glance items
599 + *
600 + * @param array $items The existing glance items.
601 + *
602 + * @return array The extended glance items.
603 + */
604 + public static function dashboard_glance_items( $items ) {
605 + \add_filter( 'number_format_i18n', '\Activitypub\custom_large_numbers', 10, 3 );
606 +
607 + if ( ! is_user_disabled( get_current_user_id() ) ) {
608 + $follower_count = sprintf(
609 + // translators: %s: number of followers
610 + _n(
611 + '%s Follower',
612 + '%s Followers',
613 + count_followers( \get_current_user_id() ),
614 + 'activitypub'
615 + ),
616 + \number_format_i18n( count_followers( \get_current_user_id() ) )
617 + );
618 + $items['activitypub-followers-user'] = sprintf(
619 + '<a class="activitypub-followers" href="%1$s" title="%2$s">%3$s</a>',
620 + \esc_url( \admin_url( 'users.php?page=activitypub-followers-list' ) ),
621 + \esc_attr__( 'Your followers', 'activitypub' ),
622 + \esc_html( $follower_count )
623 + );
624 + }
625 +
626 + if ( ! is_user_type_disabled( 'blog' ) && current_user_can( 'manage_options' ) ) {
627 + $follower_count = sprintf(
628 + // translators: %s: number of followers
629 + _n(
630 + '%s Follower (Blog)',
631 + '%s Followers (Blog)',
632 + count_followers( Users::BLOG_USER_ID ),
633 + 'activitypub'
634 + ),
635 + \number_format_i18n( count_followers( Users::BLOG_USER_ID ) )
636 + );
637 + $items['activitypub-followers-blog'] = sprintf(
638 + '<a class="activitypub-followers" href="%1$s" title="%2$s">%3$s</a>',
639 + \esc_url( \admin_url( 'options-general.php?page=activitypub&tab=followers' ) ),
640 + \esc_attr__( 'The Blog\'s followers', 'activitypub' ),
641 + \esc_html( $follower_count )
642 + );
643 + }
644 +
645 + \remove_filter( 'number_format_i18n', '\Activitypub\custom_large_numbers', 10, 3 );
646 +
647 + return $items;
349 648 }
350 649 }