Skip to content

Commit

Permalink
v 2.80.0
Browse files Browse the repository at this point in the history
Settings v 0.21.0
- Handle « uncheck all »
  • Loading branch information
Darklg committed Jun 2, 2024
1 parent 93c4de5 commit 2888527
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
30 changes: 24 additions & 6 deletions inc/WPUBaseSettings/WPUBaseSettings.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace wpubasesettings_0_20_0;
namespace wpubasesettings_0_21_0;

/*
Class Name: WPU Base Settings
Description: A class to handle native settings in WordPress admin
Version: 0.20.0
Version: 0.21.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand Down Expand Up @@ -202,7 +202,8 @@ public function add_settings() {
$section['after_section'] = '';
}
if (isset($section['wpubasesettings_checkall']) && $section['wpubasesettings_checkall']) {
$section['after_section'] .= '<button class="wpubasesettings-check-all">' . __('Check all', __NAMESPACE__) . '</button>';
$check_label = __('Check all', __NAMESPACE__);
$section['after_section'] .= '<button class="wpubasesettings-check-all" data-check-label="' . $check_label . '" data-uncheck-label="' . __('Uncheck all', __NAMESPACE__) . '">' . $check_label . '</button>';
if (!$has_check_all) {
$has_check_all = true;
add_action('admin_footer', array(&$this, 'admin_footer_checkall'));
Expand Down Expand Up @@ -582,9 +583,26 @@ function admin_footer_checkall() {
echo <<<EOT
<script>
jQuery(document).ready(function() {
jQuery(".wpubasesettings-check-all").on("click", function(e) {
e.preventDefault();
jQuery(this).prev(".form-table").find(":checkbox").prop("checked", true);
jQuery(".wpubasesettings-check-all").each(function() {
var _btn = jQuery(this),
_table = _btn.prev(".form-table"),
_checkboxes = _table.find(":checkbox"),
_check_all = true;
_btn.on("click", function(e) {
e.preventDefault();
_checkboxes.prop("checked", _check_all);
_checkboxes.trigger("change");
});
function check_checkboxes_mode() {
var _checked = _checkboxes.filter(":checked").length;
_check_all = _checked < _checkboxes.length;
_btn.text(_check_all ? _btn.data("check-label") : _btn.data("uncheck-label"));
}
_checkboxes.on("change", check_checkboxes_mode);
check_checkboxes_mode();
});
});
</script>
Expand Down
6 changes: 3 additions & 3 deletions wpubaseplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/WordPressUtilities/wpubaseplugin
Update URI: https://github.com/WordPressUtilities/wpubaseplugin
Description: A framework for a WordPress plugin
Version: 2.79.0
Version: 2.80.0
Author: Darklg
Author URI: https://darklg.me/
Text Domain: wpubaseplugin
Expand All @@ -20,7 +20,7 @@

class WPUBasePlugin {

public $version = '2.79.0';
public $version = '2.80.0';

private $utilities_classes = array(
'messages' => array(
Expand All @@ -36,7 +36,7 @@ class WPUBasePlugin {
'name' => 'WPUBaseAdminPage'
),
'settings' => array(
'namespace' => 'wpubasesettings_0_20_0',
'namespace' => 'wpubasesettings_0_21_0',
'name' => 'WPUBaseSettings'
),
'cron' => array(
Expand Down

0 comments on commit 2888527

Please sign in to comment.