Tribe__Events__Linked_Posts::get_create_or_find_labels( object $post_type, boolean $creation_enabled )
A several-step process that prints the “Create or Find {Linked Post Type Name}” labels.
Contents
Numerous steps and caveats are covered in this method so that we can make these labels, which are rather important, as translation-friendly as possible.
Parameters
- $post_type
-
(object) (Required) The linked post type whose label is being rendered.
- $creation_enabled
-
(boolean) (Required) Whether the current user can create post types. If false, they can only add existing ones.
Return
(string)
Source
File: src/Tribe/Linked_Posts.php
public function get_create_or_find_labels( $post_type, $creation_enabled ) {
$plural_name = $this->linked_post_types[ $post_type ]['name'];
$singular_name = ! empty( $this->linked_post_types[ $post_type ]['singular_name'] ) ? $this->linked_post_types[ $post_type ]['singular_name'] : $plural_name;
$singular_name_lowercase = ! empty( $this->linked_post_types[ $post_type ]['singular_name_lowercase'] ) ? $this->linked_post_types[ $post_type ]['singular_name_lowercase'] : $singular_name;
// First, determine what indefinite article we should use for the post type (important for English and several other languages).
$indefinite_article = _x( 'a', 'Indefinite article for the phrase "Find a {post type name}. Will be replaced with "an" if the {post type name} starts with a vowel.', 'the-events-calendar' );
$post_type_starts_with = substr( $singular_name, 0, 1 );
$post_type_starts_with = strtolower( $post_type_starts_with );
$english_vowels = array( 'a', 'e', 'i', 'o', 'u' );
if ( in_array( $post_type_starts_with, $english_vowels ) ) {
$indefinite_article = _x( 'an', 'Indefinite article for the phrase "Find a {post type name}" when the {post type name} starts with a vowel, e.g. "Find an Organizer".', 'the-events-calendar' );
}
// Here we render the main label string. The "core" linked post types (venue and organizer) are explicitly named to make
// translation a bit easier for the many languages where the words *around* the post type name may need to be different
// based on the specific post type name. For non-"core" post types, we just dynamically populate the post type name.
switch ( $post_type ) {
// Organizers
case Tribe__Events__Organizer::POSTTYPE :
if ( tribe_is_organizer_label_customized() ) {
$label = esc_attr(
sprintf(
_x( 'Find %1$s %2$s', '"Find an Organizer", but when the word "Organizer" is customized to something else.', 'the-events-calendar' ),
$indefinite_article,
$singular_name
)
);
if ( $creation_enabled ) {
$label = esc_attr(
sprintf(
_x( 'Create or Find %s', '"Create or Find Organizer", but when the word "Organizer" is customized to something else.', 'the-events-calendar' ),
$singular_name
)
);
}
} else {
$label = $creation_enabled
? esc_attr__( 'Create or Find an Organizer', 'the-events-calendar' )
: esc_attr__( 'Find an Organizer', 'the-events-calendar' );
}
break;
// Venues
case Tribe__Events__Venue::POSTTYPE :
if ( tribe_is_venue_label_customized() ) {
$label = esc_attr(
sprintf(
_x( 'Find %1$s %2$s', '"Find a Venue", but when the word "Venue" is customized to something else.', 'the-events-calendar' ),
$indefinite_article,
$singular_name
)
);
if ( $creation_enabled ) {
$label = esc_attr(
sprintf(
_x( 'Create or Find %s', '"Create or Find Venue", but when the word "Venue" is customized to something else.', 'the-events-calendar' ),
$singular_name
)
);
}
} else {
$label = $creation_enabled
? esc_attr__( 'Create or Find a Venue', 'the-events-calendar' )
: esc_attr__( 'Find a Venue', 'the-events-calendar' );
}
break;
// Any other potential Linked Post types
default :
$label = esc_attr(
sprintf(
_x( 'Find %1$s %2$s', 'The "Find a {post type name}" label for custom linked post types that are *not* Venues or Organizers', 'the-events-calendar' ),
$indefinite_article,
$singular_name
)
);
if ( $creation_enabled ) {
$label = esc_attr(
sprintf(
_x( 'Create or Find %s', 'The "Create or Find {post type name}" label for custom linked post types that are *not* Venues or Organizers', 'the-events-calendar' ),
$singular_name
)
);
}
break;
}
return $label;
}
Changelog
| Version | Description |
|---|---|
| 4.6.3 | Introduced. |