1. Home
  2. Docs
  3. Rules Developer Guide
  4. Extending Rules
  5. Events

Events

Rules are triggered using the existing WordPress hooks system. This means that adding your events to rules consists of simply “describing” your existing hooks that fire within your plugin or theme.

rules_describe_event( $type, $hook, $definition );

/**
 * @param  string          (required)   $type        Event type: 'action' or 'filter'
 * @param  string          (required)   $hook        The name of the hook
 * @param  array|callable  (required)   $definition  The event definition
 */

For a detailed specification of the $definition, see the Definitions page.

@Example Code

/* Post Title Filter */
rules_describe_event( 'filter', 'the_title', array(
    'title' => 'Post Title Is Filtered',
    'description' => 'The post title is filtered before it is output to the page.',
    'arguments' => array(
        'title' => array( 
            'argtype' => 'string', 
            'label' => 'Post Title', 
            'description' => 'The post title' 
        ),
        'post_id' => array( 
            'argtype' => 'int', 
            'class' => 'WP_Post', 
            'label' => 'Post ID', 
            'description' => 'The ID of the post whose title is being filtered' 
        ),
    ),
));

/* User Created Action */
rules_describe_event( 'action', 'user_register', function() { 
    return array(
        'title' => 'User Has Been Created',
        'description' => 'Access data for a new user immediately after they are added to the database.',
        'arguments' => array(
            'user_id' => array( 
                'argtype' => 'int',
                'class' => 'WP_User',
                'label' => 'User ID',
                'description' => 'The id of the newly created user',
            ),
        ),
    );
});

Note: Action events and filter events both perform the exact same way in the context of a rule, except that rules are able to modify the returned value of filter events.

Was this article helpful to you? Yes No

How can we help?