PluginProbe
MaxButtons – Create buttons / 6.25
MaxButtons – Create buttons v6.25
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / classes / field.php

field.php in MaxButtons – Create buttons 6.25, at classes/field.php

121 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MaxButtons;
3 defined('ABSPATH') or die('No direct access permitted');
4
5 class maxField
6 {
7
8 /* Static class variables */
9 static $templates = '';
10 static $position = 0;
11
12 /* Field data */
13 public $id;
14 public $name;
15 public $value = '';
16
17 /* Layout options */
18 public $note;
19 public $label;
20 public $title;
21 public $default;
22
23 // Specific options */
24 public $placeholder = ''; // text / textarea
25 public $icon; // checkbox-icon
26 public $checked = ''; // checkbox / radio
27 public $input_class = ''; // inputs
28 public $before_input; // text
29 public $content = ''; // generic / spacer
30 public $min; // number
31
32 /* Border radius */
33 public $radius_tl;
34 public $radius_tr;
35 public $radius_bl, $radius_br;
36
37 //public
38
39 /* Template */
40 public $template;
41 public $main_class = 'option'; // row class - start template
42 public $esc_function = 'esc_attr';
43
44 /* Publish brake */
45 public $publish = true;
46 public $output = '';
47
48 public function __construct($template = 'text', $args = array() )
49 {
50 self::$position++;
51 $this->template = $template;
52
53 foreach($args as $item => $value)
54 {
55 $this->{$item} = $value;
56
57 }
58 }
59
60 static function setTemplates($templates)
61 {
62 self::$templates = $templates;
63
64 }
65
66
67 public function setDefault($default)
68 {
69 $this->default = __('Default:','maxbuttons') . ' ' . $default;
70
71 }
72
73 /** Output field interface
74 *
75 * @param $start_tpl Prepend a template before this field ( e.g. row defition )
76 * @param $end_tpl Append a template after this field
77 */
78
79 public function output($start_tpl = '', $end_tpl = '')
80 {
81 if ($this->esc_function)
82 {
83 $this->value = call_user_func($this->esc_function, $this->value);
84 }
85
86 $output = '';
87 if ($start_tpl != '')
88 {
89 $start_tpl = self::$templates[$start_tpl];
90 $output .= simpleTemplate::parse($start_tpl['path'], $this);
91 }
92
93 $template = self::$templates[$this->template]; // template name;
94 do_action('mb/editor/before-field-' . $this->id, $this);
95
96 $output .= simpleTemplate::parse($template['path'], $this);
97
98
99 if ($end_tpl != '')
100 {
101 if (! is_array($end_tpl))
102 $end_tpl = array($end_tpl);
103
104 foreach($end_tpl as $tpl)
105 {
106 $tpl = self::$templates[$tpl];
107 $output .= simpleTemplate::parse($tpl['path'], $this);
108 }
109 }
110
111 if ($this->publish)
112 echo $output;
113 do_action('mb/editor/after-field-'. $this->id); // hook for extra fields.
114
115 $this->output = $output;
116 return $output;
117 }
118
119
120 }
121