HEX
Server: Apache/2.4.25 (Debian)
System: Linux server17 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
User: web37 (1062)
PHP: 7.4.30
Disabled: show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
Upload Files
File: /var/www/web37/htdocs/sexnetzwerk24/wp-content/themes/classipress/includes/payments/utils/queue.php
<?php
/**
 * Queue utils
 *
 * @package Components\Payments\Utils
 */

/**
 * Defines a process to retrieve a set of items and iterate over them on a set interval
 */
class APP_Queue{

	/**
	 * Name of process occuring
	 */
	protected $identifier;

	public function __construct( $identifier, $args = array() ){

		$this->identifier = $identifier;

		$this->args = wp_parse_args( $args, array(
			'interval' => 'daily',
			'limit' => 0
		) );

		add_action( 'init', array( $this, 'schedule_process' ) );
		add_action( $this->identifier, array( $this, 'process' ) );

	}

	/**
	 * Schedules the process to happen every $interval
	 * @return void
	 */
	public function schedule_process(){
		if( !wp_next_scheduled( $this->identifier ) ){
			wp_schedule_event( time(), $this->args['interval'], $this->identifier );
		}
	}

	public function process(){

		$items_processed = 0;

		$items = $this->get_items();
		if( $items instanceof WP_Query )
			$items = $items->posts;

		if( empty( $items ) )
			return $items_processed;

		foreach( array_slice( $items, 0, $this->args['limit'] )  as $item ){
			$this->process_item( $item );
			$items_processed += 1;
		}

		return $items_processed;
	}

}