PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / trunk
Disable Admin Notices – Hide Dashboard Notifications vtrunk
1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / libs / factory / forms / controls / radio.php
disable-admin-notices / libs / factory / forms / controls Last commit date
customs 1 year ago holders 1 year ago checkbox.php 1 year ago color-and-opacity.php 1 year ago color.php 1 year ago datepicker-range.php 1 year ago dropdown-and-colors.php 1 year ago dropdown.php 1 year ago font.php 1 year ago google-font.php 1 year ago gradient.php 1 year ago hidden.php 1 year ago index.php 3 years ago integer.php 1 year ago list.php 1 year ago multiple-textbox.php 1 year ago paddings-editor.php 1 year ago pattern.php 1 year ago radio-colors.php 1 year ago radio.php 1 year ago textarea.php 1 year ago textbox.php 1 year ago url.php 1 year ago wp-editor.php 1 year ago
radio.php
85 lines
1 <?php
2
3 /**
4 * Radio Control
5 *
6 * Main options:
7 * name => a name of the control
8 * value => a value to show in the control
9 * default => a default value of the control if the "value" option is not specified
10 * items => a callback to return items or an array of items to select
11 *
12 * @author Alex Kovalev <alex.kovalevv@gmail.com>
13 * @copyright (c) 2018, Webcraftic Ltd
14 *
15 * @package factory-forms
16 * @since 1.0.0
17 */
18
19 // Exit if accessed directly
20 if( !defined('ABSPATH') ) {
21 exit;
22 }
23
24 if( !class_exists('Wbcr_FactoryForms480_RadioControl') ) {
25
26 class Wbcr_FactoryForms480_RadioControl extends Wbcr_FactoryForms480_Control {
27
28 public $type = 'radio';
29
30 /**
31 * Returns a set of available items for the radio.
32 *
33 * @since 1.0.0
34 * @return mixed[]
35 */
36 private function getItems()
37 {
38 $data = $this->getOption('data', array());
39
40 // if the data options is a valid callback for an object method
41 if( (is_array($data) && count($data) == 2 && is_object($data[0])) || is_string($data) ) {
42
43 return call_user_func($data);
44 }
45
46 // if the data options is an array of values
47 return $data;
48 }
49
50 /**
51 * Preparing html attributes before rendering html of the control.
52 *
53 * @since 1.0.0
54 * @return void
55 */
56 protected function beforeHtml()
57 {
58 $name_on_form = $this->getNameOnForm();
59 $this->addHtmlAttr('name', $name_on_form);
60 }
61
62 /**
63 * Shows the html markup of the control.
64 *
65 * @since 1.0.0
66 * @return void
67 */
68 public function html()
69 {
70 $items = $this->getItems();
71 $value = $this->getValue();
72 ?>
73 <?php foreach($items as $item) {
74 $checked = ($item[0] == $value)
75 ? 'checked="checked"'
76 : '';
77 ?>
78 <span class="factory-form-radio-item">
79 <lable class="factory-from-radio-label"><?php echo esc_html($item[1]); ?></lable>
80 <input type="radio" <?php $this->attrs() ?> value="<?php echo esc_attr($item[0]) ?>" <?php echo $checked ?>/>
81 </span>
82 <?php }
83 }
84 }
85 }