Skip to content

Add Dashboard widgets for ActivityPub profiles #1658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/1658-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Profile sections have been moved from the Welcome page to new Dashboard widgets for easier access.
50 changes: 50 additions & 0 deletions includes/wp-admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Activitypub\Comment;
use Activitypub\Collection\Actors;
use Activitypub\Collection\Extra_Fields;
use Activitypub\Model\Blog;

use function Activitypub\count_followers;
use function Activitypub\get_content_visibility;
use function Activitypub\is_user_type_disabled;
Expand Down Expand Up @@ -674,6 +676,12 @@ function ( $id ) {
*/
public static function add_dashboard_widgets() {
\wp_add_dashboard_widget( 'activitypub_blog', \__( 'ActivityPub Plugin News', 'activitypub' ), array( self::class, 'blog_dashboard_widget' ) );
if ( user_can_activitypub( \get_current_user_id() ) && ! is_user_type_disabled( 'user' ) ) {
\wp_add_dashboard_widget( 'activitypub_profile', \__( 'ActivityPub Author profile', 'activitypub' ), array( self::class, 'profile_dashboard_widget' ) );
}
if ( ! is_user_type_disabled( 'blog' ) ) {
\wp_add_dashboard_widget( 'activitypub_blog_profile', \__( 'ActivityPub Blog profile', 'activitypub' ), array( self::class, 'blogprofile_dashboard_widget' ) );
}
}

/**
Expand All @@ -692,4 +700,46 @@ public static function blog_dashboard_widget() {
);
echo '</div>';
}

/**
* Add the ActivityPub Author profile as a Dashboard widget.
*/
public static function profile_dashboard_widget() {
$user = Actors::get_by_id( \get_current_user_id() );
?>
<p>
<?php \esc_html_e( 'People can follow you by using your author name:', 'activitypub' ); ?>
</p>
<p><label for="activitypub-user-identifier"><?php \esc_html_e( 'Username', 'activitypub' ); ?></label><input type="text" class="large-text code" id="activitypub-user-identifier" value="<?php echo \esc_attr( $user->get_webfinger() ); ?>" readonly /></p>
<p><label for="activitypub-user-url"><?php \esc_html_e( 'Profile URL', 'activitypub' ); ?></label><input type="text" class="large-text code" id="activitypub-user-url" value="<?php echo \esc_attr( $user->get_url() ); ?>" readonly /></p>
<p>
<?php \esc_html_e( 'Authors who can not access this settings page will find their username on the "Edit Profile" page.', 'activitypub' ); ?>
<a href="<?php echo \esc_url( \admin_url( '/profile.php#activitypub' ) ); ?>">
<?php \esc_html_e( 'Customize username on "Edit Profile" page.', 'activitypub' ); ?>
</a>
</p>
<?php
}

/**
* Add the ActivityPub Blog profile as a Dashboard widget.
*/
public static function blogprofile_dashboard_widget() {
$user = new Blog();
?>
<p>
<?php \esc_html_e( 'People can follow your blog by using:', 'activitypub' ); ?>
</p>
<p><label for="activitypub-user-identifier"><?php \esc_html_e( 'Username', 'activitypub' ); ?></label><input type="text" class="large-text code" id="activitypub-user-identifier" value="<?php echo \esc_attr( $user->get_webfinger() ); ?>" readonly /></p>
<p><label for="activitypub-user-url"><?php \esc_html_e( 'Profile URL', 'activitypub' ); ?></label><input type="text" class="large-text code" id="activitypub-user-url" value="<?php echo \esc_attr( $user->get_url() ); ?>" readonly /></p>
<p>
<?php \esc_html_e( 'This blog profile will federate all posts written on your blog, regardless of the author who posted it.', 'activitypub' ); ?>
<?php if ( current_user_can( 'manage_options' ) ) : ?>
<a href="<?php echo \esc_url( \admin_url( '/options-general.php?page=activitypub&tab=blog-profile' ) ); ?>">
<?php \esc_html_e( 'Customize the blog profile.', 'activitypub' ); ?>
</a>
<?php endif; ?>
</p>
<?php
}
}
Loading