LLMS_Frontend_Assets::enqueue_content_protection()

Enqueue inline copy prevention scripts.


Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.frontend.assets.php

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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' );
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.