Skip to content

Commit

Permalink
v 0.20.0
Browse files Browse the repository at this point in the history
- Update dependencies.
- Actions buttons for logs.
  • Loading branch information
Darklg committed Jun 10, 2024
1 parent 1651237 commit 4b70276
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 72 deletions.
38 changes: 33 additions & 5 deletions inc/WPUBaseAdminDatas/WPUBaseAdminDatas.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*
Class Name: WPU Base Admin Datas
Description: A class to handle datas in WordPress admin
Version: 3.12.0
Version: 3.14.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand Down Expand Up @@ -383,18 +383,39 @@ public function validate_field_value($field, $value) {
---------------------------------------------------------- */

public function delete_lines_postAction() {
if (current_user_can($this->user_level) && !empty($_POST) && isset($_POST['select_line'], $_POST['page']) && is_array($_POST['select_line'])) {
$has_filtered_view = isset($_POST['filter_key'], $_POST['filter_value']);
if (current_user_can($this->user_level) && !empty($_POST) && isset($_POST['page'])) {
$action_id = 'action-main-form-admin-datas-' . $_POST['page'];
if (isset($_POST[$action_id]) && wp_verify_nonce($_POST[$action_id], 'action-main-form-' . $_POST['page'])) {
$this->delete_lines($_POST['select_line']);
if (isset($_POST['filter_key'], $_POST['filter_value'], $_POST['delete_filter_lines'])) {
$this->delete_line_by_filter($_POST['filter_key'], $_POST['filter_value']);
$has_filtered_view = false;
}
if (isset($_POST['select_line']) && is_array($_POST['select_line'])) {
$this->delete_lines($_POST['select_line']);
}
}
}
if (isset($_POST['page'])) {
wp_redirect($this->pagename);
$_url = $this->pagename;
if ($has_filtered_view) {
$_url = add_query_arg(array(
'filter_key' => $_POST['filter_key'],
'filter_value' => $_POST['filter_value']
), $_url);
}
wp_redirect($_url);
die;
}
}

function delete_line_by_filter($field, $value) {
global $wpdb;
$wpdb->query(
"DELETE FROM " . $this->tablename . " WHERE " . esc_sql($field) . " = '" . esc_sql($value) . "';"
);
}

public function delete_lines($lines = array()) {
$_lines = array();
foreach ($lines as $line) {
Expand Down Expand Up @@ -858,7 +879,14 @@ public function get_admin_table($values = array(), $args = array()) {
$content .= '</tbody>';
$content .= '</table>';
if ($has_id) {
$content .= '<p class="admindatas-delete-button">' . get_submit_button(__('Delete', $this->settings['plugin_id']), 'delete', 'delete_lines', false) . '</p>';
$content .= '<p class="admindatas-delete-button">';
$content .= get_submit_button(__('Delete', $this->settings['plugin_id']), 'delete', 'delete_lines', false);
if ($has_filter_key) {
$content .= ' ' . get_submit_button(__('Delete filtered lines', $this->settings['plugin_id']), 'delete_filter', 'delete_filter_lines', false);
$content .= '<input type="hidden" name="filter_key" value="' . esc_attr($_GET['filter_key']) . '" />';
$content .= '<input type="hidden" name="filter_value" value="' . esc_attr($_GET['filter_value']) . '" />';
}
$content .= '</p>';
}
$content .= '</form>';
$content .= $clear_form;
Expand Down
1 change: 1 addition & 0 deletions inc/WPUBaseMessages/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
13 changes: 13 additions & 0 deletions inc/WPUBaseMessages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
WPU Base Messages
---

Add notices in your plugin.

## Insert in the INIT hook

```php
if (is_admin()) {
require_once __DIR__ . '/inc/WPUBaseMessages/WPUBaseMessages.php';
$this->messages = new \wpubaseplugin\WPUBaseMessages($this->options['plugin_id']);
}
```
82 changes: 82 additions & 0 deletions inc/WPUBaseMessages/WPUBaseMessages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
namespace wpuactionlogs;

/*
Class Name: WPU Base Messages
Description: A class to handle messages in WordPress
Version: 1.3.4
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
License: MIT License
License URI: https://opensource.org/licenses/MIT
*/

defined('ABSPATH') || die;

class WPUBaseMessages {

private $transient_msg;
private $transient_prefix;
private $notices_categories = array(
'notice',
'updated',
'update-nag',
'error'
);

public function __construct($prefix = '') {
if (wp_doing_cron()) {
return;
}
if (!is_user_logged_in()) {
return;
}
$current_user = wp_get_current_user();
if (is_object($current_user)) {
$prefix .= $current_user->ID;
}

// Set Messages
$this->transient_prefix = sanitize_title(basename(__FILE__)) . $prefix;
$this->transient_msg = $this->transient_prefix . '__messages';

// Add hook
add_action('admin_notices', array(&$this,
'admin_notices'
));
}

/* Set notices messages */
public function set_message($id, $message, $group = '') {
if (wp_doing_cron()) {
return;
}
$messages = (array) get_transient($this->transient_msg);
if (!in_array($group, $this->notices_categories)) {
$group = $this->notices_categories[0];
}
$messages[$group][$id] = $message;
set_transient($this->transient_msg, $messages);
}

/* Display notices */
public function admin_notices() {
if (wp_doing_cron()) {
return;
}
$messages = (array) get_transient($this->transient_msg);
if (!empty($messages)) {
foreach ($messages as $group_id => $group) {
if (is_array($group)) {
foreach ($group as $message) {
echo '<div class="' . $group_id . ' notice is-dismissible"><p>' . $message . '</p></div>';
}
}
}
}

// Empty messages
delete_transient($this->transient_msg);
}
}
1 change: 1 addition & 0 deletions inc/WPUBaseMessages/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
2 changes: 1 addition & 1 deletion lang/wpuactionlogs-fr_FR.l10n.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['New Post'=>'Nouvel article','Back'=>'Retour','No'=>'Non','Yes'=>'Oui','Submit'=>'Envoyer','Items %s - %s'=>'Articles %s - %s','<strong>Filter :</strong> %s • <strong>Value :</strong> %s'=>'<strong>Filtre:</strong> %s • <strong>Valeur :</strong> %s','Reset'=>'Réinitialiser','Search'=>'Rechercher','Clear'=>'Vider','Show more details'=>'Afficher plus de détails','Edit'=>'Modifier','View'=>'Voir','Delete'=>'Supprimer','Export all'=>'Tout exporter','Export filtered view'=>'Exporter la vue filtrée','Settings'=>'Réglages','Check all'=>'Tout cocher','Uncheck all'=>'Tout décocher','Settings saved.'=>'Paramètres sauvegardés.','Upload New Media'=>'','Language'=>'','Save'=>'','Currently online'=>'Actuellement en ligne','Useful logs about what’s happening on your website admin.'=>'Des logs utiles sur ce qui se passe dans l’administration de votre site Web.','User ID'=>'ID de l’utilisateur','Action type'=>'Type d’action','Action detail'=>'Détails de l’action','Action source'=>'Source de l’action','Action interface'=>'Interface','Actions'=>'Actions','Interfaces'=>'Interfaces','Extras'=>'Extras','Enable logs for “%s”'=>'Activer les journaux pour les « %s »','Disable logs on %s'=>'Désactiver les journaux pour %s','Posts'=>'Publications','Menus'=>'Menus','Terms'=>'Termes','Options'=>'Options','Emails'=>'Emails','Users'=>'Utilisateurs','Plugins'=>'Extensions','Disable on web'=>'Désactiver sur web','web interface'=>'l’interface web','Disable on cron'=>'Désactiver sur cron','cron interface'=>'l’interface cron','Disable on CLI'=>'Désactiver sur CLI','CLI interface'=>'l’interface CLI','Display active users'=>'Afficher les utilisateurs actifs','Purge after N days'=>'Purger après N jours','Logs will be automatically deleted after this number of days. Set to 0 to disable'=>'Les logs seront automatiquement supprimés après ce nombre de jours. Définir à 0 pour désactiver','Select an user: '=>'Sélectionnez un utilisateur : ','All'=>'Tous','ID'=>'ID','Date'=>'Date','Account'=>'Compte','Save Changes'=>'Sauvegarder','No active users'=>'Aucun utilisateur actif','Online here:'=>'En ligne ici :','(you)'=>'(vous)'],'language'=>'fr_FR','x-generator'=>'Poedit 3.4.4'];
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['New Post'=>'Nouvel article','Back'=>'Retour','No'=>'Non','Yes'=>'Oui','Submit'=>'Envoyer','Items %s - %s'=>'Articles %s - %s','<strong>Filter :</strong> %s • <strong>Value :</strong> %s'=>'<strong>Filtre:</strong> %s • <strong>Valeur :</strong> %s','Reset'=>'Réinitialiser','Search'=>'Rechercher','Clear'=>'Vider','Show more details'=>'Afficher plus de détails','Edit'=>'Modifier','View'=>'Voir','Delete'=>'Supprimer','Delete filtered lines'=>'Supprimer les lignes filtrées','Export all'=>'Tout exporter','Export filtered view'=>'Exporter la vue filtrée','Settings'=>'Réglages','Check all'=>'Tout cocher','Uncheck all'=>'Tout décocher','Settings saved.'=>'Paramètres sauvegardés.','Upload New Media'=>'Envoi d\'un nouveau média','Language'=>'Langue','Save'=>'Sauvegarder','Currently online'=>'Actuellement en ligne','Useful logs about what’s happening on your website admin.'=>'Des logs utiles sur ce qui se passe dans l’administration de votre site Web.','Actions'=>'Actions','User ID'=>'ID de l’utilisateur','Action type'=>'Type d’action','Action detail'=>'Détails de l’action','Action source'=>'Source de l’action','Action interface'=>'Interface','Interfaces'=>'Interfaces','Extras'=>'Extras','Enable logs for “%s”'=>'Activer les journaux pour les « %s »','Disable logs on %s'=>'Désactiver les journaux pour %s','Posts'=>'Publications','Menus'=>'Menus','Terms'=>'Termes','Options'=>'Options','Emails'=>'Emails','Users'=>'Utilisateurs','Plugins'=>'Extensions','Disable on web'=>'Désactiver sur web','web interface'=>'l’interface web','Disable on cron'=>'Désactiver sur cron','cron interface'=>'l’interface cron','Disable on CLI'=>'Désactiver sur CLI','CLI interface'=>'l’interface CLI','Display active users'=>'Afficher les utilisateurs actifs','Purge after N days'=>'Purger après N jours','Logs will be automatically deleted after this number of days. Set to 0 to disable'=>'Les logs seront automatiquement supprimés après ce nombre de jours. Définir à 0 pour désactiver','Select an user: '=>'Sélectionnez un utilisateur : ','All'=>'Tous','ID'=>'ID','Date'=>'Date','Account'=>'Compte','Save Changes'=>'Sauvegarder','Purge old logs'=>'Purger les vieux journaux','Delete all logs'=>'Supprimer tous les journaux','All logs have been deleted'=>'Tous les journaux ont été supprimés','Old logs have been purged'=>'Les vieux journaux ont été purgés','No active users'=>'Aucun utilisateur actif','Online here:'=>'En ligne ici :','(you)'=>'(vous)'],'language'=>'fr_FR','x-generator'=>'Poedit 3.4.4'];
Binary file modified lang/wpuactionlogs-fr_FR.mo
Binary file not shown.
Loading

0 comments on commit 4b70276

Please sign in to comment.