If File Exists

If File Exists Install Statistics

0
100%
Today: 11 Yesterday: 11 All-time: 8,850 downloads
If File Exists Icon

Try plugin: If File Exists

We'll create fresh WordPress site with If File Exists installed. You have 20 minutes to test the plugin after that site we'll be deleted.

Takes ~10 seconds to install.

About If File Exists

Check if a file exists and return true/false or display a string containing information about the file.

1


0


0


0


0

updated: 1 year ago
since: 15 years ago
author: Scott Reilly

Description

This plugin provides the functions c2c_if_file_exists(), c2c_if_theme_file_exists(), c2c_if_plugin_file_exists() that check if a file exists and either return true/false or display a string containing information about the file.

  • If a format string is not passed to it, the functions return a simple boolean (true or false) indicating if the specified file exists.
  • 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 file_name, file_url, or file_path). If the $echo argument is true, that string is displayed on the page. Regardless of the value of $echo, the response string is returned by the function.

By default, c2c_if_file_exists() 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 $dir argument. c2c_if_theme_file_exists() assumes you are looking for a file relative to the currently active theme’s home directory. c2c_if_plugin_file_exists() assumes you are looking for a file relative to the directory that contains WordPress plugins.

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Developer Documentation

Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the template tags and hooks provided by the plugin.

As an overview, these are the template tags provided by the plugin:

  • c2c_if_file_exists() : Checks if a file exists and returns true/false or displays a string containing information about the file.
  • c2c_if_plugin_file_exists() : Checks if a file exists (relative to the plugins directory) and returns true/false or displays a string containing information about the file.
  • c2c_if_theme_file_exists() : 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.

Theses are the hooks provided by the plugin:

  • c2c_if_file_exists : Filter that allows use of an alternative approach to safely invoke c2c_if_file_exists() 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.
  • c2c_if_plugin_file_exists : Filter that allows use of an alternative approach to safely invoke c2c_if_plugin_file_exists() 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.
  • c2c_if_theme_file_exists : Filter that allows use of an alternative approach to safely invoke c2c_if_theme_file_exists() 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.