Namespacing
We use namespacing to keep our plugin code distinct from other plugins, libraries, and themes.
Namespaces
Our plugins utilize a couple of namespaces. The PHP namespace is the namespacing that our new architecture uses. These namespaces are a relatively new development and we still have a lot of code using our legacy namespaces. Here are both namespacing approaches you will find within our codebase. The first can be found in src/TEC
while the legacy can be found in src/Tribe
.
Product | PHP namespace | Legacy namespace |
---|---|---|
Tribe Common | TEC\Common | Tribe\Common |
Event Aggregator | TEC\Events\Aggregator | Tribe\Events\Aggregator |
The Events Calendar | TEC\Events | Tribe\Events |
The Events Calendar Pro | TEC\Events_Pro | Tribe\Events_Pro |
Virtual Events | TEC\Events_Virtual | Tribe\Events_Virtual |
Community Events | TEC\Events_Community | Tribe\Events_Community |
Community Tickets | TEC\Events_Community_Tickets | Tribe\Events_Community_Tickets |
Eventbrite Tickets | TEC\Events_Eventbrite | Tribe\Events_Eventbrite |
Filter Bar | TEC\Events_Filter_Bar | Tribe\Events_Filter_Bar |
Event Tickets | TEC\Tickets | Tribe\Tickets |
Event Tickets Plus | TEC\Tickets_Plus | Tribe\Tickets_Plus |
Prefixes
Each plugin and major product area has its own prefix for hooks, container slugs, and PHP namespaces. The prefixes are as follows:
Product | Hook prefix | Container prefix |
---|---|---|
Tribe Common | tec_ | common. |
Event Aggregator | tec_aggregator_ | aggregator. |
The Events Calendar | tec_events_ | tec. |
The Events Calendar Pro | tec_events_pro_ | pro. |
Virtual Events | tec_events_virtual_ | events-virtual. |
Community Events | tec_events_community_ | community. |
Community Tickets | tec_community_tickets_ | community-tickets. |
Eventbrite Tickets | tec_events_eventbrite_ | eventbrite. |
Filter Bar | tec_events_filter_ | filterbar. |
Event Tickets | tec_tickets_ | tickets. |
Event Tickets Plus | tec_tickets_plus_ | tickets-plus. |
Image Widget | tec_image_ | image. |
Image Widget Plus | tec_image_plus_ | image-plus. |
Despite being embedded within the-events-calendar, Event Aggregator deserves (and gets) its own prefix.
Hook examples
<?php
// hook in tribe common for firing the bacon action
do_action( 'tec_bacon' );
// hook in TEC for firing the potato action
do_action( 'tec_events_potato' );
// hook in the Event Aggregator section of TEC for firing the squid action
do_action( 'tec_aggregator_squid' );
Container slug examples
<?php
// declare singleton for the panda class in tribe-common, then call it
tribe_singleton( 'common.panda', 'TEC\\Common\\Panda' );
tribe( 'common.panda' );
// declare singleton for the squirrel admin class in TEC, then call it
tribe_singleton( 'tec.admin.squirrel', 'TEC\\Events\\Admin\\Squirrel' );
tribe( 'tec.admin.squirrel' );
// declare singleton for the baboon class in the Event Aggregator code within TEC, then call it
tribe_singleton( 'aggregator.baboon', 'TEC\\Events\\Aggregator\\Baboon' );
tribe( 'aggregator.baboon' );
Style and script slugs
When registering and enqueuing scripts and styles, we should append -css
in the case of stylesheets. Example:
Asset slug | Asset type |
---|---|
tec-post-editor | JS |
tec-post-editor-css | CSS |
Note that in this instance we prefer hyphens over underscores.