LogoLogo
Ajaxify HomeWP.org RepoDLX Plugins
Ajaxify Comments
Ajaxify Comments
  • 👋Welcome to Ajaxify Comments
  • First Time Users
    • Installing the Plugin
    • Finding the Settings
    • Getting Started
    • Menu Helper
  • 🖌️Customization
    • Labels and Translations
    • Appearance Settings
  • 🤓Advanced Topics
    • Callbacks
    • Disable Scroll to Posted Comment (Anchor)
    • Disable URL Updating
    • Lazy Loading Comments
    • Selectors
    • WPML and Translations
  • Developers
    • Script Debugging
    • Actions and Filters
      • Changing Labels Programmatically
    • GitHub Repo
    • Changelog
  • Theme Integrations
    • Ollie
    • Twenty Twenty-Three
  • Plugin Integrations
    • Confetti
    • Comment Edit Core
  • Quick Links
    • Ajaxify Home
    • Support
    • GitHub Repo
    • WordPress.org Plugin Page
Powered by GitBook
LogoLogo

Download

  • GitHub
  • WP.org Repo

Support

  • WP.org Support
  • DLX Support
  • Contact

DLX Plugins

On this page
  • OnBeforeSelectElements Callback
  • OnBeforeSubmitComment Callback
  • OnAfterPostComment Callback
  • OnBeforeUpdateComments Callback
  • OnAfterUpdateComments Callback

Was this helpful?

Export as PDF
  1. Advanced Topics

Callbacks

PreviousAppearance SettingsNextDisable Scroll to Posted Comment (Anchor)

Last updated 1 year ago

Was this helpful?

Callbacks allow you to run custom JavaScript code in certain parts of execution. For example, if you have an Edit Comments plugin, you can run a custom function that initializes the plugin after a comment has been posted.

Each callback can pass arguments, which are documented below and will be in scope for any custom JS functionality that needs to run.

A common use-case of callbacks is another plugin that needs to run before, during, and after Ajaxify Comments loads.

OnBeforeSelectElements Callback

This allows you to run JavaScript code before Ajaxify Comments has selected the DOM elements.

One argument is in scope, which is a jQuery representation of the DOM elements selected.

If you'd rather use a native JS event, you can use the event: wpacBeforeSelectElements

document.addEventListener( 'wpacBeforeSelectElements', function( e ) {
	console.log( 'Custom event fired:', e );
	console.log( 'Extracted body:', e.detail.dom );
} );

OnBeforeSubmitComment Callback

This callback provides no arguments.

If you'd rather use a native JS event, you can use the event: wpacBeforeSelectElements

document.addEventListener( 'wpacBeforeSelectElements', function( e ) {
	console.log( 'Custom event fired:', e );
} );

OnAfterPostComment Callback

Arguments:

  1. commentUrl (string)

  2. unapproved (boolean)

If you'd rather use a native JS event, you can use the event: wpacAfterPostComment

document.addEventListener( 'wpacAfterPostComment', function( e ) {
	console.log( 'Custom event fired:', e );
	console.log( 'Extracted body:', e.detail.commentUrl, e.detail.unapproved );
} );

OnBeforeUpdateComments Callback

Arguments

  • newDom (jQuery DOM element)

  • commentUrl (string)

If you'd rather use a native JS event, you can use the event: wpacBeforeUpdateComments

document.addEventListener( 'wpacAfterPostComment', function( e ) {
	console.log( 'Custom event fired:', e );
	console.log( 'Extracted body:', e.detail.newDom, e.detail.commentUrl );
} );

OnAfterUpdateComments Callback

Arguments

  • newDom (jQuery DOM element)

  • commentUrl (string)

document.addEventListener( 'wpacAfterUpdateComments', function( e ) {
	console.log( 'Custom event fired:', e );
	console.log( 'Extracted body:', e.detail.newDom, e.detail.commentUrl );
} );
🤓