1+ <?php
2+
3+ namespace Solid ;
4+
5+ class DisplayConditionSolidDynamicsMacro extends \ElementorPro \Modules \DisplayConditions \Conditions \Base \Condition_Base {
6+ public function get_name () {
7+ return 'solid_dynamics_macro ' ;
8+ }
9+
10+ public function get_label () {
11+ return esc_html__ ( 'Solid Dynamics Macro ' , 'solid-dynamics ' );
12+ }
13+
14+ public function get_group () {
15+ return 'other ' ;
16+ }
17+
18+ public function check ( $ args ) : bool {
19+ $ value = solid_dynamics_macro ($ args ['macro ' ]);
20+ return boolval ($ value );
21+ }
22+
23+ public function get_options () {
24+ $ this ->add_control (
25+ 'macro ' ,
26+ [
27+ 'label ' => __ ( 'Macro ' , 'solid-dynamics ' ),
28+ 'type ' => \Elementor \Controls_Manager::TEXT ,
29+ ]
30+ );
31+ }
32+ }
33+
34+ function solid_dynamics_macro ($ macro ) {
35+ $ items = explode ('| ' , $ macro );
36+ $ type = $ items [0 ] ?? '' ;
37+ $ field = $ items [1 ] ?? '' ;
38+ $ meta_key = $ items [2 ] ?? '' ;
39+
40+ // TODO: add index for repeater fields.
41+ // $index = $items[3];
42+
43+ if (empty ($ type ) || empty ($ field )) {
44+ return ;
45+ }
46+
47+ switch ($ type ) {
48+ case 'post ' :
49+ global $ post ;
50+
51+ if ($ field === 'meta ' && !empty ($ meta_key )) {
52+ return get_post_meta ($ post ->ID , $ meta_key , true );
53+ }
54+
55+ return $ post ->$ field ;
56+ case 'user ' :
57+ $ user = wp_get_current_user ();
58+
59+ if ($ field === 'meta ' && !empty ($ meta_key )) {
60+ return get_user_meta ($ user ->ID , $ meta_key , true );
61+ }
62+
63+ return $ user ->$ field ;
64+ case 'function ' :
65+ $ function_name = $ field ;
66+
67+ if (is_callable ($ function_name )) {
68+ return $ function_name ();
69+ };
70+
71+ return ;
72+ // TODO: add option
73+ // case 'option':
74+ // $option = get_option($field);
75+ // return $option;
76+ // TODO: add author
77+ // case 'author':
78+ // $author = get_queried_object();
79+ // return $author->name;
80+ // TODO: add term
81+ // case 'term':
82+ // $term = get_queried_object();
83+ // return $term->name;
84+ }
85+ }
0 commit comments