ACF_Local_JSON::get_filename
Gets the filename for an ACF JSON file.
Method of the class: ACF_Local_JSON{}
Hooks from the method
Returns
String|true|false.
Usage
$ACF_Local_JSON = new ACF_Local_JSON(); $ACF_Local_JSON->get_filename( $key, $post );
- $key(string) (required)
- The ACF post key.
- $post(array) (required)
- The main ACF post array.
Changelog
| Since 6.3 | Introduced. |
ACF_Local_JSON::get_filename() ACF Local JSON::get filename code ACF 6.8.8
public function get_filename( $key, $post ) {
$load_path = '';
if ( is_array( $this->files ) && isset( $this->files[ $key ] ) ) {
$load_path = $this->files[ $key ];
}
/**
* Filters the filename used when saving JSON.
*
* @since 6.2
*
* @param string $filename The default filename.
* @param array $post The main post array for the item being saved.
* @param string $load_path The path that the item was loaded from.
*/
$filename = apply_filters( 'acf/json/save_file_name', $key . '.json', $post, $load_path );
if ( ! is_string( $filename ) ) {
return false;
}
$filename = sanitize_file_name( $filename );
// sanitize_file_name() can potentially remove all characters.
if ( empty( $filename ) ) {
return false;
}
return $filename;
}