pods_function_or_file

Check if a Function exists or File exists in Theme / Child Theme.

Description

pods_function_or_file( (string) $function_or_file, (constant) $function_name = null, (constant) $file_dir = null, (null) $file_name = null ); 

Parameters (4)

0. $function_or_file (string)
Function or file name to look for.
1. $function_name — Optional. (constant) => null
Function name to look for.
2. $file_dir — Optional. (constant) => null
Drectory to look into
3. $file_name — Optional. (null) => null
Filename to look for

Usage

  1. if ( !function_exists( 'pods_function_or_file' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/general.php'; 
  3.  
  4. // Function or file name to look for. 
  5. $function_or_file = ''; 
  6.  
  7. // (optional) Function name to look for. 
  8. $function_name = null; 
  9.  
  10. // (optional) Drectory to look into 
  11. $file_dir = null; 
  12.  
  13. // (optional) Filename to look for 
  14. $file_name = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = pods_function_or_file($function_or_file, $function_name, $file_dir, $file_name); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/general.php  
  1. function pods_function_or_file ( $function_or_file, $function_name = null, $file_dir = null, $file_name = null ) { 
  2. $found = false; 
  3. $function_or_file = (string) $function_or_file; 
  4. if ( false !== $function_name ) { 
  5. if ( null === $function_name ) 
  6. $function_name = $function_or_file; 
  7. $function_name = str_replace( array( 
  8. '__',  
  9. '__',  
  10. '__' 
  11. ), '_', preg_replace( '/[^a-z^A-Z^_][^a-z^A-Z^0-9^_]*/', '_', (string) $function_name ) ); 
  12. if ( function_exists( 'pods_custom_' . $function_name ) ) 
  13. $found = array( 'function' => 'pods_custom_' . $function_name ); 
  14. elseif ( function_exists( $function_name ) ) 
  15. $found = array( 'function' => $function_name ); 
  16. if ( false !== $file_name && false === $found ) { 
  17. if ( null === $file_name ) 
  18. $file_name = $function_or_file; 
  19. $file_name = str_replace( array( 
  20. '__',  
  21. '__',  
  22. '__' 
  23. ), '_', preg_replace( '/[^a-z^A-Z^0-9^_]*/', '_', (string) $file_name ) ) . '.php'; 
  24. $custom_location = apply_filters( 'pods_file_directory', null, $function_or_file, $function_name, $file_dir, $file_name ); 
  25. if ( defined( 'PODS_FILE_DIRECTORY' ) && false !== PODS_FILE_DIRECTORY ) 
  26. $custom_location = PODS_FILE_DIRECTORY; 
  27. if ( !empty( $custom_location ) && locate_template( trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) ) 
  28. $found = array( 'file' => trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ); 
  29. elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) ) 
  30. $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ); 
  31. elseif ( locate_template( 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) ) 
  32. $found = array( 'file' => 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ); 
  33. elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) ) 
  34. $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ); 
  35.  
  36. return apply_filters( 'pods_function_or_file', $found, $function_or_file, $function_name, $file_name );