User Guide for the WordPress Wenpai Community Short Link Plugin

WordPress WPCommunity Short Link Plugin Usage Guide

Plugin Overview

Discourse Short Links is a WordPress Must-Use plugin that provides a concise, easy-to-remember short link service for the WPCommunity. With this plugin, you can use short links like wpcy.com/t/123 to quickly access community content and obtain detailed access statistics.

Features

:link: Short Link Redirection

Supports 6 content type short links:

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
/p/123 Post wpcy.com/p/789 → Specific Post
/g/name Group wpcy.com/g/staff → Staff Group
/h/tag Tag wpcy.com/h/wordpress → WordPress Tag

:bar_chart: Access Statistics

  • Real-time Stats: Every short link visit is recorded.
  • Multi-dimensional Analysis:
    • Today/Yesterday/Last 7 Days/Total Visits
    • Distribution by Type (Topic, Category, User, etc.)
    • Top Links Ranking (Top 10)
  • Auto-cleanup: Retains data from the last 30 days.

:control_knobs: Dashboard Widget

View statistical overview directly on the WordPress dashboard homepage, no need to enter the settings page.

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) activate automatically; no manual activation required.

2. Configuration (Optional)

Add custom configuration to wp-config.php:

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

// Whether to enable statistics (default: true)
define('DISCOURSE_SHORTLINK_STATS', true);

Usage

Accessing Short Links

Simply enter the short link directly in your browser for automatic redirection:

https://wpcy.com/t/123

The browser will automatically 301 redirect to:

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

Viewing Statistics

  1. Log in to the WordPress admin.
  2. Find the “Short Link Stats” widget on the dashboard homepage.
  3. View the data.

Resetting Statistics

To clear all statistical data:

  1. Click the “Reset” button in the “Short Link Stats” widget.
  2. Confirm the action.
  3. All historical data will be cleared.

API Interface

The plugin provides a REST API interface for programmatic access:

Get Statistics

GET /wp-json/discourse/v1/shortlink-stats
Authorization: Admin permissions required.

Response Example:

{
  "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: Admin permissions required.

Data Storage

Statistical data is stored in the WordPress database wp_options table:

  • Field Name: discourse_shortlink_stats
  • Data Format: Serialized PHP array
  • Auto-cleanup: Data older than 30 days is automatically deleted.

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 link not redirecting?

A: Check the following:

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

Q: Statistics not showing?

A: Possible reasons:

  1. No one has visited the short link yet.
  2. Browser cache causing the dashboard not to refresh.
  3. Try using the REST API to verify data.

Q: How to migrate statistics?

A: Simply export the discourse_shortlink_stats record from the wp_options table.

Version History

  • v1.1.0 - Added tag (/h/) and group (/g/) support.
  • v1.0.0 - Initial version, supporting topics, categories, users, posts.

Plugin Author: WPCommunity
Open Source License: MIT
Project Address: For internal use