forked from YOURLS/API-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
52 lines (46 loc) · 1.18 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
Plugin Name: Custom API action
Plugin URI: http://yourls.org/
Description: Define custom API action 'delete'
Version: 1.0
Author: Ozh
Author URI: http://ozh.org/
*/
// Define custom action "delete"
yourls_add_filter( 'api_action_delete', 'my_delete_function' );
// Actually delete
function my_delete_function() {
// Need 'shorturl' parameter
if( !isset( $_REQUEST['shorturl'] ) ) {
return array(
'statusCode' => 400,
'simple' => "Need a 'shorturl' parameter",
'message' => 'error: missing param',
);
}
$shorturl = $_REQUEST['shorturl'];
// Check if valid shorturl
if( !yourls_is_shorturl( $shorturl ) ) {
return array(
'statusCode' => 404,
'simple ' => 'Error: short URL not found',
'message' => 'error: not found',
);
}
// Delete shorturl
$keyword = yourls_get_relative_url( $shorturl );
if( yourls_delete_link_by_keyword( $keyword ) ) {
return array(
'statusCode' => 200,
'simple' => "Shorturl $shorturl deleted",
'message' => 'success: deleted',
);
} else {
return array(
'statusCode' => 500,
'simple' => 'Error: could not delete shorturl, not sure why :-/',
'message' => 'error: unknown error',
);
}
}