Skip to content
Open
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/add-make-actor-table-columns-filterable
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

make actor table columns filterable
42 changes: 0 additions & 42 deletions includes/wp-admin/table/class-blocked-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,6 @@ public function process_admin_notices() {
\settings_errors( 'activitypub' );
}

/**
* Get columns.
*
* @return array
*/
public function get_columns() {
return array(
'cb' => '<input type="checkbox" />',
'username' => \__( 'Username', 'activitypub' ),
'post_title' => \__( 'Name', 'activitypub' ),
'webfinger' => \__( 'Profile', 'activitypub' ),
'modified' => \__( 'Blocked date', 'activitypub' ),
);
}

/**
* Returns sortable columns.
*
* @return array
*/
public function get_sortable_columns() {
return array(
'username' => array( 'username', true ),
'post_title' => array( 'post_title', true ),
'modified' => array( 'modified', false ),
);
}

/**
* Prepare items.
*/
Expand Down Expand Up @@ -252,20 +224,6 @@ public function get_bulk_actions() {
);
}

/**
* Column default.
*
* @param array $item Item.
* @param string $column_name Column name.
* @return string
*/
public function column_default( $item, $column_name ) {
if ( ! \array_key_exists( $column_name, $item ) ) {
return \esc_html__( 'None', 'activitypub' );
}
return \esc_html( $item[ $column_name ] );
}

/**
* Column checkbox.
*
Expand Down
43 changes: 0 additions & 43 deletions includes/wp-admin/table/class-followers.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,34 +212,6 @@ public function process_admin_notices() {
\settings_errors( 'activitypub' );
}

/**
* Get columns.
*
* @return array
*/
public function get_columns() {
return array(
'cb' => '<input type="checkbox" />',
'username' => \esc_html__( 'Username', 'activitypub' ),
'post_title' => \esc_html__( 'Name', 'activitypub' ),
'webfinger' => \esc_html__( 'Profile', 'activitypub' ),
'modified' => \esc_html__( 'Last updated', 'activitypub' ),
);
}

/**
* Returns sortable columns.
*
* @return array
*/
public function get_sortable_columns() {
return array(
'username' => array( 'username', true ),
'post_title' => array( 'post_title', true ),
'modified' => array( 'modified', false ),
);
}

/**
* Prepare items.
*/
Expand Down Expand Up @@ -339,21 +311,6 @@ public function get_bulk_actions() {
);
}

/**
* Column default.
*
* @param array $item Item.
* @param string $column_name Column name.
* @return string
*/
public function column_default( $item, $column_name ) {
if ( ! array_key_exists( $column_name, $item ) ) {
return \esc_html__( 'None', 'activitypub' );
}

return \esc_html( $item[ $column_name ] );
}

/**
* Column cb.
*
Expand Down
42 changes: 0 additions & 42 deletions includes/wp-admin/table/class-following.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,34 +168,6 @@ public function process_admin_notices() {
\settings_errors( 'activitypub' );
}

/**
* Get columns.
*
* @return array
*/
public function get_columns() {
return array(
'cb' => '<input type="checkbox" />',
'username' => \__( 'Username', 'activitypub' ),
'post_title' => \__( 'Name', 'activitypub' ),
'webfinger' => \__( 'Profile', 'activitypub' ),
'modified' => \__( 'Last updated', 'activitypub' ),
);
}

/**
* Returns sortable columns.
*
* @return array
*/
public function get_sortable_columns() {
return array(
'username' => array( 'username', true ),
'post_title' => array( 'post_title', true ),
'modified' => array( 'modified', false ),
);
}

/**
* Prepare items.
*/
Expand Down Expand Up @@ -342,20 +314,6 @@ public function get_bulk_actions() {
);
}

/**
* Column default.
*
* @param array $item Item.
* @param string $column_name Column name.
* @return string
*/
public function column_default( $item, $column_name ) {
if ( ! array_key_exists( $column_name, $item ) ) {
return \esc_html__( 'None', 'activitypub' );
}
return \esc_html( $item[ $column_name ] );
}

/**
* Column avatar.
*
Expand Down
102 changes: 102 additions & 0 deletions includes/wp-admin/table/trait-actor-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,108 @@
* Actor Table Trait.
*/
trait Actor_List_Table {
/**
* Returns the lowercase short classname which is used as keys for filtering.
*
* @return string
*/
protected static function actor_list_table_key() {
return strtolower( ( new \ReflectionClass( static::class ) )->getShortName() );
}

/**
* Column default.
*
* @param array $item Item.
* @param string $column_name Column name.
* @return string
*/
public function column_default( $item, $column_name ) {
/**
* Filters the displayed value for a column in the ActivityPub Following list table.
*
* Allows plugins to provide custom output for individual columns.
* If a non-null value is returned, it will be used instead of the
* default column rendering logic.
*
* @since 7.9.0
*
* @param string|null $value The column value. Default null.
* @param string $column_name The name of the current column.
* @param array $item The current following item data.
* @param int $user_id The user id of the local actor.
*/
$value = \apply_filters(
'activitypub_' . $this->actor_list_table_key() . '_column_value',
null,
$column_name,
$item,
$this->user_id
);

if ( null !== $value ) {
return $value;
}

if ( ! \array_key_exists( $column_name, $item ) ) {
return \esc_html__( 'None', 'activitypub' );
}
return \esc_html( $item[ $column_name ] );
}

/**
* Returns sortable columns.
*
* @return array
*/
public function get_sortable_columns() {
$columns = array(
'username' => array( 'username', true ),
'post_title' => array( 'post_title', true ),
'modified' => array( 'modified', false ),
);

/**
* Filters the sortable columns in the ActivityPub Following list table.
*
* Allows plugins to register additional sortable columns or modify the default sortable behavior.
*
* @since 7.9.0
*
* @param array<string, array> $columns Sortable columns in the format
* `column_id => array( orderby, is_sortable_default )`.
* @param int $user_id The user id of the local actor.
*/
return \apply_filters( 'activitypub_' . $this->actor_list_table_key() . '_sortable_columns', $columns, $this->user_id );
}

/**
* Get columns.
*
* @return array
*/
public function get_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'username' => \__( 'Username', 'activitypub' ),
'post_title' => \__( 'Name', 'activitypub' ),
'webfinger' => \__( 'Profile', 'activitypub' ),
'modified' => \__( 'Last updated', 'activitypub' ),
);

/**
* Filters the columns displayed in the ActivityPub Following list table.
*
* Allows plugins to add, remove, or reorder columns shown in the
* Following list table on the ActivityPub admin screen.
*
* @since 7.9.0
*
* @param string[] $columns Array of columns.
* @param int $user_id The user id of the local actor.
*/
return \apply_filters( 'activitypub_' . $this->actor_list_table_key() . '_columns', $columns, $this->user_id );
}

/**
* Sanitizes and normalizes an actor search term.
Expand Down