-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-tags.php
218 lines (173 loc) · 4.55 KB
/
template-tags.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
if ( !function_exists( 'the_form' ) ) {
/**
* Output form by $name
*
* @param $name string
*/
function the_form( $name ) {
global $scaleup_form;
$form = get_form( $name );
if ( is_object( $form ) ) {
$scaleup_form = $form;
/**
* Show alerts above the form
*/
$scaleup_form->add_action( 'header', 'scaleup_form_header_alerts' );
$scaleup_form->do_action( 'header' );
ScaleUp::get_template_part( 'form' );
$scaleup_form->do_action( 'footer' );
}
}
}
if ( !function_exists( 'the_form_attr' ) ) {
/**
* Output form attribute and its value
*
* @param $name
*/
function the_form_attr( $name ) {
$value = get_form_attr( $name );
if ( !is_null( $value ) ) {
echo "$name=\"$value\"";
}
}
}
if ( !function_exists( 'get_form_attr' ) ) {
/**
* Return value of a form attribute
*
* @param $attr
* @return mixed|null
*/
function get_form_attr( $attr ) {
global $scaleup_form;
if ( is_object( $scaleup_form ) && method_exists( $scaleup_form, 'get' ) ) {
/** @var $value mixed */
$value = $scaleup_form->get( $attr );
} else {
$value = null;
}
return $value;
}
}
if ( !function_exists( 'form_has_fields' ) ) {
/**
* Check if form has more fields and advance to the next available form field
*
* @return bool
*/
function form_has_fields(){
global $scaleup_form;
$has_fields = false;
if ( is_object( $scaleup_form ) && method_exists( $scaleup_form, 'has_fields' ) ) {
$has_fields = $scaleup_form->has_fields();
}
return $has_fields;
}
}
if ( !function_exists( 'setup_form_field_data' ) ) {
/**
* Set form field by specific name into global scope
*/
function setup_form_field_data( $name = null ) {
global $scaleup_form, $scaleup_form_field;
if ( is_object( $scaleup_form ) && method_exists( $scaleup_form, 'setup_field' ) ) {
$scaleup_form->setup_field( $name );
$scaleup_form_field = $scaleup_form->get_current_field();
}
}
}
if ( !function_exists( 'the_form_field' ) ) {
/**
* Setup field and include its template
*
* @param null $name
*/
function the_form_field( $name = null ) {
setup_form_field_data( $name );
global $scaleup_form_field;
$template_name = $scaleup_form_field->get( 'template' );
ScaleUp::get_template_part( $template_name );
}
}
if ( !function_exists( 'get_form_field_attr' ) ) {
/**
* Return value of a field attribute with name $attr
*
* @param $attr
* @return string
*/
function get_form_field_attr( $attr ) {
global $scaleup_form_field;
$value = null;
if ( is_object( $scaleup_form_field ) && method_exists( $scaleup_form_field, 'get' ) ) {
$value = apply_filters( "scaleup_form_field_{$attr}", $scaleup_form_field->get( $attr ), $scaleup_form_field );
}
return $value;
}
}
if ( !function_exists( 'the_form_field_attr' ) ) {
/**
* Output field attribute and its value
*
* @param $attr
*/
function the_form_field_attr( $attr ) {
$value = get_form_field_attr( $attr );
if ( !is_null( $value ) ) {
echo "$attr=\"$value\"";
}
}
}
if ( !function_exists( 'has_form_field_attr' ) ) {
/**
* Return true if form field has a specific attribute
*
* @param $attr
* @return bool
*/
function has_form_field_attr( $attr ) {
return !is_null( get_form_field_attr( $attr ) );
}
}
if ( !function_exists( 'the_view' ) ) {
/**
* Output view based on provided args
*
* @param string $name
* @param string $template_part
* @param array $args
*/
function the_view( $name, $template_part = null, $args = array() ) {
$default = array(
'vars' => array(),
'template_part' => $template_part,
);
$args = wp_parse_args( $args, $default );
$view = ScaleUp::get_view( $name );
if ( $view ) {
$view->render( $args[ 'vars' ], $args );
} else {
get_template_part( $name, $template_part );
}
}
}
if ( !function_exists( 'the_view_part' ) ) {
/**
* Output part of the current view
*
* @param string $template_part
* @param array $args
*/
function the_view_part( $template_part, $args = array() ) {
$site = ScaleUp::get_site();
if ( property_exists( $site, 'view' ) && is_object( $site->view ) ) {
/*** @var $view ScaleUp_View */
$view = $site->view;
if ( is_object( $view ) && method_exists( $view, 'render_template_part' ) ) {
$view->render_template_part( $template_part, $args );
}
}
}
}