Categories
Package/plugin/module WordPress

Safe Function Call v1.0

I’d like to announce the first official release of the Safe Function Call plugin (v1.0) for WordPress.

Safely call functions that may not be available (for example, from within a template, calling a function that is provided by a plugin that may be deactivated).

The plugin’s official homepage is located at :
coffee2code.com/wp-plugins/safe-function-call.

This new plugin is part of coffee2code’s 14 Days of Plugins (new plugin #5).

Comments welcome on this post for this version of the plugin. Comments will be closed once this release has been superseded by another.

4 replies on “Safe Function Call v1.0”

I’m trying to wrap my brain around this. Say I have a plugin I only need for a specific page templates, but prefer not to have it dump extra code in the head on all the other pages that don’t need the activated plugin. Would this be an appropriate use of Safe Function Call to pull in functions just for that template?

This functions provided by this plugin don’t control if/when/how other functions are called or used. It only protects against the function not being available. For instance, if you had a plugin that provided the function todays_weather() and you activated the plugin and put that code into your sidebar, eveything would be fine. If you then deactivate the plugin, your site will throw an error because todays_weather() no longer exists. If you had wrapped that call in a Safe Function Call, you would’ve protected yourself from the error, i.e. <?php _sfc('todays_weather'); ?>.

For what you’re describing, you probably just want to use built-in WordPress functions to do what you want, i.e.


  if( is_page('about') ) {
    todays_weather();
  }

That code will only call todays_weather() if it is being viewed on the WP page with the name “about”.

Comments are closed.