-
Notifications
You must be signed in to change notification settings - Fork 0
/
ACF.php
117 lines (110 loc) · 3.41 KB
/
ACF.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
<?php
/**
* Register ACF options page and fields.
*
* @package redirections
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'acf/init', 'redirections_register_acf_options_page' );
add_action( 'acf/init', 'redirections_register_acf_fields' );
/**
* Add options page at the end of admin menu, available for Editors and Administrators
*/
function redirections_register_acf_options_page() {
if( function_exists( 'acf_add_options_page' ) ) {
$option_page = acf_add_options_page(
array (
'page_title' => __( 'Redirections', 'redirections' ),
'capability' => 'edit_pages',
)
);
}
}
/**
* Add a form to set redirections
*/
function redirections_register_acf_fields() {
acf_add_local_field_group(
array(
'key' => '301_redirections_group',
'title' => __( '301 Redirections', 'redirections' ),
'fields' => array(
array(
'key' => '301_redirections',
'label' => __( 'Redirections', 'redirections' ),
'name' => 'redirections',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'table',
'button_label' => __( 'Add redirection', 'redirections' ),
'sub_fields' => array(
array(
'key' => '301_redirect_from',
'label' => __( 'Redirect from', 'redirections' ),
'name' => 'redirect_from',
'type' => 'text',
'instructions' => __( 'Url which has to be redirected, without domain, e.g. /test-page', 'redirections' ),
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => '301_redirect_to',
'label' => __( 'Redirect to', 'redirections' ),
'name' => 'redirect_to',
'type' => 'url',
'instructions' => __( 'Where url should be redirected. Full url, e.g. https://testwebsite.com/test-page-2', 'redirections' ),
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
),
),
),
),
'location' => array(
array(
array(
'param' => 'options_page',
'operator' => '==',
'value' => 'acf-options-redirections',
),
),
),
'menu_order' => 1,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
)
);
}