updater options

This commit is contained in:
parkel committed 2026-11-18 01:46:55 +01:00
1 parent dccb8ed9bd
commit db897ac2dd
8 files changed
+503 -36

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ WordPress-plugin voor recente berichten van Instagram, Facebook en X en voor een
## WordPress instellen
Open **HG Plugins → Social Feed**. Vul een gebruikersnaam in voor Instagram of X. Voor Facebook volstaat de paginanaam uit de URL of het numerieke pagina-ID. Dit is genoeg om de profiellinks en iconen te gebruiken.
Open **HG Plugins → Social Feed** en kies het tabblad **Instagram**, **Facebook** of **X**. Vul een gebruikersnaam in voor Instagram of X. Voor Facebook volstaat de paginanaam uit de URL of het numerieke pagina-ID. Dit is genoeg om de profiellinks en iconen te gebruiken. Op het tabblad **Shortcodes** vind je voorbeelden voor het plaatsen van de feed en de iconenbalk.
Voor automatische berichten zijn aanvullende toegangsgegevens nodig.
+99
View File
@@ -0,0 +1,99 @@
.hgsf-admin .hgsf-admin-tabs {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-bottom: 24px;
border-bottom: 1px solid #c3c4c7;
}
.hgsf-admin .hgsf-admin-tabs a {
padding: 14px 22px;
border-bottom: 3px solid transparent;
color: #50575e;
font-size: 15px;
font-weight: 600;
text-decoration: none;
}
.hgsf-admin .hgsf-admin-tabs a:hover,
.hgsf-admin .hgsf-admin-tabs a[aria-current="page"] {
color: #135e96;
}
.hgsf-admin .hgsf-admin-tabs a[aria-current="page"] {
border-color: #2271b1;
}
.hgsf-admin .hgsf-admin-card {
padding: 24px 28px;
margin-bottom: 20px;
background: #fff;
border: 1px solid #dcdcde;
border-radius: 8px;
}
.hgsf-admin .hgsf-admin-card h2 {
margin-top: 0;
}
.hgsf-admin .hgsf-admin-form {
display: grid;
gap: 16px;
max-width: 620px;
margin-top: 22px;
}
.hgsf-admin .hgsf-admin-form p,
.hgsf-admin .hgsf-admin-card > :last-child {
margin-bottom: 0;
}
.hgsf-admin .hgsf-admin-field {
display: grid;
gap: 7px;
}
.hgsf-admin .hgsf-admin-field label {
font-weight: 600;
}
.hgsf-admin .hgsf-admin-field input {
width: 100%;
min-height: 38px;
margin: 0;
}
.hgsf-admin .hgsf-admin-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.hgsf-admin .hgsf-shortcodes {
display: grid;
grid-template-columns: max-content 1fr;
gap: 12px 20px;
align-items: baseline;
}
.hgsf-admin .hgsf-shortcodes dd {
margin: 0;
}
.hgsf-admin code {
overflow-wrap: anywhere;
}
@media (max-width: 782px) {
.hgsf-admin .hgsf-admin-tabs a {
padding: 12px;
}
.hgsf-admin .hgsf-admin-card {
padding: 20px;
}
.hgsf-admin .hgsf-shortcodes {
grid-template-columns: 1fr;
}
}
+4 -2
View File
@@ -2,7 +2,8 @@
/**
* Plugin Name: HG Social Feed
* Description: Toont recente berichten en profiellinks van Instagram, Facebook en X.
* Version: 0.2.0
* Version: 0.2.1
* Update URI: https://code.hosting.hippogrief.nl/hippogrief/wp-plugins/src/branch/main/hg_socialfeed
* Requires at least: 6.5
* Requires PHP: 8.1
* Author: Hippogrief
@@ -11,8 +12,9 @@
*/
if (!defined('ABSPATH')) exit;
require_once __DIR__ . '/includes/hg-plugin-updates.php';
define('HGSF_VERSION', '0.2.0');
define('HGSF_VERSION', '0.2.1');
define('HGSF_PLUGIN_FILE', __FILE__);
require_once __DIR__ . '/includes/sources.php';
+57 -28
View File
@@ -11,10 +11,23 @@ HG_Plugin_Admin::register([
'callback' => 'hgsf_admin_page',
]);
add_action('admin_enqueue_scripts', static function (string $hook): void {
if ($hook === HG_Plugin_Admin::hook('hg-socialfeed')) {
wp_enqueue_style('hgsf-admin', plugins_url('assets/admin.css', HGSF_PLUGIN_FILE), ['hg-admin-menu'], HGSF_VERSION);
}
});
function hgsf_admin_url(string $tab, array $args = []): string {
return add_query_arg(['page' => 'hg-socialfeed', 'tab' => $tab] + $args, admin_url('admin.php'));
}
function hgsf_admin_page(): void {
if (!current_user_can('manage_options')) {
wp_die('Geen toegang.', '', ['response' => 403]);
}
$tabs = array_map(static fn (array $provider): string => $provider['label'], HGSF_SOURCES) + ['shortcodes' => 'Shortcodes'];
$tab = $_GET['tab'] ?? '';
$tab = is_string($tab) && isset($tabs[$tab]) ? $tab : 'instagram';
$notice = match ($_GET['hgsf_notice'] ?? '') {
'saved' => ['success', 'Instellingen opgeslagen.'],
'synced' => ['success', 'Berichten opgehaald.'],
@@ -25,25 +38,37 @@ function hgsf_admin_page(): void {
default => null,
};
?>
<div class="wrap hg-suite">
<div class="wrap hg-suite hgsf-admin">
<header class="hg-suite-header">
<span class="hg-suite-mark" aria-hidden="true">HG</span>
<div><h1>HG Social Feed</h1><p>Beheer de bronnen voor berichten en profieliconen.</p></div>
</header>
<hr class="wp-header-end">
<?php if ($notice) : ?>
<div class="notice notice-<?php echo esc_attr($notice[0]); ?>"><p><?php echo esc_html($notice[1]); ?></p></div>
<div class="notice notice-<?php echo esc_attr($notice[0]); ?> inline"><p><?php echo esc_html($notice[1]); ?></p></div>
<?php endif; ?>
<div class="hg-suite-grid">
<?php foreach (HGSF_SOURCES as $source => $provider) :
hgsf_admin_source($source, $provider['label']);
endforeach; ?>
</div>
<nav class="hgsf-admin-tabs" aria-label="Pluginonderdelen">
<?php foreach ($tabs as $key => $label) : ?>
<a href="<?php echo esc_url(hgsf_admin_url($key)); ?>" <?php if ($key === $tab) echo 'aria-current="page"'; ?>><?php echo esc_html($label); ?></a>
<?php endforeach; ?>
</nav>
<h2>Plaatsen op de website</h2>
<p><code>[hg_socialfeed]</code> toont de recentste berichten en links naar de profielen.</p>
<p><code>[hg_sociallinks]</code> toont alleen de iconenbalk met links naar de ingestelde profielen.</p>
<p>Beperk desgewenst de bronnen met <code>sources="instagram,facebook"</code>.</p>
<?php if ($tab === 'shortcodes') : ?>
<section class="hgsf-admin-card">
<h2>Plaatsen op de website</h2>
<p>Plaats een shortcode in een shortcodeblok op de gewenste pagina.</p>
<dl class="hgsf-shortcodes">
<dt><code>[hg_socialfeed]</code></dt>
<dd>Toont de recentste berichten van de ingestelde platforms.</dd>
<dt><code>[hg_sociallinks]</code></dt>
<dd>Toont een iconenbalk met links naar de ingestelde profielen.</dd>
</dl>
<p>Kies specifieke platforms met bijvoorbeeld <code>[hg_socialfeed sources="instagram,facebook"]</code>.</p>
</section>
<?php else : ?>
<?php hgsf_admin_source($tab, $tabs[$tab]); ?>
<?php endif; ?>
</div>
<?php
}
@@ -68,39 +93,40 @@ function hgsf_admin_source(string $source, string $label): void {
};
$can_sync = $connection['token'] && ($source !== 'x' || $connection['enabled']);
?>
<section class="hg-suite-card">
<section class="hgsf-admin-card">
<h2><?php echo esc_html($label); ?></h2>
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
<p>Stel een profiel in voor de iconenbalk. Voeg een toegangstoken toe om berichten op te halen.</p>
<form class="hgsf-admin-form" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
<input type="hidden" name="action" value="hgsf_settings">
<input type="hidden" name="source" value="<?php echo esc_attr($source); ?>">
<?php wp_nonce_field('hgsf_settings_' . $source, 'hgsf_nonce_' . $source); ?>
<p>
<label for="hgsf-<?php echo esc_attr($source); ?>-username"><?php echo esc_html($field); ?></label><br>
<div class="hgsf-admin-field">
<label for="hgsf-<?php echo esc_attr($source); ?>-username"><?php echo esc_html($field); ?></label>
<input type="text" id="hgsf-<?php echo esc_attr($source); ?>-username" name="username" maxlength="31"
value="<?php echo esc_attr($connection['username']); ?>" autocapitalize="none" spellcheck="false">
</p>
</div>
<?php if ($source === 'facebook') : ?>
<p>
<label for="hgsf-facebook-profile">Paginanaam in de URL</label><br>
<div class="hgsf-admin-field">
<label for="hgsf-facebook-profile">Paginanaam in de URL</label>
<input type="text" id="hgsf-facebook-profile" name="profile" maxlength="75"
value="<?php echo esc_attr($connection['profile']); ?>" autocapitalize="none" spellcheck="false">
<br><span class="description">Optioneel voor de profiellink. Bijvoorbeeld mijnbedrijf uit facebook.com/mijnbedrijf.</span>
</p>
value="<?php echo esc_attr($connection['profile']); ?>" autocapitalize="none" spellcheck="false" aria-describedby="hgsf-facebook-profile-help">
<span class="description" id="hgsf-facebook-profile-help">Optioneel voor de profiellink, bijvoorbeeld mijnbedrijf uit facebook.com/mijnbedrijf.</span>
</div>
<?php endif; ?>
<p>
<label for="hgsf-<?php echo esc_attr($source); ?>-token">Toegangstoken</label><br>
<div class="hgsf-admin-field">
<label for="hgsf-<?php echo esc_attr($source); ?>-token">Toegangstoken</label>
<input type="password" id="hgsf-<?php echo esc_attr($source); ?>-token" name="token" autocomplete="new-password"
maxlength="2048" aria-describedby="hgsf-<?php echo esc_attr($source); ?>-token-help">
<br><span class="description" id="hgsf-<?php echo esc_attr($source); ?>-token-help">
<span class="description" id="hgsf-<?php echo esc_attr($source); ?>-token-help">
<?php echo esc_html($connection['token'] ? 'Laat leeg om het huidige token voor dit account te behouden.' : $help[0]); ?>
<a href="<?php echo esc_url($help[1]); ?>">Documentatie</a>
</span>
</p>
</div>
<?php if ($source === 'x') : ?>
<p><label><input type="checkbox" name="enabled" value="1" <?php checked($connection['enabled']); ?>>
X-berichten automatisch ophalen. X rekent per API-gebruik.</label></p>
<?php endif; ?>
<p>
<div class="hgsf-admin-actions">
<button type="submit" name="operation" value="save" class="button button-primary">Opslaan</button>
<?php if ($can_sync) : ?>
<button type="submit" name="operation" value="sync" class="button">Nu synchroniseren</button>
@@ -108,8 +134,11 @@ function hgsf_admin_source(string $source, string $label): void {
<?php if ($connection['token']) : ?>
<button type="submit" name="operation" value="disconnect" class="button">Koppeling verwijderen</button>
<?php endif; ?>
</p>
</div>
</form>
</section>
<section class="hgsf-admin-card">
<h2>Synchronisatie</h2>
<?php if (!$can_sync) : ?>
<p>Automatisch ophalen staat uit.</p>
<?php elseif (!empty($snapshot['error'])) : ?>
@@ -137,7 +166,7 @@ function hgsf_handle_settings(): void {
check_admin_referer('hgsf_settings_' . $source, 'hgsf_nonce_' . $source);
$result = hgsf_with_connection_lock(static fn () => hgsf_save_settings($source, $_POST), $source);
$notice = is_wp_error($result) ? 'busy' : $result;
wp_safe_redirect(add_query_arg(['page' => 'hg-socialfeed', 'hgsf_notice' => $notice], admin_url('admin.php')));
wp_safe_redirect(hgsf_admin_url($source, ['hgsf_notice' => $notice]), 303);
exit;
}
+317
View File
@@ -0,0 +1,317 @@
<?php
/** HG release updates, bundled identically in each standalone HG plugin. */
if (!defined('ABSPATH')) exit;
if (!class_exists('HG_Plugin_Updates_1_0_0', false)) {
// Bump this class suffix and VERSION together when changing the bundled updater.
final class HG_Plugin_Updates_1_0_0 {
private const VERSION = '1.0.0';
private const REPOSITORY = 'https://code.hosting.hippogrief.nl/hippogrief/wp-plugins';
private const RELEASE_API = 'https://code.hosting.hippogrief.nl/api/v1/repos/hippogrief/wp-plugins/releases';
private const CACHE = 'hg_plugin_releases';
private const PAGE = 'hg-plugin-updates';
private const MODULES = [
'hg-contactform' => ['HG Contactformulier', 'hg-contactform'],
'hg-hephaestusaperture' => ['HG Hephaestus Aperture', 'hg-hephaestusaperture'],
'hg-registrations' => ['HG Inschrijvingen', 'hg-registrations'],
'hg-socialfeed' => ['HG Social Feed', 'hg_socialfeed'],
];
private static array $downloads = [];
public static function prefer(array $selected): array {
return version_compare(self::VERSION, $selected['version'], '>')
? ['class' => self::class, 'version' => self::VERSION]
: $selected;
}
public static function boot(): void {
$selected = apply_filters('hg_plugin_updates_implementation', ['class' => '', 'version' => '0']);
if ($selected['class'] !== self::class) return;
add_filter('update_plugins_code.hosting.hippogrief.nl', [self::class, 'native_update'], 10, 3);
add_filter('upgrader_pre_download', [self::class, 'verify_download'], 10, 4);
add_filter('upgrader_source_selection', [self::class, 'verify_package'], 9, 4);
add_filter('http_request_args', [self::class, 'download_args'], 10, 2);
add_action('admin_menu', [self::class, 'menu'], 21);
add_action('admin_post_hg_plugin_updates_refresh', [self::class, 'refresh']);
}
private static function package_base(): string {
return self::REPOSITORY . '/releases/download/';
}
private static function update_uri(string $slug): string {
return self::REPOSITORY . '/src/branch/main/' . str_replace('-', '_', $slug);
}
private static function module(string $file, array $data): ?string {
$slug = basename($file, '.php');
if (!isset(self::MODULES[$slug]) || dirname($file) === '.' || basename($file) !== "$slug.php" || validate_file($file) !== 0) {
return null;
}
$uri = $data['UpdateURI'] ?? '';
// Recognize installed releases from before the updater was bundled.
if ($uri === self::update_uri($slug) || ($uri === '' && ($data['Name'] ?? '') === self::MODULES[$slug][0])) {
return $slug;
}
return null;
}
private static function releases(bool $refresh = false): array {
$cached = get_site_transient(self::CACHE);
if (!$refresh && is_array($cached)) {
return $cached;
}
$result = self::fetch_releases();
set_site_transient(self::CACHE, $result, $result['error'] ? 5 * MINUTE_IN_SECONDS : 6 * HOUR_IN_SECONDS);
return $result;
}
private static function fetch_releases(): array {
$updates = [];
$limit = 50;
for ($page = 1; $page <= 20; $page++) {
$response = wp_safe_remote_get(add_query_arg(['limit' => $limit, 'page' => $page], self::RELEASE_API), [
'headers' => ['Accept' => 'application/json'],
'timeout' => 5,
'redirection' => 0,
'limit_response_size' => 2 * MB_IN_BYTES,
]);
$status = (int) wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
$releases = json_decode($body, true);
if ($status !== 200 || !is_array($releases) || !str_starts_with(ltrim($body), '[')) {
return ['error' => $status === 404 ? 'Ontoegankelijk' : 'Onbereikbaar', 'updates' => []];
}
foreach ($releases as $release) {
self::add_release($release, $updates);
}
$link = wp_remote_retrieve_header($response, 'link');
if (count($releases) < $limit && !str_contains(implode(',', (array) $link), 'rel="next"')) {
return ['error' => '', 'updates' => $updates];
}
}
return ['error' => 'Onbereikbaar', 'updates' => []];
}
private static function add_release(mixed $release, array &$updates): void {
if (!is_array($release) || ($release['draft'] ?? null) !== false || ($release['prerelease'] ?? null) !== false) {
return;
}
$tag = $release['tag_name'] ?? '';
$assets = $release['assets'] ?? null;
if (!is_string($tag) || !is_array($assets) || !preg_match('/^([a-z-]+)-v([0-9]+\.[0-9]+\.[0-9]+)$/D', $tag, $matches)) {
return;
}
[, $slug, $version] = $matches;
if (!isset(self::MODULES[$slug]) || (isset($updates[$slug]) && version_compare($version, $updates[$slug]['version'], '<='))) {
return;
}
$asset_urls = [];
foreach ($assets as $asset) {
$name = $asset['name'] ?? '';
if ($name !== "$slug-$version.zip" && $name !== "$slug.zip") continue;
$package = self::package_base() . "$tag/$name";
if (($asset['browser_download_url'] ?? '') === $package) {
$asset_urls[$name] = $package;
}
}
$package = $asset_urls["$slug-$version.zip"] ?? $asset_urls["$slug.zip"] ?? null;
if ($package) {
$updates[$slug] = [
'id' => self::update_uri($slug),
'slug' => $slug,
'version' => $version,
'new_version' => $version,
'url' => self::REPOSITORY . '/releases/tag/' . $tag,
'package' => $package,
];
}
}
public static function native_update($update, array $data, string $file) {
$slug = self::module($file, $data);
if (!$slug) return $update;
// WordPress can run its own update check during an anonymous admin-post request.
$can_fetch = wp_doing_cron() || current_user_can('update_plugins') || (defined('WP_CLI') && WP_CLI);
$releases = $can_fetch ? self::releases() : get_site_transient(self::CACHE);
return $releases['updates'][$slug] ?? $update;
}
private static function sync_updates(array $plugins, array $releases): void {
$transient = get_site_transient('update_plugins');
$transient = is_object($transient) ? clone $transient : new stdClass();
$previous = $transient->response ?? [];
$previous_no_update = $transient->no_update ?? [];
$transient->response = $previous;
$transient->no_update = $previous_no_update;
foreach ($plugins as $file => $data) {
$release = $releases[$data['slug']] ?? null;
if ($release && version_compare($release['version'], $data['Version'], '>')) {
$transient->response[$file] = (object) ($release + ['plugin' => $file]);
unset($transient->no_update[$file]);
} else {
unset($transient->response[$file]);
}
}
if ($previous != $transient->response || $previous_no_update != $transient->no_update) {
set_site_transient('update_plugins', $transient);
}
}
private static function installed(): array {
$installed = [];
foreach (get_plugins() as $file => $data) {
$slug = self::module($file, $data);
if ($slug) {
$installed[$file] = $data + ['slug' => $slug];
}
}
uasort($installed, static fn ($a, $b) => strcasecmp($a['Name'], $b['Name']));
return $installed;
}
public static function verify_download($reply, string $package, $upgrader, array $context) {
// WordPress bulk updates pass the plugin file without an action or type in this hook.
$file = $context['plugin'] ?? '';
if (is_wp_error($reply) || $file === '' || !str_starts_with($package, self::package_base())) {
return $reply;
}
$data = get_plugins()[$file] ?? [];
$slug = self::module($file, $data);
$release = $slug ? self::releases()['updates'][$slug] ?? null : null;
if (!$release || $package !== $release['package'] || !version_compare($release['version'], $data['Version'], '>')) {
return new WP_Error('hg_update_unavailable', 'Deze HG-update is niet meer beschikbaar. Controleer opnieuw op updates.');
}
// Keep a working installation active if native single-plugin validation rejects the update.
remove_filter('upgrader_pre_install', [$upgrader, 'deactivate_plugin_before_upgrade']);
self::$downloads[$file] = $release;
return $reply;
}
public static function download_args(array $args, string $url): array {
if (str_starts_with($url, self::package_base())) {
$args['redirection'] = 0;
}
return $args;
}
public static function verify_package($source, string $remote_source, $upgrader, array $context) {
global $wp_filesystem;
$file = $context['plugin'] ?? '';
$release = self::$downloads[$file] ?? null;
if (!$release || is_wp_error($source)) {
return $source;
}
unset(self::$downloads[$file]);
$slug = $release['slug'];
$source = trailingslashit($source);
$contents = $wp_filesystem->get_contents($source . basename($file));
$headers = str_replace("\r", "\n", substr((string) $contents, 0, 8 * KB_IN_BYTES));
$read = static function (string $field) use ($headers): string {
preg_match('/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . $field . ':(.*)$/mi', $headers, $matches);
return _cleanup_header_comment($matches[1] ?? '');
};
if (basename($source) !== self::MODULES[$slug][1] || !$read('Plugin Name')
|| $read('Version') !== $release['version'] || $read('Update URI') !== $release['id']) {
return new WP_Error('hg_update_package', 'Het ZIP-bestand komt niet overeen met de gekozen HG-release.');
}
if (!is_php_version_compatible($read('Requires PHP')) || !is_wp_version_compatible($read('Requires at least'))) {
return new WP_Error('hg_update_requirements', 'Deze HG-release vereist een nieuwere versie van WordPress of PHP.');
}
// Keep the active plugin basename when an existing installation renamed its directory.
if (basename($source) !== dirname($file)) {
$destination = trailingslashit($remote_source) . dirname($file);
if (!$wp_filesystem->move(untrailingslashit($source), $destination)) {
return new WP_Error('hg_update_directory', 'De bestaande plug-inmap kon niet worden behouden.');
}
return trailingslashit($destination);
}
return $source;
}
public static function menu(): void {
add_submenu_page('hg-plugins', 'HG Plugin-updates', 'Updates', 'update_plugins', self::PAGE, [self::class, 'screen']);
}
private static function authorize(): void {
if (!current_user_can('manage_options') || !current_user_can('update_plugins')) {
wp_die('Geen toegang.', '', ['response' => 403]);
}
}
public static function refresh(): void {
self::authorize();
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
wp_die('Ongeldig verzoek.', '', ['response' => 405]);
}
check_admin_referer('hg_plugin_updates_refresh');
$releases = self::releases(true);
self::sync_updates(self::installed(), $releases['updates']);
wp_safe_redirect(add_query_arg('page', self::PAGE, admin_url('admin.php')), 303);
exit;
}
public static function screen(): void {
self::authorize();
$plugins = self::installed();
$releases = self::releases();
self::sync_updates($plugins, $releases['updates']);
?>
<div class="wrap hg-suite">
<header class="hg-suite-header">
<span class="hg-suite-mark" aria-hidden="true">HG</span>
<div><h1>HG Plugin-updates</h1><p>Controleer de geïnstalleerde HG-plug-ins op nieuwe releases.</p></div>
</header>
<hr class="wp-header-end">
<?php if ($releases['error']) : ?>
<div class="notice notice-warning inline"><p><?php echo $releases['error'] === 'Ontoegankelijk'
? 'De releasebron is niet openbaar toegankelijk. Probeer het opnieuw zodra de repository en releases openbaar zijn.'
: 'De releases konden niet worden opgehaald. Probeer het later opnieuw.'; ?></p></div>
<?php endif; ?>
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
<input type="hidden" name="action" value="hg_plugin_updates_refresh">
<?php wp_nonce_field('hg_plugin_updates_refresh'); ?>
<p><button type="submit" class="button button-primary">Op updates controleren</button>
<a class="button" href="<?php echo esc_url(self::REPOSITORY . '/releases'); ?>">Releases bekijken</a></p>
</form>
<div style="overflow-x:auto" role="region" aria-label="Geïnstalleerde HG-plug-ins" tabindex="0">
<table class="widefat striped">
<thead><tr><th scope="col">Plug-in</th><th scope="col">Geïnstalleerd</th><th scope="col">Laatste release</th><th scope="col">Status</th></tr></thead>
<tbody>
<?php foreach ($plugins as $file => $plugin) :
$release = $releases['updates'][$plugin['slug']] ?? null;
$available = $release && version_compare($release['version'], $plugin['Version'], '>');
?>
<tr>
<th scope="row"><?php echo esc_html($plugin['Name']); ?></th>
<td><?php echo esc_html($plugin['Version']); ?></td>
<td><?php if ($release) : ?><a href="<?php echo esc_url($release['url']); ?>"><?php echo esc_html($release['version']); ?></a><?php else : ?>—<?php endif; ?></td>
<td>
<?php if ($available) : ?>
<?php // The bulk upgrader keeps the active state even when updating one plugin. ?>
<a class="button" aria-label="<?php echo esc_attr($plugin['Name'] . ' bijwerken'); ?>" href="<?php echo esc_url(wp_nonce_url(add_query_arg([
'action' => 'update-selected', 'plugins' => $file,
], network_admin_url('update.php')), 'bulk-update-plugins')); ?>">Nu bijwerken</a>
<?php elseif ($release) : ?>Actueel
<?php elseif ($releases['error']) : ?>Onbekend
<?php else : ?>Geen installatiepakket
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php
}
}
add_filter('hg_plugin_updates_implementation', [HG_Plugin_Updates_1_0_0::class, 'prefer']);
add_action('plugins_loaded', [HG_Plugin_Updates_1_0_0::class, 'boot'], 5);
}
+4 -1
View File
@@ -1,7 +1,7 @@
=== HG Social Feed ===
Requires at least: 6.5
Requires PHP: 8.1
Stable tag: 0.2.0
Stable tag: 0.2.1
License: GPLv2 or later
Recente berichten en profiellinks van Instagram, Facebook en X.
@@ -18,6 +18,9 @@ Upload en activeer de plugin. Open HG Plugins → Social Feed om de gewenste pro
== Changelog ==
= 0.2.1 =
Beheertabs per platform en voor shortcodes. Openbare releases controleren via HG Plugins → Updates.
= 0.2.0 =
Facebook-paginaberichten, optionele X-synchronisatie, een gecombineerd overzicht met bronselectie en een losse shortcode voor profieliconen.
+2
View File
@@ -19,6 +19,7 @@ files = (
"readme.txt",
"LICENSE",
"includes/hg-admin-menu.php",
"includes/hg-plugin-updates.php",
"includes/admin.php",
"includes/sources.php",
"includes/instagram.php",
@@ -26,6 +27,7 @@ files = (
"includes/x.php",
"includes/shortcode.php",
"assets/hg-admin-menu.css",
"assets/admin.css",
"assets/feed.css",
"assets/feed.js",
)
+19 -4
View File
@@ -165,10 +165,25 @@ $admins = get_users(['role' => 'administrator', 'number' => 1, 'fields' => 'ID']
hgsf_test(!empty($admins), 'An administrator is required for the nonce test.');
wp_set_current_user($admins[0]);
require_once ABSPATH . 'wp-admin/includes/template.php';
ob_start();
hgsf_admin_page();
$admin_html = ob_get_clean();
hgsf_test(substr_count($admin_html, 'type="password"') === 3 && !str_contains($admin_html, '-fixture-token'), 'Admin renders three source settings without revealing tokens.');
$original_tab = $_GET['tab'] ?? null;
foreach (['instagram', 'facebook', 'x', 'shortcodes'] as $tab) {
$_GET['tab'] = $tab;
ob_start();
hgsf_admin_page();
$admin_html = ob_get_clean();
hgsf_test(substr_count($admin_html, 'aria-current="page"') === 1, 'One active admin tab for ' . $tab);
hgsf_test(!str_contains($admin_html, '-fixture-token'), 'Admin does not reveal tokens for ' . $tab);
if ($tab === 'shortcodes') {
hgsf_test(!str_contains($admin_html, 'type="password"') && str_contains($admin_html, '[hg_sociallinks]'), 'Shortcode tab shows usage without connection fields.');
} else {
hgsf_test(substr_count($admin_html, 'type="password"') === 1 && str_contains($admin_html, 'name="source" value="' . $tab . '"'), 'Only the selected platform form renders.');
}
}
if ($original_tab === null) {
unset($_GET['tab']);
} else {
$_GET['tab'] = $original_tab;
}
$request_count = count($requests);
hgsf_test(hgsf_save_settings('facebook', ['operation' => 'save', 'username' => '12345', 'profile' => 'updated.page']) === 'saved', 'Updating the Facebook profile link succeeds.');
hgsf_test($connections['facebook']['token'] === 'fb-fixture-token' && count($requests) === $request_count, 'Updating an icon link preserves the Page token without fetching posts.');