$v) {
$new[$k] = $v;
if ($k === 'title') {
$new['blyzer_status'] = __('On the website', 'blyzer-events');
$new['blyzer_api'] = __('Connection', 'blyzer-events');
$new['blyzer_key'] = __('API key', 'blyzer-events');
}
}
return $new;
}
public static function render(string $col, int $postId): void
{
if ($col === 'blyzer_status') {
$published = get_post_status($postId) === 'publish';
echo ''
. esc_html($published ? __('Published', 'blyzer-events') : __('Draft – not visible', 'blyzer-events'))
. '';
return;
}
if ($col === 'blyzer_api') {
if (trim((string) get_post_meta($postId, '_blyzer_api_key', true)) === '') {
echo '' . esc_html__('No key yet', 'blyzer-events') . '';
return;
}
$info = Connection::describe(Api::status($postId));
$icons = ['ok' => '✓', 'unknown' => '•'];
$class = $info['status'] === 'ok' ? 'ok' : ($info['status'] === 'unknown' ? 'neutral' : 'warning');
echo ''
. esc_html(($icons[$info['status']] ?? '⚠') . ' ' . $info['label']) . '';
return;
}
if ($col === 'blyzer_key') {
$k = trim((string) get_post_meta($postId, '_blyzer_api_key', true));
echo $k === '' ? '—' : '' . esc_html(Connection::maskedKey($k)) . '';
return;
}
}
private static function verifyUrl(int $postId): string
{
return wp_nonce_url(admin_url('admin-post.php?action=blyzer_verify_api&post_id=' . $postId), 'blyzer_verify_api_' . $postId);
}
public static function handleVerify(): void
{
$postId = isset($_GET['post_id']) ? absint(wp_unslash($_GET['post_id'])) : 0;
if (!$postId) wp_die(esc_html__('Missing event ID.', 'blyzer-events'));
check_admin_referer('blyzer_verify_api_' . $postId);
if (!current_user_can('edit_post', $postId)) wp_die(esc_html__('You are not allowed to do this.', 'blyzer-events'));
Api::ping($postId);
wp_safe_redirect(wp_get_referer() ?: admin_url('edit.php?post_type=blyzer_event'));
exit;
}
public static function rowActions(array $actions, $post): array
{
if ($post->post_type !== 'blyzer_event') return $actions;
unset($actions['inline hide-if-no-js']);
if (current_user_can('edit_post', $post->ID) && trim((string) get_post_meta($post->ID, '_blyzer_api_key', true)) !== '') {
$actions['blyzer_verify'] = '' . esc_html__('Check connection', 'blyzer-events') . '';
}
return $actions;
}
}