LLMS_Frontend_Assets::enqueue_content_protection()
Enqueue inline copy prevention scripts.
Return Return
(void)
Source Source
File: includes/class.llms.frontend.assets.php
public static function enqueue_content_protection() {
$allow_copying = ! llms_parse_bool( get_option( 'lifterlms_content_protection', 'no' ) ) || llms_can_user_bypass_restrictions( get_current_user_id() );
/**
* Filters whether or not content prevention is enabled.
*
* This hook runs on the `wp` action, at this point the current user is available and
* the global `$post` has already been set up.
*
* @since 5.6.0
*
* @param boolean $allow_copying Whether or not copying is allowed. If `true`, copying
* is allowed, otherwise copy prevention scripts are
* loaded.
*/
$allow_copying = apply_filters( 'llms_skip_content_prevention', $allow_copying );
if ( $allow_copying ) {
return;
}
ob_start();
?>
( function(){
function dispatchEvent( type ) {
document.dispatchEvent( new Event( type ) );
}
document.addEventListener( 'copy', function( event ) {
event.preventDefault();
event.clipboardData.setData( 'text/plain', '<?php echo __( 'Copying is not allowed.', 'lifterlms' ); ?>' );
dispatchEvent( 'llms-copy-prevented' );
}, false );
document.addEventListener( 'contextmenu', function( event ) {
if ( event.target && 'IMG' === event.target.nodeName ) {
event.preventDefault();
dispatchEvent( 'llms-context-prevented' );
}
}, false );
} )();
<?php
$script = ob_get_clean();
llms()->assets->enqueue_inline( 'llms-integrity', $script, 'header' );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.6.0 | Introduced. |