wp-slack icon indicating copy to clipboard operation
wp-slack copied to clipboard

Provide more information on creating custom events

Open joshuarichard opened this issue 9 years ago • 4 comments

I know this repo has been a little stale lately, but I'm looking for any guidance on adding a new event. I read the docs but below was all I found and it was mind-numbingly unhelpful:

// It's possible to add more events using slack_get_events filter. 
// Here's an example to add new event when a user is logged in:
add_filter( 'slack_get_events', function( $events ) {
    $events['user_login'] = array(
        'action'      => 'wp_login',
        'description' => __( 'When user logged in', 'slack' ),
        'message'     => function( $user_login ) {
            return sprintf( '%s is logged in', $user_login );
        }
    );

    return $events;
} );

I'm trying to add a page creation/deletion/update event. All I'm trying to get answered is where would add_filter() even go, the only instance of it is found in /includes/post-type.php and the code in there doesn't bear any resemblance to the example code above. I can troll the slack API after that.

joshuarichard avatar Aug 17 '15 04:08 joshuarichard

Short

See https://github.com/gedex/wp-slack-edd/blob/master/slack-edd.php#L35 for example usage.


Long

I'm not positive, but the key here lies in the $events arrary. I suspect that user_login is whatever name you give to the WordPress API Action wp_login that's being fired. So if you look through the Plugin API/Action Reference you can edit the action setting in above with an action name.

Further did you see how filter slack_get_events is called by https://github.com/gedex/wp-slack/blob/082376a4bd3530cf7f90f72d252e92d35040b7fc/includes/event-manager.php#L57 to fire off for the various events? That might more.

Don't forget to Add New the Slack integration from within WP Admin once you've added the code.

michael-cannon avatar Aug 17 '15 23:08 michael-cannon

@gedex do you want user login trigger added in main plugin for future release? If so, I can work on this.

christ0ph3r avatar Oct 26 '15 03:10 christ0ph3r

@christ0ph3r IMHO, the features that can be implemented in core for easy integration could be all the features like: https://wordpress.org/plugins/user-activity-log/

If the user want something, will check it. But if you want the plugin more neat and light, the existing is simply awesome.

Just make an awesome documentation with all sorts of information.

mayeenulislam avatar Jul 26 '16 06:07 mayeenulislam

trying to use the action hooh edit_post which only returns an ID. Still doesnt show a notification.

add_filter( 'slack_get_events', function( $events ) { $events['post_updated_rc'] = array( 'action' => 'edit_post', 'description' => __( 'When a post is updated', 'slack' ), 'message' => function( $post_updated_rc ) { return sprintf( '%s updated', $post_updated_rc ); } ); return $events; } );

Im making the assumption here that $post_updated_rc is the returned values from the original action call.

Anyone have luck getting notifications on updates working?

roberthuttinger avatar Aug 16 '16 17:08 roberthuttinger