Skip to content

Commit 21206ec

Browse files
pfefferlemattwiebe
andauthored
search for followers and order the output list (#502)
* search for followers and order the output list * re-use existing nonce! * verify nonce for search! --------- Co-authored-by: Matt Wiebe <[email protected]>
1 parent efd98ac commit 21206ec

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

includes/model/class-follower.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static function init_from_cpt( $post ) {
315315
$object->set_id( $post->guid );
316316
$object->set_name( $post->post_title );
317317
$object->set_summary( $post->post_excerpt );
318-
$object->set_published( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_published ) ) );
318+
$object->set_published( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_date ) ) );
319319
$object->set_updated( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) ) );
320320

321321
return $object;

includes/table/class-followers.php

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,24 @@ public function __construct() {
3030

3131
public function get_columns() {
3232
return array(
33-
'cb' => '<input type="checkbox" />',
34-
'avatar' => \__( 'Avatar', 'activitypub' ),
35-
'name' => \__( 'Name', 'activitypub' ),
36-
'username' => \__( 'Username', 'activitypub' ),
37-
'url' => \__( 'URL', 'activitypub' ),
38-
'updated' => \__( 'Last updated', 'activitypub' ),
39-
//'errors' => \__( 'Errors', 'activitypub' ),
40-
//'latest-error' => \__( 'Latest Error Message', 'activitypub' ),
33+
'cb' => '<input type="checkbox" />',
34+
'avatar' => \__( 'Avatar', 'activitypub' ),
35+
'post_title' => \__( 'Name', 'activitypub' ),
36+
'username' => \__( 'Username', 'activitypub' ),
37+
'url' => \__( 'URL', 'activitypub' ),
38+
'published' => \__( 'Followed', 'activitypub' ),
39+
'modified' => \__( 'Last updated', 'activitypub' ),
4140
);
4241
}
4342

4443
public function get_sortable_columns() {
45-
return array();
44+
$sortable_columns = array(
45+
'post_title' => array( 'post_title', true ),
46+
'modified' => array( 'modified', false ),
47+
'published' => array( 'published', false ),
48+
);
49+
50+
return $sortable_columns;
4651
}
4752

4853
public function prepare_items() {
@@ -55,8 +60,32 @@ public function prepare_items() {
5560
$page_num = $this->get_pagenum();
5661
$per_page = 20;
5762

58-
$followers = FollowerCollection::get_followers( $this->user_id, $per_page, $page_num );
59-
$counter = FollowerCollection::count_followers( $this->user_id );
63+
$args = array();
64+
65+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
66+
if ( isset( $_GET['orderby'] ) ) {
67+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
68+
$args['orderby'] = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
69+
}
70+
71+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
72+
if ( isset( $_GET['order'] ) ) {
73+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
74+
$args['order'] = sanitize_text_field( wp_unslash( $_GET['order'] ) );
75+
}
76+
77+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
78+
if ( isset( $_GET['s'] ) && isset( $_REQUEST['_wpnonce'] ) ) {
79+
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
80+
if ( wp_verify_nonce( $nonce, 'bulk-' . $this->_args['plural'] ) ) {
81+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
82+
$args['s'] = sanitize_text_field( wp_unslash( $_GET['s'] ) );
83+
}
84+
}
85+
86+
$followers_with_count = FollowerCollection::get_followers_with_count( $this->user_id, $per_page, $page_num, $args );
87+
$followers = $followers_with_count['followers'];
88+
$counter = $followers_with_count['total'];
6089

6190
$this->items = array();
6291
$this->set_pagination_args(
@@ -69,14 +98,13 @@ public function prepare_items() {
6998

7099
foreach ( $followers as $follower ) {
71100
$item = array(
72-
'icon' => esc_attr( $follower->get_icon_url() ),
73-
'name' => esc_attr( $follower->get_name() ),
74-
'username' => esc_attr( $follower->get_preferred_username() ),
75-
'url' => esc_attr( $follower->get_url() ),
76-
'identifier' => esc_attr( $follower->get_id() ),
77-
'updated' => esc_attr( $follower->get_updated() ),
78-
'errors' => $follower->count_errors(),
79-
'latest-error' => $follower->get_latest_error_message(),
101+
'icon' => esc_attr( $follower->get_icon_url() ),
102+
'post_title' => esc_attr( $follower->get_name() ),
103+
'username' => esc_attr( $follower->get_preferred_username() ),
104+
'url' => esc_attr( $follower->get_url() ),
105+
'identifier' => esc_attr( $follower->get_id() ),
106+
'published' => esc_attr( $follower->get_published() ),
107+
'modified' => esc_attr( $follower->get_updated() ),
80108
);
81109

82110
$this->items[] = $item;
@@ -116,11 +144,11 @@ public function column_cb( $item ) {
116144
}
117145

118146
public function process_action() {
119-
if ( ! isset( $_REQUEST['followers'] ) || ! isset( $_REQUEST['_apnonce'] ) ) {
147+
if ( ! isset( $_REQUEST['followers'] ) || ! isset( $_REQUEST['_wpnonce'] ) ) {
120148
return false;
121149
}
122-
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_apnonce'] ) );
123-
if ( ! wp_verify_nonce( $nonce, 'activitypub-followers-list' ) ) {
150+
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
151+
if ( ! wp_verify_nonce( $nonce, 'bulk-' . $this->_args['plural'] ) ) {
124152
return false;
125153
}
126154

templates/blog-user-followers-list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<input type="hidden" name="tab" value="followers" />
2222
<?php
2323
$table->prepare_items();
24+
$table->search_box( 'Search', 'search' );
2425
$table->display();
2526
?>
26-
<?php wp_nonce_field( 'activitypub-followers-list', '_apnonce' ); ?>
2727
</form>
2828
</div>

templates/user-followers-list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<input type="hidden" name="page" value="activitypub-followers-list" />
1515
<?php
1616
$table->prepare_items();
17+
$table->search_box( 'Search', 'search' );
1718
$table->display();
1819
?>
19-
<?php wp_nonce_field( 'activitypub-followers-list', '_apnonce' ); ?>
2020
</form>
2121
</div>

0 commit comments

Comments
 (0)