WordPress plugin intelligence profile

Safe Function Call

Safely and easily call functions that may not be available (such as those provided by a plugin that gets deactivated)

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 6.8
Current version1.4
WordPress coverageTested up to WordPress 6.8
Minimum stackWP 1.5 · PHP —
Directory statusactive
Last directory update14 Apr 20251y ago
Active installations10Adoption metric — not a quality score
WordPress.org rating5.0 / 5 from 1 ratings
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records Safe Function Call version 1.4 as active, updated 1y ago and tested up to WordPress 6.8.

Overview

About this plugin

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:

>

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:

>

” 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:

>

Filter invocation method

To further prevent issues in your code should this plugin itself become deactivated, you can use indirect filter invocation to call the plugin functions. Each function has an associated filter with the same name as the function. Simply use apply_filters() to invoke that function instead of calling the function directly.

g. instead of:

>

Do:

>

If you’re relying on the return value of a function and this plugin gets deactivated, note that the apply_filters() call will return the name of the function you intended to call, so you should check the return value to ensure the function got called.

Instead of:

>

Do:

== 'some_plugin_function' ) { // Work with the value of $x here. } else { // The Safe Function Call plugin isn't active. $x = 0; // Maybe set the variable to something that makes sense in this scenario.

>

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

Developer Documentation

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:

  • _sfc(): Safely call a function and get its return value.
  • _sfce(): Safely call a function and echo its sanitized 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).

These are the hooks provided by the plugin. They are intended for filter invocation usage rather than typical content filtering.

  • _sfc: Filter to safely invoke _sfc() 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.
  • _sfce: Filter to safely invoke _sfce() 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.
  • _sfcf: Filter to safely invoke _sfcf() 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.
  • _sfcm: Filter to safely invoke _sfcm() 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.
WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • coffee2code
  • error
  • function
  • template
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 6.8

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 6.8.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to6.8
Minimum requirementsWordPress 1.5 · PHP not listed
Update activity14 Apr 20251y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.