1
difenduandada
2024-10-15 7fd2948ee35c8e147ed35ce6d8502f94a98ddd22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
 
class Widget_HTML extends Widget {
    function __construct() {
         $this->name = 'HTML';
         $this->id_base = 'html';
         $this->description = 'Show HTML / TEXT';
    }
    public function widget( $instance, $args = array() ){
        echo $instance['text'];
    }
 
    public function form( $instance = array() ){
 
        if(!isset( $instance['text'] )){
            $instance['text'] = '';
        }
        ?>
        <div class="mb-3">
            <label class="form-label">HTML / TEXT:</label>
            <textarea class="form-control" rows="5" name="text"><?php echo $instance['text'] ?></textarea>
        </div>
        <?php
    }
}
 
register_widget( 'Widget_HTML' );
 
class Widget_Paragraph extends Widget {
    function __construct() {
         $this->name = 'Paragraph';
         $this->id_base = 'paragraph';
         $this->description = 'Show text paragraph (HTML not allowed)';
    }
    public function widget( $instance, $args = array() ){
        if(!isset( $instance['text'] )){
            $instance['text'] = '';
        }
        if(!isset( $instance['align'] )){
            $instance['align'] = 'none';
        }
        $align_class = null;
        if($instance['align'] != 'none'){
            if($instance['align'] == 'left'){
                $align_class = 'text-start text-left';
            } else if($instance['align'] == 'center'){
                $align_class = 'text-center';
            } else if($instance['align'] == 'right'){
                $align_class = 'text-end text-right';
            }
        }
        echo '<p'.($align_class ? ' class="' . $align_class . '"' : '').'>';
        echo htmlentities(nl2br($instance['text']));
        echo '</p>';
    }
 
    public function form( $instance = array() ){
 
        if(!isset( $instance['text'] )){
            $instance['text'] = '';
        }
        if(!isset( $instance['align'] )){
            $instance['align'] = 'none';
        }
        ?>
        <div class="mb-3">
            <label class="form-label">TEXT:</label>
            <textarea class="form-control" rows="5" name="text"><?php echo $instance['text'] ?></textarea>
        </div>
        <div class="mb-3">
            <label class="form-label"><?php _e('Align') ?>:</label>
            <select class="form-control" name="align">
                <?php
 
                $opts = array(
                    'none' => 'None',
                    'left' => 'Left',
                    'center' => 'Center',
                    'right' => 'Right'
                );
 
                foreach ($opts as $key => $value) {
                    $selected = '';
                    if($key == $instance['align']){
                        $selected = 'selected';
                    }
                    echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
                }
                ?>
            </select>
        </div>
        <?php
    }
}
 
register_widget( 'Widget_Paragraph' );
 
class Widget_Heading extends Widget {
    function __construct() {
         $this->name = 'Heading';
         $this->id_base = 'heading';
         $this->description = 'Heading typography, can be used as widget title or label.';
    }
    public function widget( $instance, $args = array() ){
        if(!isset( $instance['tag'] )){
            $instance['tag'] = 'h3';
        }
        if(!isset( $instance['class'] )){
            $instance['class'] = '';
        }
        if(!isset( $instance['text'] )){
            $instance['text'] = '';
        }
        echo '<'.$instance['tag'].' class="'.$instance['class'].'">';
        echo htmlentities($instance['text']);
        echo '</'.$instance['tag'].'>';
    }
 
    public function form( $instance = array() ){
 
        if(!isset( $instance['tag'] )){
            $instance['tag'] = 'h3';
        }
        if(!isset( $instance['class'] )){
            $instance['class'] = '';
        }
        if(!isset( $instance['text'] )){
            $instance['text'] = '';
        }
        ?>
        <div class="mb-3">
            <label class="form-label"><?php _e('Heading tag') ?>:</label>
            <select class="form-control" name="tag">
                <?php
 
                $opts = array(
                    'h1' => 'h1',
                    'h2' => 'h2',
                    'h3' => 'h3',
                    'h4' => 'h4',
                    'h5' => 'h5',
                    'div' => 'div',
                );
 
                foreach ($opts as $key => $value) {
                    $selected = '';
                    if($key == $instance['tag']){
                        $selected = 'selected';
                    }
                    echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
                }
                ?>
            </select>
        </div>
        <div class="mb-3">
            <label class="form-label">TEXT:</label>
            <textarea class="form-control" rows="5" name="text"><?php echo $instance['text'] ?></textarea>
        </div>
        <div class="mb-3">
            <label class="form-label"><?php _e('Div class (Optional)') ?>:</label>
            <input type="text" class="form-control" name="class" placeholder="widget" value="<?php echo $instance['class'] ?>">
        </div>
        <?php
    }
}
 
register_widget( 'Widget_Heading' );
 
class Widget_Banner extends Widget {
    function __construct() {
         $this->name = 'Banner Ad';
         $this->id_base = 'banner_ad';
         $this->description = 'Show banner advertisement';
    }
    public function widget( $instance, $args = array() ){
        echo '<div class="banner-ad-wrapper"><div class="banner-ad-content" style="padding: 20px 0; text-align: center;">';
        echo $instance['text'];
        echo '</div></div>';
    }
 
    public function form( $instance = array() ){
        if(!isset( $instance['text'] )){
            $instance['text'] = '';
        }
        ?>
        <p>This widget is similar to HTML widget, the difference is that it comes with a banner div to fit the theme style. You can also style it on theme style.css</p>
        <div class="mb-3">
            <label class="form-label">HTML / TEXT:</label>
            <textarea class="form-control" rows="5" name="text"><?php echo $instance['text'] ?></textarea>
        </div>
        <?php
    }
}
 
register_widget( 'Widget_Banner' );
 
?>