Skip to content

Instantly share code, notes, and snippets.

@ozh

ozh/plugin.php

Created Sep 1, 2017
Embed
What would you like to do?
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>";
}
@noerrorsfound

This comment has been minimized.

Copy link

@noerrorsfound noerrorsfound commented Aug 31, 2018

Useful! Thanks.

@AhmadKahlid

This comment has been minimized.

Copy link

@AhmadKahlid AhmadKahlid commented Nov 11, 2018

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

This comment has been minimized.

Copy link

@AhmadKahlid AhmadKahlid commented Nov 12, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.