How to create custom actions in globally connected forms

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:

  1. enable local editing of any meta field in the admin interface.
  2. preserve local field values during global synchronization.
  3. control updates to linked posts based on specific meta field conditions.

That’s how it looks

Backend screenshot of Greyd.Forms follow-up actions with recipient field filled out

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 '<style>
			textarea[name="mail_to"],
			body.gc_linked .editor-post-publish-button__button {
				cursor: initial !important;
				pointer-events: unset !important;
				opacity: 1 !important;
			}
		</style>';
	}
}
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 );
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us