Download the PHP package stellarwp/schema without Composer
On this page you can find all versions of the php package stellarwp/schema. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stellarwp/schema
More information about stellarwp/schema
Files in stellarwp/schema
Package schema
Short Description A library for simplifying the creation and updates of custom tables within WordPress.
License GPL-2.0
Informations about the package schema
Schema Builder
A library for simplifying the creation, update, and field modification of custom tables within WordPress.
Installation
It's recommended that you install Schema as a project dependency via Composer:
We actually recommend that this library gets included in your project using Strauss.
Luckily, adding Strauss to your
composer.json
is only slightly more complicated than adding a typical dependency, so checkout our strauss docs.
Usage prerequisites
To actually use the schema library, you must have two additional libraries in your project:
- A Dependency Injection Container (DI Container) that is compatible with di52 (We recommend using di52.).
- The stellarwp/db library.
In order to keep this library as light as possible, those dependencies are not included in the library itself. To avoid version compatibility issues, those libraries are also not included as Composer dependencies. Instead, you must include them in your project. We recommend including them via composer using Strauss, just like you have done with this library.
Important note on ALL examples
All examples within the documentation for this project will be assuming that you are using Strauss to prefix the namespaces provided by this library.
The examples will be using:
Boom\Shakalaka\
as the namespace prefix, though will sometimes be referenced asPREFIX\
for the purpose of brevity in the docs.BOOM_SHAKALAKA_
as the constant prefix.
Getting started
For a full understanding of what is available in this library and how to use it, definitely read through the full documentation. But for folks that want to get rolling with the basics quickly, try out the following.
Initializing the library
Creating a table
Let's say you want a new custom table called sandwiches
(with the default WP prefix, it'd be wp_sandwiches
). You'll need a class file for the table. For the sake of this example, we'll be assuming this class is going into a Tables/
directory and is reachable via the Boom\Shakalaka\Tables
namespace.
Here's what the properties and method mean:
$base_table_name
: The name of the table without the prefix.$group
: The group that the table belongs to - this is for organizational purposes.$schema_slug
: An identifier for the table. This is used in storing your table's schema version inwp_options
.$uid_column
: The name of the column that is used to uniquely identify each row.get_definition()
: This should return the base SQL definition used to create yoursandwiches
table. To get the full SQL (with any field schemas included), you can callget_sql()
!
Registering the table
The Schema library gets initialized automatically when you register at table or a field schema. To register your table, simply use the handy Register::table()
method within the plugins_loaded
:
That's it!
The table will be automatically registered, created, and updated during the plugins_loaded
action at priority 1000
! _(that priority number is filterable via the stellarwp_schema_up_plugins_loaded_priority
filter)_
Documentation
Here's some more advanced documentation to get you rolling on using this library at a deeper level:
- Setting up Strauss
- Schema management
- Table schemas
- Versioning
- Registering tables
- Deregistering tables
- Table collection
- Publicly accessible methods
- Field schemas
- Versioning
- Registering fields
- Deregistering fields
- Field collection
- Publicly accessible methods
- Automated testing
Acknowledgements
Special props go to @lucatume and @stratease for their initial work on this structure before it was extracted into a standalone library.