chore(Docs): Standardized documentation [skip ci]

This commit is contained in:
Sibin Grasic 2023-05-03 12:35:55 +02:00
parent f0d0fd16c6
commit bffe44b94f
4 changed files with 16 additions and 16 deletions

View file

@ -36,7 +36,7 @@ composer require oblak/wp-plugin-installer
``Base_Plugin_Installer`` is an **abstract** singleton class which can be extended to create a plugin installer class. The class is responsible for installing and activating the plugin, and updating the plugin and database schema versions.
You need to extend it and implement the ``set_defaults()`` method, which is responsible for setting the default values for the class.

If your plugin needs non-wp database tables, you need to implement the ``get_schema()`` method, and set the ``has_tables`` property to ``true``, so that the installer can create and update the tables.
If your plugin needs non-wp database tables, you need to implement the ``get_schema()`` method, and set the ``has_db_tables`` property to ``true``, so that the installer can create and update the tables.

Class depends on [Action Scheduler](https://actionscheduler.org) for running update callbacks in the background.
If your plugin uses Action Scheduler, or depends on an another plugin, which has Action Scheduler, you can skip the activation step.
@ -64,11 +64,11 @@ class My_Plugin_Installer extends Base_Plugin_Installer {
* Set the installer defaults.
*/
protected function set_defaults() {
$this->name = 'My Plugin'; // Plugin name.
$this->slug = 'my-plugin'; // Plugin slug.
$this->version = '1.0.0'; // Plugin version (current).
$this->db_version = '1.0.0'; // Database schema version (current).
$this->has_tables = true; // Does the plugin have database tables?
$this->name = 'My Plugin'; // Plugin name.
$this->slug = 'my-plugin'; // Plugin slug.
$this->version = '1.0.0'; // Plugin version (current).
$this->db_version = '1.0.0'; // Database schema version (current).
$this->has_db_tables = true; // Does the plugin have database tables?
}

/**

View file

@ -4,11 +4,11 @@ Class configuration is done by overriding the `set_defaults()` method. This meth

```php
protected function set_defaults() {
$this->name = 'My Plugin';
$this->slug = 'my-plugin';
$this->version = '1.0.0';
$this->db_version = '1.0.0';
$this->has_tables = true;
$this->name = 'My Plugin';
$this->slug = 'my-plugin';
$this->version = '1.0.0';
$this->db_version = '1.0.0';
$this->has_db_tables = true;
}
```
## name
@ -38,7 +38,7 @@ The database schema version.
Database schema version is used in order to determine if the database schema needs to be updated.
Incrementing this value will run the update callbacks

## has_tables
## has_db_tables

Whether the plugin has database tables.
If this is set to `true`, the installer will create and update the database tables.

View file

@ -2,13 +2,13 @@

``Base_Plugin_Installer`` class does the bare minimum by itself. It's meant to be extended and customized to fit your needs.
At bare minimum you can extend the class and implement the ``set_defaults()`` method, which is responsible for setting the default values for the class.
This will only get you the plugin version tracking. If you want to track database schema version, you need to implement the ``get_schema()`` method, and set the ``has_tables`` property to ``true``.
This will only get you the plugin version tracking. If you want to track database schema version, you need to implement the ``get_schema()`` method, and set the ``has_db_tables`` property to ``true``.

## Database schema enforcement

The installer class provides a way to enforce the database schema. This means that the installer will automatically create the database tables, and update them when the plugin is updated.

In order to utilize this feature, you need to implement the ``get_schema()`` method, and set the ``has_tables`` property to ``true``.
In order to utilize this feature, you need to implement the ``get_schema()`` method, and set the ``has_db_tables`` property to ``true``.

?> Schema enforcement is based on the [WooCommerce](https://woocommerce.com) schema enforcement. It uses the ``dbDelta()`` function to create and update the database tables.


View file

@ -14,7 +14,7 @@ composer require oblak/wp-plugin-installer
``Base_Plugin_Installer`` is an **abstract** singleton class which can be extended to create a plugin installer class. The class is responsible for installing and activating the plugin, and updating the plugin and database schema versions.
You need to extend it and implement the ``set_defaults()`` method, which is responsible for setting the default values for the class.

?> If your plugin needs non-wp database tables, you need to implement the ``get_schema()`` method, and set the ``has_tables`` property to ``true``, so that the installer can create and update the tables.
?> If your plugin needs non-wp database tables, you need to implement the ``get_schema()`` method, and set the ``has_db_tables`` property to ``true``, so that the installer can create and update the tables.


### Defining your installer class
@ -44,7 +44,7 @@ class My_Plugin_Installer extends Base_Plugin_Installer {
$this->slug = 'my-plugin'; // Plugin slug.
$this->version = '1.0.0'; // Plugin version (current).
$this->db_version = '1.0.0'; // Database schema version (current).
$this->has_tables = true; // Does the plugin have database tables?
$this->has_db_tables = true; // Does the plugin have database tables?
}

/**