create-wp-refine-plugin
WP Refine Plugin
Features
Easy to Use
Git clone this repository inwp-content/plugins/andnpm run bootstrap,npm run dev, that's all the stepsIntegrate with WordPress RestFul API
By default, theAPI_URLwould be{site_url}/wp-json}which is set ininc/admin.phpCRUD utility function
Default withgetPostExample, check more utilities in RefineIntegrate with JWT
We useusefulteam/jwt-authin composer, every time a WordPress user logged in, he will get JWT (for call API, if the user has enough capability) automatically.HMR (Hot Module Reload) for PHP
By usingvite-plugin-live-reload, the page will auto reload while PHP files changedMulti-React-App in one plugin
By default, we render 2 React App, 1 is for front-end page, and 1 is for admin page. You can add more React App injs/src/main.tsx
Before getting start
Tech stacks (knowledge you need to have)
Front-end
- Vite - build tool
- Refine - React Admin Framework with lots of useful utilities
- React v18
- TypeScript - compile project with type safe
- Tailwind v3 - you can install any UI library, like Ant Design, MUI, Chakra...etc
- SCSS
- React Query v4 - managing API status
- React Router v6 - front-end router, we use hash router by default which is compatible with WordPress's router
Back-end
- usefulteam/jwt-auth - get JWT if a wordpress user is logged in
Install
Clone this repository into
/wp-content/plugins.cd {your-project}/wp-content/plugins git clone https://github.com/j7-dev/wp-refine-plugin.git cd wp-refine-pluginInstall dependencies:
You must have Composer installed
npm run bootstrap # This will run `npm install` & `composer install` npm run devChange the API url to your project in
.env.developmentAPP_NAME='My Refine App' # ↑ Your App's Name APP1_SELECTOR='my-refine-app' # by default, the footer will render a <div id="my-refine-app"></div> container at front-end page footer # You can custom the render id APP2_SELECTOR='my-refine-app-metabox' # by default, in admin page, when you want to add/edit a new post with post_type=my-refine-app, another React App will render in metabox # Remove it if you don't need a metabox React App VITE_API_TIMEOUT='30000'Activate the plugin from WordPress admin
/wp-admin.
Visit your site's homepage and see the rendered application on the footer
Click
Count,Get Post Examplebutton to ensure the State and the WordPress API works
Check the admin page, you will see a new post type
My Refine Appand a new menuMy Refine AppClick Add New, you will see a React App in the metabox
Enjoy the dev
Any Suggestion ?
Welcome to open issue and start a discussion
If this project is useful for you, please give me a github star
Reference
- Inspired by Vite for WP
- Refine
- WordPress REST API Handbook