Skip to content

Commit

Permalink
Add author name to term name on term creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nlemoine committed Sep 23, 2023
1 parent a2c3fa9 commit b104705
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ function bootstrap() : void {
add_filter( 'the_author', __NAMESPACE__ . '\\filter_the_author_for_rss' );
add_filter( 'comment_moderation_recipients', __NAMESPACE__ . '\\filter_comment_moderation_recipients', 10, 2 );
add_filter( 'comment_notification_recipients', __NAMESPACE__ . '\\filter_comment_notification_recipients', 10, 2 );
add_filter( 'wp_insert_term_data', __NAMESPACE__ . '\\add_term_name', 10, 3 );
}

/**
* Set term name to user display name on term creation.
*
* @param array $data Term data.
* @param string $taxonomy Taxonomy.
* @param array $args wp_insert_term() args.
* @return array
*/
function add_term_name( array $data, string $taxonomy, array $args ) : array {

Check failure on line 72 in inc/namespace.php

View workflow job for this annotation

GitHub Actions / PHP Coding Standards

Function Authorship\add_term_name() has parameter $args with no value type specified in iterable type array.

Check failure on line 72 in inc/namespace.php

View workflow job for this annotation

GitHub Actions / PHP Coding Standards

Function Authorship\add_term_name() has parameter $data with no value type specified in iterable type array.

Check failure on line 72 in inc/namespace.php

View workflow job for this annotation

GitHub Actions / PHP Coding Standards

Function Authorship\add_term_name() return type has no value type specified in iterable type array.
if ( $taxonomy !== TAXONOMY ) {
return $data;
}
$user_id = (int) $data['slug'] ?? null;
if ( ! $user_id ) {
return $data;
}

$user = get_userdata( $user_id );
if ( ! $user ) {
return $data;
}

$data['name'] = $user->display_name;
return $data;
}

/**
Expand Down

0 comments on commit b104705

Please sign in to comment.