CI / Tests (PHP 8.1) (pull_request) Successful in 50s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m12s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m50s
CI / PHPStan (pull_request) Successful in 3m4s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
The Policies admin page listed versions but never showed what any of them said, so revising a policy meant retyping it blind into an empty draft box. Each version row now has a View action that renders that version's text on the page, editable in place. A draft is saved back to itself; editing a published or archived version branches a new draft and leaves the original alone, because acceptances are recorded against policy_version_id and text a student agreed to must stay exactly as they saw it. That viewer also exposed why a studio reported the acceptance box as unreadable — one squashed line, overlapping words, a horizontal scrollbar. Bodies are typed into a bare textarea, so most carry no markup, and the raw text was emitted with its blank lines intact but nothing to turn them into paragraphs. PolicyVersion::bodyHtml() now renders every body the way WordPress renders post content (kses, then wpautop) and feeds all three consumers: the booking/enrolment JSON, the signup form, and the new viewer. Bodies written with markup are unaffected. The other half was that .us-policy-body had no CSS whatsoever and inherited whatever the theme did with an unstyled block in a form. It is now a bounded reading box that scrolls vertically and breaks long tokens, so a pasted URL cannot force the page sideways and a long policy cannot push the accept checkbox out of view. RegistrationPage was also never enqueueing the plugin stylesheet, which is why the signup gate looked worst of all. Closes #126 Closes #127 Co-Authored-By: Claude Opus 5 <[email protected]>
183 lines
10 KiB
PHP
183 lines
10 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Unsupervised\Schedular\Policy\Policy;
|
|
use Unsupervised\Schedular\Policy\PolicyVersion;
|
|
|
|
if (! defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* @var list<\Unsupervised\Schedular\Policy\Policy> $policyList
|
|
* @var \Unsupervised\Schedular\Policy\Policy|null $selectedPolicy
|
|
* @var list<\Unsupervised\Schedular\Policy\PolicyVersion>|null $policyVersions
|
|
* @var \Unsupervised\Schedular\Policy\PolicyVersion|null $viewedVersion Version opened in the viewer, if any.
|
|
* @var string $notice Status message from the last save.
|
|
*/
|
|
?>
|
|
<div class="wrap">
|
|
<h1><?php esc_html_e('Policies', 'unsupervised-schedular'); ?></h1>
|
|
|
|
<?php if ('' !== $notice) : ?>
|
|
<div class="notice notice-success is-dismissible"><p><?php echo esc_html($notice); ?></p></div>
|
|
<?php endif; ?>
|
|
|
|
<h2><?php esc_html_e('Add Policy', 'unsupervised-schedular'); ?></h2>
|
|
<form method="post">
|
|
<?php wp_nonce_field('usc_policy_action'); ?>
|
|
<input type="hidden" name="usc_action" value="create_policy">
|
|
<table class="form-table">
|
|
<tr>
|
|
<th><label for="title"><?php esc_html_e('Title', 'unsupervised-schedular'); ?></label></th>
|
|
<td><input type="text" name="title" id="title" class="regular-text" maxlength="<?php echo esc_attr((string) Policy::MAX_TITLE_LENGTH); ?>" required></td>
|
|
</tr>
|
|
<tr>
|
|
<th><label for="slug"><?php esc_html_e('Slug', 'unsupervised-schedular'); ?></label></th>
|
|
<td>
|
|
<input type="text" name="slug" id="slug" class="regular-text" maxlength="<?php echo esc_attr((string) Policy::MAX_SLUG_LENGTH); ?>" placeholder="<?php esc_attr_e('e.g. cancellation (defaults from title)', 'unsupervised-schedular'); ?>">
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th><label for="acceptance_scope"><?php esc_html_e('Accept at', 'unsupervised-schedular'); ?></label></th>
|
|
<td>
|
|
<select name="acceptance_scope" id="acceptance_scope">
|
|
<option value="<?php echo esc_attr(Policy::SCOPE_BOOKING); ?>" selected><?php esc_html_e('Booking', 'unsupervised-schedular'); ?></option>
|
|
<option value="<?php echo esc_attr(Policy::SCOPE_SIGNUP); ?>"><?php esc_html_e('Account signup', 'unsupervised-schedular'); ?></option>
|
|
<option value="<?php echo esc_attr(Policy::SCOPE_BOTH); ?>"><?php esc_html_e('Both', 'unsupervised-schedular'); ?></option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<?php submit_button(esc_html__('Add Policy', 'unsupervised-schedular')); ?>
|
|
</form>
|
|
|
|
<hr>
|
|
|
|
<form method="get">
|
|
<input type="hidden" name="page" value="us-policies">
|
|
<label for="policy_id"><?php esc_html_e('Policy', 'unsupervised-schedular'); ?></label>
|
|
<select name="policy_id" id="policy_id" onchange="this.form.submit()">
|
|
<option value="0"><?php esc_html_e('— Select a policy —', 'unsupervised-schedular'); ?></option>
|
|
<?php foreach ($policyList as $policy) : ?>
|
|
<option value="<?php echo esc_attr((string) $policy->id); ?>" <?php selected($selectedPolicy && $selectedPolicy->id === $policy->id); ?>>
|
|
<?php echo esc_html($policy->title); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</form>
|
|
|
|
<?php if (null !== $selectedPolicy) : ?>
|
|
<h2><?php echo esc_html(sprintf(/* translators: %s: policy title */ __('Versions of "%s"', 'unsupervised-schedular'), $selectedPolicy->title)); ?></h2>
|
|
|
|
<h3><?php esc_html_e('Add Draft Version', 'unsupervised-schedular'); ?></h3>
|
|
<form method="post">
|
|
<?php wp_nonce_field('usc_policy_action'); ?>
|
|
<input type="hidden" name="usc_action" value="add_version">
|
|
<input type="hidden" name="policy_id" value="<?php echo esc_attr((string) $selectedPolicy->id); ?>">
|
|
<textarea name="body" rows="8" class="large-text" placeholder="<?php esc_attr_e('Policy text (HTML allowed)', 'unsupervised-schedular'); ?>"></textarea>
|
|
<?php submit_button(esc_html__('Add Draft', 'unsupervised-schedular')); ?>
|
|
</form>
|
|
|
|
<h3><?php esc_html_e('Versions', 'unsupervised-schedular'); ?></h3>
|
|
<?php if (empty($policyVersions)) : ?>
|
|
<p><?php esc_html_e('No versions yet. Add a draft above.', 'unsupervised-schedular'); ?></p>
|
|
<?php else : ?>
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th><?php esc_html_e('Version', 'unsupervised-schedular'); ?></th>
|
|
<th><?php esc_html_e('Status', 'unsupervised-schedular'); ?></th>
|
|
<th><?php esc_html_e('Published', 'unsupervised-schedular'); ?></th>
|
|
<th><?php esc_html_e('Actions', 'unsupervised-schedular'); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($policyVersions as $version) : ?>
|
|
<tr>
|
|
<td>
|
|
<?php echo esc_html((string) $version->versionNumber); ?>
|
|
<?php if ($selectedPolicy->currentVersionId === $version->id) : ?>
|
|
<span class="dashicons dashicons-yes" title="<?php esc_attr_e('Current', 'unsupervised-schedular'); ?>"></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?php echo esc_html($version->status); ?></td>
|
|
<td><?php echo $version->publishedAt ? esc_html($version->publishedAt) : '—'; ?></td>
|
|
<td>
|
|
<a href="<?php echo esc_url(
|
|
add_query_arg(
|
|
[
|
|
'page' => 'us-policies',
|
|
'policy_id' => (string) $selectedPolicy->id,
|
|
'version_id' => (string) $version->id,
|
|
],
|
|
admin_url('admin.php')
|
|
)
|
|
); ?>" class="button button-small">
|
|
<?php esc_html_e('View', 'unsupervised-schedular'); ?>
|
|
</a>
|
|
<?php if (PolicyVersion::STATUS_PUBLISHED !== $version->status) : ?>
|
|
<form method="post" style="display:inline;">
|
|
<?php wp_nonce_field('usc_policy_action'); ?>
|
|
<input type="hidden" name="usc_action" value="publish_version">
|
|
<input type="hidden" name="policy_id" value="<?php echo esc_attr((string) $selectedPolicy->id); ?>">
|
|
<input type="hidden" name="version_id" value="<?php echo esc_attr((string) $version->id); ?>">
|
|
<button type="submit" class="button button-small button-primary">
|
|
<?php esc_html_e('Publish', 'unsupervised-schedular'); ?>
|
|
</button>
|
|
</form>
|
|
<?php else : ?>
|
|
<em><?php esc_html_e('Current', 'unsupervised-schedular'); ?></em>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
|
|
<?php if (null !== $viewedVersion) : ?>
|
|
<hr>
|
|
<h3>
|
|
<?php echo esc_html(sprintf(
|
|
/* translators: 1: version number, 2: version status. */
|
|
__('Version %1$d (%2$s)', 'unsupervised-schedular'),
|
|
$viewedVersion->versionNumber,
|
|
$viewedVersion->status
|
|
)); ?>
|
|
</h3>
|
|
|
|
<?php // Rendered exactly as the booking and signup gates render it, so this doubles as a preview. ?>
|
|
<div class="us-policy-version-body" style="background:#fff;border:1px solid #c3c4c7;padding:0 1em;max-width:50em;overflow-wrap:break-word;">
|
|
<?php echo wp_kses_post($viewedVersion->bodyHtml()); ?>
|
|
</div>
|
|
|
|
<?php $editingDraft = PolicyVersion::STATUS_DRAFT === $viewedVersion->status; ?>
|
|
<h4><?php esc_html_e('Edit', 'unsupervised-schedular'); ?></h4>
|
|
<p class="description">
|
|
<?php
|
|
echo esc_html(
|
|
$editingDraft
|
|
? __('This version is still a draft, so your changes are saved to it directly.', 'unsupervised-schedular')
|
|
: __('This version has been published, so saving an edit creates a new draft version from this text and leaves the published one untouched.', 'unsupervised-schedular')
|
|
);
|
|
?>
|
|
</p>
|
|
<form method="post">
|
|
<?php wp_nonce_field('usc_policy_action'); ?>
|
|
<input type="hidden" name="usc_action" value="edit_version">
|
|
<input type="hidden" name="policy_id" value="<?php echo esc_attr((string) $selectedPolicy->id); ?>">
|
|
<input type="hidden" name="version_id" value="<?php echo esc_attr((string) $viewedVersion->id); ?>">
|
|
<textarea name="body" rows="12" class="large-text"><?php echo esc_textarea((string) $viewedVersion->body); ?></textarea>
|
|
<?php
|
|
submit_button(
|
|
$editingDraft
|
|
? esc_html__('Save Draft', 'unsupervised-schedular')
|
|
: esc_html__('Save as New Draft', 'unsupervised-schedular')
|
|
);
|
|
?>
|
|
</form>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|