1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LSX Health Plan Plan specific functions. |
4
|
|
|
* |
5
|
|
|
* @package lsx-health-plan |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace lsx_health_plan\functions\plan; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Return a true or false if the search is enabled. |
12
|
|
|
* |
13
|
|
|
* @return boolean |
14
|
|
|
*/ |
15
|
|
|
function is_search_enabled() { |
|
|
|
|
16
|
|
|
$enabled = false; |
17
|
|
|
if ( function_exists( 'lsx_search' ) ) { |
|
|
|
|
18
|
|
|
$search_instance = \LSX_Search::get_instance(); |
|
|
|
|
19
|
|
|
if ( null !== $search_instance ) { |
|
|
|
|
20
|
|
|
$enabled = $search_instance->frontend->is_search_enabled(); |
21
|
|
|
} |
22
|
|
|
} |
|
|
|
|
23
|
|
|
return $enabled; |
24
|
|
|
} |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Return a true or false if the search if the plan has sections. |
28
|
|
|
* |
29
|
|
|
* @param integer $plan_id |
|
|
|
|
30
|
|
|
* @return boolean |
31
|
|
|
*/ |
32
|
|
|
function has_sections( $plan_id = 0 ) { |
33
|
|
|
$sections = false; |
34
|
|
|
if ( 0 === $plan_id ) { |
|
|
|
|
35
|
|
|
$plan_id = get_the_ID(); |
36
|
|
|
} |
|
|
|
|
37
|
|
|
$lsx_hp = lsx_health_plan(); |
38
|
|
|
$sections = $lsx_hp->frontend->plan_query->query_sections( $plan_id ); |
39
|
|
|
return $sections; |
40
|
|
|
} |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns the sections for a plan |
44
|
|
|
* |
45
|
|
|
* @param integer $plan_id |
|
|
|
|
46
|
|
|
* @param boolean $group_sections |
|
|
|
|
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
function get_sections( $group_sections = false ) { |
50
|
|
|
$lsx_hp = lsx_health_plan(); |
51
|
|
|
$sections = $lsx_hp->frontend->plan_query->get_sections( $group_sections ); |
52
|
|
|
return $sections; |
53
|
|
|
} |
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Gets the current sections array values. |
57
|
|
|
* |
58
|
|
|
* @param string $section_key |
|
|
|
|
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
function get_section_info( $section_key = '' ) { |
62
|
|
|
$section_info = array(); |
63
|
|
|
|
64
|
|
|
$sections = get_sections(); |
65
|
|
|
if ( ! empty( $sections ) ) { |
|
|
|
|
66
|
|
|
foreach ( $sections as $key => $values ) { |
|
|
|
|
67
|
|
|
$current_key = sanitize_title( $values['title'] ); |
68
|
|
|
if ( $current_key === $section_key ) { |
|
|
|
|
69
|
|
|
return $values; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
|
|
|
|
73
|
|
|
return $section_info; |
74
|
|
|
} |
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* This will group title from the first section item. |
78
|
|
|
* |
79
|
|
|
* @param array $sections |
|
|
|
|
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
function get_group_title( $sections = array() ) { |
83
|
|
|
$group_title = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) ); |
84
|
|
|
if ( ! empty( $sections ) ) { |
|
|
|
|
85
|
|
|
$first_section = reset( $sections ); |
86
|
|
|
if ( isset( $first_section['group'] ) && '' !== $first_section['group'] ) { |
|
|
|
|
87
|
|
|
$group_title = $first_section['group']; |
88
|
|
|
} |
89
|
|
|
} |
|
|
|
|
90
|
|
|
return $group_title; |
91
|
|
|
} |
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the sections for a plan |
95
|
|
|
* |
96
|
|
|
* @param integer $plan_id |
|
|
|
|
97
|
|
|
* @param string $title |
|
|
|
|
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
|
function get_permalink( $plan_id = 0, $title = '' ) { |
101
|
|
|
if ( 0 === $plan_id ) { |
|
|
|
|
102
|
|
|
$plan_id = get_the_ID(); |
103
|
|
|
} |
|
|
|
|
104
|
|
|
$url = \get_permalink( $plan_id ); |
|
|
|
|
105
|
|
|
if ( '' !== $title ) { |
|
|
|
|
106
|
|
|
$url .= sanitize_title( $title ) . '/'; |
107
|
|
|
} |
|
|
|
|
108
|
|
|
return $url; |
109
|
|
|
} |
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
|
|
|
|
112
|
|
|
* Return a true or false if the search is enabled. |
113
|
|
|
* |
114
|
|
|
* @return boolean |
115
|
|
|
*/ |
116
|
|
|
function is_filters_disabled( $disabled = false ) { |
117
|
|
|
$is_disabled = \lsx_health_plan\functions\get_option( 'plan_filters_disabled', false ); |
118
|
|
|
if ( false !== $is_disabled ) { |
|
|
|
|
119
|
|
|
$disabled = true; |
120
|
|
|
} |
|
|
|
|
121
|
|
|
return $disabled; |
122
|
|
|
} |
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Generates a unique ID for the current section item you are viewing, e.g Day 1 of Week 1. |
126
|
|
|
* Can only be used on the single plan pages and endpoints. |
127
|
|
|
* |
128
|
|
|
* @param string $section_key |
|
|
|
|
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
|
|
function generate_section_id( $section_key = '' ) { |
132
|
|
|
$key = get_the_ID(); |
|
|
|
|
133
|
|
|
if ( '' === $section_key ) { |
|
|
|
|
134
|
|
|
$section_key = get_query_var( 'section' ); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$section_key = sanitize_title( $section_key ); |
138
|
|
|
|
139
|
|
|
if ( '' !== $section_key && \lsx_health_plan\functions\plan\has_sections() ) { |
|
|
|
|
140
|
|
|
$group_title = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) ); |
141
|
|
|
$section_info = \lsx_health_plan\functions\plan\get_section_info( $section_key ); |
142
|
|
|
$key .= '_' . sanitize_key( $group_title ) . '_' . sanitize_key( $section_info['title'] ); |
143
|
|
|
} |
|
|
|
|
144
|
|
|
return $key; |
145
|
|
|
} |
|
|
|
|
146
|
|
|
|