File plugins

File plugins can add custom functionality that you can apply to files and folders.

Generally, they are being accessed through the contextual menu called “Open with..” or the “New” button.

A plugin can also be set to be used as the default method or opening a particular type of files. This can be set from the control panel section FilesPluginsDefaults.

Creating a plugin

In this example we'll create a plugin which calculates a folder's total size.

Start by creating a new empty folder inside customizables/plugins/. For this example we'll create customizables/plugins/folder_size.

Create the PHP file customizables/plugins/folder_size/app.php.

Plugins can have multiple files, but this is the only required one. It needs to follow a particular template:

<?php
 
class custom_folder_size extends \FileRun\Files\Plugin {
 
 
	static $localeSection = 'Custom Actions';
 
	function init() {
		$this->JSconfig = [
			"title" => self::t('Calculate folder size'),
			'iconCls' => 'fa fa-fw fa-hdd-o',
			'folder' => true,
			"popup" => true, 'width' => 400, 'height' => 300,
			'requires' => ['folder']
		];
	}
 
	function run() {
		$data = $this->prepareRead(['expect' => 'folder']);
 
		$size = \FM::getFolderSize($data['fullPath']);
		if (!$size) {
			echo 'Error: '.\FM::$errMsg;
		}
		echo \FM::formatFileSize($size);
	}
}
Note that the class name custom_folder_size follows the plugin's folder name.

The init() method defines some properties for the plugin, like the fact that it applies only to folders and it opens in a popup.

The run() method is what gets executed inside the opened popup.

To test the plugin, you need to clear the browser's cache and reload FileRun in your browser, otherwise the user interface will not refresh and you will not see the option in the contextual menu.