Skip to content

Commit b8b683b

Browse files
committed
Fix post search
Search uses tokens for authentication so check to see if we have a current token in addition to a logged in user. Cleanup the parameter passing to $this->get_posts() as well as otherwise some values can be set to null which break wp_getposts() in some circumstances.
1 parent 24c0179 commit b8b683b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

includes/class-mastodon-api.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,10 +1574,16 @@ public function api_search( $request ) {
15741574
);
15751575
}
15761576
}
1577-
} elseif ( is_user_logged_in() ) {
1578-
$args['s'] = $request->get_param( 'q' );
1579-
$args['offset'] = $request->get_param( 'offset' );
1580-
$args['posts_per_page'] = $request->get_param( 'limit' );
1577+
} elseif ( is_user_logged_in() || $this->oauth->get_token() ) {
1578+
$q_param = $request->get_param( 'q' );
1579+
if( $q_param != null ) { $args['s'] = $q_param; }
1580+
1581+
$offset_param = $request->get_param( 'offset' );
1582+
if( $offset_param != null ) { $args['offset'] = $offset_param; }
1583+
1584+
$ppp_param = $request->get_param( 'limit' );
1585+
if( $ppp_param != null ) { $args['posts_per_page'] = $ppp_param; }
1586+
15811587
$ret['statuses'] = array_merge( $ret['statuses'], $this->get_posts( $args ) );
15821588
}
15831589
}

0 commit comments

Comments
 (0)