DWS WP Framework
  • Welcome
  • Primary goals
    • Modular design
    • No 3rd-party dependencies
  • Key concepts and dev tools
    • PHP and WP requirements
    • Object-Oriented Programming
    • Semantic Versioning
    • Version Control (git / GitHub)
    • Dependency Management (Composer)
    • Automated Testing (Codeception + Github Actions)
    • Dependency Injection (PHP-DI)
    • Coding Standards (PHPCS and PHPMD)
    • Dependencies Scoping (PHP-Scoper)
    • TypeScript and Sass
    • Task Runners (Grunt)
  • Setting up your dev environment
    • Windows
  • Your first plugin
    • Multiple plugins using the framework on the same site
  • Frequently Asked Questions
  • Bootstrapper Module
    • Motivation
    • How it works
    • How to use
    • White Labeling
  • Helpers Module
    • Motivation
    • How to use
  • Foundations Module
    • Motivation and How to use
    • Actions
      • Local action traits
      • Extension action traits
      • Integration action traits
    • States
    • Utilities
      • Stores
      • Handlers and Services
        • Logging Service
  • Plugin
    • Main Plugin Instance
    • Plugin Components
  • Hierarchies
  • Helpers
  • Utilities Module
    • Motivation and How to use
    • Hooks Service
      • Scoped Handler
    • Shortcodes Service
    • Templating Service
    • Assets Service
      • Scripts Handler
      • Styles Handler
    • CRON Events Service
      • Action Scheduler Handler
    • Admin Notices Service
    • Dependencies Service
    • Validation Service
  • Core Module
    • Motivation and How to use
    • Plugin Tree
      • Plugin Root
      • Plugin Functionality
    • Plugin Components
      • Internationalization
      • Installation / Upgrade / Uninstallation
  • Settings Module
    • Motivation and How to use
    • Settings Service
      • WordPress Handler
      • MetaBox Handler
      • ACF Handler
    • Validated Settings
  • WooCommerce Module
    • Motivation and How to use
    • Extended WC Logger
    • WC Settings Handler
Powered by GitBook
On this page

Was this helpful?

  1. Foundations Module
  2. Actions

Extension action traits

PreviousLocal action traitsNextIntegration action traits

Last updated 4 years ago

Was this helpful?

Similarly to the explored on the page before, extension action traits allow you to hook into an action method without overriding it directly thus maintaining the default trait logic. Moreover, since they're traits, they're easily reusable!

We'll continue using the output action for consistency. An output extension trait must make use of the OutputtableExtensionTrait like this:

<?php

namespace DeepWebSolutions\Plugins\MyTestPlugin\Actions;

use DeepWebSolutions\Framework\Foundations\Actions\Outputtable\OutputFailureException;
use DeepWebSolutions\Framework\Foundations\Actions\Outputtable\OutputtableExtensionTrait;

trait MyOutputExtensionTrait {
    use OutputtableExtensionTrait; // USE THIS
    
    protected function my_output_extension(): ?OutputFailureException {
        // do something
        
        return null;
    }
}

Just like with the local action trait, it's enough to "import" your extension trait into your class -- no need to use the default OutputtableTrait too. And just like with the local action traits, the concepts explained here apply to all defined actions (you just need to use the corresponding extension trait).

There is one thing you need to pay attention to -- the name of the extension method. It's no coincidence that the example above uses the method my_output_extension. The name of the method is derived from the name of the trait. Basically these are the rules:

  • If the trait has the suffix Trait, it is removed.

  • Before every capital letter, an underscore is added.

  • The string is turned to lowercase.

Therefore, since my example trait is named MyOutputExtensionTrait, the method must be named my_output_extension. If you misname it, it will simply be ignored.

The Foundations module comes with a few pre-built extension traits, but they usually don't make sense unless their context is fully understood. We will explore them on other pages.

local action traits