Skip to content

Commit

Permalink
v 2.56.1
Browse files Browse the repository at this point in the history
Toolbox v 0.2.1 :
- Better field protection.
- Default hidden fields.
- Handle more basic field types.
  • Loading branch information
Darklg committed Oct 24, 2023
1 parent b4f1841 commit a41ac1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
28 changes: 12 additions & 16 deletions inc/WPUBaseToolbox/WPUBaseToolbox.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace wpubasetoolbox_0_2_0;
namespace wpubasetoolbox_0_2_1;

/*
Class Name: WPU Base Toolbox
Description: Cool helpers for WordPress Plugins
Version: 0.2.0
Version: 0.2.1
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand Down Expand Up @@ -33,12 +33,16 @@ public function get_form_html($form_id, $fields = array(), $args = array()) {
'form_classname' => 'cssc-form',
'field_box_classname' => 'box',
'submit_box_classname' => 'box--submit',
'hidden_fields' => array(),
'nonce_id' => $form_id,
'nonce_name' => $form_id . '_nonce'
);
$args = array_merge($default_args, $args);

$args = apply_filters('wpubasetoolbox_get_form_html_args_' . __NAMESPACE__, $args);
if (!is_array($args['hidden_fields']) || !isset($args['hidden_fields'])) {
$args['hidden_fields'] = array();
}

/* Start form */
$html .= '<form class="' . esc_attr($args['form_classname']) . '" id="' . esc_attr($form_id) . '" action="" method="post">';
Expand All @@ -50,10 +54,8 @@ public function get_form_html($form_id, $fields = array(), $args = array()) {

/* Submit box */
$html .= '<div class="' . esc_attr($args['submit_box_classname']) . '">';
if (isset($args['hidden_fields']) && is_array($args['hidden_fields'])) {
foreach ($args['hidden_fields'] as $field_id => $field_value) {
$html .= '<input type="hidden" name="' . $field_id . '" value="' . esc_attr($field_value) . '" />';
}
foreach ($args['hidden_fields'] as $field_id => $field_value) {
$html .= '<input type="hidden" name="' . esc_attr($field_id) . '" value="' . esc_attr($field_value) . '" />';
}
$html .= wp_nonce_field($args['nonce_id'], $args['nonce_name'], 0, 0);
$html .= '<button class="' . esc_attr($args['button_classname']) . '" type="submit"><span>' . $args['button_label'] . '</span></button>';
Expand Down Expand Up @@ -88,13 +90,13 @@ public function get_field_html($field_name, $field, $form_id, $args = array()) {
/* Data */
/* Values */
$field_id = $form_id . '__' . $field_name;
$field_id_name = ' name="' . $field_name . '" id="' . $field_id . '"';
$field_id_name = ' name="' . esc_attr($field_name) . '" id="' . esc_attr($field_id) . '"';
if ($field['required']) {
$field_id_name .= ' required';
}

/* Label */
$default_label = '<label for="' . $field_id . '">';
$default_label = '<label for="' . esc_attr($field_id) . '">';
$default_label .= $field['label'];
if ($field['required']) {
$default_label .= ' <em>*</em>';
Expand All @@ -117,15 +119,9 @@ public function get_field_html($field_name, $field, $form_id, $args = array()) {
$html .= '</select>';
break;

case 'email':
case 'url':
case 'number':
case 'text':
$html .= $default_label;
$html .= '<input ' . $field_id_name . ' type="' . $field['type'] . '" value="' . esc_attr($field['value']) . '" />';
break;
default:

$html .= $default_label;
$html .= '<input ' . $field_id_name . ' type="' . esc_attr($field['type']) . '" value="' . esc_attr($field['value']) . '" />';
}

if ($html) {
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.56.0
Version: 2.56.1
Author: Darklg
Author URI: https://darklg.me/
Text Domain: wpubaseplugin
Expand All @@ -18,7 +18,7 @@

class WPUBasePlugin {

public $version = '2.56.0';
public $version = '2.56.1';

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

0 comments on commit a41ac1a

Please sign in to comment.