-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
58 lines (50 loc) · 1.83 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
53
54
55
56
57
58
<?php
/*
Plugin Name: Purge All Logs
Plugin URI: https://github.com/SophiaAtkinson/yourls-purge-all-logs
Description: Purges all logs for YOURLS
Version: 1.0
Author: Sophia Atkinson
Author URI: https://sophia.wtf
*/
// Register the plugin admin page
yourls_add_action('plugins_loaded', 'purge_all_logs_add_page');
function purge_all_logs_add_page()
{
yourls_register_plugin_page('purge_logs', 'Purge Logs', 'purge_all_logs_page_display');
}
// Display the plugin page content
function purge_all_logs_page_display()
{
// Check if the form is submitted
if (isset($_POST['purge_logs'])) {
// Call the function to purge logs
purge_all_logs();
}
echo '<h2>Purge <strong>All</strong> Logs</h2>';
echo '<p><strong>Warning:</strong> This action is irreversible and will permanently delete all logs in Yourls. It is highly recommended to take a database snapshot before proceeding.</p>';
echo '<form id="purge-logs-form" method="post">';
echo '<input type="submit" name="purge_logs" value="Purge Logs" onclick="return confirmPurgeLogs();">';
echo '</form>';
echo '<script>
function confirmPurgeLogs() {
return confirm("This action is irreversible and will permanently delete ALL YOURLS logs. Are you sure you want to proceed?");
}
</script>';
}
// Function to purge all logs
function purge_all_logs()
{
global $ydb;
// Check if the user is authorized to perform this action (optional)
// For example, you might check for admin privileges here
// Purge all logs from the database
$delete_logs = $ydb->query("DELETE FROM `" . YOURLS_DB_TABLE_LOG . "`");
// Check if the logs were successfully purged
if ($delete_logs) {
yourls_add_notice('success', 'Logs purged successfully!');
} else {
yourls_add_notice('error', 'Failed to purge logs.');
}
}
?>