|
2 | 2 |
|
3 | 3 | namespace SnapCache\Admin; |
4 | 4 |
|
| 5 | +use SnapCache\Memcached; |
5 | 6 | use SnapCache\Options; |
6 | 7 |
|
7 | 8 | class SettingsMain { |
@@ -94,14 +95,52 @@ public static function field_object_cache(): void { |
94 | 95 | } |
95 | 96 |
|
96 | 97 | public static function field_memcached_servers(): void { |
| 98 | + $configurable = ! Options::isMemcachedServersInWpConfig(); |
| 99 | + |
97 | 100 | $val = esc_textarea( get_option( 'snapcache_memcached_servers', 'localhost:11211' ) ); |
98 | 101 | ?> |
99 | 102 | <textarea name="snapcache_memcached_servers" rows="5" cols="50" class="large-text" |
| 103 | + <?php |
| 104 | + if ( ! $configurable ) { |
| 105 | + echo 'style="display: none"'; } ?> |
100 | 106 | ><?php echo $val; ?></textarea> |
101 | 107 | <p class="description"> |
102 | | - One host per line. Format: <code>host:port</code>. |
| 108 | + <?php if ( $configurable ) : ?> |
| 109 | + One host per line. Format: <code>host:port</code> or <code>host:port weight</code>. |
103 | 110 | Default is <code>localhost:11211</code>. |
104 | | - </p> |
105 | | - <?php |
| 111 | + </p> |
| 112 | + <?php |
| 113 | + else : |
| 114 | + $mc = Memcached::getSnapCacheMemcached(); |
| 115 | + $servers = $mc::getServersFromConfig(); |
| 116 | + ?> |
| 117 | + <table class="widefat striped" style="width: auto; margin-top: 10px;"> |
| 118 | + <thead> |
| 119 | + <tr> |
| 120 | + <th scope="col" style="padding-left: 10pt; width: auto">Host</th> |
| 121 | + <th scope="col" style="text-align: center; padding-left: 20pt; width: auto"> |
| 122 | + Port</th> |
| 123 | + <th scope="col" style="text-align: center; padding-left: 20pt; width: auto"> |
| 124 | + Weight</th> |
| 125 | + </tr> |
| 126 | + </thead> |
| 127 | + <tbody> |
| 128 | + <?php foreach ( $servers as $server ) : ?> |
| 129 | + <tr> |
| 130 | + <td style="padding-left: 10pt"><?php echo esc_html( $server[0] ); ?></td> |
| 131 | + <td style="text-align: center; padding-left: 20pt"> |
| 132 | + <?php echo esc_html( $server[1] ?? 11211 ); ?></td> |
| 133 | + <td style="text-align: center; padding-left: 20pt"> |
| 134 | + <?php echo esc_html( $server[2] ?? 0 ); ?></td> |
| 135 | + </tr> |
| 136 | + <?php endforeach; ?> |
| 137 | + </tbody> |
| 138 | + </table> |
| 139 | + <p> |
| 140 | + To change the server list, either edit <code>SNAPCACHE_MEMCACHED_SERVERS</code> |
| 141 | + in <code>wp-config.php</code> or remove it and refresh this page. |
| 142 | + </p> |
| 143 | + <?php |
| 144 | + endif; |
106 | 145 | } |
107 | 146 | } |
0 commit comments