=== Auto-hyperlink URLs ===
Contributors: coffee2code
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ARCFJ9TX3522
Tags: links, link, URLs, url, auto-link, hyperlink, make_clickable, coffee2code
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Requires at least: 4.7
Tested up to: 4.9
Stable tag: 5.2
Automatically turns plaintext URLs and email addresses into links.
== Description ==
Automatically turns plaintext URLs and email addresses into links.
This plugin seeks to replace and extend WordPress's default auto-hyperlinking function. This plugin uses different pattern matching expressions than the WordPress default in order to prevent inappropriate adjacent characters from becoming part of the link (as WordPress has improved over the years, nowadays this is just a few edge cases like text links that are braced or bracketed) and it prevents invalid URIs (i.e. http://blah) from becoming links.
More significantly, this plugin adds configurability to the auto-hyperlinker such that you can configure:
* If you want text URLs to only show the hostname
* If you want text URLs truncated after N characters
* If you want auto-hyperlinked URLs to open in new browser window or not
* If you want the URI scheme (i.e. "http://") to be stripped for displayed links
* The text to come before and after the link text for truncated links
* If you want rel="nofollow" to be supported
* If you wish to support additional domain extensions not already configured into the plugin
* If you want certain domains to be omitted from auto-linking
This plugin will recognize any explicit URI scheme (http|https|ftp|news)://, etc, as well as email addresses. It also adds the new ability to recognize Class B domain references (i.e. "somesite.net", not just domains prepended with "www.") as valid links (i.e. "wordpress.org" would get auto-hyperlinked)
The following domain extensions (aka TLDs, Top-Level Domains) are recognized by the plugin: com, org, net, gov, edu, mil, us, info, biz, ws, name, mobi, cc, tv. These only comes into play when you have a plaintext URL that does not have an explicit URI scheme specified. If you need support for additional TLDs, you can add more via the plugin's admin options page or via filter.
This plugin also activates auto-hyperlinking of text links within post/page content.
Links: [Plugin Homepage](http://coffee2code.com/wp-plugins/auto-hyperlink-urls/) | [Plugin Directory Page](https://wordpress.org/plugins/auto-hyperlink-urls/) | [GitHub](https://github.com/coffee2code/auto-hyperlink-urls/) | [Author Homepage](http://coffee2code.com/)
== Installation ==
1. Whether installing or updating, whether this plugin or any other, it is always advisable to back-up your data before starting
1. Unzip `auto-hyperlink-urls.zip` inside the `/wp-content/plugins/` directory (or install via the built-in WordPress plugin installer)
1. Activate the plugin through the 'Plugins' admin menu in WordPress
1. (optional) Go to the Settings -> Autohyperlink admin settings page (which you can also get to via the Settings link next to the plugin on
the Manage Plugins page) and customize the settings.
== Screenshots ==
1. A screenshot of the plugin's admin options page.
== Examples ==
(when running with default configuration):
* "wordpress.org"
`wordpress.org`
* "http://www.cnn.com"
`www.cnn.com`
* "person@example.com"
`person@example.com`
To better illustrate what results you might get using the various settings above, here are examples.
For the following, assume the following URL is appearing as plaintext in a post: `www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php`
And unless explicitly stated, the results are using default values (nofollow is false, hyperlink emails is true, Hyperlink Mode is 0)
* By default:
`www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php`
* With Hyperlink Mode set to 1
`www.somelonghost.com`
* With Hyperlink Mode set to 15
`www.somelonghos...`
* With Hyperlink Mode set to 15, nofollow set to true, open in new window set to false, truncation before of "[", truncation after of "...]"
`[www.somelonghos...]`
== Filters ==
The plugin exposes seven filters for hooking. Typically, customizations utilizing these hooks would be put into your active theme's functions.php file, or used by another plugin.
**c2c_autohyperlink_urls_filters (filter)**
This hook allows you to customize which filters get processed by the plugin.
Arguments:
* $filters (array): The filters whose text should be auto-hyperlinked. Default `array( 'the_content', 'the_excerpt', 'widget_text' )`.
Example:
`
/**
* Auto-hyperlink additional filters.
*
* @param array $filters
* @return array
*/
function my_c2c_autohyperlink_urls_filters( $filters ) {
// Add in another filter to process.
$filters[] = 'my_custom_filter';
return $filters;
}
add_filter( 'c2c_autohyperlink_urls_filters', 'my_c2c_autohyperlink_urls_filters' );
`
**autohyperlink_urls_class (filter)**
This hook allows you to customize the class added to links created by the plugin.
Arguments:
* $class (string): The class name. Default 'autohyperlink'.
Example:
`
// Set default class for links added by Auto-hyperlink URLs.
add_filter( 'autohyperlink_urls_class', function ( $class ) { return 'myclass'; } );
`
**autohyperlink_urls_link_attributes (filter)**
This hook allows you to add custom attributes to links created by the plugin.
Arguments:
* $attributes (array): The link attributes already created by the plugin.
* $context (string): The context for the link. Either 'url' or 'email'. Default 'url'.
* $title (string): The text for the link's title attribute.
Example:
`
/**
* Output 'title' attribute for link, as done by plugin prior to v5.0.
*
* @param array $attributes The attributes for the link tag.
* @param string $context The context for the link. Either 'url' or 'email'. Default 'url'.
* @param string $title The text for the link's title attribute.
* @return array
*/
function add_title_attribute_for_autohyperlink_urls( $attributes, $context = 'url', $title = '' ) {
if ( $title ) {
$attributes['title'] = $title;
}
return $attributes;
}
add_filter( 'autohyperlink_urls_link_attributes', 'add_title_attribute_for_autohyperlink_urls', 10, 3 );
`
**autohyperlink_urls_tlds (filter)**
This hook allows you to custom the list of supported TLDs for non-URI scheme link auto-hyperlinking. Note that the value sent to the hook includes the default TLDs plus those added via the 'more_extensions' setting. Also note that the TLDs are defined as a '|'-separated string.
Arguments:
* $tlds (string): The supported TLDs. Default `'com|org|net|gov|edu|mil|us|info|biz|ws|name|mobi|cc|tv'`.
Example:
`
// Add support for more TLDs.
add_filter( 'autohyperlink_urls_tlds', function ( $tlds ) { return $tlds . '|in|io|tt'; } );
`
**autohyperlink_urls_truncate_link (filter)**
This hook allows you to custom how truncated links are displayed.
Arguments:
* $url (string): The potentially truncated URL.
* $original_url (string): The full, original URL.
* $context (string): The context for the link. Either 'url' or 'email'. Default 'url'.
**autohyperlink_urls_custom_exclusions (filter)**
This hook allows you to define custom logic to determine if a link should be hyperlinked.
Arguments:
* $should (bool): Should the link be hyperlinked? Default true.
* $url (string): The full URL.
* $domain (string): Just the domain/host part of the URL.
Example:
`
/**
* Don't hyperlink links on the front page.
*
* @param bool $should
* @param string $url
* @param string $domain
* @return bool
*/
function my_autohyperlink_urls_custom_exclusions( $should, $url, $domain ) {
if ( is_front_page() ) {
return false;
} else {
return $should;
}
}
add_filter( 'autohyperlink_urls_custom_exclusions', 'my_autohyperlink_urls_custom_exclusions' );
`
**autohyperlink_urls_exclude_domains (filter)**
This hook allows you to specify domains that should not get auto-hyperlinked. Note that the value sent to the hook includes the value of the 'exclude_domains' setting. Note that only the domain (without URI scheme or trailing slash) should be specified.
Arguments:
* $excluded_domains (array): The domains already being excluded. Default empty array.
Example:
`
/**
* Exclude certain domains from being auto-hyperlinked.
*
* @param array $excluded_domains
* @return array
*/
function my_autohyperlink_urls_exclude_domains( $excluded_domains ) {
$excluded_domains[] = 'youtube.com';
$excluded_domains[] = 'example.com';
return $excluded_domains;
}
add_filter( 'autohyperlink_urls_exclude_domains', 'my_autohyperlink_urls_exclude_domains' );
`
== Changelog ==
= 5.2 (2018-05-03) =
Highlights:
* This release consists of fixes for some minor bugs, improved handling of URLs containing parentheses, drops compatibility with versions of WordPress older than 4.7, and some behind-the-scenes changes.
Details:
* Fix: Fix and improve handling of parentheses in URLs
* Fix: Prevent error when `can_do_hyperlink()` is passed an invalid URL
* Change: Reformat code (minor) for `hyperlink_urls()` to sync with core coding standards
* Change: Update plugin framework to 047
* 047:
* Don't save default setting values to database on install
* Change "Cheatin', huh?" error messages to "Something went wrong.", consistent with WP core
* Note compatibility through WP 4.9+
* Drop compatibility with version of WP older than 4.7
* 046:
* Fix `reset_options()` to reference instance variable `$options`
* Note compatibility through WP 4.7+
* Update copyright date (2017)
* 045:
* Ensure `reset_options()` resets values saved in the database
* New: Add README.md
* Change: Store setting name in constant
* Change: Unit tests:
* Sync changes to `Tests_Formatting_MakeClickable` with core's version (largely code formatting changes)
* Revamp handling and testing of settings
* Simplify implementations of `set_option()`
* Add explicit tests for 'strip_protocol' set as true
* Default `WP_TESTS_DIR` to `/tmp/wordpress-tests-lib` rather than erroring out if not defined via environment variable
* Enable more error output for unit tests
* Change: Tweak plugin description
* Change: Add GitHub link to readme
* Change: Fix code example in readme
* Change: Modify formatting of hook name in readme to prevent being uppercased when shown in the Plugin Directory
* Change: Note compatibility through WP 4.9+
* Change: Drop compatibility with versions of WP older than 4.7
* Change: Update copyright date (2018)
= 5.1 (2016-06-19) =
* New: Add setting 'require_scheme' to allow preventing plugin from auto-linking URIs without explicit schemes (i.e. 'http://').
* Change: Make the comparison for domains against the exclude list case insensitive. Props mqudsi.
* Change: Update plugin framework to 044:
* 044
* Add `reset_caches()` to clear caches and memoized data. Use it in `reset_options()` and `verify_config()`.
* Add `verify_options()` with logic extracted from `verify_config()` for initializing default option attributes.
* Add `add_option()` to add a new option to the plugin's configuration.
* Add filter 'sanitized_option_names' to allow modifying the list of whitelisted option names.
* Change: Refactor `get_option_names()`.
* 043
* Disregard invalid lines supplied as part of hash option value.
* 042
* Update `disable_update_check()` to check for HTTP and HTTPS for plugin update check API URL.
* Translate "Donate" in footer message.
* Note compatibility through WP 4.5.
* Change: Construct strings in a cleaner way with `sprintf()` rather than piecing strings and variables together.
* Change: Minor code reformatting.
* Change: Prevent web invocation of unit test bootstrap.php.
* Change: Note compatibility through WP 4.5+.
* Bugfix: Add appropriate spacing so v5.0's changelog entry gets properly parsed.
= 5.0 (2016-01-26) =
Highlights:
This release revives active development of the plugin after many years and includes many, many changes. Backwards compatilibility has been maintained; it just handles things better and introduces a number of new features. Some notable changes:
* Introduced setting and filter to add support for preventing specified domains from getting auto-linked.
* Introduced filter to support custom handlers to determine if and when text links should get auto-linked.
* Improved text link detection and handling.
* Links within ``, ``, `