Нема описа

Shortcodes.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit;
  7. }
  8. /**
  9. * Class PUM_Shortcodes
  10. *
  11. * This class maintains a global set of all registered PUM shortcodes.
  12. */
  13. class PUM_Shortcodes {
  14. /**
  15. * @var PUM_Shortcodes Static Instance
  16. */
  17. private static $instance;
  18. /**
  19. * @var array Holds array of registered $shortcode_tags => $shortcode_objects.
  20. */
  21. private $shortcodes = array();
  22. /**
  23. * Main PUM_Shortcodes Instance
  24. *
  25. * @return PUM_Shortcodes
  26. */
  27. public static function instance() {
  28. if ( ! isset( self::$instance ) && ! ( self::$instance instanceof PUM_Shortcodes ) ) {
  29. self::$instance = new self;
  30. }
  31. return self::$instance;
  32. }
  33. /**
  34. * Add a shortcode object to the collection.
  35. *
  36. * @param PUM_Shortcode $shortcode
  37. */
  38. public function add_shortcode( PUM_Shortcode $shortcode ) {
  39. $this->shortcodes[ $shortcode->tag() ] = $shortcode;
  40. }
  41. /**
  42. * Get all shortcodes.
  43. *
  44. * @return array PUM_Shortcode
  45. */
  46. public function get_shortcodes() {
  47. return $this->shortcodes;
  48. }
  49. /**
  50. * Get shortcode by tag.
  51. *
  52. * @param $tag
  53. *
  54. * @return bool|mixed
  55. */
  56. public function get_shortcode( $tag ) {
  57. return isset( $this->shortcodes[ $tag ] ) ? $this->shortcodes[ $tag ] : false;
  58. }
  59. }