All features

Cherry Blossom feature

Content types Post Types: Lifecycle trait

Provides post type lifecycle and REST integration.

Provides post type lifecycle and REST integration.

Capabilities and extension points

Registers dynamic post type lifecycle hooks.

Dispatches post creation and save callbacks.

  • param int $post_id Post ID.
  • param \WP_Post $post Post object.
  • param bool $update Whether an existing post was updated.
  • param \WP_Post|null $post_before Post object before the update, or null for new posts.

Handles a newly created post.

Override this method in a dedicated post type class when creation needs additional behavior.

  • param int $post_id Post ID.
  • param \WP_Post $post Post object.

Handles a saved post.

This runs for both new and updated posts after terms and core metadata have been persisted.

  • param int $post_id Post ID.
  • param \WP_Post $post Post object.
  • param bool $update Whether an existing post was updated.
  • param \WP_Post|null $post_before Post object before the update, or null for new posts.

Dispatches post deletion callbacks.

  • param int $post_id Post ID.
  • param \WP_Post $post Deleted post object.

Handles a deleted post.

  • param int $post_id Post ID.
  • param \WP_Post $post Deleted post object.

Filters post data before WordPress inserts or updates the post.

  • param array $data Sanitized post data.
  • param array $postarr Post data with defaults applied.
  • param array $unsanitized_postarr Original post data.
  • param bool $update Whether an existing post is updated.
  • return array Filtered post data.

Filters post data before WordPress inserts or updates the post.

Override this method to provide class-owned filtering behavior.

  • param array $data Sanitized post data.
  • param array $postarr Post data with defaults applied.
  • param array $unsanitized_postarr Original post data.
  • param bool $update Whether an existing post is updated.
  • return array Filtered post data.

Filters REST API query arguments for this post type.

  • param array $arguments Query arguments.
  • param \WP_REST_Request $request REST API request.
  • return array Filtered query arguments.

Filters a REST API response for this post type.

  • param \WP_REST_Response $response REST API response.
  • param \WP_Post $post Post object.
  • param \WP_REST_Request $request REST API request.
  • return \WP_REST_Response Filtered REST API response.

Determines whether a value represents this post type.

  • param int|\WP_Post $post Post ID or object.
  • return bool Whether the post belongs to this definition.

Source reference

This editable reference page is based on the PHP documentation in content-types/post-types/traits/trait-lifecycle.php.