-
Notifications
You must be signed in to change notification settings - Fork 10
/
template-tags.php
57 lines (52 loc) · 1.29 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
<?php
/**
* @param string $form_id
* @param callback $callback
*
* @throws InvalidArgumentException when WP_DEBUG is on
* @return bool TRUE if the form was registered, otherwise FALSE
*/
function wp_register_form( $form_id, $callback ) {
$registrar = WP_Form_Registrar::get_instance();
try { // mask the exceptions for the non-OO API
$registrar->register( $form_id, $callback );
return TRUE;
} catch ( InvalidArgumentException $e ) {
if ( defined('WP_DEBUG') && WP_DEBUG ) {
throw $e;
}
return FALSE; // the form was not registered
}
}
/**
* Deregister a form.
*
* @param string $form_id
* @return bool TRUE if removed, FALSE if it didn't exist to begin with
* Either way, it's not registered anymore
*/
function wp_deregister_form( $form_id ) {
$registrar = WP_Form_Registrar::get_instance();
return $registrar->deregister( $form_id );
}
/**
* Get a registered form
*
* @param string $form_id
*
* @throws Exception when WP_DEBUG is on
* @return bool|WP_Form
*/
function wp_get_form( $form_id ) {
$registrar = WP_Form_Registrar::get_instance();
try {
$args = func_get_args();
$form = call_user_func_array( array( $registrar, 'get_form' ), $args );
} catch ( Exception $e ) {
if ( defined('WP_DEBUG') && WP_DEBUG ) {
throw $e;
}
return FALSE;
}
return $form;
}