/wp-content/plugins/the-events-calendar/src/functions/template-tags/organizer.php

https://gitlab.com/ezgonzalez/integral · PHP · 286 lines · 130 code · 29 blank · 127 comment · 27 complexity · 1f82f1a5502c6c71219f76a1bdc8b0d7 MD5 · raw file

  1. <?php
  2. /**
  3. * Organizer Functions
  4. *
  5. * Display functions (template-tags) for use in WordPress templates.
  6. */
  7. // Don't load directly
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. die( '-1' );
  10. }
  11. if ( class_exists( 'Tribe__Events__Main' ) ) {
  12. /**
  13. * Organizer ID
  14. *
  15. * Returns the event Organizer ID.
  16. *
  17. * @param int $postId Can supply either event id or organizer id.
  18. * If none specified, current post is used.
  19. * If given an event with multiple organizers,
  20. * the first organizer ID is returned.
  21. *
  22. * @return int Organizer
  23. */
  24. function tribe_get_organizer_id( $postId = null ) {
  25. $postId = Tribe__Events__Main::postIdHelper( $postId );
  26. $organizer_id = null;
  27. if ( is_numeric( $postId ) && $postId > 0 ) {
  28. $tribe_ecp = Tribe__Events__Main::instance();
  29. // check if $postId is an organizer id
  30. if ( $tribe_ecp->isOrganizer( $postId ) ) {
  31. $organizer_id = $postId;
  32. } else {
  33. $organizer_id = tribe_get_event_meta( $postId, '_EventOrganizerID', true );
  34. }
  35. }
  36. return apply_filters( 'tribe_get_organizer_id', $organizer_id, $postId );
  37. }
  38. /**
  39. * Get the IDs of all organizers associated with an event
  40. *
  41. * @param int $event_id The event post ID. Defaults to the current event.
  42. *
  43. * @return array
  44. */
  45. function tribe_get_organizer_ids( $event_id = null ) {
  46. $event_id = Tribe__Events__Main::postIdHelper( $event_id );
  47. $organizer_ids = array();
  48. if ( is_numeric( $event_id ) && $event_id > 0 ) {
  49. if ( Tribe__Events__Main::instance()->isOrganizer( $event_id ) ) {
  50. $organizer_ids[] = $event_id;
  51. } else {
  52. $organizer_ids = tribe_get_event_meta( $event_id, '_EventOrganizerID', false );
  53. // for some reason we store a blank "0" element in this array.
  54. // let's scrub this garbage out
  55. $organizer_ids = array_filter( (array) $organizer_ids );
  56. }
  57. }
  58. return apply_filters( 'tribe_get_organizer_ids', $organizer_ids, $event_id );
  59. }
  60. /**
  61. * Get Organizer Label Singular
  62. *
  63. * Returns the singular version of the Organizer Label
  64. *
  65. * @return string
  66. */
  67. function tribe_get_organizer_label_singular() {
  68. return apply_filters( 'tribe_organizer_label_singular', esc_html__( 'Organizer', 'the-events-calendar' ) );
  69. }
  70. /**
  71. * Get Organizer Label Plural
  72. *
  73. * Returns the plural version of the Organizer Label
  74. *
  75. * @return string
  76. */
  77. function tribe_get_organizer_label_plural() {
  78. return apply_filters( 'tribe_organizer_label_plural', esc_html__( 'Organizers', 'the-events-calendar' ) );
  79. }
  80. /**
  81. * Get the organizer label
  82. *
  83. * @param bool $singular TRUE to return the singular label, FALSE to return plural
  84. *
  85. * @return string
  86. */
  87. function tribe_get_organizer_label( $singular = true ) {
  88. if ( $singular ) {
  89. return tribe_get_organizer_label_singular();
  90. } else {
  91. return tribe_get_organizer_label_plural();
  92. }
  93. }
  94. /**
  95. * Get Organizer
  96. *
  97. * Returns the name of the Organizer
  98. *
  99. * @param int $postId Can supply either event id or organizer id, if none specified, current post is used
  100. *
  101. * @return string Organizer's Name
  102. */
  103. function tribe_get_organizer( $postId = null ) {
  104. $postId = Tribe__Events__Main::postIdHelper( $postId );
  105. $organizer_id = (int) tribe_get_organizer_id( $postId );
  106. $output = '';
  107. if ( $organizer_id > 0 ) {
  108. $output = esc_html( get_the_title( $organizer_id ) );
  109. }
  110. return apply_filters( 'tribe_get_organizer', $output, $organizer_id );
  111. }
  112. /**
  113. * Organizer Test
  114. *
  115. * Returns true or false depending on if the post id has/is a n organizer
  116. *
  117. * @param int $postId Can supply either event id or organizer id, if none specified, current post is used
  118. *
  119. * @return bool
  120. */
  121. function tribe_has_organizer( $postId = null ) {
  122. $postId = Tribe__Events__Main::postIdHelper( $postId );
  123. $has_organizer = ( tribe_get_organizer_id( $postId ) > 0 ) ? true : false;
  124. return apply_filters( 'tribe_has_organizer', $has_organizer );
  125. }
  126. /**
  127. * Organizer Email
  128. *
  129. * Returns the Organizer's Email
  130. *
  131. * @param int $postId Can supply either event id or organizer id, if none specified, current post is used
  132. *
  133. * @return string Organizer's Email
  134. */
  135. function tribe_get_organizer_email( $postId = null ) {
  136. $postId = Tribe__Events__Main::postIdHelper( $postId );
  137. $output = esc_html( tribe_get_event_meta( tribe_get_organizer_id( $postId ), '_OrganizerEmail', true ) );
  138. return apply_filters( 'tribe_get_organizer_email', $output );
  139. }
  140. /**
  141. * Organizer Page Link
  142. *
  143. * Returns the event Organizer Name with a link to their single organizer page
  144. *
  145. * @param int $postId Can supply either event id or organizer id, if none specified, current post is used
  146. * @param bool $full_link If true outputs a complete HTML <a> link, otherwise only the URL is output
  147. * @param bool $echo If true, echo the link, otherwise return
  148. *
  149. * @return string Organizer Name and Url
  150. */
  151. function tribe_get_organizer_link( $postId = null, $full_link = true, $echo = false ) {
  152. // As of TEC 4.0 this argument is deprecated
  153. // If needed precede the call to this function with echo
  154. if ( $echo != false ) _deprecated_argument( __FUNCTION__, '4.0' );
  155. $org_id = tribe_get_organizer_id( $postId );
  156. if ( class_exists( 'Tribe__Events__Pro__Main' ) ) {
  157. $url = esc_url_raw( get_permalink( $org_id ) );
  158. if ( $full_link ) {
  159. $name = tribe_get_organizer( $org_id );
  160. $attr_title = the_title_attribute( array( 'post' => $org_id, 'echo' => false ) );
  161. $link = ! empty( $url ) && ! empty( $name ) ? '<a href="' . esc_url( $url ) . '" title="'.$attr_title.'"">' . $name . '</a>' : false;
  162. } else {
  163. $link = $url;
  164. }
  165. // Remove this in or before 5.x to fully deprecate the echo arg
  166. if ( $echo ) {
  167. echo apply_filters( 'tribe_get_organizer_link', $link, $postId, $echo, $url );
  168. } else {
  169. return apply_filters( 'tribe_get_organizer_link', $link, $postId, $full_link, $url );
  170. }
  171. }
  172. //Return Organizer Name if Pro is not Active
  173. return tribe_get_organizer( $org_id );
  174. }
  175. /**
  176. * Organizer Phone
  177. *
  178. * Returns the event Organizer's phone number
  179. *
  180. * @param int $postId Can supply either event id or organizer id, if none specified, current post is used
  181. *
  182. * @return string Organizer's Phone Number
  183. */
  184. function tribe_get_organizer_phone( $postId = null ) {
  185. $postId = Tribe__Events__Main::postIdHelper( $postId );
  186. $output = esc_html( tribe_get_event_meta( tribe_get_organizer_id( $postId ), '_OrganizerPhone', true ) );
  187. return apply_filters( 'tribe_get_organizer_phone', $output );
  188. }
  189. /**
  190. * Organizer website url
  191. *
  192. * Returns the event Organizer Name with a url to their supplied website
  193. *
  194. * @param $postId post ID for an event
  195. *
  196. * @return string
  197. **/
  198. if ( ! function_exists( 'tribe_get_organizer_website_url' ) ) { // wrapped in if function exists to maintain compatibility with community events 3.0.x. wrapper not needed after 3.1.x.
  199. function tribe_get_organizer_website_url( $postId = null ) {
  200. $postId = Tribe__Events__Main::postIdHelper( $postId );
  201. $output = esc_url( esc_html( tribe_get_event_meta( tribe_get_organizer_id( $postId ), '_OrganizerWebsite', true ) ) );
  202. return apply_filters( 'tribe_get_organizer_website_url', $output );
  203. }
  204. }
  205. /**
  206. * Organizer website link
  207. *
  208. * Returns the event Organizer Name with a link to their supplied website
  209. *
  210. * @param $post_id post ID for an event
  211. * @param $label text for the link
  212. *
  213. * @return string
  214. **/
  215. function tribe_get_organizer_website_link( $post_id = null, $label = null ) {
  216. $post_id = tribe_get_organizer_id( $post_id );
  217. $url = tribe_get_event_meta( $post_id, '_OrganizerWebsite', true );
  218. if ( ! empty( $url ) ) {
  219. $label = is_null( $label ) ? $url : $label;
  220. if ( ! empty( $url ) ) {
  221. $parseUrl = parse_url( $url );
  222. if ( empty( $parseUrl['scheme'] ) ) {
  223. $url = "http://$url";
  224. }
  225. }
  226. $html = sprintf(
  227. '<a href="%s" target="%s">%s</a>',
  228. esc_attr( esc_url( $url ) ),
  229. apply_filters( 'tribe_get_organizer_website_link_target', '_self' ),
  230. apply_filters( 'tribe_get_organizer_website_link_label', esc_html( $label ) )
  231. );
  232. } else {
  233. $html = '';
  234. }
  235. return apply_filters( 'tribe_get_organizer_website_link', $html );
  236. }
  237. /**
  238. * Get all the organizers
  239. *
  240. * @param $deprecated
  241. * @param $posts_per_page Maximum number of results
  242. *
  243. * @return array An array of organizer post objects.
  244. */
  245. function tribe_get_organizers( $deprecated = null, $posts_per_page = -1 ) {
  246. if ( null !== $deprecated ) {
  247. _deprecated_argument( __FUNCTION__, '3.0', 'This parameter is no longer supported.' );
  248. }
  249. $organizers = get_posts(
  250. array(
  251. 'post_type' => Tribe__Events__Main::ORGANIZER_POST_TYPE,
  252. 'posts_per_page' => $posts_per_page,
  253. )
  254. );
  255. return $organizers;
  256. }
  257. }