class-itthinx-updates-admin.php
4.81 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
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
<?php
if ( !defined( 'ABSPATH' ) ) {
exit;
}
class Itthinx_Updates_Admin {
public static function init() {
if ( is_multisite() ) {
add_action( 'network_admin_menu', array( __CLASS__, 'admin_menu' ) );
add_filter( 'network_admin_plugin_action_links_'. plugin_basename( ITTHINX_UPDATES_FILE ), array( __CLASS__, 'admin_settings_link' ) );
} else {
add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
add_filter( 'plugin_action_links_'. plugin_basename( ITTHINX_UPDATES_FILE ), array( __CLASS__, 'admin_settings_link' ) );
}
if ( isset( $_POST['action'] ) && ( $_POST['action'] == 'ix-force-update-check' ) && wp_verify_nonce( $_POST['itthinx-updates-force-check'], 'admin' ) ) {
if ( current_user_can( 'update_plugins' ) ) {
set_site_transient( 'update_plugins', null );
wp_safe_redirect( admin_url( 'plugins.php?page=itthinx-updates' ) );
exit;
}
}
}
public static function admin_settings_link( $links ) {
if ( current_user_can( 'manage_options' ) ) {
if ( is_multisite() ) {
$links = array( '<a href="' . get_admin_url( null, 'network/plugins.php?page=itthinx-updates' ) . '">' . __( 'Settings', ITTHINX_UPDATES_PLUGIN_DOMAIN ) . '</a>' ) + $links;
} else {
$links = array( '<a href="' . get_admin_url( null, 'plugins.php?page=itthinx-updates' ) . '">' . __( 'Settings', ITTHINX_UPDATES_PLUGIN_DOMAIN ) . '</a>' ) + $links;
}
}
return $links;
}
public static function admin_menu() {
add_plugins_page(
__( 'Itthinx Updates', ITTHINX_UPDATES_PLUGIN_DOMAIN ),
__( 'Itthinx Updates', ITTHINX_UPDATES_PLUGIN_DOMAIN ),
'manage_options',
'itthinx-updates',
array( __CLASS__, 'settings' )
);
}
public static function settings() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'Access denied.', ITTHINX_UPDATES_PLUGIN_DOMAIN ) );
}
if ( isset( $_POST['action'] ) && ( $_POST['action'] == 'set' ) && wp_verify_nonce( $_POST['itthinx-updates-settings'], 'admin' ) ) {
$service_key = !empty( $_POST['service_key'] ) ? trim( $_POST['service_key'] ) : '';
Itthinx_Updates::set_service_key( $service_key );
}
echo '<h1>';
echo __( 'Itthinx Updates', ITTHINX_UPDATES_PLUGIN_DOMAIN );
echo '</h1>';
echo '<h2>';
echo __( 'Service Key', ITTHINX_UPDATES_PLUGIN_DOMAIN );
echo '</h2>';
$service_key = Itthinx_Updates::get_service_key( '' );
echo '<div>';
echo '<form name="settings" method="post" action="">';
echo '<div class="itthinx-updates">';
echo '<p>';
echo '<label>';
echo __( 'Service Key', ITTHINX_UPDATES_PLUGIN_DOMAIN );
echo ' ';
echo sprintf( '<input style="display:block;width:80%%;" type="text" name="service_key" value="%s" placeholder="%s" />', esc_attr( $service_key ), esc_attr( __( 'Input your service key here …', ITTHINX_UPDATES_PLUGIN_DOMAIN ) ) );
echo '</label>';
echo '</p>';
echo '<p>';
echo __( 'Automatic updates require a valid user account on <a href="http://www.itthinx.com/">itthinx.com</a> and a service key.', ITTHINX_UPDATES_PLUGIN_DOMAIN );
echo '</p>';
echo '<p>';
echo __( 'To obtain your service key, visit the <a href="http://www.itthinx.com/service-key/">Service Key</a> page, log in and then copy the service key that appears on that page and paste it in the field above.', ITTHINX_UPDATES_PLUGIN_DOMAIN );
echo '</p>';
wp_nonce_field( 'admin', 'itthinx-updates-settings', true, true );
echo '<div class="buttons">';
echo sprintf( '<input class="save button button-primary" type="submit" name="submit" value="%s" />', esc_attr( __( 'Save', ITTHINX_UPDATES_PLUGIN_DOMAIN ) ) );
echo '<input type="hidden" name="action" value="set" />';
echo '</div>'; // .buttons
echo '</div>'; // .itthinx-updates
echo '</form>';
echo '</div>';
if ( current_user_can( 'update_plugins' ) ) {
echo '<h2>';
echo __( 'Updates', ITTHINX_UPDATES_PLUGIN_DOMAIN );
echo '</h2>';
$update_data = wp_get_update_data();
if ( !empty( $update_data['title'] ) ) {
echo '<div class="itthinx-updates">';
echo '<p>';
echo esc_html( $update_data['title'] );
echo '</p>';
echo '</div>'; // .itthinx-updates
}
echo '<div>';
echo '<form name="settings" method="post" action="">';
echo '<div class="itthinx-updates">';
echo '<p>';
echo __( 'You can click the button to force WordPress to check for updates.', ITTHINX_UPDATES_PLUGIN_DOMAIN );
echo '</p>';
wp_nonce_field( 'admin', 'itthinx-updates-force-check', true, true );
echo '<div class="buttons">';
echo sprintf( '<input class="update button" type="submit" name="submit" value="%s" />', esc_attr( __( 'Check', ITTHINX_UPDATES_PLUGIN_DOMAIN ) ) );
echo '<input type="hidden" name="action" value="ix-force-update-check" />';
echo '</div>'; // .buttons
echo '</div>'; // .itthinx-updates
echo '</form>';
echo '</div>';
}
}
}
add_action( 'init', array( 'Itthinx_Updates_Admin', 'init' ) );