class-fragments.php 851 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class Booked_WC_Fragments {
  3. protected $slug;
  4. protected $name;
  5. private function __construct($slug, $name) {
  6. $this->slug = $slug;
  7. $this->name = (string) $name;
  8. $this->_set_path();
  9. }
  10. protected function _set_path() {
  11. if ( $this->name !== '' ) {
  12. $template_path = "{$this->slug}-{$this->name}.php";
  13. } else {
  14. $template_path = "{$this->slug}.php";
  15. }
  16. $this->template_path = BOOKED_WC_PLUGIN_DIR . 'fragments/' . $template_path;
  17. return $this;
  18. }
  19. protected function _get_path() {
  20. return $this->template_path;
  21. }
  22. public static function load($slug, $name=null) {
  23. $fragments = new self($slug, $name);
  24. include($fragments->_get_path());
  25. }
  26. public static function get_path($slug, $name=null) {
  27. $fragments = new self($slug, $name);
  28. return $fragments->_get_path();
  29. }
  30. }