Skip to content

Commit 1ad65c1

Browse files
committed
simplify field
1 parent 9d77347 commit 1ad65c1

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

classes/display-condition-solid-dynamics-macro.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ function solid_dynamics_macro($macro) {
3535
$items = explode('|', $macro);
3636
$type = $items[0] ?? '';
3737
$field = $items[1] ?? '';
38-
$meta_key = $items[2] ?? '';
3938

4039
// TODO: add index for repeater fields.
41-
// $index = $items[3];
40+
// $index = $items[2];
4241

4342
if (empty($type) || empty($field)) {
4443
return;
@@ -48,24 +47,23 @@ function solid_dynamics_macro($macro) {
4847
case 'post':
4948
global $post;
5049

51-
if ($field === 'meta' && !empty($meta_key)) {
52-
return get_post_meta($post->ID, $meta_key, true);
50+
if ($post->$field !== null) {
51+
return $post->$field;
5352
}
5453

55-
return $post->$field;
54+
return get_post_meta($post->ID, $field, true);
5655
case 'user':
5756
$user = wp_get_current_user();
5857

59-
if ($field === 'meta' && !empty($meta_key)) {
60-
return get_user_meta($user->ID, $meta_key, true);
58+
if ($user->$field !== null) {
59+
return $user->$field;
6160
}
6261

63-
return $user->$field;
64-
case 'function':
65-
$function_name = $field;
62+
return get_user_meta($user->ID, $field, true);
6663

67-
if (is_callable($function_name)) {
68-
return $function_name();
64+
case 'function':
65+
if (is_callable($field)) {
66+
return $field();
6967
};
7068

7169
return;

classes/post-field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function _register_controls() {
2626
$this->add_control(
2727
'fieldname',
2828
[
29-
'label' => __( 'Callback', 'solid-dynamics' ),
29+
'label' => __( 'Post Field', 'solid-dynamics' ),
3030
'type' => \Elementor\Controls_Manager::TEXT,
3131
]
3232
);

0 commit comments

Comments
 (0)