-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.php
72 lines (61 loc) · 1.89 KB
/
settings.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
<?php
defined( 'ABSPATH' ) || exit;
class EpcwSettings {
/**
* The single instance of the class.
*/
protected static $_instance = null;
/**
* Main Instance.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* EpcwWidget Constructor.
*/
public function __construct() {
add_action('init', array($this, 'init'));
}
/**
* Init.
*/
public function init() {
if (current_user_can('administrator')) {
add_action('admin_init', array($this, 'register_settings'));
add_action('admin_menu', array($this, 'register_options_page'));
}
}
public function register_settings() {
add_option( 'epcw_api_key', '');
register_setting( 'epcw_options_group', 'epcw_api_key', 'epcw_callback' );
}
public function register_options_page() {
add_options_page(esc_html__( 'Envato Purchase Code Widget', 'epcw' ), esc_html__( 'EPCW', 'epcw' ), 'manage_options', 'epcw', array($this, 'options_page'));
}
public function options_page() {
?>
<div style="background: #fff;padding: 30px;max-width: 480px;margin-top: 20px;">
<h1><?php esc_html_e( 'Envato API Key', 'epcw' ); ?></h1>
<form method="post" action="options.php">
<?php settings_fields( 'epcw_options_group' ); ?>
<div style="margin-top:30px;">
<input type="text" style="width:100%;padding: 5px;" id="epcw_api_key" name="epcw_api_key" value="<?php echo esc_html(get_option('epcw_api_key')); ?>" />
</div>
<?php submit_button(); ?>
</form>
</div>
<?php
}
}
/**
* Returns the main instance of EpcwSettings.
*/
function EpcwSettings() {
return EpcwSettings::instance();
}
// Global for backwards compatibility.
$GLOBALS['EpcwSettings'] = EpcwSettings();