This repository has been archived by the owner on Aug 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.php
80 lines (66 loc) · 2.14 KB
/
address.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
<?php
/**
* Register Fields API configuration
*
* @param WP_Fields_API $wp_fields
*/
function example_my_user_address( $wp_fields ) {
// Object type: User
$object_type = 'user';
// Object subtype: n/a
$object_subtype = null;
// Form: User Edit Profile
$form_id = 'user-edit';
//////////////////////
// Section: Address //
//////////////////////
$section_id = 'address';
$section_args = array(
'label' => __( 'Address', 'my-text-domain' ), // @todo Update text domain
'form' => $form_id,
'controls' => array(), // We will add our controls below
);
// Address Line 1
$section_args['controls']['address_1'] = array(
'type' => 'text',
'label' => __( 'Address 1', 'my-text-domain' ), // @todo Update text domain
);
// Address Line 2
$section_args['controls']['address_2'] = array(
'type' => 'text',
'label' => __( 'Address 2', 'my-text-domain' ), // @todo Update text domain
);
// City
$section_args['controls']['address_city'] = array(
'type' => 'text',
'label' => __( 'City', 'my-text-domain' ), // @todo Update text domain
);
// State / Region
$section_args['controls']['address_state'] = array(
'type' => 'text',
'label' => __( 'State / Region', 'my-text-domain' ), // @todo Update text domain
// You could also use 'select' type and set the 'datasource' or 'choices' option
);
// Zip / Postal Code
$section_args['controls']['address_zip'] = array(
'type' => 'text',
'label' => __( 'Zip / Postal Code', 'my-text-domain' ), // @todo Update text domain
);
// Zip / Postal Code
$section_args['controls']['address_country'] = array(
'type' => 'select',
'label' => __( 'Country', 'my-text-domain' ), // @todo Update text domain
'datasource' => array(
// Get list of Countries from taxonomy datasource
'type' => 'term',
'get_args' => array(
'taxonomy' => 'country'
),
),
// You could also pass in all countries in 'choices' option
// with array( 'US' => 'United States' )
);
// Add the section
$wp_fields->add_section( $object_type, $section_id, $object_subtype, $section_args );
}
add_action( 'fields_register', 'example_my_user_address' );