Skip to content

Instantly share code, notes, and snippets.

@mklasen
Last active July 13, 2022 19:21
Show Gist options
  • Save mklasen/0c3891d1e91f2d4eb2bf1897e79d0588 to your computer and use it in GitHub Desktop.
Save mklasen/0c3891d1e91f2d4eb2bf1897e79d0588 to your computer and use it in GitHub Desktop.
Save custom fields to custom plugin folder. All three examples do exactly the same thing in different ways.
<?php
class Plugin {
public function __construct() {
add_filter( 'acf/settings/save_json', array( $this, 'acf_location' ) );
add_filter( 'acf/settings/load_json', array( $this, 'acf_locations' ) );
}
public function acf_location() {
return plugin_dir_path( __FILE__ ) . 'acf-json/';
}
public function acf_locations() {
return array(plugin_dir_path( __FILE__ ) . 'acf-json/');
}
}
new Plugin();
<?php
add_filter( 'acf/settings/save_json', 'acf_location' );
add_filter( 'acf/settings/load_json', 'acf_locations' );
function acf_location() {
return '/var/www/app/www/content/plugins/maatwerk-plugin/acf-json';
}
function acf_location() {
return array('/var/www/app/www/content/plugins/maatwerk-plugin/acf-json');
}
<?php
add_filter( 'acf/settings/save_json', function() {
return '/var/www/app/www/content/plugins/maatwerk-plugin/acf-json';
});
add_filter( 'acf/settings/load_json', function() {
return array('/var/www/app/www/content/plugins/maatwerk-plugin/acf-json');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment