HEX
Server: Apache
System: Linux sxb1plmcpnl510113.prod.sxb1.secureserver.net 4.18.0-553.58.1.lve.el8.x86_64 #1 SMP Fri Jul 4 12:07:06 UTC 2025 x86_64
User: acnbijigo78q (10488831)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/acnbijigo78q/public_html/jetk.sa/wp-content/plugins/wpml-all-import/classes/Attachments.php
<?php

namespace WPML\AI;
/**
 * Class Attachments
 * @package WPML\AI
 */
class Attachments {

	/**
	 * @var null|string Location of the file to unlink.
	 */
	static $URL;

	/**
	 * Things to do before single post is going to be imported.
	 */
	public function beforePostImport() {
		$this->allowToDeleteAttachments();
	}

	/**
	 * Things to do after single post has been imported.
	 */
	public function afterPostImport() {
		$this->removeFilter();
	}

	/**
	 * Set location of the file to unlink (after WPMl core resets it to null).
	 */
	private function allowToDeleteAttachments() {
		add_filter( 'wp_delete_file', [ $this, 'grabUrlInDeleteFileFilter'], 1, 1 );
		add_filter( 'wp_delete_file', [ $this, 'restoreUrlInDeleteFileFilter'], 20, 1 );
	}

	/**
	 * Removes filters registered with \WPML\AI\attachments::allowToDeleteAttachments
	 */
	private function removeFilter() {
		remove_filter( 'wp_delete_file', [ $this, 'grabUrlInDeleteFileFilter'], 1, 1 );
		remove_filter( 'wp_delete_file', [ $this, 'restoreUrlInDeleteFileFilter'], 20, 1 );
		self::$URL = null;
	}

	/**
	 * Save file location.
	 *
	 * @param $url File location
	 */
	public function grabUrlInDeleteFileFilter( $url ) {
		self::$URL = $url;
	}

	/**
	 * Restore file location.
	 *
	 * @param $url null|string File location.
	 *
	 * @return string|null File location
	 */
	public function restoreUrlInDeleteFileFilter( $url ) {
		if ( self::$URL ) {
			$url = self::$URL;
		}
		return $url;
	}
}