>
Download This Plugin | |
Download Elegant Themes | |
Name | Safe Function Call |
Version | 1.2.2 |
Author | Scott Reilly |
Rating | 0 |
Last updated | 2015-02-11 05:28:00 |
Downloads |
1169
|
Download Plugins Speed Test plugin for Wordpress |
Home page PageSpeed score has been degraded by 0%, while Post page PageSpeed score has been degraded by 0%
Safe Function Call plugin added 4 bytes of resources to the Home page and 4 bytes of resources to the sample Post page.
Safe Function Call plugin added 0 new host(s) to the Home page and 0 new host(s) to the sample Post page.
Great! Safe Function Call plugin ads no tables to your Wordpress blog database.Safely call a function, class method, or object method in a manner that doesn't generate errors if those plugins cease to exist.
Various helper functions are provided that provide handy variations of this theme:
_sfc()
: Safely call a function and get its return value_sfce()
: Safely call a function and echo its return value_sfcf()
: Safely call a function; if it doesn't exist, then a fallback function (if specified) is called_sfcm()
: Safely call a function; if it doesn't exist, then echo a message (if provided)Let's assume you had something like this in a template:
<?php list_cities( 'Texas', 3 ); ?>
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:
<?php _sfc( 'list_cities', 'Texas', 3 ); ?>
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:
<?php _sfcm( 'list_cities', 'The cities listing is temporarily disabled.', 'Texas', 3 ); ?>
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:
<?php
function unavailable_function_handler( $function_name ) { echo "The function $function_name is not available."; }
_sfcf( 'nonexistent_function', 'unavailable_function_handler' );
?>
In the event you want to safely call a function and echo its value, you can use _sfce()
like so:
<?php _sfce( 'largest_city', 'Tx' ); ?>
Which is roughly equivalent to doing :
<?php if function_exists( 'largest_city' ) { echo largest_city( 'Tx' ); } ?>
Links: Plugin Homepage | Plugin Directory Page | Author Homepage