Preparing the Plugin

Estimated reading: 2 minutes

The plugin will be working closely with Beaver Builder, Timber and Toolbox. That means that we’ll also be using functionality that is added to these three plugins, making it very lean and quick to add new Modules and Twigs.

Adding the twig template directory

We will need to add the twig-templates for the plugin to the array of views-directories. This array tells the Twig Engine to look for the templates in the order that they are specified in, skipping the rest once a match has been made.

Adding Alias Modules

We will also need to add the Alias Modules using Beaver Builder’s API. Alias Modules are much easier to register, because you are actually using all the code that has already been added for the parent module, and you don’t need to re-create all that.

<?php

/**
 Plugin Name: Toolbox Starter Plugin
 Plugin URI: https://www.toolboxstarterplugin.com/
 Description: Starter Plugin for Toolbox, Using Timber
 Version: 1.0
 Author: Didou Schol
 Text Domain: textdomain
 Domain Path: /languages
 Author URI: https://www.badabing.nl
 */

define( 'TOOLBOXSTARTER_VERSION' 	, '1.0' );
define( 'TOOLBOXSTARTER_DIR'		, plugin_dir_path( __FILE__ ) );
define( 'TOOLBOXSTARTER_FILE'		, __FILE__ );
define( 'TOOLBOXSTARTER_URL' 		, plugins_url( '/', __FILE__ ) );


// include the starter.inc.php where functions are namespaced
include_once( 'lib/starter.inc.php' );

/**
 * adds the plugins twig_templates directory to the paths where Timber will look for templates
 */
add_filter( 'toolbox_twig_views_locations'      , '\starter\add_twigs_dir' , 25 ,1  );

/**
 * add plugin twig filters
 */
add_filter( 'timber/twig' 						, '\starter\add_twig_filters' );

/**
 * register alias modules with a high priority #
 */
add_action( 'init' 								, '\starter\register_alias_modules' , 100 , 1 );
Expand

The Toolbox Starter Plugin is setting a few constants that will be used throughout the plugin files. It also includes a namespaced function-file that holds a few callbacks that we will be using for this plugin.

Review plugin files

Please review the plugin files to see how the plugin’s ‘twig_templates/’ directory is added to the views-array by adding the callback to the toolbox_twig_views_locations filter.

The init action-hook is used to load the files that will register the Alias Module and optional Settings Form.

Share this Doc

Preparing the Plugin

Or copy link

CONTENTS