CNHSA Content Federation
This article documents how content gets published from the CNO site to the CNHSA site. It is quite technical.
Hey, look! Pictures!
Technical diagrams can be seen in the CNO Site Figma Folder. This is a multi-page Figjam that leans heavily on UML-style Sequence Diagrams (watch a quick Udemy lecture here).
Plugins Overview
- CNO to CNHSA Plugin
- CNHSA to CNO Plugin
Both share the following conventions / architecture:
Terms
inc/WPhas files (and subdirectories) related to WordPress actions (hooks, cron events, post/payload creation, etc)inc/Transportis for files related to sending/receiving data over HTTPHTTP_Gatewayclass is for sending (outbound) dataRest_Routerclass is for receiving (inbound) data
General Overview:
inc/is where PHP livestests/is where the PHPUnit tests livesrc/is where the React code (for Admin Screen) lives
Plugin Lifecycle
*-content-federation.php is required by WordPress. It instantiates a new ChoctawNation\*_Federation\Plugin_Loader class and wires its methods to the necessary WordPress hooks:
register_activation_hook- On
activate, the plugin tries to grab any storedoptionsfrom the DB.
- On
register_uninstsall_hook- On
uninstall, the plugin will delete any storedoptions.
- On
add_action( 'plugins_loaded', array( $plugin, 'load_plugin' ) )
load_plugin is the hook/callback pair that does all the heavy lifting:
- Registers rest routes
- Loads admin screen for configuring federation
- Wires up cron hook callbacks and other business
- This is where all the necessary classes and their dependencies are created, injected and called.
How it works: CNO to CNHSA
Traffic scope: CNO Services & Locations posts -> CNHSA Services & [Clinic/Additional-Facility] posts
Outbound traffic
When a user updates a services/locations post, the save_post_{$post_type} hook is fired by WordPress and a cron event is scheduled to run. This allows content editors to move on with their life and not have to wait for content to get federated over to the CNHSA site.
Why a cron event?[Click to expand]
Without this step, saving a post would have to wait until federation was complete before the post was saved.
Posts are linked via id stored in post_meta (not necessarily registered as an ACF field). If an ID doesn’t exist, chances are you’re creating a new resource. If it does exist, you’re updating a resource.
When the cron event fires, the plugin:
- Builds the payload
- Sends the payload (
Transport\Http_Gateway) - Sends emails on error
- Updates the post_meta with the returned CNHSA post id
Inbound traffic: CNHSA
- Post is created
- ACF fields are updated
canonicaltag is updated- Successful id is returned
- Emails on error
How it works: CNHSA to CNO
Basically the same as above, but instead of going ACF to ACF, we’re going Blocks to ACF, so the payload is parsed a bit differently.
Also, right now [03/04/2026] this direction is only for the “CNHSA Eligibility Guidelines”