WordPress Wén Pài Community Shortlink Plugin User Guide

WordPress Community Short Links Plugin User Guide

Plugin Overview

Discourse Short Links is a WordPress Must-Use (MU) plugin that provides clean, memorable short links for the WordPress Community (Discourse) platform. With this plugin, you can quickly access community content using concise URLs like wpcy.com/t/123, and obtain detailed access statistics.

Key Features

:link: Short Link Redirection

Supports six types of content:

Short Link Format Target Content Example
/t/123 Topic wpcy.com/t/456 → Topic #456
/c/slug Category wpcy.com/c/plugins → Plugins category
/u/user User wpcy.com/u/admin → User profile page
/p/123 Post wpcy.com/p/789 → Specific post (post number)
/g/name Group wpcy.com/g/staff → Staff group
/h/tag Tag wpcy.com/h/wordpress → WordPress tag

:bar_chart: Access Statistics

  • Real-time tracking: Every short link visit is recorded.
  • Multi-dimensional analytics:
    • Daily / Yesterday / Last 7 days / Total visits
    • Breakdown by content type (topics, categories, users, etc.)
    • Top 10 most-clicked links
  • Automatic cleanup: Data older than 30 days is automatically deleted.

:control_knobs: Dashboard Widget

View summary statistics directly on your WordPress dashboard homepage — no need to navigate to settings.

Installation

1. Upload to the MU-Plugins Directory

# Place the plugin file in the mu-plugins directory
/wp-content/mu-plugins/discourse-shortlinks.php

Note: MU-Plugins (Must-Use Plugins) are auto-activated — no manual activation required.

2. Configuration (Optional)

Add custom configuration to your wp-config.php:

// Discourse site URL (default: https://wpcommunity.com)
define('DISCOURSE_SHORTLINK_URL', 'https://your-discourse.com');

// Enable statistics tracking (default: true)
define('DISCOURSE_SHORTLINK_STATS', true);

Usage

Accessing Short Links

Simply enter a short link directly into your browser:

https://wpcy.com/t/123

The browser will automatically perform a 301 redirect to:

https://wpcommunity.com/t/-/123

Viewing Statistics

  1. Log in to your WordPress admin dashboard.
  2. Locate the “Short Link Stats” widget on the dashboard homepage.
  3. Review the displayed metrics.

Resetting Statistics

To clear all collected statistics:

  1. In the “Short Link Stats” widget, click the “Reset” button.
  2. Confirm the action.
  3. All historical data will be permanently erased.

API Endpoints

The plugin exposes REST API endpoints for programmatic access:

Retrieve Statistics

GET /wp-json/discourse/v1/shortlink-stats
Authorization: Administrator privileges required

Example response:

{
  "total": 1234,
  "today": 56,
  "yesterday": 78,
  "week": 345,
  "by_type": {
    "topic": 800,
    "category": 200,
    "user": 150,
    "post": 50,
    "group": 20,
    "tag": 14
  },
  "top_links": {
    "topic:123": 100,
    "topic:456": 80,
    "category:plugins": 45
  }
}

Reset Statistics

POST /wp-json/discourse/v1/shortlink-reset
Authorization: Administrator privileges required

Data Storage

Statistics are stored in the WordPress database table wp_options:

  • Option name: discourse_shortlink_stats
  • Data format: Serialized PHP array
  • Auto-cleanup: Records older than 30 days are automatically removed.

Technical Specifications

Item Description
Plugin type MU-Plugin (Must-Use Plugin)
PHP version 8.0+
WordPress version 6.0+
Redirect type 301 Permanent Redirect
Execution priority init hook, priority 1

Frequently Asked Questions

Q: Short links aren’t redirecting?

A: Check the following:

  1. Ensure the plugin file resides in the mu-plugins directory.
  2. Verify the URL format is correct (e.g., /t/number).
  3. Confirm the DISCOURSE_SHORTLINK_URL configuration is set correctly.

Q: Statistics aren’t showing up?

A: Possible causes:

  1. No visits have yet occurred to any short links.
  2. Browser caching prevents dashboard updates — try hard-refreshing.
  3. Use the REST API to verify whether data exists.

Q: How do I migrate statistics?

A: Export the discourse_shortlink_stats record from the wp_options table.

Version History

  • v1.1.0 – Added support for tags (/h/) and groups (/g/).
  • v1.0.0 – Initial release; supports topics, categories, users, and posts.

Plugin Author: WPCommunity
License: MIT
Project URL: Internal use only