HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux newsites.squeezer-software.com 6.8.0-90-generic #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/sites/ileskneiss/wp-content/plugins/learnpress/assets/src/js/utils/hook.js
const Hook = {
	hooks: { action: {}, filter: {} },
	addAction( action, callable, priority, tag ) {
		this.addHook( 'action', action, callable, priority, tag );
		return this;
	},
	addFilter( action, callable, priority, tag ) {
		this.addHook( 'filter', action, callable, priority, tag );
		return this;
	},
	doAction( action ) {
		return this.doHook( 'action', action, arguments );
	},
	applyFilters( action ) {
		return this.doHook( 'filter', action, arguments );
	},
	removeAction( action, tag ) {
		this.removeHook( 'action', action, tag );
		return this;
	},
	removeFilter( action, priority, tag ) {
		this.removeHook( 'filter', action, priority, tag );
		return this;
	},
	addHook( hookType, action, callable, priority, tag ) {
		if ( undefined === this.hooks[ hookType ][ action ] ) {
			this.hooks[ hookType ][ action ] = [];
		}
		const hooks = this.hooks[ hookType ][ action ];
		if ( undefined === tag ) {
			tag = action + '_' + hooks.length;
		}
		this.hooks[ hookType ][ action ].push( { tag, callable, priority } );
		return this;
	},
	doHook( hookType, action, args ) {
		args = Array.prototype.slice.call( args, 1 );

		if ( undefined !== this.hooks[ hookType ][ action ] ) {
			let hooks = this.hooks[ hookType ][ action ],
				hook;

			hooks.sort( function( a, b ) {
				return a.priority - b.priority;
			} );

			for ( let i = 0; i < hooks.length; i++ ) {
				hook = hooks[ i ].callable;
				if ( typeof hook !== 'function' ) {
					hook = window[ hook ];
				}

				if ( 'action' === hookType ) {
					args[ i ] = hook.apply( null, args );
				} else {
					args[ 0 ] = hook.apply( null, args );
				}
			}
		}

		if ( 'filter' === hookType ) {
			return args[ 0 ];
		}
		return args;
	},
	removeHook( hookType, action, priority, tag ) {
		if ( undefined !== this.hooks[ hookType ][ action ] ) {
			const hooks = this.hooks[ hookType ][ action ];
			for ( let i = hooks.length - 1; i >= 0; i-- ) {
				if ( ( undefined === tag || tag === hooks[ i ].tag ) && ( undefined === priority || priority === hooks[ i ].priority ) ) {
					hooks.splice( i, 1 );
				}
			}
		}
		return this;
	},
};

export default Hook;