Introduction

Wix Forum events are fired in your site's backend when certain changes occur in your forum. You can write event handlers that react to these events. Event handler functions receive data that correspond to the event that has occurred. Use event handlers to create custom responses to the events.

Note: Backend events do not fire when previewing your site.

To add an event handler, add an events.js file to the Backend section of your code files if one does not already exist. All event handler functions for your site are defined in this file.

Event handler functions are defined using the following pattern:

Copy
export function <wixAppName>_<eventName>(event) { }

For example, an event handler that handles a forum post being created looks like this:

Copy
export function wixForum_onPostCreated(event) {}
Did this help?

onCategoryCreated( )


A backend event that fires when a new forum category is created.

The onCategoryCreated() event handler runs when a new forum category is created in your site. The received CreatedCategory object contains information about the new category that was created.

Notes:

  • If you create a category from your published site, onCategoryCreated() runs only when you finish defining the settings and click Create. If you create a category using the forum settings in the Editor, onCategoryCreated() will run with the default settings as soon as you click Add New Category. As you continue to define the category settings, onCategoryUpdated() will run.

  • Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCategoryCreated(event: CreatedCategory): void;
Method Parameters
eventCreatedCategoryRequired

Information about the forum category that was created.

In this example, the category header background is a color.

JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCategoryCreated(event) { const categoryId = event.categoryId; const categoryName = event.category.name; } /* Full category object: * { * "_id": "5f88058be9b6b100175b154d", * "name": "My Category Name", * "headerTitle": "My Category Header Title", * "description": "This is a description of my category.", * "headerType": "COLOR", * "headerBackgroundColor": { * "color": "#8F98E2", * "opacity": 0.5 * }, * "headerTextColor": { * "color": "#9E3B1B", * "opacity": 1 * }, * "rank": 2, * "slug": "my-category-name", * "pageUrl": "/forum/my-category-name", * "postCount": 0, * "postViewCount": 0, * "writeProtected": "false", * "_createdDate": "2020-10-26T07\:18\:20.297Z", * "_updatedDate": "2020-10-26T07\:18\:20.297Z" * } */
Did this help?

onCategoryDeleted( )


A backend event that fires when a forum category is deleted.

The onCategoryDeleted() event handler runs when an existing forum category in your site is deleted. The received DeletedCategory object contains information about the category that was deleted.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCategoryDeleted(event: DeletedCategory): void;
Method Parameters
eventDeletedCategoryRequired

Information about the forum category that was deleted.

A backend event that occurs when a forum category is deleted
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCategoryDeleted(event) { const deletedCategoryId = event.categoryId; console.log("Category deleted"); }
Did this help?

onCategoryUpdated( )


A backend event that fires when a forum category is updated.

The onCategoryUpdated() event handler runs when a an existing forum category in your site is updated. The received UpdatedCategory object contains information about the category that was updated.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCategoryUpdated(event: UpdatedCategory): void;
Method Parameters
eventUpdatedCategoryRequired

Information about the forum category that was updated.

In this example, the category header background is an image.

JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCategoryUpdated(event) { const categoryId = event.categoryId; const categoryName = event.category.name; } /* Full category object: * { * "_id": "5f88058be9b6b100175b154d", * "name": "My Updated Category Name", * "headerTitle": "My Updated Category Header Title", * "description": "This is a description of my category.", * "headerType": "IMAGE", * "headerImage": "wix:image://v1/a27d24_3...46~mv2.jpg/_.jpg#originWidth=940&originHeight=529", * "headerImageOverlayColor": { * "color": "#40E0D0", * "opacity": 0.1 * }, * "rank": 2, * "slug": "my-updated-category-name", * "pageUrl": "/forum/my-updated-category-name", * "postCount": 3, * "postViewCount": 56, * "writeProtected": "true", * "_createdDate": "2020-10-26T07\:18\:20.297Z", * "_updatedDate": "2020-11-04T12\:27\:05.592Z" * } */
Did this help?

onCommentCreated( )


A backend event that fires when a new forum comment is created.

The onCommentCreated() event handler runs when a new forum comment is created in your site. The received CreatedComment object contains information about the new comment that was created.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentCreated(event: CreatedComment): void;
Method Parameters
eventCreatedCommentRequired

Information about the forum comment that was created.

A backend event that occurs when a new forum comment is created
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentCreated(event) { const commentId = event.commentId; const commentText = event.comment.plainContent; } /* Full comment object: * { * "_id": "5f88058be9b6b100175b154c", * "postId":"5f88058be9b6b100175b154a", * "_ownerId":"32cf071a-ck2f-450f-ad74-5a25db0b1b6g", * "plainContent": "This is my comment text.", * "replyCount": 0, * "likeCount": 0, * "upvoteCount": 0, * "downvoteCount": 0, * "score": 0, * "_createdDate": "2020-10-26T07\:18\:20.297Z", * "_editedDate": null, * "_lastActivityDate": "2020-10-26T07\:18\:20.297Z", * "pageUrl": "/forum/main/comment/5f88058be9b6b100175b154c" * } */
Did this help?

onCommentDeleted( )


A backend event that fires when a forum comment is deleted.

The onCommentDeleted() event handler runs when an existing forum comment in your site is deleted. The received DeletedComment object contains information about the comment that was deleted.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentDeleted(event: DeletedComment): void;
Method Parameters
eventDeletedCommentRequired

Information about the forum comment that was deleted.

A backend event that occurs when a forum comment is deleted
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentDeleted(event) { const deletedCommentId = event.commentId; console.log("Comment deleted"); }
Did this help?

onCommentDownvoted( )


A backend event that fires when a forum comment is downvoted.

The onCommentDownvoted() event handler runs when an existing forum comment in your site is downvoted. The received DownvotedComment object contains information about the comment that was downvoted.

Notes:

  • Only comments on posts with a postType of "QUESTION" can be voted on.

  • Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentDownvoted(event: DownvotedComment): void;
Method Parameters
eventDownvotedCommentRequired

Information about the forum comment that was downvoted.

A backend event that occurs when a forum comment is downvoted
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentDownvoted(event) { const downvotedCommentId = event.commentId; console.log("Comment downvoted"); }
Did this help?

onCommentLiked( )


A backend event that fires when a forum comment is liked.

The onCommentLiked() event handler runs when an existing forum comment in your site is liked. The received LikedComment object contains information about the comment that was liked.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentLiked(event: LikedComment): void;
Method Parameters
eventLikedCommentRequired

Information about the forum comment that was liked.

A backend event that occurs when a forum comment is liked
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentLiked(event) { const likedCommentId = event.commentId; console.log("Comment liked"); }
Did this help?

onCommentMarkedAsBest( )


A backend event that fires when a forum comment is marked as best.

The onCommentMarkedAsBest() event handler runs when an existing forum comment in your site is marked as best. The received MarkedAsBestComment object contains information about the comment that was marked as best.

Notes:

  • Only comments on posts with a postType of "QUESTION" can be marked as best.

  • Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentMarkedAsBest(event: MarkedAsBestComment): void;
Method Parameters
eventMarkedAsBestCommentRequired

Information about the forum comment that was marked as best.

A backend event that occurs when a forum comment is marked as best
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentMarkedAsBest(event) { const bestCommentId = event.commentId; console.log("Comment marked as best"); }
Did this help?

onCommentReported( )


A backend event that fires when a forum comment is reported.

The onCommentReported() event handler runs when a site visitor reports a comment on your site. The received ReportedComment object contains information about the comment that was reported.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentReported(event: ReportedComment): void;
Method Parameters
eventReportedCommentRequired

Information about the forum comment that was reported.

A backend event that occurs when a forum comment is reported
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentReported(event) { const reportedCommentId = event.commentId; const typeOfReport = event.reportType; console.log("Comment reported"); }
Did this help?

onCommentUnliked( )


A backend event that fires when a forum comment is unliked.

The onCommentUnliked() event handler runs when a like is removed from an existing forum comment in your site. The received UnlikedComment object contains information about the comment that was unliked.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentUnliked(event: UnlikedComment): void;
Method Parameters
eventUnlikedCommentRequired

Information about the forum comment that was unliked.

A backend event that occurs when a forum comment is unliked
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentUnliked(event) { const unlikedCommentId = event.commentId; console.log("Comment unliked"); }
Did this help?

onCommentUnmarkedAsBest( )


A backend event that fires when a forum comment is unmarked as best.

The onCommentUnmarkedAsBest() event handler runs when an existing forum comment in your site is unmarked as best. The received UnmarkedAsBestComment object contains information about the comment that was unmarked as best.

Notes:

  • Only comments on posts with a postType of "QUESTION" can be marked and unmarked as best.

  • Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentUnmarkedAsBest(event: UnmarkedAsBestComment): void;
Method Parameters
eventUnmarkedAsBestCommentRequired

Information about the forum comment that was unmarked as best.

A backend event that occurs when a forum comment is unmarked as best
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentUnmarkedAsBest(event) { const unmarkedCommentId = event.commentId; console.log("Comment unmarked as best"); }
Did this help?

onCommentUnvoted( )


A backend event that fires when a vote is removed from a forum comment.

The onCommentUnvoted() event handler runs when a vote is removed from a forum comment. The received UnvotedComment object contains information about the comment that was unvoted.

Notes:

  • Only comments on posts with a postType of "QUESTION" can be voted on.

  • Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentUnvoted(event: UnvotedComment): void;
Method Parameters
eventUnvotedCommentRequired

Information about the forum comment that was upvoted.

A backend event that occurs when a forum comment is upvoted
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentUpvoted(event) { const upvotedCommentId = event.commentId; console.log("Comment upvoted"); }
Did this help?

onCommentUpdated( )


A backend event that fires when a forum comment is updated.

The onCommentUpdated() event handler runs when a an existing forum comment in your site is updated. The received UpdatedComment object contains information about the comment that was updated.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentUpdated(event: UpdatedComment): void;
Method Parameters
eventUpdatedCommentRequired

Information about the forum comment that was updated.

A backend event that occurs when a forum comment is updated
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentUpdated(event) { const commentId = event.commentId; const commentText = event.comment.plainContent; } /* Full comment object: * { * "_id": "5f88058be9b6b100175b154c", * "postId":"5f88058be9b6b100175b154a", * "_ownerId":"32cf071a-ck2f-450f-ad74-5a25db0b1b6g", * "plainContent": "This is my updated comment text.", * "replyCount": 2, * "likeCount": 5, * "upvoteCount": 4, * "downvoteCount": 6, * "score": -2, * "_createdDate": "2020-10-26T07\:18\:20.297Z", * "_editedDate": "2020-11-04T12\:27\:05.592Z", * "_lastActivityDate": "2020-11-04T12\:27\:05.592Z", * "pageUrl": "/forum/main/comment/5f88058be9b6b100175b154c" * } */
Did this help?

onCommentUpvoted( )


A backend event that fires when a forum comment is upvoted.

The onCommentUpvoted() event handler runs when an existing forum comment in your site is upvoted. The received UpvotedComment object contains information about the comment that was upvoted.

Notes:

  • Only comments on posts with a postType of "QUESTION" can be upvoted.

  • Backend events are not fired when previewing your site.

Method Declaration
Copy
function onCommentUpvoted(event: UpvotedComment): void;
Method Parameters
eventUpvotedCommentRequired

Information about the forum comment that was upvoted.

A backend event that occurs when a forum comment is upvoted
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onCommentUpvoted(event) { const upvotedCommentId = event.commentId; console.log("Comment upvoted"); }
Did this help?

onPostClosed( )


A backend event that fires when a forum post is closed.

The onPostClosed() event handler runs when an existing forum post in your site is closed. When a forum post is closed, members can't comment on the post. The received ClosedPost object contains information about the post that was closed.

Notes:

  • By default, forum posts are open.

  • Backend events are not fired when previewing your site.

Method Declaration
Copy
function onPostClosed(event: ClosedPost): void;
Method Parameters
eventClosedPostRequired

Information about the forum post that was closed.

A backend event that occurs when a forum post is closed
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onPostClosed(event) { const closedPostId = event.postId; console.log("Post closed to comments"); }
Did this help?

onPostCreated( )


A backend event that fires when a new forum post is created.

The onPostCreated() event handler runs when a new forum post is created in your site. The received CreatedPost object contains information about the new post that was created.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onPostCreated(event: CreatedPost): void;
Method Parameters
eventCreatedPostRequired

Information about the forum post that was created.

A backend event that occurs when a new forum post is created
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onPostCreated(event) { const postId = event.postId; const postPageUrl = event.post.pageUrl; } /* Full post object: * { * "_id": "5f88058be9b6b100175b154c", * "categoryId":"5f88058be9b6b100175b154a", * "_ownerId":"32cf071a-ck2f-450f-ad74-5a25db0b1b6g", * "title": "What topics should we discuss?", * "plainContent": "Let us know what you think in the comments below.", * "pinned": "false", * "commentingDisabled": "false", * "commentCount": 0, * "likeCount": 0, * "viewCount": 0, * "_createdDate": "2020-10-26T07\:18\:20.297Z", * "_editedDate": null, * "_lastActivityDate": "2020-10-26T07\:18\:20.297Z", * "slug": "what-topics-should-we-discus", * "pageUrl": "/forum/category-name/what-topics-should-we-discuss", * "postType": "QUESTION" * } */
Did this help?

onPostDeleted( )


A backend event that fires when a forum post is deleted.

The onPostDeleted() event handler runs when an existing forum post in your site is deleted. The received DeletedPost object contains information about the post that was deleted.

Note: Backend events are not fired when previewing your site.

Method Declaration
Copy
function onPostDeleted(event: DeletedPost): void;
Method Parameters
eventDeletedPostRequired

Information about the forum post that was deleted.

A backend event that occurs when a forum post is deleted
JavaScript
// Place this code in a file named events.js // in the Backend section of your code files. export function wixForum_onPostDeleted(event) { const deletedPostId = event.postId; console.log("Post deleted"); }
Did this help?