Skip to content

mastodon_api_account

Alex Kirk edited this page Feb 8, 2025 · 20 revisions

Modify the account data returned for /api/account/{user_id} requests.

Example

add_filter( 'mastodon_api_account', function( $user_data, $user_id ) {
    $user = get_user_by( 'ID', $user_id );

    $account                 = new Account_Entity();
    $account->id             = strval( $user->ID );
    $account->username       = $user->user_login;
    $account->display_name   = $user->display_name;

    return $account;
}, 10, 2 );

Auto-generated Example

add_filter(
    'mastodon_api_account',
    function (
        Enable_Mastodon_Apps\Entity\Account $account = null,
        int $user_id,
        WP_REST_Request $request = null,
        WP_Post $post = null
    ) {
        // Your code here
        return $account;
    },
    10,
    4
);

Parameters

  • Enable_Mastodon_Apps\Entity\Account|null $account The account data.
  • int $user_id The requested user ID.
  • WP_REST_Request|null $request The request object.
  • WP_Post|null $post The post object.

Returns

Enable_Mastodon_Apps\Entity\Account|null The modified account data.

Files

apply_filters( 'mastodon_api_account', null, $post->post_author, null, $post )
apply_filters( 'mastodon_api_account', null, $comment->user_id, null, $comment )
apply_filters( 'mastodon_api_account', null, $post->post_author, null, $post )
apply_filters( 'mastodon_api_account', null, $q, null, null )
apply_filters( 'mastodon_api_account', null, $user->ID, null, null )
apply_filters( 'mastodon_api_account', null, $comment->comment_author_url, $request, null )
\apply_filters( 'mastodon_api_account', null, $acct, $request, null )
\apply_filters( 'mastodon_api_account', null, $user_id, $request, null )

Hooks

Clone this wiki locally