Skip to main content

Overview

The Quick Fix endpoint applies automated optimizations to WordPress posts based on issues identified during a GEO audit. It can insert Answer Card blocks, add author information, and apply other content improvements.

Endpoint Details

method
string
required
POST
endpoint
string
required
/wp-json/geoai/v1/quick-fix

Authentication

Requires authentication with a user account that has edit_post capability for the specified post. See REST API Overview for authentication methods.

Request Parameters

post_id
integer
required
The ID of the WordPress post to apply the fix to. Must be a valid post ID that exists in your WordPress database.
fix_id
string
required
The identifier of the fix to apply. Available fix IDs:
  • insert_answer_card - Inserts an Answer Card block at the beginning of the post
  • add_author - Adds author byline information (coming in future update)

Response

Success Response (200)

When the fix is applied successfully:
success
boolean
Always true for successful requests.
message
string
Confirmation message: “Quick fix applied successfully.”
data
object
Additional data returned by specific fixes (not present for all fix types).
data.content
string
The updated post content after applying the fix.
data.notice
string
Additional information about what was changed.

Error Response (500)

When the fix fails to apply:
success
boolean
Always false for failed requests.
message
string
Error message describing what went wrong.

Examples

cURL Example

# Insert Answer Card block
curl -X POST https://example.com/wp-json/geoai/v1/quick-fix \
  -u "username:application_password" \
  -H "Content-Type: application/json" \
  -d '{
    "post_id": 123,
    "fix_id": "insert_answer_card"
  }'

JavaScript (Fetch API)

// From within WordPress admin (using nonce)
fetch('/wp-json/geoai/v1/quick-fix', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-WP-Nonce': wpApiSettings.nonce
  },
  body: JSON.stringify({
    post_id: 123,
    fix_id: 'insert_answer_card'
  })
})
.then(response => response.json())
.then(data => {
  if (data.success) {
    console.log('Fix applied:', data.message);
    if (data.data) {
      console.log('Notice:', data.data.notice);
    }
  } else {
    console.error('Fix failed:', data.message);
  }
})
.catch(error => console.error('Request failed:', error));

PHP (WordPress)

$response = wp_remote_post(
  rest_url('geoai/v1/quick-fix'),
  array(
    'headers' => array(
      'Content-Type' => 'application/json',
      'X-WP-Nonce' => wp_create_nonce('wp_rest')
    ),
    'body' => json_encode(array(
      'post_id' => 123,
      'fix_id' => 'insert_answer_card'
    ))
  )
);

if (!is_wp_error($response)) {
  $body = json_decode(wp_remote_retrieve_body($response), true);
  
  if ($body['success']) {
    echo $body['message'];
    if (isset($body['data']['notice'])) {
      echo ' - ' . $body['data']['notice'];
    }
  } else {
    echo 'Error: ' . $body['message'];
  }
}

Python (Requests)

import requests
from requests.auth import HTTPBasicAuth

response = requests.post(
    'https://example.com/wp-json/geoai/v1/quick-fix',
    auth=HTTPBasicAuth('username', 'application_password'),
    json={
        'post_id': 123,
        'fix_id': 'insert_answer_card'
    }
)

if response.status_code == 200:
    data = response.json()
    if data['success']:
        print(f"Success: {data['message']}")
        if 'data' in data and 'notice' in data['data']:
            print(f"Notice: {data['data']['notice']}")
    else:
        print(f"Failed: {data['message']}")
else:
    print(f"Request failed: {response.status_code}")

Response Examples

Successful Answer Card Insertion

{
  "success": true,
  "message": "Quick fix applied successfully.",
  "data": {
    "content": "<!-- wp:geoai/answer-card {\"tldr\":\"\",\"keyFacts\":[]} />\n\n<!-- wp:paragraph -->\n<p>Your existing post content...</p>\n<!-- /wp:paragraph -->",
    "notice": "Answer Card inserted at the top of the post."
  }
}

Successful Fix (No Additional Data)

{
  "success": true,
  "message": "Quick fix applied successfully."
}

Error Responses

Missing Required Parameters

{
  "code": "rest_missing_callback_param",
  "message": "Missing parameter(s): fix_id",
  "data": {
    "status": 400,
    "params": ["fix_id"]
  }
}

Insufficient Permissions

{
  "code": "rest_forbidden",
  "message": "Sorry, you are not allowed to edit this post.",
  "data": {
    "status": 403
  }
}

Invalid Fix ID

{
  "success": false,
  "message": "Invalid fix ID."
}

Invalid Post ID

{
  "success": false,
  "message": "Post not found."
}

Answer Card Already Exists

{
  "success": false,
  "message": "Answer Card already exists in this post."
}

Post Update Failed

{
  "success": false,
  "message": "Failed to update post: Database error occurred."
}

Available Fixes

insert_answer_card

Inserts a GEO AI Answer Card block at the beginning of the post content. What it does:
  • Checks if an Answer Card block already exists
  • Inserts the block markup: <!-- wp:geoai/answer-card {"tldr":"","keyFacts":[]} /-->
  • Places it at the very top of the post content
  • Returns the updated content
Errors:
  • Returns error if Answer Card already exists in the post
  • Returns error if post ID is invalid
  • Returns error if post update fails
Implementation: See /home/daytona/workspace/source/includes/class-geoai-rest.php:150

add_author

This fix is planned for a future release. Currently returns an empty success response.
Will add author byline information to enhance post authority signals.

Implementation Details

The Quick Fix endpoint is implemented in /home/daytona/workspace/source/includes/class-geoai-rest.php:109.

Permission Check

The endpoint verifies that the current user has edit_post capability for the specified post before applying any fixes.

Fix Application Process

  1. Validates post_id and fix_id parameters
  2. Checks user permissions
  3. Routes to the appropriate fix handler based on fix_id
  4. Applies the fix (may modify post content)
  5. Returns success confirmation with optional additional data

Content Modification

Fixes that modify post content (like insert_answer_card) use wp_update_post() to save changes. This triggers all standard WordPress hooks, so other plugins can respond to the changes.

Best Practices

Always run an audit first to identify which fixes are needed. The audit response includes fix_available flags for each issue.
Some fixes (like Answer Card insertion) will fail if the content already exists. Handle these errors gracefully.
If applying fixes to multiple posts programmatically, ensure you have backups. Fixes modify post content directly.
Only use fix IDs that are documented as available. Invalid fix IDs return an error.
New fix types may be added in future updates. Check the audit response for available fixes.

Workflow Example

Here’s a complete workflow for auditing and fixing a post:
async function auditAndFix(postId) {
  // Step 1: Run audit
  const auditResponse = await fetch('/wp-json/geoai/v1/audit', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-WP-Nonce': wpApiSettings.nonce
    },
    body: JSON.stringify({ post_id: postId })
  });
  
  const auditData = await auditResponse.json();
  
  if (!auditData.success) {
    console.error('Audit failed:', auditData.message);
    return;
  }
  
  // Step 2: Find fixable issues
  const fixableIssues = auditData.data.issues.filter(issue => issue.fix_available);
  
  console.log(`Found ${fixableIssues.length} fixable issues`);
  
  // Step 3: Apply fixes
  for (const issue of fixableIssues) {
    const fixResponse = await fetch('/wp-json/geoai/v1/quick-fix', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-WP-Nonce': wpApiSettings.nonce
      },
      body: JSON.stringify({
        post_id: postId,
        fix_id: issue.id
      })
    });
    
    const fixData = await fixResponse.json();
    
    if (fixData.success) {
      console.log(`Fixed: ${issue.id}`);
    } else {
      console.error(`Failed to fix ${issue.id}: ${fixData.message}`);
    }
  }
  
  console.log('All fixes applied');
}

// Run it
auditAndFix(123);

Audit

Run a GEO audit to identify issues before applying fixes

API Overview

Learn about authentication and common patterns

Build docs developers (and LLMs) love