1. Home
  2. Docs
  3. Application Framework
  4. Annotations Reference

Annotations Reference

The MWP Framework reads annotations on doc-blocks from classes, methods, and properties using the Doctrine annotation reading library. This allows automatic registration of your functions to core WordPress based on the documentation you write.

@Example Code

Adding a function to the core WordPress ‘init’ action using an annotation

namespace MyNamespace\MyPackage;

class MyClass
{
    /**
     * We want to do this after WordPress initializes
     * so we simply add an annotation that documents it.
     * 
     * @MWP\WordPress\Action( for="init" )
     *
     * @return void
     */
    public function someFunction()
    {
        // we want this code to run when wordpress does the 'init' action!
    }
}

In the example above, the MWP Framework will read the annotations on your class method, see the one called @MWP\WordPress\Action, and attach the method to the WordPress action for “init”. There are a handful of other annotations (such as @MWP\WordPress\Filter) that you can also use to register your plugin functions to core WordPress.

The singleton instance of your primary plugin class is already attached to WordPress by the boilerplate code when you generated your plugin. If you are using annotations in additional classes, you will need to create an instance of that class and attach it to WordPress using the MWP Framework.

$framework->attach( $object )

use MWP\Framework\Framework;
use MyNamespace\MyPackage\MyClass;

$myObject = new MyClass();

Framework::instance()->attach( $myObject );

@Annotations List

Was this article helpful to you? Yes No

How can we help?