=== Safe Function Call === Contributors: coffee2code Donate link: http://coffee2code.com/donate Tags: function, template, plugin, error, coffee2code Requires at least: 1.5 Tested up to: 2.9.1 Stable tag: 1.1 Version: 1.1 Safely and easily call functions that may not be available (such as those provided by a plugin that gets deactivated) == Description == Safely and easily call functions that may not be available (such as those provided by a plugin that gets deactivated). Assuming you had something like this in a template: `` If you deactivated the plugin that provided `list_cities()`, your site would generate an error when that template is accessed. You can instead use `_sfc()`, which is provided by this plugin to call other functions, like so: `` That will simply do nothing if the `list_cities()` function is not available. If you'd rather display a message when the function does not exist, use `_sfcm()` instead, like so: `` In this case, if `list_cities()` is not available, the text "The cities listing is temporarily disabled." will be displayed. If you'd rather call another function when the function does not exist, use _sfcf() instead, like so: `` In the event you want to safely call a function and echo its value, you can use `_sfce()` like so: `` Which is roughly equivalent to doing : `` == Installation == 1. Unzip `safe-function-call.zip` inside the `/wp-content/plugins/` directory (or install via the built-in WordPress plugin installer) 1. Activate the plugin through the 'Plugins' admin menu in WordPress 1. Use any of the four functions provided by this plugin as desired == Template Tags == The plugin provides four functions for your use. *Note: These functions are not limited to use in templates* = Functions = * `` This will safely invoke the function by the name of `$function_name`. You can specify an arbitrary number of additional arguments that will get passed to `$function_name()`. If `$function_name()` does not exist, nothing is displayed and no error is generated. * `` The same as `_sfc()` except that it echoes the return value of `$function_name()` before returning that value. * `` The same as `_sfc()` except that it invokes `$function_name_if_missing()` (if it exists), if `$function_name()` does not exist. `$function_name_if_missing()` is sent `$function_name` as its first argument, and then subsequently all arguments that would have otherwise been sent to `$function_name()`. * `` The same as `_sfc()` except that it displays a message (the value of `$message_if_missing`), if `$function_name()` does not exist. = Arguments = * `$function_name` A string representing the name of the function to be called. * `$message_if_missing` (For `_sfcm()` only.) The message to be displayed if `$function_name()` does not exist as a function. * `$function_name_if_missing` (For `_sfcf()` only.) The function to be called if `$function_name()` does not exist as a function. = Examples = * `` "Austin, Dallas, Fort Worth" * `` "" * `` "Austin, Dallas, Fort Worth" * `` "Unable to list cities at the moment" * `` "Houston" * `` == Frequently Asked Questions == = Do the functions provided by this plugin capture any error messages generated by the specified function? = No. = Why would I use any of these functions instead of checking if `function_exists()` directly? = The functions provided by this plugin provide a more concise syntax for checking for function existence (using `function_exists()` under the hood). `_sfce()` will both echo and return the echoed value, which may be of use in certain circumstances. And also, since the name of the function to be safely called is passed as an argument, it can be easily and more concisely be parameterized. == Changelog == = 1.1 = * Add new template function _sfcf() to allow calling a function when the intended function isn't available * Add PHPDoc documentation * Minor formatting tweaks * Note compatibility with WP 2.9+ * Update copyright date * Update readme.txt (including adding Changelog) = 1.0 = * Initial release