Greyd.Suite enables you to synchronize posts across several websites with Global Content. However, you can customize specific meta fields — like a forms admin mail_to
field — locally for individual posts without disrupting global synchronization.
How it works
With a simple code snippet added to your child theme's functions.php
you can:
- enable local editing of any meta field in the admin interface.
- preserve local field values during global synchronization.
- control updates to linked posts based on specific meta field conditions.
That’s how it looks
Adapting for Any Meta Field
This approach is not limited to mail_to
or not even to the post type forms. You can customize any meta field for any post type by replacing mail_to
with your desired meta key and also adjusting the post type value. Adjust the snippet logic as needed for your use case.
Example Use Case
Synchronize a global post type while allowing localized values, such as region-specific email addresses or descriptions, ensuring consistency and flexibility.
* Enable editing of the „mail_to“ field in the Forms post type.
* This functionality ensures that the „mail_to“ field can be customized locally, even for globally synchronized forms.
* It also ensures that buttons like „publish“ remain accessible for posts with global content links.
*/
function admin_forms_enable_metabox_field() {
global $post_type;
if ( ‚tp_forms‘ === $post_type ) {
echo “;
}
}
add_action( ‚admin_head‘, ‚admin_forms_enable_metabox_field‘ );
/**
* Prevent overwriting of the „mail_to“ meta value when syncing forms via global content.
* This ensures the locally defined „mail_to“ value remains intact.
*
* @param mixed $meta_value The current meta value for „mail_to“.
* @param int $post_id The ID of the post being synced.
* @param WP_Post $post The post object being synced.
*
* @return mixed The „mail_to“ value from the local post.
*/
function filter_mail_to_field_before_import( $meta_value, $post_id, $post ) {
return get_post_meta( $post_id, ‚mail_to‘, true );
}
add_filter( ‚greyd_import_post_meta-mail_to‘, ‚filter_mail_to_field_before_import‘, 10, 3 );
/**
* Allow updates to linked posts only if the „mail_to“ field is defined.
* This provides granular control over synchronization behavior.
*
* @param bool $allow Whether the update should be allowed.
* @param int $post_id The ID of the post being checked.
*
* @return bool Whether to allow the update of the linked post.
*/
function allow_update_of_linked_post_with_mail_to_field( $allow, $post_id ) {
$meta = get_post_meta( $post_id, ‚mail_to‘, true );
if ( ! empty( $meta ) ) {
$allow = true;
}
return $allow;
}
add_filter( ‚gc_allow_update_of_linked_post‘, ‚allow_update_of_linked_post_with_mail_to_field‘, 10, 2 );