PHPackages                             kodansha/wack-preview - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. kodansha/wack-preview

ActiveWordpress-plugin

kodansha/wack-preview
=====================

Helpers to make it possible to preview posts on frontend.

v0.2.1(2mo ago)0306—0%GPL-3.0-or-laterPHPPHP &gt;=8.2CI passing

Since Mar 12Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/kodansha/wack-preview)[ Packagist](https://packagist.org/packages/kodansha/wack-preview)[ Docs](https://github.com/kodansha/wack-preview)[ RSS](/packages/kodansha-wack-preview/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (16)Used By (0)

WACK Preview
============

[](#wack-preview)

**WACK Preview** is a WordPress plugin that helps you to implement a preview system for unpublished drafts on your frontend application.

How it works
------------

[](#how-it-works)

Originally designed for use with the WACK Stack, this plugin can also be used with other decoupled, headless WordPress setups that use separate frontend applications, such as those utilizing the REST API or WPGraphQL.

This plugin replaces the default permalinks and preview links for posts (and other custom post types) generated by WordPress.

Preview links are generated with a JWT token as a parameter. By verifying this JWT using the same secret key on your frontend application, you can ensure the token was legitimately generated by WordPress. This lets you securely fetch data before it is published.

Installation
------------

[](#installation)

- Requires PHP 8.2 or later
- Requires WordPress 6.9 or later
- Requires Composer

### Using Composer

[](#using-composer)

```
composer require kodansha/wack-preview
```

Note

This plugin is not available on the WordPress.org plugin repository. The only installation method currently available is through Composer.

Configuration
-------------

[](#configuration)

To use WACK Preview, you need to configure URL mappings for displaying pages on the frontend. Additionally, you must set up a secret token for preview URLs.

You can configure these settings using one of the following methods:

- Define settings with the `WACK_PREVIEW_SETTINGS` constant
- Configure settings through the WordPress admin menu

### Setting via `WACK_PREVIEW_SETTINGS` constant

[](#setting-via-wack_preview_settings-constant)

Define `WACK_PREVIEW_SETTINGS` in functions.php or similar:

```
define('WACK_PREVIEW_SETTINGS', [
    // URL of frontend
    'frontend_base_url' => 'https://frontend.example.com',
    // Preview token settings
    'preview_token' => [
        // Secret key for Token generation
        'secret_key' => 'THIS_IS_A_SECRET_KEY',
        // Expiry time of token (seconds)
        'expiry_time' => 60 * 60 * 24
    ],
    // Path mappings for publish and preview links
    // %id% will be replaced with the actual post id when generating links
    // e.g. /post/%id% -> /post/123
    // The generated links will replace the original links
    'path_mappings' => [
        // Mapping for each post types
        // This example is for the default "post" type
        'post' => [
            'publish' => '/posts/%id%',
            'preview' => '/posts/preview/%id%'
        ],
        // Another custom post type you would like to rewrite permalinks
        // %slug% will be replaced with the actual post slug (name) when generating links
        // e.g. /news/%slug% -> /news/an-awesome-news
        // Note that the post slug may not be set in some cases. In such cases, the post ID will be automatically used as a fallback.
        'news' => [
            'publish' => '/news/%slug%',
            // You can set a preview path including query string
            // query strings will be merged with "preview_token" and "preview"
            'preview' => '/news/preview?slug=%slug%'
        ],
    ],
]);
```

Note

The secret\_key is used to sign tokens with HMAC-SHA256 (HS256). A minimum length of 32 bytes is required. Using a shorter key will result in a fatal error at runtime. Generate a sufficiently long random value with a command such as `openssl rand -hex 32`.

Note

On multisite WordPress installations, the WACK\_PREVIEW\_SETTINGS constant does not function as expected. In such cases, configure settings individually for each site using the admin menu.

### Setting via WordPress admin menu

[](#setting-via-wordpress-admin-menu)

Navigate to the WACK Preview settings screen in the WordPress admin menu and follow the on-screen instructions.

Tip

If settings are defined in both the `WACK_PREVIEW_SETTINGS` constant and the admin menu, the constant's settings will take precedence. This allows flexible configuration - for example, you could define only the `secret_key` as a constant (keeping it out of the database) while managing other settings through the admin screen.

Preview token payload
---------------------

[](#preview-token-payload)

The preview token is a JWT token that contains the following payload:

```
{
  // Post ID (or post slug if "%slug%" template is set in the path mappings)
  // Note: If the post does not have the slug, it will fallback to the post ID even if the "%slug%" template is set.
  "sub": 123,
  // Issuer (always set to `wack-preview`)
  "iss": "wack-preview",
  // Issued at (UNIX timestamp)
  "iat": 1630000000,
  // Expiry time (UNIX timestamp)
  "exp": 1630003600
}
```

This means that the frontend application can verify the token is valid for the specified post by checking the `sub` field.

API
---

[](#api)

### `wack_preview_verify_token`

[](#wack_preview_verify_token)

```
function wack_preview_verify_token(string $preview_token): bool

```

This is a utility function provided as a convenient API. It can be used in WordPress themes to verify preview tokens and control access to unpublished posts.

It returns `true` if the token is valid, `false` otherwise.

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance91

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~84 days

Total

8

Last Release

72d ago

PHP version history (2 changes)v0.1.0PHP &gt;=8.1

v0.2.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/19324b7c1443d7275e10ceb66dd9004cba4a09640900791eb5c5040080ab4096?d=identicon)[kodansha](/maintainers/kodansha)

---

Top Contributors

[![5t111111](https://avatars.githubusercontent.com/u/333180?v=4)](https://github.com/5t111111 "5t111111 (31 commits)")

---

Tags

pluginwordpress

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/kodansha-wack-preview/health.svg)

```
[![Health](https://phpackages.com/badges/kodansha-wack-preview/health.svg)](https://phpackages.com/packages/kodansha-wack-preview)
```

###  Alternatives

[sybrew/the-seo-framework

An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.

47078.8k](/packages/sybrew-the-seo-framework)[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.6k](/packages/afragen-git-updater)[webdevstudios/cmb2-attached-posts

Custom field for CMB2 for creating post relationships.

13565.5k](/packages/webdevstudios-cmb2-attached-posts)[iceicetimmy/acf-post-type-selector

Post type selector for Advanced Custom Fields.

559.0k](/packages/iceicetimmy-acf-post-type-selector)[alleyinteractive/pest-plugin-wordpress

WordPress Pest Integration

263.7k1](/packages/alleyinteractive-pest-plugin-wordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
