Open wahke opened 2 years ago
Hello. I have thoughts about it, thanks. Dunno how to write wp plugins but I'll take a look
Hello, anything change about a Wordpress Plugin ? Maybe with your new API its more easy ?
Hey @wahke I may suggest something like that:
<?php
/**
* @package LGSL
* @version 0.0.1
*/
/*
Plugin Name: LGSL Plugin (Live Game Server List)
Plugin URI: https://github.com/tltneon/lgsl/
Description: This is just a plugin to parsing data from LGSL
Author: tltneon
Version: 0.0.1
Author URI: https://github.com/tltneon
*/
function getLgslPath() {
return "http://lgsl7.test";
}
function getLgslServers() {
$response = wp_remote_retrieve_body(wp_remote_get(getLgslPath() . "/src/lgsl_feed.php")) ?? "[]";
return json_decode($response, true);
}
function lgsl() {
$servers = getLgslServers();
$out = "<div class='card-wrapper w-full' id='lgsl'><article class='card card-list'><div class='card-content flex-grow'><h2 class='entry-title'>Live Game Server List</h2><table class='wp-list-table widefat striped table-view-list posts'>";
$out .= "
<tr>
<th>Name</th>
<th>IP</th>
<th>Port</th>
<th>Game</th>
<th>Map</th>
<th>Players</th>
<th>Status</th>
</tr>";
foreach ($servers as $server) {
$isOnline = $server['online'] ? 'online' : 'offline';
$out .= "
<tr>
<td><a href='" . getLgslPath() . "/?ip={$server['ip']}&port={$server['port']}' target='_blank' class='link'>{$server['name']}</a></td>
<td>{$server['ip']}</td>
<td>{$server['port']}</td>
<td>{$server['game']}</td>
<td>{$server['map']}</td>
<td>{$server['players']}/{$server['maxplayers']}</td>
<td>{$isOnline}</td>
</tr>";
}
$out .= "</table></div></article></div>";
print($out);
}
add_action( 'get_footer', 'lgsl');
function lgslCss() {
echo "
<style type='text/css'>
#lgsl div.card-content {
margin: auto;
}
</style>
";
}
add_action( 'get_footer', 'lgslCss' );
function wporg_options_page() {
add_menu_page(
'LGSL Page',
'LGSL Page',
'manage_options',
'lgsl',
'lgsl_page_html'
);
}
add_action( 'admin_menu', 'wporg_options_page' );
function lgsl_page_html() {
lgsl();
}
It able to show table with servers in the footer of page.
I can't figure out how to save string setting so just replace
http://lgsl7.test
with your lgsl link
Hello, maybe you could think about an integration with Wordpress?