Skip to content

Commit

Permalink
v 2.52.1
Browse files Browse the repository at this point in the history
Base Fields v 0.15.3 :
- Help text under fields.
- Default value.
  • Loading branch information
Darklg committed Jul 29, 2023
1 parent 5bb39a4 commit 352b85f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
21 changes: 18 additions & 3 deletions inc/WPUBaseFields/WPUBaseFields.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace wpubasefields_0_15_2;
namespace wpubasefields_0_15_3;

/*
Class Name: WPU Base Fields
Description: A class to handle fields in WordPress
Version: 0.15.2
Version: 0.15.3
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand All @@ -14,7 +14,7 @@

class WPUBaseFields {
private $script_id;
private $version = '0.15.2';
private $version = '0.15.3';
private $fields = array();
private $field_groups = array();
private $supported_types = array(
Expand Down Expand Up @@ -122,6 +122,9 @@ function build_fields($fields = array(), $field_groups = array()) {
if (!isset($field['required'])) {
$field['required'] = false;
}
if (!isset($field['help'])) {
$field['help'] = false;
}
if (!isset($field['preview_format'])) {
$field['preview_format'] = 'thumbnail';
}
Expand Down Expand Up @@ -171,6 +174,15 @@ function display_box_content($post, $args) {

/* Shared settings */
$value = get_post_meta($post->ID, $field_id, 1);
if (isset($field['default_value'])) {
if (is_null($value)) {
$value = $field['default_value'];
}
if (isset($field['data']) && in_array($field['type'], array('radio', 'select', 'checkboxes')) && !isset($field['data'][$value])) {
$value = $field['default_value'];
}
}

$displayed_value = is_array($value) ? serialize($value) : $value;
$field_name = 'wpubasefields_' . $field_id;
$id_name = ' name="' . $field_name . '" id="' . $field_name . '" ';
Expand Down Expand Up @@ -293,6 +305,9 @@ function display_box_content($post, $args) {
}

$field_html .= '<input class="wpubasefield-input-control" type="hidden" name="' . $field_name . '__control" value="1" />';
if ($field['help']) {
$field_html .= '<small class="wpubasefield-msg-help">' . $field['help'] . '</small>';
}
$field_html .= '<small class="wpubasefield-msg-invalid">' . __('This field is invalid', 'wpubasefields') . '</small>';

if ($field_html) {
Expand Down
6 changes: 6 additions & 0 deletions inc/WPUBaseFields/assets/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
margin-top: 1em;
}

.wpubasefield-msg-invalid,
.wpubasefield-msg-help {
display: block;
margin-top: 0.5em;
}

.wpubasefield-input[data-valid="1"] .wpubasefield-msg-invalid {
display: none;
}
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.52.0
Version: 2.52.1
Author: Darklg
Author URI: https://darklg.me/
Text Domain: wpubaseplugin
Expand All @@ -18,7 +18,7 @@

class WPUBasePlugin {

public $version = '2.52.0';
public $version = '2.52.1';

private $utilities_classes = array(
'messages' => array(
Expand All @@ -42,7 +42,7 @@ class WPUBasePlugin {
'name' => 'WPUBaseCron'
),
'fields' => array(
'namespace' => 'wpubasefields_0_15_2',
'namespace' => 'wpubasefields_0_15_3',
'name' => 'WPUBaseFields'
),
'update' => array(
Expand Down

0 comments on commit 352b85f

Please sign in to comment.