Plugins are used for WordPress specific filters and actions that modify the functionality of third-party plugins.
You can either extend plugin classes from core to override some functionality or create a plugin of your own.
This is an example of extending an existing plugin from the core.
In the plugin we can define custom templates for forms, if custom layout should be used in the frontend. Template setting will appear under Form Settings -> Form Layout -> Form template
<?php
namespace gotoAndPlay\Plugins;
use gotoAndCore\Plugins\GravityForms as GForms;
class GravityForms extends GForms {
public function __construct() {
parent::__construct();
$this->addTemplate('[name]', [
'template' => '[Template name]',
'args' => [
'container_class' => 'grid',
'row_class' => 'grid__col grid__col--xs-12',
'button_container' => false,
'button_container_class' => '',
],
]);
}
}
We will also need to tell our theme to use this plugin instead of the one in core. We can do so in Theme.php
inside constructor method.
$list = [
'gravityforms/gravityforms.php' => 'gotoAndPlay\Plugins\GravityForms',
];
When we define a plugin path as the key this way the plugin will only be added if the required plugin is activated
If we do not want it to depend on an installed plugin we can just add it this way.
$this->plugins = [
'gravity-forms' => new GravityForms(),
];
And don’t forget to use the class.
use gotoAndPlay\Plugins\GravityForms;