-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclass-meetup-widgets-admin.php
More file actions
70 lines (62 loc) · 2.16 KB
/
class-meetup-widgets-admin.php
File metadata and controls
70 lines (62 loc) · 2.16 KB
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
<?php
/**
* Handles any admin view functionality
*
* @package Meetup_Widgets
* @since 3.0.0
*/
if ( ! class_exists( 'Meetup_Widgets_Admin' ) ) {
/**
* Set up the Settings section to save Meetup.com API key
*/
class Meetup_Widgets_Admin {
/**
* Initialize the settings screen
*/
public function __construct() {
// TODO deal with translations.
add_filter( 'admin_init', array( $this, 'register_fields' ) );
}
/**
* Register the section in Settings -> General
*/
function register_fields() {
register_setting( 'general', 'vs_meet_options', array( $this, 'validate' ) );
add_settings_section( 'vs_meet', __( 'Meetup API Settings', 'meetup-widgets' ), array( $this, 'setting_section_vs_meetup' ), 'general' );
add_settings_field( 'vs_meetup_api_key', sprintf( '<label for="vs_meetup_api_key">%s</label>', __( 'Meetup API Key:', 'meetup-widgets' ) ), array( $this, 'setting_vs_meetup_api_key' ), 'general', 'vs_meet' );
}
/**
* Display the API key directions
*/
function setting_section_vs_meetup() {
printf(
'<p>%s</p>',
sprintf(
// Translators: %s is the link to the meetup.com API key page.
__( 'To use this plugin, you need to a meetup.com API key. You can find your API key at the <a href="%s">“Getting An API Key”</a> page. Click the lock next to the input field, then copy the contents of the input into the Meetup API field below.', 'meetup-widgets' ),
'https://secure.meetup.com/meetup_api/key/'
)
);
}
/**
* Display an input for the API key
*/
function setting_vs_meetup_api_key() {
$options = get_option( 'vs_meet_options' );
printf( '<input id="vs_meetup_api_key" name="vs_meet_options[vs_meetup_api_key]" size="40" type="text" value="%s" />', esc_attr( $options['vs_meetup_api_key'] ) );
}
/**
* Sanitize and validate input
*
* @param array $input an array to sanitize.
* @return array a valid array.
*/
public function validate( $input ) {
$output = array();
if ( preg_match( '/^[a-zA-Z0-9]{0,40}$/i', $input['vs_meetup_api_key'] ) ) {
$output['vs_meetup_api_key'] = $input['vs_meetup_api_key'];
}
return $output;
}
}
} // End if().