-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin-page.php
149 lines (125 loc) · 3.9 KB
/
admin-page.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
<?php
/**
* Página e configurações do plugin o Painel Admin
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
// Adiciona página no sub-menu "Configurações"
add_action( 'admin_menu', function() {
add_submenu_page(
'options-general.php', // slug name for the parent menu
'Santho API Plugin', // text to be displayed in the title tags of the page
'Santho API', // text to be used for the menu
'manage_options', // user capability required for this menu to be displayed
'sapi_plugin', // slug name to refer to this menu by
'sapi_plugin_page' // function to be called to output the content for this page
);
});
add_action( 'admin_init', function () {
$df_group = SAPI_SET_GROUP;
// Registra grupo de opções
register_setting( 'sapi-fields', $df_group );
// Adiciona seção de campos de opções
add_settings_section(
'sapi-plugin-section',
__( 'Santho API' ),
'sapi_settings_section_callback',
'sapi-fields'
);
// Campo opção - Login slug
$ct_login = sapi_get_custom_login();
$login_url = get_home_url('', $ct_login['slug']);
add_settings_field(
'sapi_login_slug',
__( 'Novo caminho URL de login' ),
'sapi_render_text_field',
'sapi-fields',
'sapi-plugin-section',
array(
'st_group' => $df_group,
'label_for' => 'sapi_login_slug',
'default' => $ct_login['slug'],
'sanitize' => 'sanitize_title',
'description' => __( 'Login: <a target="_blank" href="' . $login_url . '">' . $login_url . '</a>' )
)
);
// Campo opção - Redirecionamento após logout
add_settings_field(
'sapi_logout_redir',
__( 'Redirecionamento no logout' ),
'sapi_render_text_field',
'sapi-fields',
'sapi-plugin-section',
array(
'st_group' => $df_group,
'label_for' => 'sapi_logout_redir',
'type' => 'url',
'default' => get_home_url(),
'sanitize' => 'esc_url',
'description' => __( 'URL destino para redirecionamento quando o usuário fizer logout.' )
)
);
// Campo opção - Prefixo API
$api_prefix = sapi_setting('sapi_api_prefix', SAPI_API_PREFIX);
$api_url = get_rest_url();
add_settings_field(
'sapi_api_prefix',
__( 'Endpoint para API' ),
'sapi_render_text_field',
'sapi-fields',
'sapi-plugin-section',
array(
'st_group' => $df_group,
'label_for' => 'sapi_api_prefix',
'default' => $api_prefix,
'sanitize' => 'sanitize_title',
'description' => __( 'Rest API URL: <a target="_blank" href="' . $api_url . '">' . $api_url . '</a>' )
)
);
});
function sapi_settings_section_callback() {
echo __( '<h4 style="margin-bottom:0">Wordpress API Reset Plugin</h4>' );
echo __ ( 'Defina as opções básicas para Santho API:' );
}
function sapi_render_text_field( $args ) {
$group = $args['st_group'];
$options = get_option( $group );
$name = $args['label_for'];
$type = ( isset($args['type']) ? $args['type'] : 'text' );
$description = $args['description'];
if ( !isset($options[$name]) || empty($options[$name]) ) {
if ( isset($args['default']) ) {
$value = $args['default'];
}
else {
$value = null;
}
}
else {
$value = $options[$name];
}
if ( isset($args['sanitize']) && !empty($value) ) {
$sanitize = $args['sanitize'];
$value = $sanitize($value);
}
$html = '<input type="' . $type . '"';
$html .= ' name="' . $group . '['. $name .']"';
$html .= ' id="' . $name .'"';
$html .= ' value="' . $value . '"';
$html .= ' class="regular-text"';
$html .= '>';
if ( isset($description) ) {
$html .= '<p class="description">' . $description .'</p>';
}
echo $html;
}
function sapi_plugin_page() {
?>
<form action='options.php' method='post'> <?php
settings_fields( 'sapi-fields' );
do_settings_sections( 'sapi-fields' );
submit_button(); ?>
</form>
<?php
}