PHP 7.4.33
Preview: wp-manager.php Size: 2.88 KB
/var/www/nea-dev.wpress.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: 38 × Files: 4
Name Size Perms Modified Actions
- drwxrwxr-x 2024-09-06 15:10:18
Edit Download
- drwxrwxr-x 2025-05-23 08:31:10
Edit Download
- drwxrwxr-x 2025-05-08 15:08:01
Edit Download
- drwxrwxr-x 2025-06-15 21:06:09
Edit Download
facetwp DIR
- drwxrwxr-x 2025-05-09 07:03:28
Edit Download
- drwxrwxr-x 2025-04-21 15:13:26
Edit Download
- drwxrwxr-x 2024-09-12 17:21:26
Edit Download
- drwx------ 2025-07-14 08:08:34
Edit Download
- drwxrwxr-x 2025-07-14 04:37:29
Edit Download
- drwxrwxr-x 2024-09-06 15:08:18
Edit Download
- drwxrwxr-x 2024-09-06 15:08:16
Edit Download
- drwxrwxr-x 2025-06-25 08:14:39
Edit Download
- drwxrwxr-x 2025-03-04 13:12:03
Edit Download
- drwxrwxr-x 2024-09-12 17:21:42
Edit Download
- drwxrwxr-x 2025-07-07 12:00:00
Edit Download
- drwxrwxr-x 2025-04-15 16:54:02
Edit Download
- drwxr-xr-x 2025-06-30 14:07:32
Edit Download
- drwxrwxr-x 2025-02-19 11:22:50
Edit Download
- drwxrwxr-x 2025-05-23 08:31:31
Edit Download
- drwxrwxr-x 2025-02-04 10:18:25
Edit Download
- drwx------ 2025-07-08 06:22:30
Edit Download
wordfence DIR
- drwxrwxr-x 2025-04-16 15:32:30
Edit Download
- drwxrwxr-x 2025-07-15 15:00:07
Edit Download
- drwxrwxr-x 2025-01-23 11:39:22
Edit Download
wp-fusion DIR
- drwxrwxr-x 2025-02-20 05:27:12
Edit Download
- drwxrwxr-x 2025-07-15 15:00:01
Edit Download
- drwxrwxr-x 2025-07-15 15:00:30
Edit Download
- drwxrwxr-x 2025-07-15 15:00:04
Edit Download
- drwxrwxr-x 2025-02-10 12:47:27
Edit Download
- drwxrwxr-x 2025-01-30 09:32:13
Edit Download
- drwxrwxr-x 2025-04-16 11:01:03
Edit Download
- drwxrwxr-x 2025-06-10 07:48:50
Edit Download
- drwxrwxr-x 2024-10-01 20:42:41
Edit Download
- drwxr-xr-x 2025-01-22 09:26:44
Edit Download
- drwxrwxr-x 2024-09-16 17:57:23
Edit Download
- drwxrwxr-x 2024-09-16 17:56:05
Edit Download
- drwxrwxr-x 2024-09-06 15:09:58
Edit Download
- drwxrwxr-x 2025-07-15 15:00:05
Edit Download
28 B lrwxrwxr-x 2024-06-21 17:57:26
Edit Download
2.17 KB lrwxrwxr-x 2025-02-03 15:07:48
Edit Download
85.21 KB lrw------- 2025-07-08 12:55:00
Edit Download
2.88 KB lrw-r--r-- 2025-10-16 05:48:40
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).