| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
|
| 4 |
use WPAdminify\Inc\Utils; |
| 5 |
/** |
| 6 |
* |
| 7 |
* Field: typography |
| 8 |
* |
| 9 |
* @since 1.0.0 |
| 10 |
* @version 1.0.0 |
| 11 |
*/ |
| 12 |
if ( ! class_exists( 'ADMINIFY_Field_typography' ) ) { |
| 13 |
class ADMINIFY_Field_typography extends ADMINIFY_Fields { |
| 14 |
|
| 15 |
public $chosen = false; |
| 16 |
|
| 17 |
public $value = []; |
| 18 |
|
| 19 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 20 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 21 |
} |
| 22 |
|
| 23 |
public function render() { |
| 24 |
echo wp_kses_post( $this->field_before() ); |
| 25 |
|
| 26 |
$args = wp_parse_args( |
| 27 |
$this->field, |
| 28 |
[ |
| 29 |
'font_family' => true, |
| 30 |
'font_weight' => true, |
| 31 |
'font_style' => true, |
| 32 |
'font_size' => true, |
| 33 |
'line_height' => true, |
| 34 |
'letter_spacing' => true, |
| 35 |
'text_align' => true, |
| 36 |
'text_transform' => true, |
| 37 |
'color' => true, |
| 38 |
'chosen' => true, |
| 39 |
'preview' => true, |
| 40 |
'subset' => true, |
| 41 |
'multi_subset' => false, |
| 42 |
'extra_styles' => false, |
| 43 |
'backup_font_family' => false, |
| 44 |
'font_variant' => false, |
| 45 |
'word_spacing' => false, |
| 46 |
'text_decoration' => false, |
| 47 |
'custom_style' => false, |
| 48 |
'compact' => false, |
| 49 |
'exclude' => '', |
| 50 |
'unit' => 'px', |
| 51 |
'line_height_unit' => '', |
| 52 |
'preview_text' => 'The quick brown fox jumps over the lazy dog', |
| 53 |
] |
| 54 |
); |
| 55 |
|
| 56 |
if ( $args['compact'] ) { |
| 57 |
$args['text_transform'] = false; |
| 58 |
$args['text_align'] = false; |
| 59 |
$args['font_size'] = false; |
| 60 |
$args['line_height'] = false; |
| 61 |
$args['letter_spacing'] = false; |
| 62 |
$args['preview'] = false; |
| 63 |
$args['color'] = false; |
| 64 |
} |
| 65 |
|
| 66 |
$default_value = [ |
| 67 |
'font-family' => '', |
| 68 |
'font-weight' => '', |
| 69 |
'font-style' => '', |
| 70 |
'font-variant' => '', |
| 71 |
'font-size' => '', |
| 72 |
'line-height' => '', |
| 73 |
'letter-spacing' => '', |
| 74 |
'word-spacing' => '', |
| 75 |
'text-align' => '', |
| 76 |
'text-transform' => '', |
| 77 |
'text-decoration' => '', |
| 78 |
'backup-font-family' => '', |
| 79 |
'color' => '', |
| 80 |
'custom-style' => '', |
| 81 |
'type' => '', |
| 82 |
'subset' => '', |
| 83 |
'extra-styles' => [], |
| 84 |
]; |
| 85 |
|
| 86 |
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value; |
| 87 |
$this->value = wp_parse_args( $this->value, $default_value ); |
| 88 |
$this->chosen = $args['chosen']; |
| 89 |
$chosen_class = ( $this->chosen ) ? ' adminify--chosen' : ''; |
| 90 |
$line_height_unit = ( ! empty( $args['line_height_unit'] ) ) ? $args['line_height_unit'] : $args['unit']; |
| 91 |
|
| 92 |
echo '<div class="adminify--typography' . esc_attr( $chosen_class ) . '" data-depend-id="' . esc_attr( $this->field['id'] ) . '" data-unit="' . esc_attr( $args['unit'] ) . '" data-line-height-unit="' . esc_attr( $line_height_unit ) . '" data-exclude="' . esc_attr( $args['exclude'] ) . '">'; |
| 93 |
|
| 94 |
echo '<div class="adminify--blocks adminify--blocks-selects">'; |
| 95 |
|
| 96 |
// |
| 97 |
// Font Family |
| 98 |
if ( ! empty( $args['font_family'] ) ) { |
| 99 |
echo '<div class="adminify--block">'; |
| 100 |
echo '<div class="adminify--title">' . esc_html__( 'Font Family', 'adminify' ) . '</div>'; |
| 101 |
echo Utils::wp_kses_custom( $this->create_select( [ $this->value['font-family'] => $this->value['font-family'] ], 'font-family', esc_html__( 'Select a font', 'adminify' ) ) ); |
| 102 |
echo '</div>'; |
| 103 |
} |
| 104 |
|
| 105 |
// |
| 106 |
// Backup Font Family |
| 107 |
if ( ! empty( $args['backup_font_family'] ) ) { |
| 108 |
echo '<div class="adminify--block adminify--block-backup-font-family hidden">'; |
| 109 |
echo '<div class="adminify--title">' . esc_html__( 'Backup Font Family', 'adminify' ) . '</div>'; |
| 110 |
echo wp_kses_post( |
| 111 |
$this->create_select( |
| 112 |
apply_filters( |
| 113 |
'adminify_field_typography_backup_font_family', |
| 114 |
[ |
| 115 |
'Arial, Helvetica, sans-serif', |
| 116 |
"'Arial Black', Gadget, sans-serif", |
| 117 |
"'Comic Sans MS', cursive, sans-serif", |
| 118 |
'Impact, Charcoal, sans-serif', |
| 119 |
"'Lucida Sans Unicode', 'Lucida Grande', sans-serif", |
| 120 |
'Tahoma, Geneva, sans-serif', |
| 121 |
"'Trebuchet MS', Helvetica, sans-serif'", |
| 122 |
'Verdana, Geneva, sans-serif', |
| 123 |
"'Courier New', Courier, monospace", |
| 124 |
"'Lucida Console', Monaco, monospace", |
| 125 |
'Georgia, serif', |
| 126 |
'Palatino Linotype', |
| 127 |
] |
| 128 |
), |
| 129 |
'backup-font-family', |
| 130 |
esc_html__( 'Default', 'adminify' ) |
| 131 |
) |
| 132 |
); |
| 133 |
echo '</div>'; |
| 134 |
} |
| 135 |
|
| 136 |
// |
| 137 |
// Font Style and Extra Style Select |
| 138 |
if ( ! empty( $args['font_weight'] ) || ! empty( $args['font_style'] ) ) { |
| 139 |
|
| 140 |
// |
| 141 |
// Font Style Select |
| 142 |
echo '<div class="adminify--block adminify--block-font-style hidden">'; |
| 143 |
echo '<div class="adminify--title">' . esc_html__( 'Font Style', 'adminify' ) . '</div>'; |
| 144 |
echo '<select class="adminify--font-style-select" data-placeholder="Default">'; |
| 145 |
|
| 146 |
if ( ( ! $this->chosen ) ){ |
| 147 |
$typo_options = esc_html__( 'Default', 'adminify' ); |
| 148 |
} else { |
| 149 |
$typo_options = ''; |
| 150 |
} |
| 151 |
echo '<option value="">' . esc_html( $typo_options ). '</option>'; |
| 152 |
|
| 153 |
if ( ! empty( $this->value['font-weight'] ) || ! empty( $this->value['font-style'] ) ) { |
| 154 |
echo '<option value="' . esc_attr( strtolower( $this->value['font-weight'] . $this->value['font-style'] ) ) . '" selected></option>'; |
| 155 |
} |
| 156 |
echo '</select>'; |
| 157 |
echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[font-weight]' ) ) . '" class="adminify--font-weight" value="' . esc_attr( $this->value['font-weight'] ) . '" />'; |
| 158 |
echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[font-style]' ) ) . '" class="adminify--font-style" value="' . esc_attr( $this->value['font-style'] ) . '" />'; |
| 159 |
|
| 160 |
// |
| 161 |
// Extra Font Style Select |
| 162 |
if ( ! empty( $args['extra_styles'] ) ) { |
| 163 |
echo '<div class="adminify--block-extra-styles hidden">'; |
| 164 |
echo ( ! $this->chosen ) ? '<div class="adminify--title">' . esc_html__( 'Load Extra Styles', 'adminify' ) . '</div>' : ''; |
| 165 |
$placeholder = ( $this->chosen ) ? esc_html__( 'Load Extra Styles', 'adminify' ) : esc_html__( 'Default', 'adminify' ); |
| 166 |
echo wp_kses_post( $this->create_select( $this->value['extra-styles'], 'extra-styles', $placeholder, true ) ); |
| 167 |
echo '</div>'; |
| 168 |
} |
| 169 |
|
| 170 |
echo '</div>'; |
| 171 |
} |
| 172 |
|
| 173 |
// |
| 174 |
// Subset |
| 175 |
if ( ! empty( $args['subset'] ) ) { |
| 176 |
echo '<div class="adminify--block adminify--block-subset hidden">'; |
| 177 |
echo '<div class="adminify--title">' . esc_html__( 'Subset', 'adminify' ) . '</div>'; |
| 178 |
$subset = ( is_array( $this->value['subset'] ) ) ? $this->value['subset'] : array_filter( (array) $this->value['subset'] ); |
| 179 |
echo wp_kses_post( $this->create_select( $subset, 'subset', esc_html__( 'Default', 'adminify' ), $args['multi_subset'] ) ); |
| 180 |
echo '</div>'; |
| 181 |
} |
| 182 |
|
| 183 |
// |
| 184 |
// Text Align |
| 185 |
if ( ! empty( $args['text_align'] ) ) { |
| 186 |
echo '<div class="adminify--block">'; |
| 187 |
echo '<div class="adminify--title">' . esc_html__( 'Text Align', 'adminify' ) . '</div>'; |
| 188 |
echo wp_kses_post( |
| 189 |
$this->create_select( |
| 190 |
[ |
| 191 |
'inherit' => esc_html__( 'Inherit', 'adminify' ), |
| 192 |
'left' => esc_html__( 'Left', 'adminify' ), |
| 193 |
'center' => esc_html__( 'Center', 'adminify' ), |
| 194 |
'right' => esc_html__( 'Right', 'adminify' ), |
| 195 |
'justify' => esc_html__( 'Justify', 'adminify' ), |
| 196 |
'initial' => esc_html__( 'Initial', 'adminify' ), |
| 197 |
], |
| 198 |
'text-align', |
| 199 |
esc_html__( 'Default', 'adminify' ) |
| 200 |
) |
| 201 |
); |
| 202 |
echo '</div>'; |
| 203 |
} |
| 204 |
|
| 205 |
// |
| 206 |
// Font Variant |
| 207 |
if ( ! empty( $args['font_variant'] ) ) { |
| 208 |
echo '<div class="adminify--block">'; |
| 209 |
echo '<div class="adminify--title">' . esc_html__( 'Font Variant', 'adminify' ) . '</div>'; |
| 210 |
echo wp_kses_post( |
| 211 |
$this->create_select( |
| 212 |
[ |
| 213 |
'normal' => esc_html__( 'Normal', 'adminify' ), |
| 214 |
'small-caps' => esc_html__( 'Small Caps', 'adminify' ), |
| 215 |
'all-small-caps' => esc_html__( 'All Small Caps', 'adminify' ), |
| 216 |
], |
| 217 |
'font-variant', |
| 218 |
esc_html__( 'Default', 'adminify' ) |
| 219 |
) |
| 220 |
); |
| 221 |
echo '</div>'; |
| 222 |
} |
| 223 |
|
| 224 |
// |
| 225 |
// Text Transform |
| 226 |
if ( ! empty( $args['text_transform'] ) ) { |
| 227 |
echo '<div class="adminify--block">'; |
| 228 |
echo '<div class="adminify--title">' . esc_html__( 'Text Transform', 'adminify' ) . '</div>'; |
| 229 |
echo wp_kses_post( |
| 230 |
$this->create_select( |
| 231 |
[ |
| 232 |
'none' => esc_html__( 'None', 'adminify' ), |
| 233 |
'capitalize' => esc_html__( 'Capitalize', 'adminify' ), |
| 234 |
'uppercase' => esc_html__( 'Uppercase', 'adminify' ), |
| 235 |
'lowercase' => esc_html__( 'Lowercase', 'adminify' ), |
| 236 |
], |
| 237 |
'text-transform', |
| 238 |
esc_html__( 'Default', 'adminify' ) |
| 239 |
) |
| 240 |
); |
| 241 |
echo '</div>'; |
| 242 |
} |
| 243 |
|
| 244 |
// |
| 245 |
// Text Decoration |
| 246 |
if ( ! empty( $args['text_decoration'] ) ) { |
| 247 |
echo '<div class="adminify--block">'; |
| 248 |
echo '<div class="adminify--title">' . esc_html__( 'Text Decoration', 'adminify' ) . '</div>'; |
| 249 |
echo wp_kses_post( |
| 250 |
$this->create_select( |
| 251 |
[ |
| 252 |
'none' => esc_html__( 'None', 'adminify' ), |
| 253 |
'underline' => esc_html__( 'Solid', 'adminify' ), |
| 254 |
'underline double' => esc_html__( 'Double', 'adminify' ), |
| 255 |
'underline dotted' => esc_html__( 'Dotted', 'adminify' ), |
| 256 |
'underline dashed' => esc_html__( 'Dashed', 'adminify' ), |
| 257 |
'underline wavy' => esc_html__( 'Wavy', 'adminify' ), |
| 258 |
'underline overline' => esc_html__( 'Overline', 'adminify' ), |
| 259 |
'line-through' => esc_html__( 'Line-through', 'adminify' ), |
| 260 |
], |
| 261 |
'text-decoration', |
| 262 |
esc_html__( 'Default', 'adminify' ) |
| 263 |
) |
| 264 |
); |
| 265 |
echo '</div>'; |
| 266 |
} |
| 267 |
|
| 268 |
echo '</div>'; |
| 269 |
|
| 270 |
echo '<div class="adminify--blocks adminify--blocks-inputs">'; |
| 271 |
|
| 272 |
// |
| 273 |
// Font Size |
| 274 |
if ( ! empty( $args['font_size'] ) ) { |
| 275 |
echo '<div class="adminify--block">'; |
| 276 |
echo '<div class="adminify--title">' . esc_html__( 'Font Size', 'adminify' ) . '</div>'; |
| 277 |
echo '<div class="adminify--input-wrap">'; |
| 278 |
echo '<input type="number" name="' . esc_attr( $this->field_name( '[font-size]' ) ) . '" class="adminify--font-size adminify--input adminify-input-number" value="' . esc_attr( $this->value['font-size'] ) . '" step="any" />'; |
| 279 |
echo '<span class="adminify--unit">' . esc_attr( $args['unit'] ) . '</span>'; |
| 280 |
echo '</div>'; |
| 281 |
echo '</div>'; |
| 282 |
} |
| 283 |
|
| 284 |
// |
| 285 |
// Line Height |
| 286 |
if ( ! empty( $args['line_height'] ) ) { |
| 287 |
echo '<div class="adminify--block">'; |
| 288 |
echo '<div class="adminify--title">' . esc_html__( 'Line Height', 'adminify' ) . '</div>'; |
| 289 |
echo '<div class="adminify--input-wrap">'; |
| 290 |
echo '<input type="number" name="' . esc_attr( $this->field_name( '[line-height]' ) ) . '" class="adminify--line-height adminify--input adminify-input-number" value="' . esc_attr( $this->value['line-height'] ) . '" step="any" />'; |
| 291 |
echo '<span class="adminify--unit">' . esc_attr( $line_height_unit ) . '</span>'; |
| 292 |
echo '</div>'; |
| 293 |
echo '</div>'; |
| 294 |
} |
| 295 |
|
| 296 |
// |
| 297 |
// Letter Spacing |
| 298 |
if ( ! empty( $args['letter_spacing'] ) ) { |
| 299 |
echo '<div class="adminify--block">'; |
| 300 |
echo '<div class="adminify--title">' . esc_html__( 'Letter Spacing', 'adminify' ) . '</div>'; |
| 301 |
echo '<div class="adminify--input-wrap">'; |
| 302 |
echo '<input type="number" name="' . esc_attr( $this->field_name( '[letter-spacing]' ) ) . '" class="adminify--letter-spacing adminify--input adminify-input-number" value="' . esc_attr( $this->value['letter-spacing'] ) . '" step="any" />'; |
| 303 |
echo '<span class="adminify--unit">' . esc_attr( $args['unit'] ) . '</span>'; |
| 304 |
echo '</div>'; |
| 305 |
echo '</div>'; |
| 306 |
} |
| 307 |
|
| 308 |
// |
| 309 |
// Word Spacing |
| 310 |
if ( ! empty( $args['word_spacing'] ) ) { |
| 311 |
echo '<div class="adminify--block">'; |
| 312 |
echo '<div class="adminify--title">' . esc_html__( 'Word Spacing', 'adminify' ) . '</div>'; |
| 313 |
echo '<div class="adminify--input-wrap">'; |
| 314 |
echo '<input type="number" name="' . esc_attr( $this->field_name( '[word-spacing]' ) ) . '" class="adminify--word-spacing adminify--input adminify-input-number" value="' . esc_attr( $this->value['word-spacing'] ) . '" step="any" />'; |
| 315 |
echo '<span class="adminify--unit">' . esc_attr( $args['unit'] ) . '</span>'; |
| 316 |
echo '</div>'; |
| 317 |
echo '</div>'; |
| 318 |
} |
| 319 |
|
| 320 |
echo '</div>'; |
| 321 |
|
| 322 |
// |
| 323 |
// Font Color |
| 324 |
if ( ! empty( $args['color'] ) ) { |
| 325 |
$default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="' . esc_attr( $default_value['color'] ) . '"' : ''; |
| 326 |
echo '<div class="adminify--block adminify--block-font-color">'; |
| 327 |
echo '<div class="adminify--title">' . esc_html__( 'Font Color', 'adminify' ) . '</div>'; |
| 328 |
echo '<div class="adminify-field-color">'; |
| 329 |
echo '<input type="text" name="' . esc_attr( $this->field_name( '[color]' ) ) . '" class="adminify-color adminify--color" value="' . esc_attr( $this->value['color'] ) . '"' . esc_attr( $default_color_attr ) . ' />'; |
| 330 |
echo '</div>'; |
| 331 |
echo '</div>'; |
| 332 |
} |
| 333 |
|
| 334 |
// |
| 335 |
// Custom style |
| 336 |
if ( ! empty( $args['custom_style'] ) ) { |
| 337 |
echo '<div class="adminify--block adminify--block-custom-style">'; |
| 338 |
echo '<div class="adminify--title">' . esc_html__( 'Custom Style', 'adminify' ) . '</div>'; |
| 339 |
echo '<textarea name="' . esc_attr( $this->field_name( '[custom-style]' ) ) . '" class="adminify--custom-style">' . esc_attr( $this->value['custom-style'] ) . '</textarea>'; |
| 340 |
echo '</div>'; |
| 341 |
} |
| 342 |
|
| 343 |
// |
| 344 |
// Preview |
| 345 |
$always_preview = ( $args['preview'] !== 'always' ) ? ' hidden' : ''; |
| 346 |
|
| 347 |
if ( ! empty( $args['preview'] ) ) { |
| 348 |
echo '<div class="adminify--block adminify--block-preview' . esc_attr( $always_preview ) . '">'; |
| 349 |
echo '<div class="adminify--toggle fas fa-toggle-off"></div>'; |
| 350 |
echo '<div class="adminify--preview">' . esc_attr( $args['preview_text'] ) . '</div>'; |
| 351 |
echo '</div>'; |
| 352 |
} |
| 353 |
|
| 354 |
echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[type]' ) ) . '" class="adminify--type" value="' . esc_attr( $this->value['type'] ) . '" />'; |
| 355 |
echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[unit]' ) ) . '" class="adminify--unit-save" value="' . esc_attr( $args['unit'] ) . '" />'; |
| 356 |
|
| 357 |
echo '</div>'; |
| 358 |
|
| 359 |
echo wp_kses_post( $this->field_after() ); |
| 360 |
} |
| 361 |
|
| 362 |
public function create_select( $options, $name, $placeholder = '', $is_multiple = false ) { |
| 363 |
$multiple_name = ( $is_multiple ) ? '[]' : ''; |
| 364 |
$multiple_attr = ( $is_multiple ) ? ' multiple data-multiple="true"' : ''; |
| 365 |
$chosen_rtl = ( $this->chosen && is_rtl() ) ? ' chosen-rtl' : ''; |
| 366 |
|
| 367 |
$output = '<select name="' . esc_attr( $this->field_name( '[' . $name . ']' . $multiple_name ) ) . '" class="adminify--' . esc_attr( $name ) . esc_attr( $chosen_rtl ) . '" data-placeholder="' . esc_attr( $placeholder ) . '"' . $multiple_attr . '>'; |
| 368 |
$output .= ( ! empty( $placeholder ) ) ? '<option value="">' . esc_attr( ( ! $this->chosen ) ? $placeholder : '' ) . '</option>' : ''; |
| 369 |
|
| 370 |
if ( ! empty( $options ) ) { |
| 371 |
foreach ( $options as $option_key => $option_value ) { |
| 372 |
if ( $is_multiple ) { |
| 373 |
$selected = ( in_array( $option_value, $this->value[ $name ] ) ) ? ' selected' : ''; |
| 374 |
$output .= '<option value="' . esc_attr( $option_value ) . '"' . esc_attr( $selected ) . '>' . esc_attr( $option_value ) . '</option>'; |
| 375 |
} else { |
| 376 |
$option_key = ( is_numeric( $option_key ) ) ? $option_value : $option_key; |
| 377 |
$selected = ( $option_key === $this->value[ $name ] ) ? ' selected' : ''; |
| 378 |
$output .= '<option value="' . esc_attr( $option_key ) . '"' . esc_attr( $selected ) . '>' . esc_attr( $option_value ) . '</option>'; |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
$output .= '</select>'; |
| 384 |
|
| 385 |
return $output; |
| 386 |
} |
| 387 |
|
| 388 |
public function enqueue() { |
| 389 |
if ( ! wp_script_is( 'adminify-webfontloader' ) ) { |
| 390 |
ADMINIFY::include_plugin_file( 'fields/typography/google-fonts.php' ); |
| 391 |
|
| 392 |
wp_enqueue_script( 'adminify-webfontloader', 'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js', [ 'adminify' ], '1.6.28', true ); |
| 393 |
|
| 394 |
$webfonts = []; |
| 395 |
|
| 396 |
$customwebfonts = apply_filters( 'adminify_field_typography_customwebfonts', [] ); |
| 397 |
|
| 398 |
if ( ! empty( $customwebfonts ) ) { |
| 399 |
$webfonts['custom'] = [ |
| 400 |
'label' => esc_html__( 'Custom Web Fonts', 'adminify' ), |
| 401 |
'fonts' => $customwebfonts, |
| 402 |
]; |
| 403 |
} |
| 404 |
|
| 405 |
$webfonts['safe'] = [ |
| 406 |
'label' => esc_html__( 'Safe Web Fonts', 'adminify' ), |
| 407 |
'fonts' => apply_filters( |
| 408 |
'adminify_field_typography_safewebfonts', |
| 409 |
[ |
| 410 |
'Arial', |
| 411 |
'Arial Black', |
| 412 |
'Helvetica', |
| 413 |
'Times New Roman', |
| 414 |
'Courier New', |
| 415 |
'Tahoma', |
| 416 |
'Verdana', |
| 417 |
'Impact', |
| 418 |
'Trebuchet MS', |
| 419 |
'Comic Sans MS', |
| 420 |
'Lucida Console', |
| 421 |
'Lucida Sans Unicode', |
| 422 |
'Georgia, serif', |
| 423 |
'Palatino Linotype', |
| 424 |
] |
| 425 |
), |
| 426 |
]; |
| 427 |
|
| 428 |
$webfonts['google'] = [ |
| 429 |
'label' => esc_html__( 'Google Web Fonts', 'adminify' ), |
| 430 |
'fonts' => apply_filters( |
| 431 |
'adminify_field_typography_googlewebfonts', |
| 432 |
adminify_get_google_fonts() |
| 433 |
), |
| 434 |
]; |
| 435 |
|
| 436 |
$defaultstyles = apply_filters( 'adminify_field_typography_defaultstyles', [ 'normal', 'italic', '700', '700italic' ] ); |
| 437 |
|
| 438 |
$googlestyles = apply_filters( |
| 439 |
'adminify_field_typography_googlestyles', |
| 440 |
[ |
| 441 |
'100' => 'Thin 100', |
| 442 |
'100italic' => 'Thin 100 Italic', |
| 443 |
'200' => 'Extra-Light 200', |
| 444 |
'200italic' => 'Extra-Light 200 Italic', |
| 445 |
'300' => 'Light 300', |
| 446 |
'300italic' => 'Light 300 Italic', |
| 447 |
'normal' => 'Normal 400', |
| 448 |
'italic' => 'Normal 400 Italic', |
| 449 |
'500' => 'Medium 500', |
| 450 |
'500italic' => 'Medium 500 Italic', |
| 451 |
'600' => 'Semi-Bold 600', |
| 452 |
'600italic' => 'Semi-Bold 600 Italic', |
| 453 |
'700' => 'Bold 700', |
| 454 |
'700italic' => 'Bold 700 Italic', |
| 455 |
'800' => 'Extra-Bold 800', |
| 456 |
'800italic' => 'Extra-Bold 800 Italic', |
| 457 |
'900' => 'Black 900', |
| 458 |
'900italic' => 'Black 900 Italic', |
| 459 |
] |
| 460 |
); |
| 461 |
|
| 462 |
$webfonts = apply_filters( 'adminify_field_typography_webfonts', $webfonts ); |
| 463 |
|
| 464 |
wp_localize_script( |
| 465 |
'adminify', |
| 466 |
'adminify_typography_json', |
| 467 |
[ |
| 468 |
'webfonts' => $webfonts, |
| 469 |
'defaultstyles' => $defaultstyles, |
| 470 |
'googlestyles' => $googlestyles, |
| 471 |
] |
| 472 |
); |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
public function enqueue_google_fonts( $method = 'enqueue' ) { |
| 477 |
$is_google = false; |
| 478 |
|
| 479 |
if ( ! empty( $this->value['type'] ) ) { |
| 480 |
$is_google = ( $this->value['type'] === 'google' ) ? true : false; |
| 481 |
} else { |
| 482 |
ADMINIFY::include_plugin_file( 'fields/typography/google-fonts.php' ); |
| 483 |
$is_google = ( array_key_exists( $this->value['font-family'], adminify_get_google_fonts() ) ) ? true : false; |
| 484 |
} |
| 485 |
|
| 486 |
if ( $is_google ) { |
| 487 |
|
| 488 |
// set style |
| 489 |
$font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : ''; |
| 490 |
$font_weight = ( ! empty( $this->value['font-weight'] ) ) ? $this->value['font-weight'] : ''; |
| 491 |
$font_style = ( ! empty( $this->value['font-style'] ) ) ? $this->value['font-style'] : ''; |
| 492 |
|
| 493 |
if ( $font_weight || $font_style ) { |
| 494 |
$style = $font_weight . $font_style; |
| 495 |
if ( ! empty( $style ) ) { |
| 496 |
$style = ( $style === 'normal' ) ? '400' : $style; |
| 497 |
ADMINIFY::$webfonts[ $method ][ $font_family ][ $style ] = $style; |
| 498 |
} |
| 499 |
} else { |
| 500 |
ADMINIFY::$webfonts[ $method ][ $font_family ] = []; |
| 501 |
} |
| 502 |
|
| 503 |
// set extra styles |
| 504 |
if ( ! empty( $this->value['extra-styles'] ) ) { |
| 505 |
foreach ( $this->value['extra-styles'] as $extra_style ) { |
| 506 |
if ( ! empty( $extra_style ) ) { |
| 507 |
$extra_style = ( $extra_style === 'normal' ) ? '400' : $extra_style; |
| 508 |
ADMINIFY::$webfonts[ $method ][ $font_family ][ $extra_style ] = $extra_style; |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
// set subsets |
| 514 |
if ( ! empty( $this->value['subset'] ) ) { |
| 515 |
$this->value['subset'] = ( is_array( $this->value['subset'] ) ) ? $this->value['subset'] : array_filter( (array) $this->value['subset'] ); |
| 516 |
foreach ( $this->value['subset'] as $subset ) { |
| 517 |
if ( ! empty( $subset ) ) { |
| 518 |
ADMINIFY::$subsets[ $subset ] = $subset; |
| 519 |
} |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
return true; |
| 524 |
} |
| 525 |
|
| 526 |
return false; |
| 527 |
} |
| 528 |
|
| 529 |
public function output() { |
| 530 |
$output = ''; |
| 531 |
$bg_image = []; |
| 532 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 533 |
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; |
| 534 |
|
| 535 |
$font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : ''; |
| 536 |
$backup_family = ( ! empty( $this->value['backup-font-family'] ) ) ? ', ' . $this->value['backup-font-family'] : ''; |
| 537 |
|
| 538 |
if ( $font_family ) { |
| 539 |
$output .= 'font-family:"' . $font_family . '"' . $backup_family . $important . ';'; |
| 540 |
} |
| 541 |
|
| 542 |
// Common font properties |
| 543 |
$properties = [ |
| 544 |
'color', |
| 545 |
'font-weight', |
| 546 |
'font-style', |
| 547 |
'font-variant', |
| 548 |
'text-align', |
| 549 |
'text-transform', |
| 550 |
'text-decoration', |
| 551 |
]; |
| 552 |
|
| 553 |
foreach ( $properties as $property ) { |
| 554 |
if ( isset( $this->value[ $property ] ) && $this->value[ $property ] !== '' ) { |
| 555 |
$output .= $property . ':' . $this->value[ $property ] . $important . ';'; |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
$properties = [ |
| 560 |
'font-size', |
| 561 |
'line-height', |
| 562 |
'letter-spacing', |
| 563 |
'word-spacing', |
| 564 |
]; |
| 565 |
|
| 566 |
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px'; |
| 567 |
$line_height_unit = ( ! empty( $this->value['line_height_unit'] ) ) ? $this->value['line_height_unit'] : $unit; |
| 568 |
|
| 569 |
foreach ( $properties as $property ) { |
| 570 |
if ( isset( $this->value[ $property ] ) && $this->value[ $property ] !== '' ) { |
| 571 |
$unit = ( $property === 'line-height' ) ? $line_height_unit : $unit; |
| 572 |
$output .= $property . ':' . $this->value[ $property ] . $unit . $important . ';'; |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
$custom_style = ( ! empty( $this->value['custom-style'] ) ) ? $this->value['custom-style'] : ''; |
| 577 |
|
| 578 |
if ( $output ) { |
| 579 |
$output = $element . '{' . $output . $custom_style . '}'; |
| 580 |
} |
| 581 |
|
| 582 |
$this->parent->output_css .= $output; |
| 583 |
|
| 584 |
return $output; |
| 585 |
} |
| 586 |
|
| 587 |
} |
| 588 |
} |
| 589 |
|