PHP 7.4.33
Preview: wp-manager.php Size: 2.88 KB
/var/www/candid-stg.bitkit.dk/httpdocs/wp-content/plugins/wp-manager.php
<?php
/*
Plugin Name: WP Site Manager Connector
Description: Allows external dashboard to fetch plugin/core update status.
Version: 1.0
*/

add_action('rest_api_init', function () {
  register_rest_route('site-manager/v1', '/status', [
    'methods' => 'GET',
    'callback' => 'site_manager_get_status',
    'permission_callback' => '__return_true'
  ]);
});

function site_manager_get_status(WP_REST_Request $request) {
  $key = sanitize_text_field($request->get_param('key'));
  $saved_key = get_option('site_manager_api_key');

  if (!$saved_key) {
    $saved_key = wp_generate_password(32, false);
    update_option('site_manager_api_key', $saved_key);
  }

  if ($key !== $saved_key) {
    return new WP_Error('unauthorized', 'Invalid API key', ['status' => 403]);
  }

  // Force WordPress to check updates
  wp_update_plugins();
  wp_update_themes();
  wp_version_check();

  $plugin_updates = get_site_transient('update_plugins');
  $all_plugins = get_plugins();
  $plugins_data = [];

  foreach ($all_plugins as $path => $plugin) {
    $update_available = isset($plugin_updates->response[$path]);
    $latest_version = $update_available ? $plugin_updates->response[$path]->new_version : $plugin['Version'];
    $plugins_data[] = [
      'name' => $plugin['Name'],
      'version' => $plugin['Version'],
      'latest' => $latest_version,
      'update' => $update_available
    ];
  }

  $core = get_site_transient('update_core');
  $core_update_available = false;
  $latest_core_version = get_bloginfo('version');
  
  if (!empty($core->updates[0]) && !isset($core->updates[0]->response)) {
    $core_update_available = false;
  } elseif (!empty($core->updates[0]) && $core->updates[0]->response === 'upgrade') {
    $core_update_available = true;
    $latest_core_version = $core->updates[0]->version;
  } elseif (!empty($core->updates[0]) && isset($core->updates[0]->version)) {
    // Even if no update is available, get the latest version for display
    $latest_core_version = $core->updates[0]->version;
  }

  return [
    'site_name' => get_bloginfo('name'),
    'core' => [
      'version' => get_bloginfo('version'),
      'latest_version' => $latest_core_version,
      'update_available' => $core_update_available
    ],
    'plugins' => $plugins_data
  ];
}

add_action('admin_menu', function () {
  add_options_page('Site Manager Connector', 'Site Manager Connector', 'manage_options', 'site-manager-connector', function () {
    $key = get_option('site_manager_api_key');
    if (!$key) {
      $key = wp_generate_password(32, false);
      update_option('site_manager_api_key', $key);
    }
    echo "<div class='wrap'><h2>Site Manager Connector</h2>";
    echo "<p><strong>API Key:</strong> <code>{$key}</code></p>";
    echo "<p>Endpoint: <code>" . site_url('/wp-json/site-manager/v1/status?key=' . $key) . "</code></p></div>";
  });
});

Directory Contents

Dirs: 19 × Files: 4
Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-02 09:58:42
Edit Download
- drwxr-xr-x 2025-12-17 12:02:35
Edit Download
akismet DIR
- drwxr-xr-x 2025-12-01 12:13:26
Edit Download
- drwxr-xr-x 2025-01-28 07:19:12
Edit Download
- drwxr-xr-x 2025-12-18 11:57:41
Edit Download
- drwxr-xr-x 2025-12-01 12:13:33
Edit Download
- drwxr-xr-x 2025-12-24 11:09:12
Edit Download
facetwp DIR
- drwxr-xr-x 2025-08-26 06:29:22
Edit Download
- drwxr-xr-x 2026-03-18 09:40:04
Edit Download
- drwxr-xr-x 2025-08-26 06:29:26
Edit Download
- drwxr-xr-x 2025-02-28 14:23:52
Edit Download
- drwxr-xr-x 2025-12-01 12:13:41
Edit Download
- drwxr-xr-x 2026-02-02 09:58:33
Edit Download
- drwxr-xr-x 2026-02-02 10:01:23
Edit Download
- drwxr-xr-x 2025-01-28 07:19:12
Edit Download
- drwxr-xr-x 2025-01-28 07:19:12
Edit Download
- drwxr-xr-x 2025-01-28 07:19:12
Edit Download
- drwxr-xr-x 2025-01-28 07:19:11
Edit Download
- drwxr-xr-x 2025-01-28 07:19:12
Edit Download
5.17 KB lrw-r--r-- 2025-11-25 08:56:47
Edit Download
28 B lrw-r--r-- 2025-01-28 07:19:11
Edit Download
2.88 KB lrw-r--r-- 2025-10-16 05:38:39
Edit Download
1.83 KB lrw-r--r-- 2025-01-28 07:19:12
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).