updater options
This commit is contained in:
1 parent
dccb8ed9bd
commit
db897ac2dd
8 files changed
+503
-36
No files matched your search
+57
-28
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user