Tribe__Events__Community__Event_Form::should_show_linked_posts_module( string $post_type )
Indicates if either linked posts module (venues or organizers) should be rendered or not.
Contents
By default this will return true unless there are no linked posts to choose from and creation of further linked posts is disabled (in which case the UI becomes useless noise).
Parameters
- $post_type
-
(string) (Required)
Return
(bool)
Source
File: src/Tribe/Event_Form.php
public function should_show_linked_posts_module( $post_type ) {
global $wpdb;
$map = array(
Tribe__Events__Organizer::POSTTYPE => 'organizers',
Tribe__Events__Venue::POSTTYPE => 'venues',
);
// Check if this is a post type we care about
if ( ! isset( $map[ $post_type ] ) ) {
return true;
}
$prevent_new_option = 'prevent_new_' . $map[ $post_type ];
// If the prevent_new_* setting isn't turned on we can assume the module should display
if ( ! tribe( 'community.main' )->getOption( $prevent_new_option, false ) ) {
return true;
}
// Otherwise let's check and ensure there are some posts for the user to select from:
// we'll apply the same logic as in Tribe__Events__Linked_Posts::saved_linked_post_dropdown()
// in terms of determining which post statuses are relevant
$pto = get_post_type_object( $post_type );
$statuses = current_user_can( $pto->cap->edit_others_posts )
? array( 'publish', 'draft', 'private', 'pending' )
: array( 'publish' );
$fetch_post = get_posts( array(
'post_type' => $post_type,
'fields' => 'ids',
'posts_per_page' => 1,
'post_status' => $statuses,
) );
$posts_are_available = (bool) count( $fetch_post );
/**
* Dictates where the linked post module should be displayed or not.
*
* @since 4.5.2
*
* @param bool $should_show_module
* @param string $post_type
*/
return apply_filters( 'tribe_events_community_should_show_linked_posts_module',
$posts_are_available,
$post_type
);
}
Changelog
| Version | Description |
|---|---|
| 4.5.2 | Introduced. |