Skip to content

lolcabanon/sveltekit-adapter-wordpress-admin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sveltekit-adapter-wordpress-admin (SKAWA)

Adapter for SvelteKit which turns your app into a wordpress plugin admin interface.

Usage

Install with npm i -D sveltekit-adapter-wordpress-admin, setup the adapter in svelte.config.js.

Example svelte.config.js

Note: It's likely you will need to set custom base paths for Wordpress.

import adapter from 'sveltekit-adapter-wordpress-admin';

import { sveltePreprocess } from 'svelte-preprocess';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: [sveltePreprocess(), vitePreprocess()],

    kit: {
        // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
        // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
        // See https://kit.svelte.dev/docs/adapters for more information about adapters.
        adapter: adapter({
            pages: 'build',
            assets: 'build',
            fallback: null,
            indexPath: 'index.php',
            shadow: false,
            menu: {
                page_title: 'Svelte in Admin!',
                menu_title: 'Svelte in Admin!',
                icon: 'dashicons-generic',
                slug: 'svelte-in-admin'
            },
            prefix: 'skawa_svelte_in_admin',
            renderHead: (head) =>
                [...head.querySelectorAll(`link[rel="modulepreload"]`)]
                    .map((element) => element.outerHTML)
                    .join(''),
            renderBody: (body) => body.innerHTML
        }),

        embedded: true
    }
};

const host = 'https://example.com';

// handle wordpress url structure
if (process.env.NODE_ENV === 'production') {
    const base = '/wp-content/plugins/my-wp-plugin/admin/build';
    config.kit.paths = {
        base,
        assets: host + base
    };
}

export default config;

Example index.php

Note: You can choose the path by setting indexPath in the adapter config.

<!-- index.php -->
<?php

include plugin_dir_path( __FILE__ ) . 'svelte_kit_admin.php';

// add other PHP code here, like `add_action('rest_api_init', 'mu_plugin_register_routes');` and so on
?>

Note

Current limitation
You'll need to write all your PHP code in one file for the moment. Please submit an issue if you'd like me to think about a indexDir option or something. I might do it sometimes if I need it.

Attributions

This adapter was heavily inspired by sveltekit-adapter-wordpress-shortcode by @tomatrow.

WordPress plugins bindings took inspirations from this old repo by @Ebeldev.

License

MIT

About

Adapter for SvelteKit which turns your app into a wordpress plugin admin interface with a WordPress meny entry.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy