|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\WPBakery\Shortcodes; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Integrations\WPBakery\Transformer; |
|
7
|
|
|
|
|
8
|
|
|
abstract class VcShortcode extends \WPBakeryShortCode |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Override the "vc_map" data with the vc_element_settings_filter ($settings, $shortcode) filter hook. |
|
12
|
|
|
*/ |
|
13
|
|
|
public static function vcRegister(array $args = []): void |
|
14
|
|
|
{ |
|
15
|
|
|
vc_map(wp_parse_args($args, [ |
|
16
|
|
|
'base' => static::vcShortcode()->tag, |
|
17
|
|
|
'category' => glsr()->name, |
|
18
|
|
|
'description' => static::vcShortcode()->description, |
|
19
|
|
|
'icon' => static::vcShortcodeIcon(), |
|
20
|
|
|
'name' => static::vcShortcode()->name, |
|
21
|
|
|
'params' => static::vcShortcodeSettings(), |
|
22
|
|
|
'php_class_name' => static::class, |
|
23
|
|
|
'show_settings_on_create' => false, |
|
24
|
|
|
])); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public static function vcShortcode(): ShortcodeContract |
|
28
|
|
|
{ |
|
29
|
|
|
return glsr(static::vcShortcodeClass()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
abstract public static function vcShortcodeClass(): string; |
|
33
|
|
|
|
|
34
|
|
|
abstract public static function vcShortcodeIcon(): string; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Override attributes for a setting with the vc_mapper_attribute ($setting, $shortcode) filter hook. |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function vcShortcodeSettings(): array |
|
40
|
|
|
{ |
|
41
|
|
|
$controls = array_merge( |
|
42
|
|
|
static::vcSettingsConfig(), |
|
43
|
|
|
static::vcStyleConfig() |
|
44
|
|
|
); |
|
45
|
|
|
$shortcode = static::vcShortcode(); |
|
46
|
|
|
$controls = glsr()->filterArray('wpbakery/controls', $controls, $shortcode); |
|
47
|
|
|
$groups = [ // order is intentional |
|
48
|
|
|
'general' => esc_html_x('General', 'admin-text', 'site-reviews'), |
|
49
|
|
|
'design' => esc_html_x('Design', 'admin-text', 'site-reviews'), |
|
50
|
|
|
'advanced' => esc_html_x('Advanced', 'admin-text', 'site-reviews'), |
|
51
|
|
|
]; |
|
52
|
|
|
$groupedcontrols = []; |
|
53
|
|
|
foreach ($controls as $name => $args) { |
|
54
|
|
|
$transformer = new Transformer($name, $args, $shortcode->tag); |
|
55
|
|
|
$control = $transformer->control(); |
|
56
|
|
|
if (empty($control)) { |
|
57
|
|
|
continue; |
|
58
|
|
|
} |
|
59
|
|
|
$group = $control['group']; |
|
60
|
|
|
$groupHeading = $groups[$group]; |
|
61
|
|
|
$control['group'] = $groupHeading; |
|
62
|
|
|
$groupedcontrols[$group] ??= []; |
|
63
|
|
|
$groupedcontrols[$group][$name] = $control; |
|
64
|
|
|
} |
|
65
|
|
|
return array_merge(...array_map('array_values', array_values($groupedcontrols))); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected static function vcSettingsConfig(): array |
|
69
|
|
|
{ |
|
70
|
|
|
$hidden = [ |
|
71
|
|
|
'from' => [ // used to set the "from" attribute |
|
72
|
|
|
'group' => 'advanced', |
|
73
|
|
|
'save_always' => true, |
|
74
|
|
|
'std' => 'wpbakery', |
|
75
|
|
|
'type' => 'hidden', |
|
76
|
|
|
], |
|
77
|
|
|
]; |
|
78
|
|
|
return array_merge(static::vcShortcode()->settings(), $hidden); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
protected static function vcStyleConfig(): array |
|
82
|
|
|
{ |
|
83
|
|
|
return []; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|