-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin-page.php
86 lines (69 loc) · 2.45 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
<?php
if (is_admin()) {
add_action('admin_menu', 'rfs_wphook_admin_menu');
}
add_action('admin_notices', 'rfs_admin_notice');
function rfs_admin_notice(){
global $RFS_NOTICES;
foreach ($RFS_NOTICES as $notice) {
switch ($notice) {
case "not-configured" : ?>
<div class="error">
<p>RemoteFS is installed but not configured.</p>
<p>Either provide configuration via <a href="/wp-admin/options-general.php?page=rfs-settings-admin">options page</a> or provide environment vars:
<br><code>REMOTEFS_PRIVATE_URL</code>, <code>REMOTEFS_PUBLIC_URL</code>.</p>
</div>
<?php break ;
case "not-implemented-private" : ?>
<div class="error">
<p>RemoteFS has no implementation for configured private url.</p>
<p>Please check <a href="/wp-admin/options-general.php?page=rfs-settings-admin">options page</a>.</p>
</div>
<?php break ;
default: ?>
<div class="error">
<?=$notice?>
</div>
<?php
}
}
}
function rfs_wphook_admin_menu() {
add_options_page(
'Settings Admin',
'RemoteFS settings',
'manage_options',
'rfs-settings-admin',
'rfs_wphook_admin_settings_page'
);
add_action('admin_init', 'rfs_register_settings');
}
function rfs_register_settings() {
register_setting('rfs-settings-group', 'rfs-private-url');
register_setting('rfs-settings-group', 'rfs-public-url');
}
function rfs_wphook_admin_settings_page() { ?>
<div class="wrap">
<h2>RemoteFS settings</h2>
<?php $p = getenv("REMOTEFS_PRIVATE_URL"); ?>
<?php if (!empty($p)) : ?>
<p class="description">configured via environment variables</p>
<h3 class="title">Private URL</h3>
<p><code><?=getenv("REMOTEFS_PRIVATE_URL")?></code></p>
<h3 class="title">Public URL</h3>
<p><code><?=getenv("REMOTEFS_PUBLIC_URL")?></code></p>
<?php else : ?>
<form method="post" action="options.php">
<?php settings_fields( 'rfs-settings-group' ); ?>
<?php do_settings_sections( 'rfs-settings-group' ); ?>
<h3 class="title">Private URL</h3>
<p class="description">example: ftp://login:password@host:port/media</p>
<textarea name="rfs-private-url" class="large-text code" rows="2"><?=get_option('rfs-private-url')?></textarea>
<h3 class="title">Public URL</h3>
<p class="description">example: http://host/media</p>
<textarea name="rfs-public-url" class="large-text code" rows="2"><?=get_option('rfs-public-url')?></textarea>
<?php submit_button(); ?>
</form>
<?php endif ?>
</div>
<?php }