Skip to content

Commit

Permalink
chore: use network node hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenn00dle committed Feb 22, 2024
1 parent 9ac9775 commit 1e590d1
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion includes/hub/class-nodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class Nodes {
public static function init() {
add_action( 'init', [ __CLASS__, 'register_post_type' ] );
add_action( 'save_post', [ __CLASS__, 'save_post' ] );
add_action( 'save_post_' . self::POST_TYPE_SLUG, [ __CLASS__, 'sync_nodes' ] );
add_action( 'trashed_post', [ __CLASS__, 'trashed_node' ] );
add_action( 'untrashed_post', [ __CLASS__, 'untrashed_node' ] );
add_action( 'newspack_network_node_saved', [ __CLASS__, 'sync_nodes' ] );
add_action( 'newspack_network_node_trashed', [ __CLASS__, 'sync_nodes' ] );
add_action( 'newspack_network_node_untrashed', [ __CLASS__, 'sync_nodes' ] );
}

/**
Expand Down Expand Up @@ -272,6 +276,44 @@ public static function save_post( $post_id ) {
do_action( 'newspack_network_node_saved', $post_id );
}

/**
* Trashed post callback
*
* @param int $post_id The ID of the post being trashed.
* @return void
*/
public static function trashed_node( $post_id ) {
if ( self::POST_TYPE_SLUG !== get_post_type( $post_id ) ) {
return;
}

/**
* Fires an action when a node is successfully trashed in the Hub admin
*
* @param int $post_id The ID of the node post.
*/
do_action( 'newspack_network_node_trashed', $post_id );
}

/**
* Untrashed post callback
*
* @param int $post_id The ID of the post being untrashed.
* @return void
*/
public static function untrashed_node( $post_id ) {
if ( self::POST_TYPE_SLUG !== get_post_type( $post_id ) ) {
return;
}

/**
* Fires an action when a node is successfully untrashed in the Hub admin
*
* @param int $post_id The ID of the node post.
*/
do_action( 'newspack_network_node_untrashed', $post_id );
}

/**
* Sync nodes data to all nodes in network.
*
Expand Down

0 comments on commit 1e590d1

Please sign in to comment.