|
1
|
|
|
<?php |
|
2
|
|
|
namespace lsx_health_plan\classes\frontend; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Holds the functions and actions which are shared accross the post types. |
|
6
|
|
|
* |
|
7
|
|
|
* @package lsx-health-plan |
|
8
|
|
|
*/ |
|
9
|
|
|
class General { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Holds class instance |
|
13
|
|
|
* |
|
14
|
|
|
* @since 1.0.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @var object \lsx_health_plan\classes\frontend\General() |
|
17
|
|
|
*/ |
|
18
|
|
|
protected static $instance = null; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Contructor |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct() { |
|
24
|
|
|
// Before Output. |
|
25
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
26
|
|
|
add_filter( 'wp_kses_allowed_html', array( $this, 'allow_html_tags_attributes' ), 100, 2 ); |
|
27
|
|
|
|
|
28
|
|
|
// Output. |
|
29
|
|
|
add_action( 'body_class', array( $this, 'body_classes' ) ); |
|
30
|
|
|
add_filter( 'lsx_global_header_title', array( $this, 'single_title' ), 200, 1 ); |
|
31
|
|
|
add_action( 'wp_head', array( $this, 'remove_single_footer' ), 99 ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Return an instance of this class. |
|
36
|
|
|
* |
|
37
|
|
|
* @since 1.0.0 |
|
38
|
|
|
* |
|
39
|
|
|
* @return object \lsx_health_plan\classes\frontend\General() A single instance of this class. |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function get_instance() { |
|
42
|
|
|
// If the single instance hasn't been set, set it now. |
|
43
|
|
|
if ( null === self::$instance ) { |
|
44
|
|
|
self::$instance = new self(); |
|
45
|
|
|
} |
|
46
|
|
|
return self::$instance; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Registers the plugin frontend assets |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
|
public function assets() { |
|
55
|
|
|
|
|
56
|
|
|
if ( is_post_type_archive( 'plan' ) && false === \lsx_health_plan\functions\plan\is_filters_disabled() ) { |
|
57
|
|
|
wp_enqueue_script( 'isotope', LSX_HEALTH_PLAN_URL . 'assets/js/vendor/isotope.pkgd.min.js', array( 'jquery' ), null, LSX_HEALTH_PLAN_URL, true ); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
wp_enqueue_style( 'lsx-health-plan', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan.css', array(), LSX_HEALTH_PLAN_VER ); |
|
61
|
|
|
wp_style_add_data( 'lsx-health-plan', 'rtl', 'replace' ); |
|
62
|
|
|
wp_enqueue_script( 'lsx-health-plan-scripts', LSX_HEALTH_PLAN_URL . 'assets/js/src/lsx-health-plan-admin.js', array( 'jquery' ) ); |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Adds the iframe and the progress HTML tags to the allowed WordPress list. |
|
68
|
|
|
*/ |
|
69
|
|
|
public function allow_html_tags_attributes( $tags, $context ) { |
|
70
|
|
|
if ( 'post' === $context ) { |
|
71
|
|
|
$tags['iframe'] = array( |
|
72
|
|
|
'src' => true, |
|
73
|
|
|
'height' => true, |
|
74
|
|
|
'width' => true, |
|
75
|
|
|
'frameborder' => true, |
|
76
|
|
|
'allowfullscreen' => true, |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
$tags['progress'] = array( |
|
80
|
|
|
'id' => true, |
|
81
|
|
|
'value' => true, |
|
82
|
|
|
'max' => true, |
|
83
|
|
|
); |
|
84
|
|
|
return $tags; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Add body classes to body. |
|
89
|
|
|
* |
|
90
|
|
|
* @param array $classes |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
93
|
|
|
public function body_classes( $classes = array() ) { |
|
94
|
|
|
global $post; |
|
95
|
|
|
|
|
96
|
|
|
if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'lsx_health_plan_my_profile_block' ) ) { |
|
97
|
|
|
$classes[] = 'my-plan-shortcode'; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if ( is_single() && is_singular( 'plan' ) ) { |
|
101
|
|
|
$args = array( |
|
102
|
|
|
'post_parent' => get_the_ID(), |
|
103
|
|
|
'post_type' => 'plan', |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$post_id = get_the_ID(); |
|
107
|
|
|
$has_children = get_children( $args ); |
|
108
|
|
|
$has_parent = wp_get_post_parent_id( $post_id ); |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
if ( ! empty( $has_children ) ) { |
|
111
|
|
|
$plan_type_class = 'parent-plan-page'; |
|
112
|
|
|
if ( 0 !== $has_parent ) { |
|
113
|
|
|
$plan_type_class = 'parent-sub-plan-page'; |
|
114
|
|
|
} |
|
115
|
|
|
} else { |
|
116
|
|
|
$plan_type_class = 'unique-plan-page'; |
|
117
|
|
|
if ( 0 !== $has_parent ) { |
|
118
|
|
|
$plan_type_class = 'child-plan-page'; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
$classes[] = $plan_type_class; |
|
122
|
|
|
} |
|
123
|
|
|
return $classes; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Remove the single recipe and exercise title |
|
128
|
|
|
*/ |
|
129
|
|
|
public function single_title( $title ) { |
|
130
|
|
|
|
|
131
|
|
|
if ( is_single() && is_singular( 'recipe' ) ) { |
|
132
|
|
|
|
|
133
|
|
|
$title = __( 'Recipe', 'lsx-health-plan' ); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
if ( is_single() && is_singular( 'exercise' ) ) { |
|
137
|
|
|
|
|
138
|
|
|
$title = __( 'Exercise', 'lsx-health-plan' ); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return $title; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Removing footer for HP single pages. |
|
146
|
|
|
* |
|
147
|
|
|
* @return void |
|
148
|
|
|
*/ |
|
149
|
|
|
public function remove_single_footer() { |
|
150
|
|
|
if ( is_single() && is_singular( array( 'exercise', 'recipe', 'workout', 'meal' ) ) ) { |
|
151
|
|
|
remove_action( 'lsx_footer_before', 'lsx_add_footer_sidebar_area' ); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.