Skip to content

Development

Add-on Development – Guide to building add-on plugins for Virtual Media Folders.

Terminal window
# Add to composer.json
composer require soderlind/virtual-media-folders
composer require soderlind/vmfa-rules-engine
# Install dependencies
composer install
npm install
Terminal window
# Start development build with watch
npm run start
# Production build
npm run build
Terminal window
# Lint JavaScript
npm run lint:js
# Lint CSS
npm run lint:css
# Lint PHP (WordPress Coding Standards)
composer lint:php
composer fix:php
Terminal window
# PHP tests (PHPUnit with Brain Monkey)
composer test
composer test:coverage # With HTML coverage report
# JavaScript tests (Vitest)
npm test
npm run test:watch # Watch mode
npm run test:coverage # With coverage report
  • vmfa_rules_engine_folder_assigned — Fired after a rule assigns a folder
    • Parameters: $attachment_id, $folder_id, $rule
  • vmfa_rules_engine_matchers — Add custom condition matchers
  • vmfa_rules_engine_skip_if_assigned — Skip rule evaluation if folder already assigned
add_filter( 'vmfa_rules_engine_matchers', function( $matchers ) {
$matchers['custom_type'] = new My_Custom_Matcher();
return $matchers;
} );
class My_Custom_Matcher implements \VmfaRulesEngine\Conditions\MatcherInterface {
public function matches( $attachment_id, $metadata, $params ) {
// Your custom logic
return true;
}
public function get_type() {
return 'custom_type';
}
}

All endpoints require manage_options capability.

MethodEndpointDescription
GET/vmfa-rules/v1/rulesList all rules
POST/vmfa-rules/v1/rulesCreate a rule
GET/vmfa-rules/v1/rules/{id}Get a single rule
PUT/vmfa-rules/v1/rules/{id}Update a rule
DELETE/vmfa-rules/v1/rules/{id}Delete a rule
POST/vmfa-rules/v1/rules/reorderReorder rules
POST/vmfa-rules/v1/previewScan existing media (preview)
POST/vmfa-rules/v1/apply-rulesApply rules to media
GET/vmfa-rules/v1/statsGet media library statistics