Access all of Typerocket. Get Pro.
Making WordPress Plugins
( v5 )
- # Make A TypeRocket Powered WordPress Plugin
- # Core Plugin Class
- # View Plugin Migrations
- # Plugin Config
Make A TypeRocket Powered WordPress Plugin
To create a standard WordPress plugin that is powered by TypeRocket use the galaxy CLI command.
php galaxy make:plugin {phpNamespace} "{plugin name}"
This command will download a boilerplate plugin into your wp-content/plugins folder. For example, run the command:
php galaxy make:plugin MyPluginName "My Plugin"
Once run you will be asked to if you want to generate a Galaxy CLI clone in the root of your WordPress installation.
> php galaxy make:plugin MyPluginName "My Plugin"
Clone GALAXY CLI for My Plugin to project root?
If you input y you will see the following:
GALAXY CLI clone: ~/wordpress/galaxy_my_plugin
Plugin "My Plugin" with app/MyPluginTypeRocketPlugin.php created at ~/wordpress/wp-content/plugins/my-plugin
You can use the new ~/wordpress/galaxy_my_plugin CLI script to run the Galaxy CLI system using the context of your plugin. Finally, your TypeRocket plugin code should be added to ~/wordpress/wp-content/plugins/my-plugin/app/MyPluginTypeRocketPlugin.php.
Now, if you want to run a galaxy command within the plugin's context use the galaxy_my_plugin script. For example, to make a migration for the plugin run:
php galaxy_my_plugin make:migration add_my_custom_table
Core Plugin Class
The core plugin class includes a lot of features to help you get started. It includes:
- An
app/View.phpclass for loading views inside the plugin folderresources/views. - A
webpack.mx.jsfile,resources/js,resources/sass, andpublicfor your front-end code. - A
composer.jsonif it is needed. - A
database/migrationsfolder for any plugin specific migrations. - An
appfolder for your custom application PHP classes. - An
uninstallscript, but you can use theapp/MyPluginTypeRocketPlugin.phpfor the uninstallation process.
The app/MyPluginTypeRocketPlugin.php class is where all of your custom code and be added. This class includes a few methods out of the gate:
-
init()- Place all of your custom plugin code like WordPress hooks here. By default, TypeRocket includes the hooks needed to load your plugin's front-end assets and settings page. -
routes()- Place your custom routes here instead of the main TypeRocketpublic.phproutes file. -
policies()- If you are using policies in your plugin add them here not theAuthSerivceclass (AuthSerivcecan override your policies). -
activate()- Place any activation code you need here. By default, any migrations will be run when the plugin is activated because ofmigrateUp()and permalink flushed because oftr_update_site_state(). -
deactivate()- Place any deactivation code here. By default, permalinks will be flushed because oftr_update_site_state(). -
uninstall()- Place nay uninstallation code here. By default, any migrations will be unwound because ofmigrateDown(). You may want to add your owntr_update_site_state()here as well.
View Plugin Migrations
Any migrations loaded into a plugin can also be seen from the DevTool page under migrations.
Plugin Config
TypeRocket plugins do not include a config system. Also, you should not make any edits to your main app or config regarding your new plugin. Plugins should remain separate from your main TypeRocket app.
Found a typo? Something is wrong in this documentation? Fork and edit it!