-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
29 lines (26 loc) · 956 Bytes
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/*
Plugin Name: Allow Existing URLs
Plugin URI: https://github.com/elder-oss/yourls-allow-existing-urls
Description: Changes the response (to success) when a URL has already been saved and YOURLS_UNIQUE_URLS=true
Version: 1.0.0
Author: Elder Technologies Ltd
Author URI: https://www.elder.org/
*/
// block direct calls
if( !defined( 'YOURLS_ABSPATH' ) ) die();
yourls_add_filter( 'add_new_link_already_stored_filter', 'allow_existing_urls' );
// if the link has already been stored, return success anyway
function allow_existing_urls( $return, $url, $keyword, $title ) {
if ( isset( $return['code'] ) ) {
if ( $return['code'] === 'error:url' ){
if ($url_exists = yourls_url_exists( $url )) {
$return['status'] = 'success';
$return['code'] = '';
$return['errorCode'] = '200';
$return['statusCode'] = '200';
}
}
}
return yourls_apply_filter( 'after_allow_existing_urls', $return, $url, $keyword, $title );
}