Version: 1.1.5 Safely and easily call functions that may not be available (such as those provided by a plugin that gets deactivated)
The plugin provides four functions for your use. Note: These functions are not limited to use in templates
<?php function _sfc($function_name) ?>
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.
<?php function _sfce($function_name) ?>
The same as _sfc() except that it echoes the return value of $function_name() before returning that value.
<?php function _sfcf($function_name, $function_name_if_missing = '') ?>
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().
<?php function _sfcm($function_name, $message_if_missing = '') ?>
The same as _sfc() except that it displays a message (the value of $message_if_missing), if $function_name() does not exist.
$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.
<?php _sfc('list_cities', 'Texas', 3); /* Assuming list_cities() is a valid function */ ?>
"Austin, Dallas, Fort Worth"
<?php _sfc('list_cities', 'Texas', 3); /* Assuming list_cities() is not a valid function */ ?>
""
<?php _sfcm('list_cities', 'Texas', 'Unable to list cities at the moment', 3); /* Assuming list_cities() is a valid function */ ?>
"Austin, Dallas, Fort Worth"
<?php _sfcm('list_cities', 'Texas', 'Unable to list cities at the moment', 3); /* Assuming list_cities() is not a valid function */ ?>
"Unable to list cities at the moment"
<?php _sfce('largest_city', 'Tx'); /* Assuming largest_city() is a valid function that does not echo/display its return value */ ?>
"Houston"
<?php
function unavailable_function_handler( $function_name ) {
echo "Sorry, but the function {$function_name}() does not exist.";
}
_sfcf('nonexistent_function', 'unavailable_function_handler');
?>
Requires: 1.5 or higher
Compatible up to: 3.3.2
Last Updated: 2011-7-15
Downloads: 493
Got something to say? Need help?