{"id":5685,"date":"2009-06-12T00:42:16","date_gmt":"2009-06-12T00:42:16","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/if-file-exists\/"},"modified":"2025-04-18T07:54:34","modified_gmt":"2025-04-18T07:54:34","slug":"if-file-exists","status":"publish","type":"plugin","link":"https:\/\/frp.wordpress.org\/plugins\/if-file-exists\/","author":3606,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"2.4","stable_tag":"2.4","tested":"6.8.5","requires":"2.7","requires_php":"","requires_plugins":null,"header_name":"If File Exists","header_author":"Scott Reilly","header_description":"","assets_banners_color":"0074a2","last_updated":"2025-04-18 07:54:34","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\/if-file-exists\/","header_author_uri":"https:\/\/coffee2code.com\/","rating":5,"author_block_rating":0,"active_installs":10,"downloads":12530,"num_ratings":1,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":{"1.0.1":{"tag":"1.0.1","author":"coffee2code","date":"2009-06-12 00:42:16"},"1.0.3":{"tag":"1.0.3","author":"coffee2code","date":"2010-01-07 21:17:53"},"2.0":{"tag":"2.0","author":"coffee2code","date":"2010-09-06 16:26:16"},"2.1":{"tag":"2.1","author":"coffee2code","date":"2011-07-12 12:55:54"},"2.1.1":{"tag":"2.1.1","author":"coffee2code","date":"2011-12-13 17:25:42"},"2.1.2":{"tag":"2.1.2","author":"coffee2code","date":"2012-06-04 15:52:42"},"2.1.3":{"tag":"2.1.3","author":"coffee2code","date":"2012-12-11 19:31:20"},"2.2":{"tag":"2.2","author":"coffee2code","date":"2013-12-29 21:45:14"},"2.2.1":{"tag":"2.2.1","author":"coffee2code","date":"2014-09-01 06:46:16"},"2.2.10":{"tag":"2.2.10","author":"coffee2code","date":"2021-04-15 07:05:42"},"2.2.2":{"tag":"2.2.2","author":"coffee2code","date":"2015-09-08 05:58:32"},"2.2.3":{"tag":"2.2.3","author":"coffee2code","date":"2016-04-14 20:09:14"},"2.2.4":{"tag":"2.2.4","author":"coffee2code","date":"2017-02-27 21:42:04"},"2.2.5":{"tag":"2.2.5","author":"coffee2code","date":"2018-06-30 06:02:39"},"2.2.6":{"tag":"2.2.6","author":"coffee2code","date":"2019-05-24 17:29:40"},"2.2.7":{"tag":"2.2.7","author":"coffee2code","date":"2019-11-23 06:28:16"},"2.2.8":{"tag":"2.2.8","author":"coffee2code","date":"2020-04-30 07:45:36"},"2.2.9":{"tag":"2.2.9","author":"coffee2code","date":"2020-09-03 07:38:53"},"2.3":{"tag":"2.3","author":"coffee2code","date":"2021-10-15 06:32:03"},"2.3.1":{"tag":"2.3.1","author":"coffee2code","date":"2023-08-21 18:56:31"},"2.3.2":{"tag":"2.3.2","author":"coffee2code","date":"2024-08-11 05:14:45"},"2.4":{"tag":"2.4","author":"coffee2code","date":"2025-04-18 07:54:34"}},"upgrade_notice":{"2.4":"<p>Minor update: added &#039;%file_size%&#039; and &#039;%file_size_bytes%&#039; substitution tags, escaped output before display to prevent unsafe markup, noted compatibility through WP 6.8+ and PHP 8.3+, and updated copyright date (2025)<\/p>","2.3.2":"<p>Trivial update: noted compatibility through WP 6.6+, removed unit tests from release packaging, and updated copyright date (2024)<\/p>","2.3.1":"<p>Trivial update: noted compatibility through WP 6.3+ and updated copyright date (2023)<\/p>","2.3":"<p>Minor update: removed support for long-deprecated <code>if_file_exists()<\/code>, added DEVELOPER-DOCS.md, noted compatibility through WP 5.8+, and minor reorganization and tweaks to unit tests<\/p>","2.2.10":"<p>Trivial update: noted compatibility through WP 5.7+ and updated copyright date (2021)<\/p>","2.2.9":"<p>Trivial update: Restructured unit test file structure and noted compatibility through WP 5.5+.<\/p>","2.2.8":"<p>Trivial update: Fixed a link in readme.txt, updated a few URLs to be HTTPS and noted compatibility through WP 5.4+.<\/p>","2.2.7":"<p>Trivial update: noted compatibility through WP 5.3+ and updated copyright date (2020).<\/p>","2.2.6":"<p>Trivial update: created CHANGELOG.md to store historical changelog outside of readme.txt, noted compatibility through WP 5.1+, and updated copyright date (2019)<\/p>","2.2.5":"<p>Trivial update: noted compatibility through WP 4.9+, added README.md for GitHub, updated copyright date (2018), and other minor changes<\/p>","2.2.4":"<p>Trivial update: fixed some unit tests, noted compatibility through WP 4.7+, updated copyright date<\/p>","2.2.3":"<p>Trivial update: improved support for localization, minor unit test tweaks, verified compatibility through WP 4.4+, and updated copyright date (2016)<\/p>","2.2.2":"<p>Trivial update: noted compatibility through WP 4.1+ and updated copyright date (2015)<\/p>","2.2.1":"<p>Trivial update: noted compatibility through WP 4.0+; added plugin icon.<\/p>","2.2":"<p>Recommended minor update: fixed a few minor bugs; added unit tests; noted compatibility through WP 3.8+<\/p>","2.1.3":"<p>Trivial update: noted compatibility through WP 3.5+; minor documentation changes<\/p>","2.1.2":"<p>Trivial update: noted compatibility through WP 3.4+; explicitly stated license<\/p>","2.1.1":"<p>Trivial update: noted compatibility through WP 3.3+ and minor readme.txt tweaks<\/p>","2.1":"<p>Recommended minor update. Highlights: fixed a few minor bugs, added tests, clarified\/updated some documentation, and verified compatibility with WordPress 3.2.<\/p>","2.0":"<p>Recommended feature update. Highlights: added c2c_if_plugin_file_exists() and c2c_if_theme_file_exists(); added %file_directory% and %file_extension%; added hooks for customization; minor fixes and tweaks; renamed blog_time() to c2c_blog_time(); renamed class; 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":976276,"resolution":"128x128","location":"assets","locale":""}},"assets_banners":{"banner-772x250.png":{"filename":"banner-772x250.png","revision":829848,"resolution":"772x250","location":"assets","locale":""}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0.1","1.0.3","2.0","2.1","2.1.1","2.1.2","2.1.3","2.2","2.2.1","2.2.10","2.2.2","2.2.3","2.2.4","2.2.5","2.2.6","2.2.7","2.2.8","2.2.9","2.3","2.3.1","2.3.2","2.4"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[2758,35785,35784,260,9745],"plugin_category":[],"plugin_contributors":[78189],"plugin_business_model":[],"class_list":["post-5685","plugin","type-plugin","status-publish","hentry","plugin_tags-coffee2code","plugin_tags-existence","plugin_tags-exists","plugin_tags-file","plugin_tags-filesystem","plugin_contributors-coffee2code","plugin_committers-coffee2code"],"banners":{"banner":"https:\/\/ps.w.org\/if-file-exists\/assets\/banner-772x250.png?rev=829848","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/if-file-exists\/assets\/icon-128x128.png?rev=976276","icon_2x":false,"generated":false},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin provides the functions <code>c2c_if_file_exists()<\/code>, <code>c2c_if_theme_file_exists()<\/code>, <code>c2c_if_plugin_file_exists()<\/code> that check if a file exists and either return true\/false or display a string containing information about the file.<\/p>\n\n<ul>\n<li>If a format string is not passed to it, the functions returns a simple boolean (true or false) indicating if the specified file exists.<\/li>\n<li>Otherwise, the format string provided to it will be used to construct a response string, which can be customized to display information about the file (such as directory, extension, name, path, size, or url). If the <code>$echo<\/code> argument is true, that string is displayed on the page. Regardless of the value of <code>$echo<\/code>, the response string is returned by the function.<\/li>\n<\/ul>\n\n<p>By default, <code>c2c_if_file_exists()<\/code> assumes you are looking for the file relative to the default WordPress upload directory. If you wish to search another directory, specify it as the <code>$dir<\/code> argument. <code>c2c_if_theme_file_exists()<\/code> assumes you are looking for a file relative to the currently active theme's home directory. <code>c2c_if_plugin_file_exists()<\/code> assumes you are looking for a file relative to the directory that contains WordPress plugins.<\/p>\n\n<p>Links: <a href=\"https:\/\/coffee2code.com\/wp-plugins\/if-file-exists\/\">Plugin Homepage<\/a> | <a href=\"https:\/\/wordpress.org\/plugins\/if-file-exists\/\">Plugin Directory Page<\/a> | <a href=\"https:\/\/github.com\/coffee2code\/if-file-exists\/\">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\/if-file-exists\/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_if_file_exists()<\/code>        : Checks if a file exists and returns true\/false or displays a string containing information about the file.<\/li>\n<li><code>c2c_if_plugin_file_exists()<\/code> : Checks if a file exists (relative to the plugins directory) and returns true\/false or displays a string containing information about the file.<\/li>\n<li><code>c2c_if_theme_file_exists()<\/code>  : Checks if a file exists (relative to the current theme's directory) and returns true\/false or displays a string containing information about the file. If the current theme is a child theme, then the function will check if the file exists first in the child theme's directory, and if not there, then it will check the parent theme's directory.<\/li>\n<\/ul>\n\n<p>These are the hooks provided by the plugin:<\/p>\n\n<ul>\n<li><code>c2c_if_file_exists<\/code>        : Filter that allows use of an alternative approach to safely invoke <code>c2c_if_file_exists()<\/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_if_plugin_file_exists<\/code> : Filter that allows use of an alternative approach to safely invoke <code>c2c_if_plugin_file_exists()<\/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_if_theme_file_exists<\/code>  : Filter that allows use of an alternative approach to safely invoke <code>c2c_if_theme_file_exists()<\/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 install the plugin 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>In one or more of your templates, utilize one of the template tags provided by this plugin (see examples)<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<h4>2.4 (2025-04-18)<\/h4>\n\n<ul>\n<li>New: Add '%file_size%' and '%file_size_bytes%' as additional substitution tags<\/li>\n<li>Change: Escape <code>$format<\/code> and <code>$show_if_not_exists<\/code> values prior to display to omit unsafe markup<\/li>\n<li>Change: Discontinue unnecessary explicit loading of textdomain<\/li>\n<li>Change: Note compatibility through WP 6.8+<\/li>\n<li>Change: Note compatibility through PHP 8.3+<\/li>\n<li>Change: Update copyright date (2025)<\/li>\n<li>Unit tests:\n\n<ul>\n<li>Change: Change test class name to match plugin name<\/li>\n<\/ul><\/li>\n<\/ul>\n\n<h4>2.3.2 (2024-08-02)<\/h4>\n\n<ul>\n<li>Change: Note compatibility through WP 6.6+<\/li>\n<li>Change: Update copyright date (2024)<\/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 <code>composer.json<\/code> for PHPUnit Polyfill dependency<\/li>\n<li>Change: In bootstrap, store path to plugin directory in a constant<\/li>\n<\/ul><\/li>\n<\/ul>\n\n<h4>2.3.1 (2023-05-18)<\/h4>\n\n<ul>\n<li>Change: Note compatibility through WP 6.3+<\/li>\n<li>Change: Update copyright date (2023)<\/li>\n<li>New: Add a potential TODO item<\/li>\n<\/ul>\n\n<p><em>Full changelog is available in <a href=\"https:\/\/github.com\/coffee2code\/if-file-exists\/blob\/master\/CHANGELOG.md\">CHANGELOG.md<\/a>.<\/em><\/p>","raw_excerpt":"Check if a file exists and return true\/false or display a string containing information about the file.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/5685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"author":[{"embeddable":true,"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/users\/3606"}],"replies":[{"embeddable":true,"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=5685"}],"wp:attachment":[{"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=5685"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=5685"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=5685"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=5685"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=5685"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/frp.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=5685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}