Docs / Connect it

Connect WordPress

A small plugin that adds a Check this post button to the editor.

This adds a box in the post editor. The editor clicks Check this post, waits, and sees each claim with its verdict. The key stays on the server.

  1. Put the key in wp-config.phpOpen wp-config.php (above the line that says That's all, stop editing) and add define('PIJ_KEY', 'pij_live_YOUR_KEY');. Do not put it in a theme.
  2. Create the plugin fileIn wp-content/mu-plugins/ (create the folder if it is missing) make a file called news-intelligence.php and paste the code below.
  3. Open any postIn the editor sidebar you will see a News Intelligence box. Click the button. The result appears when the check is done (usually one to four minutes).
<?php
/* Plugin Name: News Intelligence check */
if (!defined('ABSPATH')) exit;

function pij_call($method, $path, $body = null) {
  if (!defined('PIJ_KEY')) return ['ok' => false, 'message' => 'PIJ_KEY is not set in wp-config.php'];
  $args = ['method' => $method, 'timeout' => 30,
    'headers' => ['Authorization' => 'Bearer ' . PIJ_KEY, 'Content-Type' => 'application/json']];
  if ($body !== null) $args['body'] = wp_json_encode($body);
  $r = wp_remote_request('https://api.chatniai.com' . $path, $args);
  if (is_wp_error($r)) return ['ok' => false, 'message' => $r->get_error_message()];
  return json_decode(wp_remote_retrieve_body($r), true) ?: ['ok' => false, 'message' => 'Empty reply'];
}

add_action('wp_ajax_pij_start', function () {
  check_ajax_referer('pij');
  if (!current_user_can('edit_posts')) wp_send_json(['ok' => false], 403);
  $text = mb_substr(wp_strip_all_tags(wp_unslash($_POST['text'] ?? '')), 0, 8000);
  $u = wp_get_current_user();
  wp_send_json(pij_call('POST', '/v1/check', ['text' => $text, 'async' => true, 'user' => $u->user_email]));
});

add_action('wp_ajax_pij_job', function () {
  check_ajax_referer('pij');
  if (!current_user_can('edit_posts')) wp_send_json(['ok' => false], 403);
  $id = preg_replace('/[^0-9a-f-]/i', '', $_POST['id'] ?? '');
  wp_send_json(pij_call('GET', '/v1/job/' . $id));
});

add_action('add_meta_boxes', function () {
  add_meta_box('pij', 'News Intelligence', 'pij_box', 'post', 'side');
});

function pij_box() { $nonce = wp_create_nonce('pij'); ?>
  <button type="button" class="button button-primary" id="pijgo">Check this post</button>
  <div id="pijout" style="margin-top:10px;font-size:13px"></div>
  <script>
  (function(){
    var out = document.getElementById('pijout'), btn = document.getElementById('pijgo');
    function post(a, d){ d.action = a; d._ajax_nonce = '<?php echo $nonce; ?>';
      return fetch(ajaxurl, {method:'POST', headers:{'Content-Type':'application/x-www-form-urlencoded'},
        body:new URLSearchParams(d)}).then(function(r){return r.json();}); }
    btn.onclick = function(){
      var text = (window.wp && wp.data) ? wp.data.select('core/editor').getEditedPostContent() : '';
      out.textContent = 'Starting...'; btn.disabled = true;
      post('pij_start', {text: text}).then(function(s){
        if (!s.job_id) { out.textContent = s.message || 'Could not start.'; btn.disabled = false; return; }
        var n = 0, t = setInterval(function(){
          post('pij_job', {id: s.job_id}).then(function(j){
            if (j.state === 'done') { clearInterval(t); btn.disabled = false; show(j.result); }
            else if (j.state === 'failed' || ++n > 90) { clearInterval(t); btn.disabled = false; out.textContent = 'The check did not finish. Try again.'; }
            else out.textContent = 'Checking... ' + (j.elapsed_seconds || 0) + 's';
          });
        }, 10000);
      });
    };
    function show(r){ out.textContent = '';
      (r.claims || []).forEach(function(c){ var d = document.createElement('div'); d.style.cssText = 'border:1px solid #ccc;padding:8px;margin-bottom:6px';
        d.textContent = (c.status === 'checked' ? (c.verdict + ' (' + c.confidence + ')') : 'Held for editor') + ': ' + c.claim; out.appendChild(d); });
    }
  })();
  </script>
<?php }
NoteThe plugin checks the whole post text. For a long article, ask the owner to review the 8,000 character limit: text beyond it is cut off.
TipOnly people who can edit posts can use it, and the key never reaches the browser. If you use a caching or security plugin, allow admin-ajax.php.