=== URL Shortener – Nano URLs: Branded Short Links, Click Tracking & Redirects ===
Contributors: fahdchouki
Tags: url shortener, short links, shortlink, redirect, link management
Requires at least: 5.6
Tested up to: 7.0
Requires PHP: 7.0
Stable tag: 1.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Self hosted URL shortener with the shortest links possible, one click copy in the editor, click stats and a REST API. No third party services.

== Description ==

Nano URLs turns any post, page, product or external address into a short link served from your own domain. Nothing is sent anywhere else: the codes, the redirects, the statistics and the API all live inside your WordPress install.

= The shortest links possible =

Codes are handed out from a counter rendered in base 62, starting at a single character. The first links on a new site look like `example.com/0`, `example.com/a`, `example.com/Z`. A code only grows to two characters once every one character code is taken, and to three once every two character code is taken. That is 62 links at one character, 3,844 at two, 238,328 at three, and 14.7 million at four.

Codes that would clash with something real are skipped automatically, so a link is never handed out that WordPress cannot serve. That covers existing posts, pages and categories, the WordPress paths such as `wp-admin` and `wp-json`, feeds, common shop URLs, and any word you add yourself. Once a code is in use, WordPress is stopped from giving that slug to a post created later, so a link you have already shared cannot be taken away from you.

= Built to be fast =

A short link is answered on `plugins_loaded`, before the theme is loaded, before the main query runs and before a single block is registered. The whole request is one cached lookup and a redirect header. On sites with a persistent object cache such as Redis or Memcached, a repeat click does not touch the database at all.

Click statistics are written after the response has been handed back to the visitor, using `fastcgi_finish_request()` where the host supports it, so counting a click costs the visitor nothing.

= One click in the editor =

* A **Short URL** panel in the block editor, and a meta box in the classic editor, with a single button that creates the link and a second that copies it.
* A **Short URL** column on the posts, pages and products list screens, with the same generate and copy buttons on every row.
* An admin bar entry on the front end.
* A quick shorten form on the plugin's own screen for any other address.

Works with any public post type, so WooCommerce products, custom post types and anything else are covered without configuration.

= A real API =

A REST namespace at `nano-urls/v1` with endpoints to create, list, read, update, delete and expand links, plus daily click counts. Authenticate with an API key issued on the plugin's API screen, an application password, or a logged in cookie with a nonce. Keys are stored as hashes and act with the permissions of the user they belong to.

There are template tags too, for use in themes and other plugins:

`$short = nanourls_shorten( 'https://example.com/page' );`
`$short = nanourls_get_short_url( $post_id, true );`
`$target = nanourls_expand( 'a7' );`

= Privacy =

This plugin makes no external connections of any kind. Click statistics are a running total and a count per day per link. No IP addresses, user agents, referrers or any other personal data are stored.

== Installation ==

1. Upload the `nano-urls` folder to `/wp-content/plugins/`, or install the plugin through the Plugins screen in WordPress.
2. Activate the plugin through the Plugins screen.
3. Make sure Settings → Permalinks is set to anything other than Plain. Short links are served from your site root and need pretty permalinks.
4. Open Nano URLs → Settings to choose your link style, or keep the defaults and start shortening.

== Frequently Asked Questions ==

= Will a short link ever clash with a real page? =

No. Before a code is handed out it is checked against existing post slugs, category and tag slugs, files and folders in your web root, WordPress reserved paths and your own reserved word list. On top of that, when WordPress later tries to give a post a slug that matches a code already in use, the plugin nudges the post to a different slug so the shared link keeps working.

= Can I keep short links in their own folder? =

Yes. Set a path prefix such as `s` or `go` under Nano URLs → Settings and links become `example.com/s/a7`. Leaving it empty gives the shortest possible link, straight from the site root.

= Can I use a separate short domain? =

Yes, if you own a domain that points at this same WordPress install. Add it as the short domain in the settings and generated links use it. The plugin does not register or configure domains for you.

= Do short links work with WooCommerce products? =

Yes. Every public post type is supported, products included. The Short URL column appears on the Products screen and the panel appears in the product editor.

= What happens when I change a post's permalink? =

Nothing breaks. Links attached to a post follow that post, and the stored destination is refreshed whenever the post is saved or republished.

= What happens if I delete a post? =

Its short link is removed with it. Use the `nanourls_delete_links_with_post` filter if you would rather keep it.

= Are the codes guessable? =

Short codes are sequential by design, because that is what makes them short. Anyone who tries `example.com/1`, `example.com/2` and so on will find your links. Do not use a short link as a secret. If you want codes that are harder to walk through, raise the minimum code length in the settings.

= Does it work with plain permalinks? =

Path based short links need pretty permalinks. With plain permalinks the plugin still resolves `example.com/?nu=a7`, and the settings screen will tell you.

= Does it slow my site down? =

No. On ordinary page loads the plugin does one cached check on the request path and then gets out of the way. Admin assets load only on the screens that use them, and the REST controller is only loaded on REST requests.

= Is my data deleted when I remove the plugin? =

Only if you ask for it. Tick "delete all data on uninstall" in the settings first. Otherwise your links and statistics survive a deactivate or delete.

== Screenshots ==

1. The links screen, with the quick shorten form and every link at a glance.
2. Settings: link structure, redirects, performance and access.
3. The API screen, with key management and endpoint documentation.
4. The Short URL column on the posts list, with generate and copy on each row.

== Changelog ==

= 1.0.2 =
* Clearer plugin name. No functional changes.

= 1.0.1 =
* Renamed the plugin to Nano URLs – URL Shortener. No functional changes.

= 1.0.0 =
* First release.
* Shortest available code allocation in base 62, base 36 or a no lookalikes character set.
* Collision safe codes, with post slug protection for codes already in use.
* Redirects answered before the theme loads, with deferred click counting.
* Block editor panel, classic meta box, list table column and admin bar entry.
* REST API with hashed API keys, plus template tags.
* Per link statistics, custom codes, expiry dates, per link redirect status.
* CSV export, multisite support, full uninstall control.

== Upgrade Notice ==

= 1.0.2 =
Name change only, nothing to do.

= 1.0.1 =
Name change only, nothing to do.

= 1.0.0 =
First release.
