class-learndash-ld-usermeta.php
1.82 KB
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
<?php
/**
* Process the block.
*
* @file
* @package Learndash_Certificate_Builer
*/
namespace LearnDash_Certificate_Builder\Component\Builder\Pdf\Blocks;
/**
* Class Learndash_Ld_Usermeta
*
* @package LearnDash_Certificate_Builder\Component\Builder\Pdf\Blocks
*/
class Learndash_Ld_Usermeta extends Block {
/**
* Trigger
*/
public function run() {
$el = sprintf( '<div id="%s">' . render_block( $this->block ) . '</div>', $this->block['id'] );
$this->html->add( $el );
$this->build_style();
}
/**
* Loop through attributes and build the style.
*/
protected function build_style() {
foreach ( $this->block['attrs'] as $key => $val ) {
switch ( $key ) {
case 'font':
if ( isset( $attrs['useFont'] ) && true === $attrs['useFont'] ) {
$this->style->add( $this->block['id'], 'font-family', "'$val'" );
}
break;
case 'fontSize':
if ( filter_var( $val, FILTER_VALIDATE_INT ) || filter_var( $val, FILTER_VALIDATE_FLOAT ) ) {
$this->style->add( $this->block['id'], 'font-size', "{$val}px" );
} else {
$this->style->add( $this->block['id'], 'font-size', "{$val}" );
}
break;
case 'textColor':
$this->style->add( $this->block['id'], 'color', "{$val}" );
break;
case 'backgroundColor':
$this->style->add( $this->block['id'], 'background-color', "{$val}" );
break;
default:
$key = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $key ) );
$this->style->add( $this->block['id'], $key, $val );
break;
}
}
if ( isset( $this->block['attrs']['useFont'] ) && true === $this->block['attrs']['useFont'] ) {
$this->style->add( $this->block['id'], 'font-family', $this->block['attrs']['font'] );
}
if ( ! isset( $this->block['attrs']['fontSize'] ) ) {
$this->style->add( $this->block['id'], 'font-size', '20px' );
}
}
}