暫無描述

class-templates.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Pre-configured packaged templates.
  4. *
  5. * @since 1.0.0
  6. */
  7. class WPForms_Templates {
  8. /**
  9. * Primary class constructor.
  10. *
  11. * @since 1.0.0
  12. */
  13. public function __construct() {
  14. $this->init();
  15. }
  16. /**
  17. * Load and init the base form template class.
  18. *
  19. * @since 1.2.8
  20. */
  21. public function init() {
  22. // Parent class template.
  23. require_once WPFORMS_PLUGIN_DIR . 'includes/templates/class-base.php';
  24. // Load default templates on WP init.
  25. add_action( 'init', [ $this, 'load' ] );
  26. }
  27. /**
  28. * Load default form templates.
  29. *
  30. * @since 1.0.0
  31. */
  32. public function load() {
  33. $templates = apply_filters(
  34. 'wpforms_load_templates',
  35. [
  36. 'blank',
  37. ]
  38. );
  39. foreach ( $templates as $template ) {
  40. $template = sanitize_file_name( $template );
  41. if ( file_exists( WPFORMS_PLUGIN_DIR . 'includes/templates/class-' . $template . '.php' ) ) {
  42. require_once WPFORMS_PLUGIN_DIR . 'includes/templates/class-' . $template . '.php';
  43. } elseif ( file_exists( WPFORMS_PLUGIN_DIR . 'pro/includes/templates/class-' . $template . '.php' ) && wpforms()->pro ) {
  44. require_once WPFORMS_PLUGIN_DIR . 'pro/includes/templates/class-' . $template . '.php';
  45. }
  46. }
  47. }
  48. }
  49. new WPForms_Templates;