LLMS_Post_Relationships::maybe_update_relationships( int $post_id )

Check relationships and delete / update related posts when a post is deleted.


Description Description

Called on delete_post hook (before a post is deleted).


Top ↑

Parameters Parameters

$post_id

(int) (Required) WP Post ID of the deleted post.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.post.relationships.php

	public function maybe_update_relationships( $post_id ) {

		$post = get_post( $post_id );
		if ( ! in_array( $post->post_type, $this->get_post_types(), true ) ) {
			return;
		}

		foreach ( $this->get_relationships() as $post_type => $relationships ) {

			if ( $post->post_type !== $post_type ) {
				continue;
			}

			foreach ( $relationships as $data ) {

				if ( in_array( $data['action'], array( 'delete', 'trash' ), true ) ) {

					$this->delete_relationships( $post, $data );

				} elseif ( 'unset' === $data['action'] ) {

					$this->unset_relationships( $post, $data );

				}
			}
		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.24.0 Unknown.
3.16.12 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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