PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / factory / forms / controls / radio.php
robin-image-optimizer / libs / factory / forms / controls Last commit date
customs 5 months ago holders 5 months ago checkbox.php 5 months ago color-and-opacity.php 5 months ago color.php 5 months ago datepicker-range.php 5 months ago dropdown-and-colors.php 5 months ago dropdown.php 5 months ago font.php 5 months ago google-font.php 5 months ago gradient.php 5 months ago hidden.php 5 months ago index.php 5 months ago integer.php 5 months ago list.php 5 months ago multiple-textbox.php 5 months ago paddings-editor.php 5 months ago pattern.php 5 months ago radio-colors.php 5 months ago radio.php 5 months ago textarea.php 5 months ago textbox.php 5 months ago url.php 5 months ago wp-editor.php 5 months ago
radio.php
81 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 * @package factory-forms
13 * @since 1.0.0
14 */
15
16 // Exit if accessed directly
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 if ( ! class_exists( 'Wbcr_FactoryForms600_RadioControl' ) ) {
22
23 class Wbcr_FactoryForms600_RadioControl extends Wbcr_FactoryForms600_Control {
24
25 public $type = 'radio';
26
27 /**
28 * Returns a set of available items for the radio.
29 *
30 * @since 1.0.0
31 * @return mixed[]
32 */
33 private function getItems() {
34 $data = $this->getOption( 'data', [] );
35
36 // if the data options is a valid callback for an object method
37 if ( ( is_array( $data ) && count( $data ) == 2 && is_object( $data[0] ) ) || is_string( $data ) ) {
38
39 return call_user_func( $data );
40 }
41
42 // if the data options is an array of values
43 return $data;
44 }
45
46 /**
47 * Preparing html attributes before rendering html of the control.
48 *
49 * @since 1.0.0
50 * @return void
51 */
52 protected function beforeHtml() {
53 $name_on_form = $this->getNameOnForm();
54 $this->addHtmlAttr( 'name', $name_on_form );
55 }
56
57 /**
58 * Shows the html markup of the control.
59 *
60 * @since 1.0.0
61 * @return void
62 */
63 public function html() {
64 $items = $this->getItems();
65 $value = $this->getValue();
66 ?>
67 <?php
68 foreach ( $items as $item ) {
69 $checked = ( $item[0] == $value )
70 ? 'checked="checked"'
71 : '';
72 ?>
73 <span class="factory-form-radio-item">
74 <lable class="factory-from-radio-label"><?php echo esc_html( $item[1] ); ?></lable>
75 <input type="radio" <?php $this->attrs(); ?> value="<?php echo esc_attr( $item[0] ); ?>" <?php echo $checked; ?>/>
76 </span>
77 <?php
78 }
79 }
80 }
81 }