Skip to content

badasswp/ping-me-on-slack

Repository files navigation

ping-me-on-slack

Get notifications on Slack when changes are made on your WP website.

Coverage Status

screenshot-1

Download

Download from WordPress plugin repository.

You can also get the latest version from any of our release tags.

Getting Started

To get started, you would need to have an incoming webhook of your own. Head over to the URL below and follow the instructions to generate your webhook:

https://api.slack.com/messaging/webhooks

If you have done this successfully, you should have something that looks like so:

https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Save these details into your Ping Me On Slack options page and you are ready to go!

ping-me-on-slack

Why Ping Me On Slack?

Ever needed to keep track of what's happening on your website? No need to look further. It does a fantastic job of logging every single activity on your website to your preferred Slack channels. It is simple and fast!

  • Get notified when a user creates, modifies or deletes a Post, Page or Image.
  • Get notified when a user creates, or posts a Comment.
  • Get notified when a user installs or activates, a Theme or Plugin.
  • Get notified when a user creates, modifies or deletes a User.
  • Get notified when a user logs in & out.

Hooks

ping_me_on_slack_{$post_type}_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_post_client', [ $this, 'post_client' ], 10, 1 );

public function post_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_{$post_type}_message

This custom hook (filter) provides the ability to add a custom Post message to be sent to your Slack Workspace. For e.g. To send a custom message when a Post draft is created by a user, you could do:

add_filter( 'ping_me_on_slack_post_message', [ $this, 'post_message' ], 10, 3 );

public function post_message( $message, $post, $event ): string {
    if ( 'draft' === $event ) {
        $message = sprintf(
            'Attention: A Post draft with ID: %d was just created, by %s!',
            $post->ID,
            get_user_by( 'id', $post->post_author )->display_name
        );
    }

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • post {WP_Post} By default this will be the WP Post object.
  • event {string} By default this will be the event that just happened.

ping_me_on_slack_form_fields

This custom hook (filter) provides a way to implement new Admin fields in the plugin's admin page. For e.g. To add a new text field, you could do:

add_filter( 'ping_me_on_slack_form_fields', [ $this, 'custom_field' ] );

public function custom_field( $fields ): array {
    return wp_parse_args(
        [
            'telephone' => [
                'type'  => 'text',
                'name'  => 'ping_me_on_slack_telephone',
                'html'  => esc_html__( 'My Telephone', 'ping-me-on-slack' ),
                'label' => esc_html__( '(555) 555-1234', 'ping-me-on-slack' ),
            ]
        ],
        $fields
    );
}

Parameters

  • fields {mixed[]} By default this will be an associative array, containing fields options.

ping_me_on_slack_comment_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_comment_client', [ $this, 'comment_client' ], 10, 1 );

public function comment_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_comment_message

This custom hook (filter) provides the ability to add a custom Comment message to be sent to your Slack Workspace. For e.g. To send a custom message when a Comment is trashed by a user, you could do:

add_filter( 'ping_me_on_slack_comment_message', [ $this, 'comment_message' ], 10, 3 );

public function comment_message( $message, $comment, $event ): string {
    if ( 'trash' === $event ) {
        $message = sprintf(
            'Attention: A Comment with ID: %d was just trashed, by %s!',
            $comment->ID,
            wp_get_current_user()->display_name
        );
    }

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • comment {WP_Comment} By default this will be the WP Comment object.
  • event {string} By default this will be the event that just happened.

ping_me_on_slack_on_ping_error

This custom hook (action) fires immediately after the Ping call is made and an exception is thrown. For e.g. you can capture errors here like so:

add_action( 'ping_me_on_slack_on_ping_error', [ $this, 'log_ping_errors' ], 10, 1 );

public function log_ping_errors( $e ): void {
    if ( $e instanceOf \Exception ) {
        wp_insert_post(
            [
                'post_type'   => 'ping_me_on_slack_logs',
                'post_title'  => sprintf(
                  'Fatal Error: %s'
                  (string) $e->getMessage()
                ),
            ]
        )
    }
}

Parameters

  • e {Exception} By default this will be an Exception.

ping_me_on_slack_login_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_login_client', [ $this, 'login_client' ], 10, 1 );

public function login_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_login_message

This custom hook (filter) provides the ability to add a custom Login message to be sent to your Slack Workspace. For e.g. To send a custom message when an Administrator logs in, you could do:

add_filter( 'ping_me_on_slack_login_message', [ $this, 'login_message' ], 10, 2 );

public function login_message( $message, $user ): string {
    if ( in_array( 'administrator', $user->roles, true ) ) {
        $message = sprintf(
            'Attention: An Administrator with ID: %d just logged in!',
            $user->ID
        );
    }

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • user {WP_User} By default this will be the WP User object.

ping_me_on_slack_logout_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_logout_client', [ $this, 'logout_client' ], 10, 1 );

public function logout_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_logout_message

This custom hook (filter) provides the ability to add a custom Logout message to be sent to your Slack Workspace. For e.g. To send a custom message when an Administrator logs out, you could do:

add_filter( 'ping_me_on_slack_logout_message', [ $this, 'logout_message' ], 10, 2 );

public function logout_message( $message, $user ): string {
    if ( in_array( 'administrator', $user->roles, true ) ) {
        $message = sprintf(
            'Attention: An Administrator with ID: %d just logged out!',
            $user->ID
        );
    }

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • user {WP_User} By default this will be the WP User object.

ping_me_on_slack_theme_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_theme_client', [ $this, 'theme_client' ], 10, 1 );

public function theme_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_theme_message

This custom hook (filter) provides the ability to add a custom theme message to be sent to your Slack Workspace. For e.g. To send a custom message when a user switches a theme:

add_filter( 'ping_me_on_slack_theme_message', [ $this, 'theme_message' ], 10, 2 );

public function theme_message( $message, $user ): string {
    if ( in_array( 'administrator', $user->roles, true ) ) {
        $message = sprintf(
            'Attention: An Administrator with ID: %d just logged out!',
            $user->ID
        );
    }

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • theme {WP_Theme} By default this will be the WP Theme object.

ping_me_on_slack_user_creation_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_user_creation_client', [ $this, 'user_creation_client' ], 10, 1 );

public function user_creation_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_user_creation_message

This custom hook (filter) provides the ability to add a custom user_creation message to be sent to your Slack Workspace. For e.g. To send a custom message when a User is created, you could do:

add_filter( 'ping_me_on_slack_user_creation_message', [ $this, 'user_creation_message' ], 10, 2 );

public function user_creation_message( $message, $user_id ): string {
    $message = sprintf(
        'Attention: A User with ID: %d was just created!',
        $user_id
    );

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • user_id {int} By default this will be the User ID.

ping_me_on_slack_user_deletion_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_user_deletion_client', [ $this, 'user_deletion_client' ], 10, 1 );

public function user_deletion_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_user_deletion_message

This custom hook (filter) provides the ability to add a custom user_deletion message to be sent to your Slack Workspace. For e.g. To send a custom message when a User is created, you could do:

add_filter( 'ping_me_on_slack_user_deletion_message', [ $this, 'user_deletion_message' ], 10, 2 );

public function user_deletion_message( $message, $user_id ): string {
    $message = sprintf(
        'Attention: A User with ID: %d was just deleted!',
        $user_id
    );

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • user_id {int} By default this will be the User ID.

ping_me_on_slack_user_modification_client

This custom hook (filter) provides the ability to customise the Slack client. For e.g. To send with a custom username, you could do:

add_filter( 'ping_me_on_slack_user_modification_client', [ $this, 'user_modification_client' ], 10, 1 );

public function user_modification_client( $client ) {
    $client->args = wp_parse_args(
        [
            'username' => 'John Doe'
        ],
        $client->args
    )

    return $client;
}

Parameters

  • client {\PingMeOnSlack\Core\Client} By default this will be the Client instance.

ping_me_on_slack_user_modification_message

This custom hook (filter) provides the ability to add a custom user_modification message to be sent to your Slack Workspace. For e.g. To send a custom message when a User is created, you could do:

add_filter( 'ping_me_on_slack_user_modification_message', [ $this, 'user_modification_message' ], 10, 2 );

public function user_modification_message( $message, $user_id ): string {
    $message = sprintf(
        'Attention: A User with ID: %d was just modified!',
        $user_id
    );

    return (string) $message;
}

Parameters

  • message {string} By default this will be the passed message.
  • user_id {int} By default this will be the User ID.