Support Forum
I'd like to use metabox to create our own simplified set of settings pages. Some of the fields would control standard WP settings, others would be for setting options on our custom themes.
Setting the values in a metabox and then replicating them out to the master setting doesn't look to be a problem, but I was curious if there's a way to modify the data my custom fields return within the editing/admin interface on the backend.
My goal would be for the standard WP setting to serve as the master record, so when we load up the custom settings page the fields would pull the values from the default WP setting. That way if something was modified programmatically by another plugin or somewhere outside of metabox it would still reflect the current value in the custom settings pages we create.
I suspect one of the https://docs.metabox.io/filters/ may help with this but was curious if anyone has experience or full examples before I start goofing around aimlessly 🙂
Thx!
Hi Denny,
Looks like it can be done with rwmb_field_meta
filter (https://docs.metabox.io/filters/#rwmb_field_meta). This filter changes the value before showing to users, e.g. it changes the value get from the database. It might be what you want.
Cheers,
Anh
Thanks Anh, that's the one I've been looking at and experimenting with.
Do you know the proper way to use it?
If I wanted to create a field that could be used for the site title (ID: site_name
), for example, I was trying the following without success:
apply_filters( 'rwmb_field_meta', 'Title Here', 'site_name', false );
apply_filters( 'rwmb_site_name_field_meta', 'Title Here');
I also tried inserting 'Title Here'
into an array per the docs but didn't work for me either.
Any thoughts are much appreciated!
Hi Denny,
The code should be like this:
add_filter( 'rwmb_site_name_field_meta', 'your_filter_function', 10, 3 );
function your_filter_function( $meta, $field, $saved ) {
return 'Title here';
}
or
add_filter( 'rwmb_field_meta', 'your_filter_function', 10, 3 );
function your_filter_function( $meta, $field, $saved ) {
if ( 'site_name' != $field['id'] ) {
return $meta;
}
return 'Title here';
}
Success! Thanks Anh, you rock 🙂