HEX
HEX
Server: Apache
System: Linux localhost.localdomain 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1001)
PHP: 8.1.32
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,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_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/ahmsolaiman.com/wp-content/plugins/types/application/models/post/deletion.php
<?php

/**
 * This class currently only does actions related to RFG groups.
 * Any future or legacy actions for "delete_post" should go here aswell.
 *
 * This class is currently only loaded if m2m is active (by Types_M2M controller).
 *
 * @since m2m
 */
class Types_Post_Deletion {

	/**
	 * State of process
	 *
	 * @var bool
	 */
	private static $is_running;


	/**
	 * @action before_delete_post
	 *
	 * @param int $postid
	 */
	public function before_delete_post( $postid ) {
		if ( self::$is_running ) {
			// prevent self calls on our item deletion
			return;
		}
		self::$is_running = true;

		$post = get_post( $postid );

		if ( $post instanceof WP_Post ) {
			$types_post_builder = new Types_Post_Builder();
			$types_post_builder->set_wp_post( $post );
			$types_post_builder->load_assigned_field_groups( 9999 );
			$types_post = $types_post_builder->get_types_post();

			if ( $field_groups = $types_post->get_field_groups() ) {
				$this->delete_field_groups_items( $field_groups );
			}
		}

		self::$is_running = false;
	}


	/**
	 * @param Types_Field_Group_Post[] $field_groups
	 */
	private function delete_field_groups_items( array $field_groups ) {
		if ( empty( $field_groups ) ) {
			// no field groups to delete
			return;
		}

		foreach ( $field_groups as $field_group ) {
			if ( ! $field_group instanceof Types_Field_Group_Repeatable ) {
				// NO RFG
				// search for rfg and delete if exists
				if ( $rfgs = $field_group->get_repeatable_groups() ) {
					$this->delete_field_groups_items( $rfgs );
				}

				continue;
			}

			// repeatable field group
			if ( $items = $field_group->get_posts() ) {
				foreach ( $items as $item ) {
					/**@var $item Types_Field_Group_Repeatable_Item */
					if ( $nested_rfgs = $item->get_field_groups() ) {
						$this->delete_field_groups_items( $nested_rfgs );
					}

					// delete item (second parameter to true will bypass the trash and really delete the item)
					wp_delete_post( $item->get_wp_post()->ID, true );
				}
			}
		}
	}
}