Hi @lucspe,
The short answer is that you can’t. These settings use WordPress’s Settings API, and it only really takes a user capability argument on a per-page basis.
Furthermore, all of these settings are saved in a single serialized entry in the database. So even if you hooked into bpfwp_settings_page
and removed those fields for users without a certain capability, they’d end up overwriting the data in the database.
I presume what you want to do is prevent a client or lower-level manager from making changes. I can see two possible solutions to this.
First, the simplest thing to do would be to just enqueue some CSS on that page in the admin which hides those settings. It wouldn’t be safe from a malicious user, who could still uncover and modify those settings. But if you just want to prevent accidental overriding or modification, that should work.
Alternatively, you can use the option_{$option_name}
hook to force the value of the API key and multiple language options whenever they’re retrieved. In your wp-config.php
you’d add some constants like this:
define('BP_GMAPS_API_KEY', 'your-api-key');
define('BP_MULTIPLE_LOCATIONS', true);
Then you’d hook in with something like this;
add_filter( 'option_bpfwp-settings', 'luscpe_override_bp_options' );
function luscpe_override_bp_options( $val, $option_name ) {
$val['google-maps-api-key'] = BP_GMAPS_API_KEY;
$val['multiple-locations'] = BP_MULTIPLE_LOCATIONS;
return $val;
}
That’s just an example. You may need to inspect $val
and make sure you’re overriding these values correctly. But once done it should make the values match what’s in your config file, regardless of what someone has put into the fields in their Business Profile.