Add "Pull Page" functionality to admin bar and REST API endpoint

This commit is contained in:
Matt Batchelder
2026-02-21 12:19:19 -05:00
parent d56d46490a
commit 158fb53d24
3 changed files with 226 additions and 0 deletions

View File

@@ -48,6 +48,15 @@ add_action( 'rest_api_init', function () {
},
] );
// ── Pull single page + theme ───────────────────────────────────────────
register_rest_route( 'oribi-sync/v1', '/pull-page', [
'methods' => 'POST',
'callback' => 'oribi_sync_rest_pull_page',
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
] );
// ── Webhook (secret-based auth, no WP login required) ─────────────────
register_rest_route( 'oribi-sync/v1', '/webhook', [
'methods' => 'POST',
@@ -86,6 +95,20 @@ function oribi_sync_rest_status(): WP_REST_Response {
] );
}
/**
* REST: Pull a single page and theme from the repo.
*/
function oribi_sync_rest_pull_page( WP_REST_Request $request ): WP_REST_Response {
$post_id = (int) $request->get_param( 'post_id' );
if ( $post_id < 1 ) {
return new WP_REST_Response( [ 'ok' => false, 'message' => 'Missing or invalid post_id.' ], 400 );
}
$result = oribi_sync_pull_page_from_repo( $post_id );
return new WP_REST_Response( $result, $result['ok'] ? 200 : 500 );
}
/**
* REST: Webhook trigger.
*