Skip to content

Instantly share code, notes, and snippets.

@ThatGuySam
Last active December 22, 2016 01:57
Show Gist options
  • Save ThatGuySam/4dc16dd40fa01690e5f6e3fca6954237 to your computer and use it in GitHub Desktop.
Save ThatGuySam/4dc16dd40fa01690e5f6e3fca6954237 to your computer and use it in GitHub Desktop.
Fallback hook for Advanced Custom Fields to prevent missing function errors
<?php
//http://wordpress.stackexchange.com/questions/243168/providing-fallback-function-and-allow-override-by-plugin
function acf_fallback(){
//https://www.advancedcustomfields.com/resources/#functions
$acf_functions = array(
'get_field',
'the_field',
);
// ACF Plugin fallback
//!is_plugin_active( 'advanced-custom-fields/acf.php' )
if( !is_admin() && !function_exists('get_field') ){//!function_exists('get_field')
function get_field($field = '', $id = false) {
return false;
}
function the_field($field = '', $id = false) {
return false;
}
function have_rows($field = '', $id = false) {
return false;
}
function has_sub_field($field = '', $id = false) {
return false;
}
function get_sub_field($field = '', $id = false) {
return false;
}
function the_sub_field($field = '', $id = false) {
return false;
}
}
}
add_action( 'init', 'acf_fallback' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment