Skip to content

Instantly share code, notes, and snippets.

@ozh
Created September 1, 2017 17:54
Show Gist options
  • Save ozh/a0090f46569b50835520d95f9481d9fd to your computer and use it in GitHub Desktop.
Save ozh/a0090f46569b50835520d95f9481d9fd to your computer and use it in GitHub Desktop.
YOURLS Plugin: delete all URLs
<?php
/*
Plugin Name: RESET URLS
Plugin URI: http://yourls.org/
Description: OMG
Version: 1.0
Author: Ozh
Author URI: http://ozh.org/
*/
// Register our plugin admin page
yourls_add_action( 'plugins_loaded', 'ozh_yourls_resetall_add_page' );
function ozh_yourls_resetall_add_page() {
yourls_register_plugin_page( 'reset', 'RESET!!', 'ozh_yourls_resetall_do_page' );
// parameters: page slug, page title, and function that will display the page itself
}
// Display admin page
function ozh_yourls_resetall_do_page() {
// Check if a form was submitted
if( isset( $_POST['reset'] ) && $_POST['reset'] == 'yes' ) {
ozh_yourls_resetall_urls();
} else {
echo <<<HTML
<h2>RESET DB</h2>
<p>DELETE ALL URLS??</p>
<form method="post">
<input type="hidden" name="reset" value="yes" />
<p><input type="submit" value="YES" /></p>
</form>
HTML;
}
}
// Update option in database
function ozh_yourls_resetall_urls() {
$sql = "TRUNCATE TABLE ". YOURLS_DB_TABLE_URL.";";
global $ydb;
$ydb->query( $sql );
echo "<p class='error'>ALL GONE OMG!!</p>";
}
@vivid-pixel
Copy link

Useful! Thanks.

@AhmadKahlid
Copy link

I receive the following error when I try to activate this plugin:
'No plugin specified, or not a valid plugin'

Another plugins (like: Random Backgrounds, Random Keywords, ...) are activated successfully.

YOURLS Version: 1.7.2

@AhmadKahlid
Copy link

I just removed the white spaces from directory name and the plugin is working now. Thanks.

@westor7
Copy link

westor7 commented Nov 19, 2021

Does this plugin works for 1.8.2 version? - thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment