{"id":1565,"date":"2004-12-21T21:15:09","date_gmt":"2004-12-21T21:15:09","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/random-file\/"},"modified":"2025-04-08T22:19:04","modified_gmt":"2025-04-08T22:19:04","slug":"random-file","status":"publish","type":"plugin","link":"https:\/\/lv.wordpress.org\/plugins\/random-file\/","author":3606,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"2.0.1","stable_tag":"2.0.1","tested":"6.8.5","requires":"2.8","requires_php":"","requires_plugins":null,"header_name":"Random File","header_author":"Scott Reilly","header_description":"","assets_banners_color":"0074a2","last_updated":"2025-04-08 22:19:04","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_s-xclick&hosted_button_id=6ARCFJ9TX3522","header_plugin_uri":"https:\/\/coffee2code.com\/wp-plugins\/random-file\/","header_author_uri":"https:\/\/coffee2code.com\/","rating":5,"author_block_rating":0,"active_installs":80,"downloads":29324,"num_ratings":1,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":{"1.0":{"tag":"1.0","author":"coffee2code","date":"2009-06-20 04:54:05"},"1.5":{"tag":"1.5","author":"coffee2code","date":"2009-06-20 05:00:46"},"1.5.1":{"tag":"1.5.1","author":"coffee2code","date":"2009-07-20 19:00:39"},"1.5.2":{"tag":"1.5.2","author":"coffee2code","date":"2010-01-05 05:06:49"},"1.6":{"tag":"1.6","author":"coffee2code","date":"2010-09-06 18:20:10"},"1.6.1":{"tag":"1.6.1","author":"coffee2code","date":"2011-07-11 22:53:31"},"1.6.2":{"tag":"1.6.2","author":"coffee2code","date":"2011-12-14 06:16:20"},"1.7":{"tag":"1.7","author":"coffee2code","date":"2012-06-12 06:04:29"},"1.7.1":{"tag":"1.7.1","author":"coffee2code","date":"2012-12-16 08:05:21"},"1.8":{"tag":"1.8","author":"coffee2code","date":"2014-01-12 09:05:21"},"1.8.1":{"tag":"1.8.1","author":"coffee2code","date":"2015-09-05 06:20:36"},"1.8.10":{"tag":"1.8.10","author":"coffee2code","date":"2021-04-24 06:19:57"},"1.8.11":{"tag":"1.8.11","author":"coffee2code","date":"2021-09-20 07:01:12"},"1.8.12":{"tag":"1.8.12","author":"coffee2code","date":"2023-08-22 18:16:27"},"1.8.2":{"tag":"1.8.2","author":"coffee2code","date":"2016-04-13 22:15:46"},"1.8.3":{"tag":"1.8.3","author":"coffee2code","date":"2017-02-27 18:57:28"},"1.8.4":{"tag":"1.8.4","author":"coffee2code","date":"2018-06-18 16:27:36"},"1.8.5":{"tag":"1.8.5","author":"coffee2code","date":"2019-03-05 05:39:11"},"1.8.6":{"tag":"1.8.6","author":"coffee2code","date":"2019-06-15 05:53:28"},"1.8.7":{"tag":"1.8.7","author":"coffee2code","date":"2019-12-15 08:11:02"},"1.8.8":{"tag":"1.8.8","author":"coffee2code","date":"2020-05-04 08:05:50"},"1.8.9":{"tag":"1.8.9","author":"coffee2code","date":"2020-08-31 07:38:31"},"2.0":{"tag":"2.0","author":"coffee2code","date":"2024-08-13 22:15:59"},"2.0.1":{"tag":"2.0.1","author":"coffee2code","date":"2025-04-08 22:19:04"}},"upgrade_notice":{"2.0.1":"<p>Trivial update: fixed some typos in documentation, noted compatibility through WP 6.8+, and updated copyright date (2025).<\/p>","2.0":"<p>Minor update: improved randomization of file selection, added support for the extensions arugment to be an array, noted compatibility through WP 6.6+, removed unit tests from release packaging, updated copyright date (2024), and other code improvements and minor changes<\/p>","1.8.12":"<p>Trivial update: added DEVELOPER-DOCS.md, noted compatibility through WP 6.3+, and updated copyright date (2023)<\/p>","1.8.11":"<p>Trivial update: noted compatibility through WP 5.8+ and minor reorganization and tweaks to unit tests<\/p>","1.8.10":"<p>Trivial update: noted compatibility through WP 5.7+ and updated copyright date (2021).<\/p>","1.8.9":"<p>Trivial update: Restructured unit test file structure, added a TODO.md file, and noted compatibility through WP 5.5+.<\/p>","1.8.8":"<p>Trivial update: Updated a few URLs to be HTTPS and noted compatibility through WP 5.4+.<\/p>","1.8.7":"<p>Trivial update: noted compatibility through WP 5.3+ and updated copyright date (2020)<\/p>","1.8.6":"<p>Trivial update: modernized unit tests, noted compatibility through WP 5.2+<\/p>","1.8.5":"<p>Trivial update: noted compatibility through WP 5.1+, updated copyright date (2019)<\/p>","1.8.4":"<p>Trivial update: noted compatibility through WP 4.9+, added README.md for GitHub, and updated copyright date (2018)<\/p>","1.8.3":"<p>Recommended minor update: fixed inccorect name of variable, noted compatibility through WP 4.7+, updated copyright date<\/p>","1.8.2":"<p>Trivial update: noted compatibility through WP 4.4+ and updated copyright date (2016)<\/p>","1.8.1":"<p>Trivial update: noted compatibility through WP 4.1+ and updated copyright date (2015)<\/p>","1.8":"<p>Recommended minor update: fixed bug which prevented specified multiple file extensions from working; added unit tests; noted compatibility through WP 3.8+<\/p>","1.7.1":"<p>Trivial update: noted compatibility through WP 3.5+<\/p>","1.7":"<p>Recommended minor update: improved compatibility and data sanitization; noted compatibility through WP 3.4+; explicitly stated license<\/p>","1.6.2":"<p>Trivial update: noted compatibility through WP 3.3+<\/p>","1.6.1":"<p>Trivial update: noted compatibility through WP 3.2+<\/p>","1.6":"<p>Feature update. Highlights: added c2c_random_files() to retrieve array of random unique files; added hooks to allow customizations; verified WP 3.0 compatibility.<\/p>"},"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"1"},"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":1091134,"resolution":"128x128","location":"assets","locale":""}},"assets_banners":{"banner-772x250.png":{"filename":"banner-772x250.png","revision":837026,"resolution":"772x250","location":"assets","locale":""}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0","1.5","1.5.1","1.5.2","1.6","1.6.1","1.6.2","1.7","1.7.1","1.8","1.8.1","1.8.10","1.8.11","1.8.12","1.8.2","1.8.3","1.8.4","1.8.5","1.8.6","1.8.7","1.8.8","1.8.9","2.0","2.0.1"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[2758,260,88,244,3790],"plugin_category":[],"plugin_contributors":[78189],"plugin_business_model":[],"class_list":["post-1565","plugin","type-plugin","status-publish","hentry","plugin_tags-coffee2code","plugin_tags-file","plugin_tags-files","plugin_tags-random","plugin_tags-randomize","plugin_contributors-coffee2code","plugin_committers-coffee2code"],"banners":{"banner":"https:\/\/ps.w.org\/random-file\/assets\/banner-772x250.png?rev=837026","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/random-file\/assets\/icon-128x128.png?rev=1091134","icon_2x":false,"generated":false},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin provides template tags that allow you to retrieve the name, path (relative or absolute), url, or fully marked-up link to a randomly chosen file or files in a specified directory.<\/p>\n\n<p>Arguments to the functions permit you to limit what file(s) can be randomly selected based on a given set of file extensions. You can also explicitly specify files that should not be randomly selected.<\/p>\n\n<p>This functionality can be useful for displaying random images\/logos or including text from random files onto your site (writing excerpts, multi-line quotes, etc). Other ideas: random ads, random CSS files, random theme template selection.<\/p>\n\n<p>Notes:<\/p>\n\n<ul>\n<li><p>If you want to actually display the name of the random file, be sure to 'echo' the results:\n<\/p><\/li>\n<li><p>Unless you limit the file search to only include a particular extension (via <code>$extensions<\/code> argument), all files in the specified <code>$dir<\/code> will be under consideration for random selection<\/p><\/li>\n<li><p>Can be run inside or outside of \"the loop\"<\/p><\/li>\n<\/ul>\n\n<p>Links: <a href=\"https:\/\/coffee2code.com\/wp-plugins\/random-file\/\">Plugin Homepage<\/a> | <a href=\"https:\/\/wordpress.org\/plugins\/random-file\/\">Plugin Directory Page<\/a> | <a href=\"https:\/\/github.com\/coffee2code\/random-file\/\">GitHub<\/a> | <a href=\"https:\/\/coffee2code.com\">Author Homepage<\/a><\/p>\n\n<h3>Developer Documentation<\/h3>\n\n<p>Developer documentation can be found in <a href=\"https:\/\/github.com\/coffee2code\/random-file\/blob\/master\/DEVELOPER-DOCS.md\">DEVELOPER-DOCS.md<\/a>. That documentation covers the template tags and hooks provided by the plugin.<\/p>\n\n<p>As an overview, these are the template tags provided by the plugin:<\/p>\n\n<ul>\n<li><code>c2c_random_file()<\/code>  : Retrieves the name of a random file from a specified directory and returns information based on the file.<\/li>\n<li><code>c2c_random_files()<\/code> : Retrieves the name, path, or link to a specified number of randomly chosen files in a specified directory.<\/li>\n<\/ul>\n\n<p>These are the hooks provided by the plugin:<\/p>\n\n<ul>\n<li><code>c2c_random_file<\/code>  : Filter to safely invoke <code>c2c_random_file()<\/code> in such a way that if the plugin were deactivated or deleted, then your calls to the function won't cause errors in your site.<\/li>\n<li><code>c2c_random_files<\/code> : Filter to safely invoke <code>c2c_random_files()<\/code> in such a way that if the plugin were deactivated or deleted, then your calls to the function won't cause errors in your site.<\/li>\n<\/ul>\n\n<!--section=installation-->\n<ol>\n<li>Install via the built-in WordPress plugin installer. Or download and unzip <code>random-file.zip<\/code> inside the plugins directory for your site (typically <code>wp-content\/plugins\/<\/code>)<\/li>\n<li>Activate the plugin through the 'Plugins' admin menu in WordPress<\/li>\n<li>Make use of the <code>c2c_random_file()<\/code> or <code>c2c_random_files()<\/code> template function in your code or template (see examples below).<\/li>\n<\/ol>\n\n<!--section=faq-->\n<dl>\n<dt id='does%20this%20plugin%20do%20dynamic%20random%20rotation%20within%20a%20loaded%20page%20%28i.e.%20randomly%20rotating%20images%20within%20a%20loaded%20page%29%3F'><h3>Does this plugin do dynamic random rotation within a loaded page (i.e. randomly rotating images within a loaded page)?<\/h3><\/dt>\n<dd><p>No. This plugin only selects a random file when the page is loaded. Once loaded, it does not currently add any dynamic functionality to automatically retrieve another random file on its own.<\/p><\/dd>\n<dt id='does%20this%20plugin%20include%20unit%20tests%3F'><h3>Does this plugin include unit tests?<\/h3><\/dt>\n<dd><p>Yes. The tests are not packaged in the release .zip file or included in plugins.svn.wordpress.org, but can be found in the <a href=\"https:\/\/github.com\/coffee2code\/random-file\/\">plugin's GitHub repository<\/a>.<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>2.0.1 (2025-04-08)<\/h4>\n\n<ul>\n<li>Fix: Fix typos in documentation<\/li>\n<li>Change: Note compatibility through WP 6.8+<\/li>\n<li>Change: Update copyright date (2025)<\/li>\n<li>Unit tests:\n\n<ul>\n<li>Change: Switch uses of <code>assertRegExp()<\/code> to <code>assertMatchesRegularExpression()<\/code> for future PHPUnit 10 compatibility<\/li>\n<li>Change: Explicitly define return type for overridden method<\/li>\n<\/ul><\/li>\n<\/ul>\n\n<h4>2.0 (2024-08-13)<\/h4>\n\n<p>Highlights:<\/p>\n\n<p>This minor update features improved randomization of file selection, adds support for the extensions argument to be an array, notes compatibility through WP 6.6+, removes unit tests from release packaging, updates copyright date (2024), and other code improvements and minor changes.<\/p>\n\n<p>Details:<\/p>\n\n<ul>\n<li>Change: Switch to using <code>wp_rand()<\/code> for more reliable randomization<\/li>\n<li>Change: Allow <code>$extensions<\/code> argument to also accept an array of extensions<\/li>\n<li>Change: Strip surrounding whitespace and leading periods from provided extensions<\/li>\n<li>Change: Explicitly return false if no file could be found<\/li>\n<li>Change: Switch to use a switch statement, which is more concise<\/li>\n<li>Change: Use cleaner <code>sprintf()<\/code> approach to outputting markup<\/li>\n<li>Hardening: Escape text shown via 'hyperlink' output (though it's never anything other than plaintext)<\/li>\n<li>Change: Note compatibility through WP 6.6+<\/li>\n<li>Change: Update copyright date (2024)<\/li>\n<li>Change: Tweak filter descriptions in <code>readme.txt<\/code><\/li>\n<li>New: Add <code>.gitignore<\/code> file<\/li>\n<li>Change: Remove development and testing-related files from release packaging<\/li>\n<li>Unit tests:\n\n<ul>\n<li>Hardening: Prevent direct web access to <code>bootstrap.php<\/code><\/li>\n<li>Allow tests to run against current versions of WordPress<\/li>\n<li>New: Add more unit tests<\/li>\n<li>New: Add <code>composer.json<\/code> for PHPUnit Polyfill dependency<\/li>\n<li>Change: In bootstrap, store path to plugin directory in a constant<\/li>\n<li>Change: Rename a test<\/li>\n<\/ul><\/li>\n<\/ul>\n\n<h4>1.8.12 (2023-05-21)<\/h4>\n\n<ul>\n<li>New: Add DEVELOPER-DOCS.md and move hooks documentation into it<\/li>\n<li>Change: Note compatibility through WP 6.3+<\/li>\n<li>Change: Update copyright date (2023)<\/li>\n<\/ul>\n\n<p><em>Full changelog is available in <a href=\"https:\/\/github.com\/coffee2code\/random-file\/blob\/master\/CHANGELOG.md\">CHANGELOG.md<\/a>.<\/em><\/p>","raw_excerpt":"Retrieve the name, path, or link to a randomly chosen file or files in a specified directory.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/1565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"author":[{"embeddable":true,"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/users\/3606"}],"replies":[{"embeddable":true,"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=1565"}],"wp:attachment":[{"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=1565"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=1565"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=1565"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=1565"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=1565"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/lv.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=1565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}