\WP_Stager_Integration\Calendar::get_filter_taxonomy_label(string $taxonomy, bool $original = false): string

Description

Get the filter taxonomy labels.

Parameters:

ParameterTypeDescription
$taxonomy string The taxonomy/field to get the label for.
$original bool Whether to return the original label or the custom label from the plugin settings. Defaults to false, returns custom labels.

Returns:

string The label for the taxonomy/field. Returns an empty string if the taxonomy/field is not supported.

Information

Fileclass-calendar.php line 2065

Full Code

/**
 * Get the filter taxonomy labels.
 *
 * @param string $taxonomy  The taxonomy/field to get the label for.
 * @param bool   $original  Whether to return the original label or the custom label from the plugin settings. Defaults to false, returns custom labels.
 *
 * @return string The label for the taxonomy/field. Returns an empty string if the taxonomy/field is not supported.
 */
public static function get_filter_taxonomy_label( $taxonomy, $original = false ) {

    // Type casting
    $taxonomy = (string) $taxonomy;
    $original = (bool) $original;

    // Define default label
    switch ( $taxonomy ) {

        case 'type':
            $default = _x( 'Event type', 'Calendar filter label for \'tags\' taxonomy', 'wp-stager-integration' );
            break;

        case 'tags':
            $default = _x( 'Tagged with', 'Calendar filter label for \'tags\' taxonomy', 'wp-stager-integration' );
            break;

        case 'status':
            $default = _x( 'Event status', 'Calendar filter label for \'status\' taxonomy', 'wp-stager-integration' );
            break;

        case 'location':
        case 'location.name':
            $default = _x( 'Location', 'Calendar filter label for \'location\' taxonomy', 'wp-stager-integration' );
            break;

        case 'location.spaces.name':
            $default = _x( 'Space', 'Calendar filter label for \'location.spaces\' taxonomy', 'wp-stager-integration' );
            break;

        case 'location.city':
            $default = _x( 'City', 'Calendar filter label for \'location.city\' taxonomy', 'wp-stager-integration' );
            break;

        case 'location.country':
            $default = _x( 'Country', 'Calendar filter label for \'location.country\' taxonomy', 'wp-stager-integration' );
            break;

        case 'ticketGroups':
        case 'ticketGroups.name':
            $default = _x( 'Ticket types', 'Calendar filter label for \'ticketGroups\' taxonomy', 'wp-stager-integration' );
            break;

        case 'eventLabels':
        case 'eventLabels.name':
            $default = _x( 'Labelled as', 'Calendar filter label for \'eventLabels\' taxonomy', 'wp-stager-integration' );
            break;

        case 'customerInterests':
        case 'customerInterests.name':
            $default = _x( 'Interests', 'Calendar filter label for \'customerInterests\' taxonomy', 'wp-stager-integration' );
            break;

        case 'programItems':
        case 'programItems.name':
            $default = _x( 'Program items', 'Calendar filter label for \'programItems\' taxonomy', 'wp-stager-integration' );
            break;

        // Default: return empty string
        default:
            $default = $taxonomy;
            break;
    }

    // Bail if $original label is requested
    if ( $original ) {
        return $default;
    }

    // Init label
    $label = $default;

    // Get custom labels
    $custom_labels = (array) (Options::get_calendar_filter_custom_labels() ?: array());

    // Loop over custom labels
    foreach ( $custom_labels as $row ) {

        // Get data
        $row_field    = (string) ( $row[ 'field' ] ?? '' );
        $custom_label = (string) ( $row[ 'label' ] ?? '' );

        // Continue if row field does not match taxonomy
        if ( $row_field !== $taxonomy ) {
            continue;
        }

        // Override with custom label
        $label = $custom_label;
        break;
    }


    /**
     * Filters the filter taxonomy label.
     *
     * @param string $label The label for the taxonomy.
     * @param string $taxonomy The taxonomy to get the label for.
     *
     * @return string The label for the taxonomy.
     *
     * @example
     * // Modify the label for the 'eventlabels.name' field
     * add_filter( 'wpstagerintegration_calendar_filter_taxonomy_label', function( $label, $taxonomy ) {
     *
     *  // Check if the taxonomy matches
     *  if ( $taxonomy === 'eventLabels.name' ) {
     *
     *      // Return a custom label
     *      return 'Event labelled as...';
     *  }
     *
     *  // Return the original label if the taxonoomy doesn't match
     *  return $label;
     * }, 10, 2 );
     */
    $label = (string) apply_filters( 'wpstagerintegration_calendar_filter_taxonomy_label', $label, $taxonomy );

    return $label;
}

💡 If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration

🎁 Limited offer: Use code WELCOME26 to get your first month for free!