1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Flatsome; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
7
|
|
|
|
8
|
|
|
abstract class FlatsomeShortcode |
9
|
|
|
{ |
10
|
|
|
abstract public function options(): array; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Override the "add_ux_builder_shortcode" data with |
14
|
|
|
* the "ux_builder_shortcode_data_{$tag}" filter hook. |
15
|
|
|
*/ |
16
|
|
|
public function register(): void |
17
|
|
|
{ |
18
|
|
|
add_shortcode($this->uxShortcode(), [$this, 'renderShortcode']); |
19
|
|
|
add_action('ux_builder_setup', function () { |
20
|
|
|
add_ux_builder_shortcode($this->uxShortcode(), [ |
|
|
|
|
21
|
|
|
'category' => glsr()->name, |
22
|
|
|
'name' => $this->name(), |
23
|
|
|
'options' => $this->options(), |
24
|
|
|
'thumbnail' => $this->icon(), |
25
|
|
|
'wrap' => false, |
26
|
|
|
]); |
27
|
|
|
}); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param array|string $atts |
32
|
|
|
*/ |
33
|
|
|
public function renderShortcode($atts = []): string |
34
|
|
|
{ |
35
|
|
|
$args = wp_parse_args($atts); |
36
|
|
|
$hide = []; |
37
|
|
|
foreach ($atts as $key => $value) { |
38
|
|
|
if (str_starts_with((string) $key, 'hide_') && Cast::toBool($value)) { |
39
|
|
|
$hide[] = substr($key, 5); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
$args['hide'] = array_filter($hide); |
43
|
|
|
if (!empty($args['visibility'])) { |
44
|
|
|
$args['class'] = ($args['class'] ?? '').' '.$args['visibility']; |
45
|
|
|
} |
46
|
|
|
return $this->shortcode()->build($args, 'flatsome'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
abstract protected function icon(): string; |
50
|
|
|
|
51
|
|
|
abstract protected function name(): string; |
52
|
|
|
|
53
|
|
|
protected function hideOptions(): array |
54
|
|
|
{ |
55
|
|
|
$options = []; |
56
|
|
|
foreach ($this->shortcode()->getHideOptions() as $key => $label) { |
57
|
|
|
$options["hide_{$key}"] = [ |
58
|
|
|
'heading' => $label, |
59
|
|
|
'type' => 'checkbox', |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
return $options; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
abstract protected function shortcode(): ShortcodeContract; |
66
|
|
|
|
67
|
|
|
protected function typeOptions(): array |
68
|
|
|
{ |
69
|
|
|
$types = glsr()->retrieveAs('array', 'review_types', []); |
70
|
|
|
if (2 > count($types)) { |
71
|
|
|
return []; |
72
|
|
|
} |
73
|
|
|
return [ |
74
|
|
|
'type' => 'select', |
75
|
|
|
'heading' => esc_html_x('Limit Reviews by Type', 'admin-text', 'site-reviews'), |
76
|
|
|
'full_width' => true, |
77
|
|
|
'default' => 'local', |
78
|
|
|
'options' => $types, |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
protected function uxShortcode(): string |
83
|
|
|
{ |
84
|
|
|
return "ux_{$this->shortcode()->shortcode}"; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|