@@ -161,8 +161,16 @@ public static function do_directory_request($args = [], $type = 'plugins')
161
161
162
162
$ e = wp_remote_retrieve_response_code ($ response );
163
163
if ($ e !== 200 ) {
164
- $ result ['error ' ] = $ response ['response ' ]['message ' ];
164
+ $ result ['error ' ] = $ response ['response ' ]['message ' ]. ' . ' ;
165
165
$ result ['code ' ] = $ response ['response ' ]['code ' ];
166
+ if (!isset ($ response ['body ' ]) || !json_validate ($ response ['body ' ])) {
167
+ return $ result ;
168
+ }
169
+ $ api_message = json_decode ($ response ['body ' ], true );
170
+ if (!isset ($ api_message ['message ' ])) {
171
+ return $ result ;
172
+ }
173
+ $ result ['error ' ] .= ' ' .$ api_message ['message ' ];
166
174
return $ result ;
167
175
}
168
176
@@ -343,6 +351,11 @@ public function render_menu()
343
351
if (isset ($ _REQUEST ['searchfor ' ])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
344
352
$ args ['search ' ] = sanitize_text_field (wp_unslash ($ _REQUEST ['searchfor ' ])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
345
353
}
354
+ // Reset paginations for new searches
355
+ $ searching = $ args ['search ' ] ?? '' ;
356
+ if (isset ($ _REQUEST ['searchingfor ' ]) && $ _REQUEST ['searchingfor ' ] !== $ searching ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
357
+ $ args ['page ' ] = 1 ;
358
+ }
346
359
347
360
$ result = $ this ->do_directory_request ($ args );
348
361
if ($ result ['success ' ] === false ) {
@@ -371,10 +384,11 @@ public function render_menu()
371
384
<form method="GET" action="<?php echo esc_url (add_query_arg (['page ' => 'classicpress-directory-integration-plugin-install ' ], remove_query_arg (['getpage ' ]))); ?> ">
372
385
<p class="cp-plugin-search-box">
373
386
<label for="searchfor" class="screen-reader-text" ><?php echo esc_html__ ('Search for plugins ' , 'classicpress-directory-integration ' ); ?> </label><br>
374
- <input type="text" id="searchfor" name="searchfor" class="wp-filter-search" placeholder="<?php echo esc_html__ ('Search for a plugin... ' , 'classicpress-directory-integration ' ); ?> "><br>
387
+ <input type="hidden" name="searchingfor" value="<?php echo esc_html ($ searching ); ?> ">
388
+ <input type="search" id="searchfor" name="searchfor" class="wp-filter-search" <?php echo $ searching !== '' ? 'value=" ' .esc_html ($ searching ).'" ' : '' ?> placeholder="<?php echo esc_html__ ('Search for a plugin... ' , 'classicpress-directory-integration ' ); ?> "><br>
375
389
<?php
376
390
foreach ((array ) $ _GET as $ key => $ val ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
377
- if (in_array ($ key , ['searchfor ' ])) {
391
+ if (in_array ($ key , ['searchfor ' , ' getpage ' ])) {
378
392
continue ;
379
393
}
380
394
echo '<input type="hidden" name=" ' . esc_attr ($ key ) . '" value=" ' . esc_html ($ val ) . '" /> ' ;
0 commit comments