PluginProbe
Customify / 2.5.2
Customify v2.5.2
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
customify / features / customizer / controls / class-Pix_Customize_Background_Control.php

class-Pix_Customize_Background_Control.php in Customify 2.5.2, at features/customizer/controls/class-Pix_Customize_Background_Control.php

283 lines 11.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Pix_Customize_Background_Control
5 * A simple Color Control
6 */
7 class Pix_Customize_Background_Control extends Pix_Customize_Control {
8 public $type = 'custom_background';
9
10 public $value = array();
11
12 public $field = array(
13 'class' => ''
14 );
15
16 public $field_defaults = array(
17 'background-color' => true,
18 'background-repeat' => true,
19 'background-attachment' => true,
20 'background-position' => true,
21 'background-image' => true,
22 'background-gradient' => false,
23 'background-clip' => false,
24 'background-origin' => false,
25 'background-size' => true,
26 'preview_media' => true,
27 'preview' => true,
28 'preview_height' => '200px',
29 'transparent' => true,
30 );
31
32 /**
33 * Render the control's content.
34 *
35 * @since 3.4.0
36 */
37 public function render_content() {
38
39 // ensure some values
40 $this->value = $this->value();
41 $this->field = array_merge( $this->field, $this->field_defaults );
42
43 if ( $this->field['background-image'] === true ) {
44
45 // NO defaults for now
46 // if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty
47 // if ( is_array( $this->field['default'] ) ) {
48 // if ( ! empty( $this->field['default']['media']['id'] ) ) {
49 // $this->value['media']['id'] = $this->field['default']['media']['id'];
50 // } else if ( ! empty( $this->field['default']['id'] ) ) {
51 // $this->value['media']['id'] = $this->field['default']['id'];
52 // }
53 //
54 // if ( ! empty( $this->field['default']['url'] ) ) {
55 // $this->value['background-image'] = $this->field['default']['url'];
56 // } else if ( ! empty( $this->field['default']['media']['url'] ) ) {
57 // $this->value['background-image'] = $this->field['default']['media']['url'];
58 // } else if ( ! empty( $this->field['default']['background-image'] ) ) {
59 // $this->value['background-image'] = $this->field['default']['background-image'];
60 // }
61 //
62 // } else {
63 // if ( is_numeric( $this->field['default'] ) ) { // Check if it's an attachment ID
64 // $this->value['media']['id'] = $this->field['default'];
65 // } else { // Must be a URL
66 // $this->value['background-image'] = $this->field['default'];
67 // }
68 // }
69 // }
70
71 if ( empty( $this->value['background-image'] ) && ! empty( $this->value['media']['id'] ) ) {
72 $img = wp_get_attachment_image_src( $this->value['media']['id'], 'full' );
73 $this->value['background-image'] = $img[0];
74 $this->value['media']['width'] = $img[1];
75 $this->value['media']['height'] = $img[2];
76 }
77
78 if ( ! is_array( $this->value ) || ! isset( $this->value['media'] ) || empty( $this->value['media'] ) ) {
79 $this->value = array();
80 $media_array = array(
81 'id' => '',
82 'height' => '',
83 'width' => '',
84 'thumbnail' => ''
85 );
86 $this->value['media'] = $media_array;
87 }
88
89 $hide = 'hide ';
90
91 if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) ) {
92 $this->field['class'] .= " noPreview";
93 }
94
95 if ( ( ! empty( $this->field['background-image'] ) && $this->field['background-image'] === true ) || isset( $this->field['preview'] ) && $this->field['preview'] === false ) {
96 $hide = '';
97 }
98
99 $placeholder = isset( $this->field['placeholder'] ) ? $this->field['placeholder'] : __( 'No media selected', 'customify' );
100
101
102 if ( ! isset( $this->value['background-image'] ) ) {
103 $this->value['background-image'] = '';
104 }
105
106 echo '<input placeholder="' . $placeholder . '" type="text" class="customify_background_input background-image ' . $hide . 'upload ' . $this->field['class'] . '" name="' . $this->label . '[background-image]" id="' . $this->manager->options_key . '[' . $this->id . '][background-image]" value="' . $this->value['background-image'] . '" data-select_name="background-image" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-image]"/>';
107 echo '<input type="hidden" class="upload-id ' . $this->field['class'] . '" name="' . $this->manager->options_key . '[media][id]" id="' . $this->manager->options_key . '[' . $this->id . '][media][id]" value="' . $this->value['media']['id'] . '" />';
108 echo '<input type="hidden" class="upload-height" name="' . $this->manager->options_key . '[media][height]" id="' . $this->manager->options_key . '[' . $this->id . '][media][height]" value="' . $this->value['media']['height'] . '" />';
109 echo '<input type="hidden" class="upload-width" name="' . $this->manager->options_key . '[media][width]" id="' . $this->manager->options_key . '[' . $this->id . '][media][width]" value="' . $this->value['media']['width'] . '" />';
110 echo '<input type="hidden" class="upload-thumbnail" name="' . $this->manager->options_key . '[media][thumbnail]" id="' . $this->manager->options_key . '[media][thumbnail]" value="' . $this->value['media']['thumbnail'] . '" />';
111
112 //Preview
113 $hide = '';
114
115 if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) || empty( $this->value['background-image'] ) ) {
116 $hide = 'hide ';
117 }
118
119 if ( empty( $this->value['media']['thumbnail'] ) && ! empty( $this->value['background-image'] ) ) { // Just in case
120 if ( ! empty( $this->value['media']['id'] ) ) {
121 $image = wp_get_attachment_image_src( $this->value['media']['id'], array( 150 ) );
122 $this->value['media']['thumbnail'] = $image[0];
123 } else {
124 $this->value['media']['thumbnail'] = $this->value['background-image'];
125 }
126 }
127
128 echo '<div class="' . $hide . 'preview_screenshot">';
129 echo '<a class="of-uploaded-image" href="' . $this->value['background-image'] . '" target="_blank">';
130 echo '<img class="preview_image" id="image_' . $this->value['media']['id'] . '" src="' . $this->value['media']['thumbnail'] . '" alt="" target="_blank" rel="external" />';
131 echo '</a>';
132 echo '</div>';
133
134 //Upload controls DIV
135 echo '<div class="upload_button_div">';
136
137 //If the user has WP3.5+ show upload/remove button
138 echo '<span class="button background_upload_button" id="' . $this->id . '-media" data-setting_id="' . $this->setting->id . '" >' . __( 'Upload', 'customify' ) . '</span>';
139
140 $hide = '';
141 if ( empty( $this->value['background-image'] ) || $this->value['background-image'] == '' ) {
142 $hide = ' hide';
143 }
144
145 echo '<span class="button remove-image' . $hide . '" id="reset_' . $this->id . '" rel="' . $this->id . '">' . __( 'Remove', 'customify' ) . '</span>';
146
147 echo '</div>';
148 }
149
150 if ( $this->field['background-repeat'] === true ) {
151 $array = array(
152 'no-repeat' => 'No Repeat',
153 'repeat' => 'Repeat All',
154 'repeat-x' => 'Repeat Horizontally',
155 'repeat-y' => 'Repeat Vertically',
156 'inherit' => 'Inherit',
157 );
158
159 if ( ! isset( $this->value['background-repeat'] ) ) {
160 $this->value['background-repeat'] = '';
161 }
162
163 echo '<select id="' . $this->id . '-repeat-select" name="' . $this->setting->id . '[background-repeat]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-repeat" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-repeat]">';
164 echo '<option></option>';
165 foreach ( $array as $k => $v ) {
166 echo '<option value="' . $k . '"' . selected( $this->value['background-repeat'], $k, false ) . '>' . $v . '</option>';
167 }
168 echo '</select>';
169 }
170
171 if ( $this->field['background-clip'] === true ) {
172 $array = array(
173 'inherit' => 'Inherit',
174 'border-box' => 'Border Box',
175 'content-box' => 'Content Box',
176 'padding-box' => 'Padding Box',
177 );
178
179 if ( ! isset( $this->value['background-clip'] ) ) {
180 $this->value['background-clip'] = '';
181 }
182
183 echo '<select id="' . $this->id . '-repeat-select" name="' . $this->setting->id . '[background-clip]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-clip" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-clip]">';
184 echo '<option></option>';
185
186 foreach ( $array as $k => $v ) {
187 echo '<option value="' . $k . '"' . selected( $this->value['background-clip'], $k, false ) . '>' . $v . '</option>';
188 }
189 echo '</select>';
190 }
191
192 if ( $this->field['background-origin'] === true ) {
193 $array = array(
194 'inherit' => 'Inherit',
195 'border-box' => 'Border Box',
196 'content-box' => 'Content Box',
197 'padding-box' => 'Padding Box',
198 );
199
200 if ( ! isset( $this->value['background-origin'] ) ) {
201 $this->value['background-origin'] = '';
202 }
203
204 echo '<select id="' . $this->id . '-repeat-select" name="' . $this->setting->id . '[background-origin]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-origin" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-origin]">';
205 echo '<option></option>';
206
207 foreach ( $array as $k => $v ) {
208 echo '<option value="' . $k . '"' . selected( $this->value['background-origin'], $k, false ) . '>' . $v . '</option>';
209 }
210 echo '</select>';
211 }
212
213 if ( $this->field['background-size'] === true ) {
214 $array = array(
215 'inherit' => 'Inherit',
216 'cover' => 'Cover',
217 'contain' => 'Contain',
218 );
219
220 if ( ! isset( $this->value['background-size'] ) ) {
221 $this->value['background-size'] = '';
222 }
223
224 echo '<select id="' . $this->id . '-repeat-select" name="' . esc_attr( $this->label ) . '[background-size]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-size" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-size]">';
225 echo '<option></option>';
226
227 foreach ( $array as $k => $v ) {
228 echo '<option value="' . $k . '"' . selected( $this->value['background-size'], $k, false ) . '>' . $v . '</option>';
229 }
230 echo '</select>';
231 }
232
233 if ( $this->field['background-attachment'] === true ) {
234 $array = array(
235 'fixed' => 'Fixed',
236 'scroll' => 'Scroll',
237 'inherit' => 'Inherit',
238 );
239
240 if ( ! isset( $this->value['background-attachment'] ) ) {
241 $this->value['background-attachment'] = '';
242 }
243
244 echo '<select id="' . $this->id . '-attachment-select" name="' . $this->setting->id . '[background-attachment]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-attachment" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-attachment]">';
245 echo '<option></option>';
246 foreach ( $array as $k => $v ) {
247 echo '<option value="' . $k . '"' . selected( $this->value['background-attachment'], $k, false ) . '>' . $v . '</option>';
248 }
249 echo '</select>';
250 }
251
252 if ( $this->field['background-position'] === true ) {
253 $array = array(
254 'left top' => 'Left Top',
255 'left center' => 'Left center',
256 'left bottom' => 'Left Bottom',
257 'center top' => 'Center Top',
258 'center center' => 'Center Center',
259 'center bottom' => 'Center Bottom',
260 'right top' => 'Right Top',
261 'right center' => 'Right center',
262 'right bottom' => 'Right Bottom',
263 );
264
265 if ( ! isset( $this->value['background-position'] ) ) {
266 $this->value['background-position'] = '';
267 }
268
269 echo '<select id="' . $this->id . '-position-select" name="' . $this->setting->id . '[background-position]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-position" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-position]">';
270 echo '<option></option>';
271
272 foreach ( $array as $k => $v ) {
273 echo '<option value="' . $k . '"' . selected( $this->value['background-position'], $k, false ) . '>' . $v . '</option>';
274 }
275 echo '</select>';
276 }
277 }
278
279 static function css_output() {
280
281 }
282 }
283