-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdater-ui.php
72 lines (53 loc) · 1.59 KB
/
updater-ui.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
abstract class APP_Upgrader_UI {
abstract function init_page();
abstract protected function can_set_key();
abstract protected function get_admin_url();
protected function maybe_set_key() {
if ( ! isset( $_POST['appthemes_submit'] ) ) {
return;
}
APP_Upgrader::set_key( trim( $_POST['appthemes_key'] ) );
echo "
<div class='updated fade'><p>"
. __( 'Saved Changes.', 'appthemes-updater' )
. "</p></div>";
}
function show_notice() {
self::maybe_set_key();
if ( APP_Upgrader::get_key() ) {
return;
}
if ( ! $this->can_set_key() ) {
return;
}
self::render( 'api-key-notice.php', array(
'admin_url' => $this->get_admin_url()
) );
}
function render_page() {
self::render( 'admin-page.php' );
if ( APP_Upgrader::get_key() ) {
self::render( 'check-for-updates.php' );
}
}
private static function render( $path, $vars = array() ) {
extract( $vars );
include dirname(__FILE__) . "/templates/$path";
}
}
class APP_Upgrader_Regular extends APP_Upgrader_UI {
function __construct() {
add_action( 'admin_notices', array( $this, 'show_notice' ) );
add_action( 'admin_menu', array( $this, 'init_page' ) );
}
protected function can_set_key() {
return current_user_can( 'manage_options' );
}
protected function get_admin_url() {
return admin_url( 'options-general.php?page=appthemes-key-config' );
}
function init_page() {
add_options_page( esc_html__( 'AppThemes Updater', 'appthemes-updater' ), esc_html__( 'AppThemes Updater', 'appthemes-updater' ), 'manage_options', 'appthemes-key-config', array( $this, 'render_page' ) );
}
}