Skip to content

Commit

Permalink
v 2.79.0
Browse files Browse the repository at this point in the history
Settings v 0.20.0
- Add an optional « check all » button.
  • Loading branch information
Darklg committed May 28, 2024
1 parent 7484a44 commit 93c4de5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
45 changes: 36 additions & 9 deletions inc/WPUBaseSettings/WPUBaseSettings.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace wpubasesettings_0_19_0;
namespace wpubasesettings_0_20_0;

/*
Class Name: WPU Base Settings
Description: A class to handle native settings in WordPress admin
Version: 0.19.0
Version: 0.20.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand Down Expand Up @@ -193,14 +193,28 @@ public function add_settings() {
'show_in_rest' => $this->settings_details,
'default' => array()
));
$has_check_all = false;
foreach ($this->settings_details['sections'] as $id => $section) {
if (current_user_can($section['user_cap'])) {
add_settings_section($id,
$section['name'],
isset($section['description']) ? $section['description'] : '',
$this->settings_details['plugin_id']
);
if (!current_user_can($section['user_cap'])) {
continue;
}
if (!isset($section['after_section'])) {
$section['after_section'] = '';
}
if (isset($section['wpubasesettings_checkall']) && $section['wpubasesettings_checkall']) {
$section['after_section'] .= '<button class="wpubasesettings-check-all">' . __('Check all', __NAMESPACE__) . '</button>';
if (!$has_check_all) {
$has_check_all = true;
add_action('admin_footer', array(&$this, 'admin_footer_checkall'));
}
}
add_settings_section(
$id,
$section['name'],
isset($section['description']) ? $section['description'] : '',
$this->settings_details['plugin_id'],
$section
);
}

foreach ($this->settings as $id => $input) {
Expand Down Expand Up @@ -333,7 +347,7 @@ public function render__field($args = array()) {
}
$id .= $attr;
$value = isset($options[$args['id']]) ? $options[$args['id']] : $args['default_value'];
if(!isset($options[$args['id']]) && isset($args['translated_from']) && $args['translated_from'] && isset($options[$args['translated_from']]) && $options[$args['translated_from']]){
if (!isset($options[$args['id']]) && isset($args['translated_from']) && $args['translated_from'] && isset($options[$args['translated_from']]) && $options[$args['translated_from']]) {
$value = $options[$args['translated_from']];
}

Expand Down Expand Up @@ -564,6 +578,19 @@ function show_lang(_lang_id){
EOT;
}

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);
});
});
</script>
EOT;
}

/* Base settings */

public function admin_menu() {
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.78.0
Version: 2.79.0
Author: Darklg
Author URI: https://darklg.me/
Text Domain: wpubaseplugin
Expand All @@ -20,7 +20,7 @@

class WPUBasePlugin {

public $version = '2.78.0';
public $version = '2.79.0';

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

0 comments on commit 93c4de5

Please sign in to comment.