
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:
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' ); } ?> 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.
E.g. instead of:
<?php _sfce( 'some_plugin_function_that_echoes', 'argument' ); ?>
Do:
<?php apply_filters( '_sfce', 'some_plugin_function_that_echoes', 'argument' ); ?>
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:
<?php $x = _sfc( 'some_plugin_function', 'argument' ); ?>
Do:
<?php $x = apply_filters( '_sfcq', 'some_plugin_function', 'argument' ); if ( $x !== '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 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:
Theses are the hooks provided by the plugin. They are intended for filter invocation usage rather than typical content filtering.
Starting from $0 per month.
Rating
Reviewers
1 reviews
Tags
Developed By
Scott Reilly
Quick & Easy
Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!
Testimonial plugins for Wordpress
Galleries plugins for Wordpress
SEO plugins for Wordpress
Contact Form plugins for Wordpress
Forms plugins for Wordpress
Social Feeds plugins for Wordpress
Social Sharing plugins for Wordpress
Events Calendar plugins for Wordpress
Sliders plugins for Wordpress
Analytics plugins for Wordpress
Reviews plugins for Wordpress
Comments plugins for Wordpress
Portfolio plugins for Wordpress
Maps plugins for Wordpress
Security plugins for Wordpress
Translation plugins for Wordpress
Ads plugins for Wordpress
Video Player plugins for Wordpress
Music Player plugins for Wordpress
Backup plugins for Wordpress
Privacy plugins for Wordpress
Optimize plugins for Wordpress
Chat plugins for Wordpress
Countdown plugins for Wordpress
Email Marketing plugins for Wordpress
Tabs plugins for Wordpress
Membership plugins for Wordpress
popup plugins for Wordpress
SiteMap plugins for Wordpress
Payment plugins for Wordpress
Coming Soon plugins for Wordpress
Ecommerce plugins for Wordpress
Customer Support plugins for Wordpress
Inventory plugins for Wordpress
Video Player plugins for Wordpress
Testimonials plugins for Wordpress
Tabs plugins for Wordpress
Social Sharing plugins for Wordpress
Social Feeds plugins for Wordpress
Slider plugins for Wordpress
Reviews plugins for Wordpress
Portfolio plugins for Wordpress
Membership plugins for Wordpress
Forms plugins for Wordpress
Events Calendar plugins for Wordpress
Contact plugins for Wordpress
Comments plugins for Wordpress
Analytics plugins for Wordpress
Common Ninja Apps
Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.
Use Collapsible Content sections to structure information on your site and make it easier for visitors to find what they need.
Add an interactive before and after slider to your site to show visual transformations, capture attention, and help visitors understand real results.
Show Messenger conversations on your website in a clear, authentic chat format.
Show posts in an X feed that keeps updates visible, improves content discovery, and helps visitors stay engaged with your latest activity.
Show Bluesky posts with a Bluesky feed that updates in real time, improves content discovery, and keeps visitors engaged with fresh activity.
Show trust badges that highlight security and reliability, build customer confidence, and help visitors feel safe making purchases on your site.
Create interactive flash cards that present questions and answers in a clear, customizable format to support learning, training, and user engagement.
Show Capterra reviews to build trust, strengthen credibility, and help visitors make confident software buying decisions that support higher sales.
Show Instagram posts in a responsive carousel layout to enhance social proof and keep your site content visually fresh.
Add WhatsApp Chat to your site to communicate with visitors, deliver instant support, and create a smoother, more trustworthy user experience.
Showcase visuals with an image grid slider that blends a grid layout and carousel motion to create a dynamic, customizable, mobile-friendly display.
Add an FAQ section to your site to answer common questions, reduce support requests, and give visitors a smoother and more confident user experience.
More plugins
The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!
