The following examples demonstrate how you might hook into these filters in your own plugin. Each example assumes that the Greyd Global Content plugin is active. For a full list of available filters, see the Global Content Filters documentation.
Add a Custom Property to the Global Post Object
PHP
// Add a custom field to every global post retrieved by get_global_post().
add_filter( 'greyd_get_global_post', function( $post, $gid ) {
if ( $post instanceof WP_Post ) {
// Inject a custom property based on a meta value.
$custom = get_post_meta( $post->ID, 'my_custom_field', true );
$post->my_custom_field = $custom ?: 'default';
}
return $post;
}, 10, 2 );Prefix Global IDs with a Custom String
PHP
// Prefix the global ID with your plugin slug.
add_filter( 'greyd_get_gid', function( $gid, $post ) {
if ( is_string( $gid ) ) {
return 'myplugin_' . $gid;
}
return $gid;
}, 10, 2 );Exclude Draft Posts from All Global Posts
PHP
// Remove draft posts from the list of global posts.
add_filter( 'greyd_get_all_global_posts', function( $posts, $query, $network_url ) {
return array_filter( $posts, function( $post ) {
return $post->post_status !== 'draft';
} );
}, 10, 3 );Allow Editing Linked Posts for Administrators Only
PHP
// Permit linked post editing only for users with the administrator role.
add_filter( 'greyd_globalcontent_user_can_edit_linked_posts', function( $can_edit ) {
return current_user_can( 'administrator' );
} );Customise Review Email Subject
PHP
// Replace the default review email subject with a custom format.
add_filter( 'greyd_reviews_mail_subject', function( $subject, $review_id ) {
return sprintf( 'New Review #%d Received', $review_id );
}, 10, 2 );