PHP code example of kodansha / wack-preview

1. Go to this page and download the library: Download kodansha/wack-preview library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kodansha / wack-preview example snippets


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%'
        ],
    ],
]);