[wp-trac] [WordPress Trac] #57249: plugin_folder parameter in get_plugins returns empty array

WordPress Trac noreply at wordpress.org
Mon Dec 5 03:49:46 UTC 2022


#57249: plugin_folder parameter in get_plugins returns empty array
--------------------------+------------------------------
 Reporter:  antonynz      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Plugins       |     Version:  trunk
 Severity:  minor         |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by antonynz):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Replying to [comment:1 petitphp]:
 > Looking at usage in Core, `$plugin_folder` expect a relative path to a
 plugin folder : `get_plugins('/classic-editor');`.

 You're right. I should have looked further into the function. The
 documentation didn't have any specific examples and I had assumed it
 grabbed the cached version of all the plugin details based on the line
 below, and how the array keys were stored when all plugins were retrieved
 i.e (classic-editor/classic-editor.php):

 {{{#!php
 if ( isset( $cache_plugins[ $plugin_folder ] ) ) {
         return $cache_plugins[ $plugin_folder ];
 }
 }}}


 get_plugins('/classic-editor'); does return the plugin details as expected
 (with the folder pruned from the array) so the returned array is different
 when a folder is added to the request, meaning any changes to the function
 would be difficult to implement.

 > wp_cache_flush();
 get_plugins(); //miss cache
 get_plugins('/classic-editor'); //miss cache
 get_plugins(); //hit cache
 get_plugins(); //hit cache
 get_plugins('/classic-editor'); //hit cache

 I can also replicate this. I had assumed it would clear the cached array
 but it just appends the new array each time so future duplicate requests
 return a cache hit.

 This means plugins not in a directory (eg hello.php) would only be
 retrievable from requesting all plugins get_plugins(); ?


 It's an unusual set up with the cache and didn't work how I initially
 expected but happy to mark this resolved.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57249#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list