Staff Directory Sync
WordPress plugin: scheduled sync of an employee directory from any API (including Microsoft Graph) into custom tables, with retries and a run log.
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/martinarafat/staff-directory-sync/archive/refs/heads/main.zipPulls the employee list from an HR API on a schedule, keeps it in custom tables, and shows it on the site with a shortcode.
Setup
- Activate the plugin.
- Go to Staff Directory in the dashboard and click Sync now (or wait for the scheduled run).
- Add
[staff_directory]to any page.
Shortcode options: department="Engineering", per_page="12", columns="3", search="no".
How the sync works
- WP-Cron job. Interval is set on the settings screen (15 min, hourly, twice a day, daily).
- Pages through the API until it has the full list. If any page fails, the whole run fails, so we never save half a list.
- Each record is compared by hash: new rows are inserted, changed rows updated, unchanged rows just marked as seen.
- All writes happen in one transaction.
- People who are missing from a complete run are set to inactive, not deleted.
- A transient lock stops two runs from overlapping.
- Every run is logged in
wp_sds_sync_runsand shown on the admin screen.
When the API is down
- Timeouts, 429 and 5xx are retried in the same run (1s, then 2s).
- If it still fails, the current data stays as it is and a retry is scheduled after 5, 10, then 20 minutes.
- An empty response counts as a failure too, otherwise it would deactivate everyone.
sds_sync_failedfires on every failure, so an email or Teams alert can be hooked in.- To test it, tick Simulate an API outage in the settings and run a sync.
Connecting a different API
Everything is on the settings screen, no code needed:
- API URL
- Auth header and value, for example
Authorization/Bearer abc123, orx-api-key/abc123. On a live site the value can go inwp-config.phpasSDS_API_AUTH_VALUEinstead. - Records path: where the list is in the JSON (
users,data.items, or empty if the response is the list) - Paging: none,
limit/skip, or a next-page link in the response. Next links are only followed on the same host, so the auth header can't leak to another site. - Field mapping: the field name for ID, name, email, phone, job title, department and photo. Dots for nested fields (
company.department), numbers for lists (businessPhones.0).
Test connection reads the first page with the saved settings and shows the first person it found, without touching the data.
The defaults are set up for the demo API at https://dummyjson.com/users.
Example for Microsoft Graph /users: records path value, paging "next page link" with @odata.nextLink, name displayName, email mail, phone businessPhones.0, job title jobTitle, department department. Graph tokens expire after an hour, so for Graph the token is better added through the sds_api_request_args filter than pasted in the settings.
Developer filters: sds_api_url, sds_api_request_args, sds_map_employee.