Skip to content

Commit

Permalink
v 2.69.0
Browse files Browse the repository at this point in the history
Toolbox v 0.12.0 :
- New helper : Array to HTML table.
  • Loading branch information
Darklg committed Feb 21, 2024
1 parent baee839 commit 7cf449c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions inc/WPUBaseSettings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (is_admin()) {
## Insert in your admin page content ( if needed )

```php
settings_errors();
echo '<form action="' . admin_url('options.php') . '" method="post">';
settings_fields($this->settings_details['option_id']);
do_settings_sections($this->options['plugin_id']);
Expand Down
52 changes: 49 additions & 3 deletions inc/WPUBaseToolbox/WPUBaseToolbox.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace wpubasetoolbox_0_11_1;
namespace wpubasetoolbox_0_12_0;

/*
Class Name: WPU Base Toolbox
Description: Cool helpers for WordPress Plugins
Version: 0.11.1
Version: 0.12.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand All @@ -15,7 +15,7 @@
defined('ABSPATH') || die;

class WPUBaseToolbox {
private $plugin_version = '0.11.1';
private $plugin_version = '0.12.0';
public function __construct() {
add_action('wp_enqueue_scripts', array(&$this,
'form_scripts'
Expand Down Expand Up @@ -395,4 +395,50 @@ function array_to_html_attributes($attributes = array()) {
return trim($html);
}

function array_to_html_table($array, $args = array()) {

/* Ensure array is ok */
if (empty($array) || !is_array($array)) {
return '';
}

/* Fix args */
$default_args = array(
'table_classname' => 'widefat',
'colnames' => array()
);
if (!is_array($args)) {
$args = array();
}
$args = array_merge($default_args, $args);

$html = '';

/* HEAD */
$html .= '<thead><tr>';
foreach ($array[0] as $key => $value) {
$label = $key;
if (isset($args['colnames'][$key])) {
$label = $args['colnames'][$key];
}
$html .= '<th>' . htmlspecialchars($label) . '</th>';
}
$html .= '</tr></thead>';

/* CONTENT */
$html .= '<tbody>';
foreach ($array as $line) {
$html .= '<tr>';
foreach ($line as $value) {
$html .= '<td>' . htmlspecialchars($value) . '</td>';
}
$html .= '</tr>';
}
$html .= '</tbody>';

/* Return content */
$html = '<table class="' . esc_attr($args['table_classname']) . '">' . $html . '</table>';
return $html;
}

}
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.68.1
Version: 2.69.0
Author: Darklg
Author URI: https://darklg.me/
Text Domain: wpubaseplugin
Expand All @@ -20,7 +20,7 @@

class WPUBasePlugin {

public $version = '2.68.1';
public $version = '2.69.0';

private $utilities_classes = array(
'messages' => array(
Expand Down Expand Up @@ -56,7 +56,7 @@ class WPUBasePlugin {
'name' => 'WPUBaseEmail'
),
'toolbox' => array(
'namespace' => 'wpubasetoolbox_0_11_1',
'namespace' => 'wpubasetoolbox_0_12_0',
'name' => 'WPUBaseToolbox'
),
'filecache' => array(
Expand Down

0 comments on commit 7cf449c

Please sign in to comment.