coresocial-sharing-popup-open
This content is intended for WordPress developers, and it may require coding knowledge of WordPress, PHP, and JavaScript. Code examples provided here may contain errors or needs some additional coding. Make sure to test the code before using it on a live website!
Action identifier (JavaScript)
Arguments
JavaScript wp.hooks action fired after the standard share window.open() call and before the optional popup.focus(). It receives the same details object and link as popup-ready.
The action still fires if the popup was blocked. Check for null. It does not report whether the visitor completed a share, and custom app/AI handlers do not necessarily emit it.
Register with wp.hooks.addAction(), not PHP add_action(). Load the listener with the wp-hooks script dependency before the relevant user interaction. The Source Code block uses its generic action template; the code example shows the actual JavaScript API.
Example
wp.hooks.addAction( 'coresocial-sharing-popup-open', 'my-site/popup-observer', function ( details, link, popup ) {
if ( ! popup ) {
console.log( 'Share popup was blocked.' );
}
} );