PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.16.0
GiveWP – Donation Plugin and Fundraising Platform v2.16.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Form / Templates.php

Templates.php in GiveWP – Donation Plugin and Fundraising Platform 2.16.0, at src/Form/Templates.php

115 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Handle Form Templates
5 *
6 * @package Give
7 * @since 2.7.0
8 */
9
10 namespace Give\Form;
11
12 use Give\Views\Form\Templates\Legacy\Legacy;
13 use Give\Views\Form\Templates\Sequoia\Sequoia;
14 use Give\Helpers\Form\Template as FormTemplateUtils;
15
16 defined( 'ABSPATH' ) || exit;
17
18 /**
19 * Class Templates
20 *
21 * @package Give\Form
22 *
23 * @since 2.7.0
24 */
25 class Templates {
26 /**
27 * Templates
28 *
29 * @var array
30 */
31 private $templates = [];
32
33
34 /**
35 * Template Objects
36 *
37 * @var Template[]
38 */
39 private $templateObjs = [];
40
41 /**
42 * Load templates
43 *
44 * @since 2.7.0
45 */
46 public function load() {
47 /**
48 * Filter list of form template
49 *
50 * @param Template[]
51 *
52 * @since 2.7.0
53 */
54 $this->templates = apply_filters(
55 'give_register_form_template',
56 [
57 'sequoia' => Sequoia::class,
58 'legacy' => Legacy::class,
59 ]
60 );
61 }
62
63 /**
64 * Get Registered templates
65 *
66 * @return Template[]
67 * @since 2.7.0
68 */
69 public function getTemplates() {
70 // Check if all templates have there object or not.
71 $remainingObjs = array_diff( array_keys( $this->templates ), array_keys( $this->templateObjs ) );
72
73 // Get object if any remaining
74 if ( $remainingObjs ) {
75 foreach ( $remainingObjs as $templateId ) {
76 $this->templateObjs[ $templateId ] = $this->getTemplateObject( $templateId );
77 }
78 }
79
80 return $this->templateObjs;
81 }
82
83 /**
84 * Get Registered form template
85 *
86 * @param string $templateId Template Id. Default to active form template.
87 *
88 * @return Template
89 * @since 2.7.0
90 */
91 public function getTemplate( $templateId = null ) {
92 $templateId = $templateId ?: FormTemplateUtils::getActiveID();
93
94 if ( isset( $this->templateObjs[ $templateId ] ) ) {
95 return $this->templateObjs[ $templateId ];
96 }
97
98 $this->templateObjs[ $templateId ] = $this->getTemplateObject( $templateId );
99
100 return $this->getTemplateObject( $templateId );
101 }
102
103 /**
104 * Get class object.
105 *
106 * @param string $templateId
107 *
108 * @return Template
109 * @since 2.7.0
110 */
111 private function getTemplateObject( $templateId ) {
112 return new $this->templates[ $templateId ]();
113 }
114 }
115