AI prompts
base on A WordPress Plugin development framework for human # WPDrill - WordPress Plugin Development Framework
WPDrill is a WordPress Plugin Development Framework for humans. It's designed to simplify the process of creating and managing WordPress plugins.
> ⚠️ Caution: This package is in the alpha stage. Expect bugs and changes. Test thoroughly before use.
## Features
1. **Menu Management**: WPDrill provides an easy way to add and manage menus in your WordPress plugin. You can easily add a new menu with an icon and position. For example, in `menu.php`, a new menu 'WPDrill' is added with a smiley icon and positioned at 3.
2. **Routing**: WPDrill provides a simple and intuitive way to manage routes in your WordPress plugin. You can define GET routes, apply middleware, and even group routes with a common prefix or middleware. For example, in `api.php`, a GET route '/wpdrill' is defined with a middleware.
3. **Middleware**: WPDrill allows you to add middleware to your routes, providing a way to perform actions before the route handler is executed.
4. **WPDrill CLI Tools**: WPDrill comes with a set of command-line tools that help in automating tasks such as scaffolding, migrations, and testing.
5. **ServiceProvider**: WPDrill uses a service provider pattern for managing class dependencies and performing dependency injection.
6. **Config**: WPDrill provides a central place to manage configuration settings for your plugin.
7. **Migrations**: WPDrill supports database migrations, allowing you to version control your database schema and apply changes incrementally.
8. **View**: WPDrill provides a simple way to manage views in your WordPress plugin. You can easily create, edit, and manage views for your plugin.
9. **Query Builder**: WPDrill provides a simple way to manage database operations in your WordPress plugin. You can easily create, read, update, and delete records in your database.
10. **Shortcode**: The Shortcode feature in WPDrill allows developers to create reusable pieces of content that can be inserted into posts or pages using a simple tag. This feature is implemented using a combination of PHP classes and views.
## Installation
The installation and configuration process of WPDrill can be done in the following steps:
1. **Download WPDrill**: You can download WPDrill from its official GitHub repository into the `plugins` directory. Use the following command in your terminal to clone the repository:
```bash
git clone https://github.com/WPDrill/framework.git
```
2. **Navigate to the WPDrill directory**: After cloning the repository, navigate to the WPDrill directory using the following command:
```bash
cd wpdrill
```
3. **Install Dependencies**: WPDrill uses Composer for managing PHP dependencies. Run the following command to install these dependencies:
```bash
composer install
```
## Plugin Initiate
After installing the necessary dependencies, the next step is to initialize the plugin. Execute the following command in your terminal:
```bash
php wpdrill plugin:init
```
OR
```bash
./wpdrill plugin:init
```
That's all! Now, proceed to your WordPress admin dashboard and activate your freshly created plugin.
## Add Admin Menu
To add a new menu in WPDrill, you need to follow the steps below:
Open the Menu Configuration File: Navigate to the `bootstrap/menu.php` file in your WPDrill plugin directory.
Define the New Menu: In the menu.php file, use the `Menu::add()` method to define a new menu. Here's an example of how you can create a new menu:
```php
use WPDrill\Facades\Menu;
use App\Handlers\ReviewXDashboardMenu;
Menu::add('ReviewX Dashboard', new ReviewXDashboardMenu(), 'manage_options')
->icon('dashicons-smiley')
->position(3);
```
You can use different types of approaches to bind handlers, the previous example was an invokable handler instance(That means it should contain `__invoke()` method.
#### Direct invokable class binding
```php
use WPDrill\Facades\Menu;
use App\Handlers\ReviewXDashboardMenu;
Menu::add('ReviewX Dashboard', ReviewXDashboardMenu::class , 'manage_options')
->icon('dashicons-smiley')
->position(3);
```
#### Class and method mapping
```php
use WPDrill\Facades\Menu;
use App\Handlers\ReviewXDashboardMenu;
Menu::add('ReviewX Dashboard', [ReviewXDashboardMenu::class, 'dashboard'] , 'manage_options')
->icon('dashicons-smiley')
->position(3);
```
#### Closure
```php
use WPDrill\Facades\Menu;
use App\Handlers\ReviewXDashboardMenu;
Menu::add('ReviewX Dashboard', function() {
echo "Dashboard";
} , 'manage_options')
->icon('dashicons-smiley')
->position(3);
```
## REST Routing
To create a route in WPDrill, you need to define it in the `routes/api.php` file. Here is an example of how you can do it:
```php
<?php
use WPDrill\Routing\Router;
Router::get('/wpdrill', [\App\Rest\Controllers\WPDrillController::class, 'show']);
```
In this example, a GET route '/wpdrill' is defined. When this route is accessed, the `show` method of the `WPDrillController` class is executed. Please replace the `WPDrillController` and `show` with the actual controller and method that should handle the request for this route.
The route controller supports the following
- Invokable Controller Instance (should contains `__invoke()` method in the class instance)
- Invokable class binding, ex: `\App\Rest\Controllers\WPDrillController::class`) (should contains `__invoke()` method in the class)
- Class and method mapping, ex: `[\App\Rest\Controllers\WPDrillController::class, 'method_name'`]`
- Closure
### Route Group
WPDrill also supports route grouping, here is the example
```php
Route::group(['prefix' => '/info'], function() {
Route::get('/about', function () {
return [
'title' => 'About WPDrill',
'content' => 'A WordPress Plugin development framework for humans',
];
});
});
```
## View
WPDrill helps you to develop a high-level templating option, it comes with a Twig template engine by default. Here is an example
```php
// app/Handlers
use WPDrill\Contracts\InvokableContract;
use WPDrill\Facades\View;
class WPDrillMenuHandler implements InvokableContract
{
public function __invoke()
{
View::output('wpdrill', [
'title' => 'Welcome to WPDrill',
'content' => 'A WordPress Plugin development framework for humans',
]);
}
}
```
Here is the view(twig) file
```twig
<!-- resources/views/wpdrill.html -->
<h1>{{ title }}</h1>
<p>
{{ content }}
</p>
```
Note: For view related configuration, check out `config/view.php`. By default, for above example - `resources/views/wpdrill.twig` file will be loaded. Change `'template_extension' => 'html'` to load resources/views/wpdrill.**html**
## Shortcode
To add a new shortcode in WPDrill, you need to follow these steps:
1. **Create a new Shortcode Class**: Create a new PHP class that implements the `ShortcodeContract`. This class should define a `render` method that returns the output of the shortcode. Here's an example:
```php
namespace App\Shortcodes;
use WPDrill\Contracts\ShortcodeContract;
use WPDrill\Facades\View;
class MyNewShortcode implements ShortcodeContract
{
public function render(array $attrs, string $content = null): string
{
// Default attributes can be defined here
$attrs = shortcode_atts(
[
'title' => 'Default Title',
],
$attrs
);
// Use the View facade to render a view for this shortcode
return View::render('shortcode/mynewshortcode', [
'title' => $attrs['title'],
'content' => $content,
]);
}
}
```
2. **Register the Shortcode**: In the `bootstrap/shortcodes.php` file, use the `Shortcode::add` method to register the new shortcode. Here's how you can do it:
```php
use WPDrill\Facades\Shortcode;
use WPDrill\Plugin;
return function(Plugin $plugin) {
Shortcode::add('mynewshortcode', \App\Shortcodes\MyNewShortcode::class);
// Existing shortcodes...
};
```
In this example, a new shortcode `[mynewshortcode]` is registered. When this shortcode is used in a post or page, the `render` method of the `MyNewShortcode` class is executed.
3. **Create the View**: Create a new PHP file in the `views/shortcode` directory for the view of this shortcode. This file should return the HTML that you want to display when the shortcode is used.
Please replace `MyNewShortcode`, `mynewshortcode`, and `shortcode/mynewshortcode` with the actual class name, shortcode tag, and view file path for your shortcode.
## Build
To build a plugin for production, you can follow these steps:
- Navigate to Your Plugin Directory: Open your terminal and navigate to the directory where your plugin is located.
- Run the Build Command:
```bash
./wpdrill plugin:build --prod
```
You can skip `--prod` if it's not a production build.
If you need any customization for the build, just goto `config/plugin` and configure the `build` section as you want.
## Getting Started
To get started with WPDrill, you need to have a basic understanding of WordPress plugin development as well as familiarity with PHP, JavaScript, Composer, and NPM.
## Documentation
For more detailed information on how to use WPDrill, refer to the individual PHP files in the `wp-content/plugins/reviewx` directory. Each file contains code that demonstrates how to use various features of WPDrill.
## Contributing
Contributions to WPDrill are welcome. Please ensure that you follow the coding standards and guidelines of the project.
## License
WPDrill is open-source software.
", Assign "at most 3 tags" to the expected json: {"id":"8920","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"