| 1 |
<?php |
| 2 |
// No direct access, please |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/** |
| 6 |
* Range Value Customizer Control |
| 7 |
* |
| 8 |
* Class BetterDocs_Customizer_Range_Value_Control |
| 9 |
* |
| 10 |
* @since 1.0.0 |
| 11 |
*/ |
| 12 |
class BetterDocs_Customizer_Range_Value_Control extends WP_Customize_Control { |
| 13 |
public $type = 'range-value'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Enqueue scripts/styles. |
| 17 |
* |
| 18 |
* @since 1.0.0 |
| 19 |
*/ |
| 20 |
public function enqueue() { |
| 21 |
wp_enqueue_script( |
| 22 |
'customizer-range-value-control', |
| 23 |
BETTERDOCS_ADMIN_URL . 'assets/js/customizer-range-value-control.js', |
| 24 |
array( 'jquery' ), |
| 25 |
rand(), |
| 26 |
true |
| 27 |
); |
| 28 |
|
| 29 |
wp_enqueue_style( |
| 30 |
'customizer-range-value-control', BETTERDOCS_ADMIN_URL . 'assets/css/customizer-range-value-control.css', |
| 31 |
array(), |
| 32 |
rand() |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Render the control's content. |
| 38 |
* |
| 39 |
* @version 1.0.0 |
| 40 |
* |
| 41 |
*/ |
| 42 |
public function render_content() { |
| 43 |
?> |
| 44 |
<?php if ( ! empty( $this->label ) ) : ?> |
| 45 |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
| 46 |
<?php endif; ?> |
| 47 |
<div class="range-slider" style="width:100%; display:flex;flex-direction: row;justify-content: flex-start;"> |
| 48 |
<span style="width:100%; flex: 1 0 0; vertical-align: middle;"><input class="range-slider__range" type="range" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->input_attrs(); $this->link(); ?>> |
| 49 |
<span class="range-slider__value">0</span></span> |
| 50 |
</div> |
| 51 |
<?php if ( ! empty( $this->description ) ) : ?> |
| 52 |
<span class="description customize-control-description"><?php echo $this->description; ?></span> |
| 53 |
<?php endif; ?> |
| 54 |
<?php |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Toogle Customizer Control |
| 60 |
* |
| 61 |
* Class BetterDocs_Customizer_Toggle_Control |
| 62 |
* |
| 63 |
* @since 1.0.0 |
| 64 |
* |
| 65 |
*/ |
| 66 |
class BetterDocs_Customizer_Toggle_Control extends WP_Customize_Control { |
| 67 |
public $type = 'ios'; |
| 68 |
|
| 69 |
/** |
| 70 |
* Enqueue scripts/styles. |
| 71 |
* |
| 72 |
* @since 1.0.0 |
| 73 |
*/ |
| 74 |
public function enqueue() { |
| 75 |
wp_enqueue_script( 'customizer-toggle-control', |
| 76 |
BETTERDOCS_ADMIN_URL . 'assets/js/customizer-toggle-control.js', |
| 77 |
array( 'jquery' ), |
| 78 |
rand(), |
| 79 |
true |
| 80 |
); |
| 81 |
wp_enqueue_style( 'pure-css-toggle-buttons', |
| 82 |
BETTERDOCS_ADMIN_URL . 'assets/css/customizer-togle-buttons.css', |
| 83 |
array(), |
| 84 |
rand() |
| 85 |
); |
| 86 |
|
| 87 |
$css = ' |
| 88 |
.disabled-control-title { |
| 89 |
color: #a0a5aa; |
| 90 |
} |
| 91 |
input[type=checkbox].tgl-light:checked + .tgl-btn { |
| 92 |
background: #0085ba; |
| 93 |
} |
| 94 |
input[type=checkbox].tgl-light + .tgl-btn { |
| 95 |
background: #a0a5aa; |
| 96 |
} |
| 97 |
input[type=checkbox].tgl-light + .tgl-btn:after { |
| 98 |
background: #f7f7f7; |
| 99 |
} |
| 100 |
|
| 101 |
input[type=checkbox].tgl-ios:checked + .tgl-btn { |
| 102 |
background: #0085ba; |
| 103 |
} |
| 104 |
|
| 105 |
input[type=checkbox].tgl-flat:checked + .tgl-btn { |
| 106 |
border: 4px solid #0085ba; |
| 107 |
} |
| 108 |
input[type=checkbox].tgl-flat:checked + .tgl-btn:after { |
| 109 |
background: #0085ba; |
| 110 |
} |
| 111 |
|
| 112 |
'; |
| 113 |
wp_add_inline_style( 'pure-css-toggle-buttons' , $css ); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Render the control's content. |
| 118 |
* |
| 119 |
* @version 1.0.0 |
| 120 |
* |
| 121 |
*/ |
| 122 |
public function render_content() { |
| 123 |
?> |
| 124 |
<label> |
| 125 |
<div style="display:flex;flex-direction: row;justify-content: flex-start;"> |
| 126 |
<span class="customize-control-title" style="flex: 2 0 0; vertical-align: middle;"><?php echo esc_html( $this->label ); ?></span> |
| 127 |
<input id="cb<?php echo $this->instance_number ?>" type="checkbox" class="tgl tgl-<?php echo $this->type?>" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> /> |
| 128 |
<label for="cb<?php echo $this->instance_number ?>" class="tgl-btn"></label> |
| 129 |
</div> |
| 130 |
<?php if ( ! empty( $this->description ) ) : ?> |
| 131 |
<span class="description customize-control-description"><?php echo $this->description; ?></span> |
| 132 |
<?php endif; ?> |
| 133 |
</label> |
| 134 |
<?php |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Alpha Color Picker Customizer Control |
| 140 |
* |
| 141 |
* Class BetterDocs_Customizer_Alpha_Color_Control |
| 142 |
* |
| 143 |
* @since 1.0.0 |
| 144 |
*/ |
| 145 |
|
| 146 |
class BetterDocs_Customizer_Alpha_Color_Control extends WP_Customize_Control { |
| 147 |
/** |
| 148 |
* Official control name. |
| 149 |
* |
| 150 |
* @var string |
| 151 |
*/ |
| 152 |
public $type = 'alpha-color'; |
| 153 |
/** |
| 154 |
* Add support for palettes to be passed in. |
| 155 |
* |
| 156 |
* Supported palette values are true, false, or an array of RGBa and Hex colors. |
| 157 |
* |
| 158 |
* @var bool |
| 159 |
*/ |
| 160 |
public $palette; |
| 161 |
/** |
| 162 |
* Add support for showing the opacity value on the slider handle. |
| 163 |
* |
| 164 |
* @var array |
| 165 |
*/ |
| 166 |
public $show_opacity; |
| 167 |
/** |
| 168 |
* Enqueue scripts/styles. |
| 169 |
* |
| 170 |
* @since 1.0.0 |
| 171 |
* |
| 172 |
*/ |
| 173 |
public function enqueue() { |
| 174 |
wp_enqueue_script( |
| 175 |
'customizer-alpha-color-picker', |
| 176 |
BETTERDOCS_ADMIN_URL . 'assets/js/alpha-color-picker.js', |
| 177 |
array( 'jquery', 'wp-color-picker' ), |
| 178 |
rand(), |
| 179 |
true |
| 180 |
); |
| 181 |
wp_enqueue_style( |
| 182 |
'customizer-alpha-color-picker', |
| 183 |
BETTERDOCS_ADMIN_URL . 'assets/css/alpha-color-picker.css', |
| 184 |
array( 'wp-color-picker' ), |
| 185 |
rand() |
| 186 |
); |
| 187 |
} |
| 188 |
/** |
| 189 |
* Render the control. |
| 190 |
*/ |
| 191 |
public function render_content() { |
| 192 |
|
| 193 |
// Output the label and description if they were passed in. |
| 194 |
if ( isset( $this->label ) && '' !== $this->label ) { |
| 195 |
echo '<span class="customize-control-title">' . sanitize_text_field( $this->label ) . '</span>'; |
| 196 |
} |
| 197 |
if ( isset( $this->description ) && '' !== $this->description ) { |
| 198 |
echo '<span class="description customize-control-description">' . sanitize_text_field( $this->description ) . '</span>'; |
| 199 |
} |
| 200 |
|
| 201 |
// Process the palette |
| 202 |
if ( is_array( $this->palette ) ) { |
| 203 |
$palette = implode( '|', $this->palette ); |
| 204 |
} else { |
| 205 |
// Default to true. |
| 206 |
$palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true'; |
| 207 |
} |
| 208 |
// Support passing show_opacity as string or boolean. Default to true. |
| 209 |
$show_opacity = ( false === $this->show_opacity || 'false' === $this->show_opacity ) ? 'false' : 'true'; |
| 210 |
// Begin the output. |
| 211 |
?> |
| 212 |
<input class="alpha-color-control" type="text" data-show-opacity="<?php echo esc_attr( $show_opacity ); ?>" data-palette="<?php echo esc_attr( $palette ); ?>" data-default-color="<?php echo esc_attr( $this->settings['default']->default ); ?>" <?php esc_attr( $this->link() ); ?> /> |
| 213 |
|
| 214 |
<?php |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Seperator Custom Customizer Control |
| 220 |
* |
| 221 |
* Class BetterDocs_Separator_Custom_Control |
| 222 |
* |
| 223 |
* @since 1.0.0 |
| 224 |
*/ |
| 225 |
|
| 226 |
class BetterDocs_Separator_Custom_Control extends WP_Customize_Control{ |
| 227 |
public $type = 'separator'; |
| 228 |
public function render_content(){ |
| 229 |
?> |
| 230 |
<label> |
| 231 |
<h4 class="betterdocs-customize-control-separator"><?php echo esc_html( $this->label ); ?></h4> |
| 232 |
<?php if ( ! empty( $this->description ) ) : ?> |
| 233 |
<span class="description customize-control-description"><?php echo $this->description; ?></span> |
| 234 |
<?php endif; ?> |
| 235 |
</label> |
| 236 |
<?php |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Title Custom Customizer Control |
| 242 |
* |
| 243 |
* Class BetterDocs_Title_Custom_Control |
| 244 |
* |
| 245 |
* @since 1.0.0 |
| 246 |
*/ |
| 247 |
|
| 248 |
class BetterDocs_Title_Custom_Control extends WP_Customize_Control{ |
| 249 |
public $type = 'title'; |
| 250 |
public function render_content(){ |
| 251 |
?> |
| 252 |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
| 253 |
<?php if ( ! empty( $this->description ) ) : ?> |
| 254 |
<span class="description customize-control-description"><?php echo $this->description; ?></span> |
| 255 |
<?php endif; ?> |
| 256 |
<?php |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
/** |
| 262 |
* Select Customizer Control |
| 263 |
* |
| 264 |
* Class BetterDocs_Select_Control |
| 265 |
* |
| 266 |
* @since 1.0.0 |
| 267 |
*/ |
| 268 |
|
| 269 |
class BetterDocs_Select_Control extends WP_Customize_Control { |
| 270 |
|
| 271 |
public $type = 'betterdocs-select'; |
| 272 |
public function render_content() { |
| 273 |
if( empty( $this->choices ) ) |
| 274 |
return; |
| 275 |
?> |
| 276 |
<select <?php $this->link(); ?> class="betterdocs-select"> |
| 277 |
<?php |
| 278 |
foreach( $this->choices as $key => $label ) { |
| 279 |
echo '<option value="' . esc_attr( $key ) . '">' . $label . '</option>'; |
| 280 |
} |
| 281 |
?> |
| 282 |
</select> |
| 283 |
<?php if( !empty( $this->label ) ) : ?> |
| 284 |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
| 285 |
<?php endif; |
| 286 |
} |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Dimension Customizer Control |
| 292 |
* |
| 293 |
* Class BetterDocs_Dimension_Control |
| 294 |
* |
| 295 |
* @since 1.0.0 |
| 296 |
*/ |
| 297 |
|
| 298 |
class BetterDocs_Dimension_Control extends WP_Customize_Control { |
| 299 |
public $type = 'dimension'; |
| 300 |
|
| 301 |
/** |
| 302 |
* Render the control's content. |
| 303 |
* |
| 304 |
* @since 1.0.0 |
| 305 |
*/ |
| 306 |
public function render_content() { |
| 307 |
?> |
| 308 |
<div class="dimension-field"> |
| 309 |
<input type="number" value="<?php echo esc_attr($this->value()); ?>" <?php $this->input_attrs(); $this->link(); ?>> |
| 310 |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
| 311 |
</div> |
| 312 |
<?php |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* Number Customizer Control |
| 318 |
* |
| 319 |
* Class BetterDocs_Dimension_Control |
| 320 |
* |
| 321 |
* @since 1.0.0 |
| 322 |
*/ |
| 323 |
|
| 324 |
class BetterDocs_Number_Control extends WP_Customize_Control { |
| 325 |
public $type = 'number'; |
| 326 |
|
| 327 |
/** |
| 328 |
* Render the control's content. |
| 329 |
* |
| 330 |
* @since 1.0.0 |
| 331 |
*/ |
| 332 |
public function render_content() { |
| 333 |
?> |
| 334 |
<div class="number-field"> |
| 335 |
<?php if ( ! empty( $this->label ) ) : ?> |
| 336 |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
| 337 |
<?php endif; ?> |
| 338 |
<input type="number" value="<?php echo esc_attr($this->value()); ?>" <?php $this->input_attrs(); $this->link(); ?>> |
| 339 |
<?php if ( ! empty( $this->description ) ) : ?> |
| 340 |
<span class="description customize-control-description"><?php echo $this->description; ?></span> |
| 341 |
<?php endif; ?> |
| 342 |
</div> |
| 343 |
<?php |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
class BetterDocs_Radio_Image_Control extends WP_Customize_Control { |
| 348 |
/** |
| 349 |
* Declare the control type. |
| 350 |
* |
| 351 |
* @since 1.0.0 |
| 352 |
*/ |
| 353 |
public $type = 'radio-image'; |
| 354 |
|
| 355 |
/** |
| 356 |
* Enqueue scripts/styles. |
| 357 |
* |
| 358 |
* @since 1.0.0 |
| 359 |
*/ |
| 360 |
public function enqueue() { |
| 361 |
wp_enqueue_script( 'jquery-ui-button' ); |
| 362 |
wp_enqueue_style( |
| 363 |
'customizer-radio-image-select', |
| 364 |
BETTERDOCS_ADMIN_URL . 'assets/css/customizer-radio-image-select.css', |
| 365 |
array(), |
| 366 |
rand() |
| 367 |
); |
| 368 |
} |
| 369 |
|
| 370 |
/** |
| 371 |
* Render the control's content. |
| 372 |
* |
| 373 |
* @since 1.0.0 |
| 374 |
*/ |
| 375 |
public function render_content() { |
| 376 |
if ( empty( $this->choices ) ) { |
| 377 |
return; |
| 378 |
} |
| 379 |
|
| 380 |
$name = '_customize-radio-' . $this->id; |
| 381 |
?> |
| 382 |
<?php if ( ! empty( $this->label ) ) : ?> |
| 383 |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
| 384 |
<?php endif; ?> |
| 385 |
<?php if ( ! empty( $this->description ) ) : ?> |
| 386 |
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span> |
| 387 |
<?php endif; ?> |
| 388 |
<div id="input_<?php echo $this->id; ?>" class="image"> |
| 389 |
<?php |
| 390 |
foreach ( $this->choices as $value => $label ) : |
| 391 |
if(isset( $label['pro'] ) && $label['pro'] === true){ ?> |
| 392 |
<label class="image-select" id="<?php echo $this->id . $value ?>"> |
| 393 |
<a target="_blank" href="<?php echo esc_url($label['url']) ?>"><img src="<?php echo esc_url( $label['image'] ) ?>" alt=""></a> |
| 394 |
<span class="go-pro"><?php esc_html_e('Go Pro','betterdocs') ?></span> |
| 395 |
</label> |
| 396 |
<?php } else { ?> |
| 397 |
<input class="image-select" type="radio" value="<?php echo esc_attr( $value ) ?>" id="<?php echo $this->id . $value; ?>" name="<?php echo esc_attr( $name ) ?>" <?php $this->link(); checked( $this->value(), $value ); ?>> |
| 398 |
<label for="<?php echo $this->id . $value; ?>"> |
| 399 |
<img src="<?php echo esc_url( $label['image'] ) ?>" alt="<?php echo esc_attr( $value ) ?>" title="<?php echo esc_attr( $value ) ?>"> |
| 400 |
</label> |
| 401 |
</input> |
| 402 |
<?php } endforeach; ?> |
| 403 |
</div> |
| 404 |
<script>jQuery(document).ready(function($) { $( '[id="input_<?php echo $this->id; ?>"]' ).buttonset(); });</script> |
| 405 |
<?php |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
/** |
| 410 |
* Load customizer conditional controler js file. |
| 411 |
* |
| 412 |
* @since 1.0.0 |
| 413 |
*/ |
| 414 |
|
| 415 |
function betterdocs_customizer_condition() { |
| 416 |
wp_enqueue_script( 'betterdocs-customize-condition', |
| 417 |
BETTERDOCS_ADMIN_URL . 'assets/js/customizer-condition.js', |
| 418 |
array(), |
| 419 |
true |
| 420 |
); |
| 421 |
} |
| 422 |
add_action( 'customize_controls_enqueue_scripts', 'betterdocs_customizer_condition' ); |
| 423 |
|
| 424 |
/** |
| 425 |
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously. |
| 426 |
* |
| 427 |
* @since 1.0.0 |
| 428 |
*/ |
| 429 |
function betterdocs_customize_preview_js() { |
| 430 |
wp_enqueue_script( 'betterdocs-customizer', |
| 431 |
BETTERDOCS_ADMIN_URL . 'assets/js/customizer.js', |
| 432 |
array( 'customize-preview' ), |
| 433 |
'', |
| 434 |
true |
| 435 |
); |
| 436 |
} |
| 437 |
add_action( 'customize_preview_init', 'betterdocs_customize_preview_js' ); |
| 438 |
|
| 439 |
?> |
| 440 |
|