Passed
Push — lsx-wp6 ( 4c21d3 )
by
unknown
04:54
created

lsx_tec_global_header_title()   C

Complexity

Conditions 16
Paths 56

Size

Total Lines 45
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 16
eloc 29
nc 56
nop 1
dl 0
loc 45
rs 5.5666
c 1
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * LSX functions and definitions - The Events Calendar.
4
 *
5
 * @package    lsx
6
 * @subpackage the-events-calendar
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
10
	exit;
11
}
12
13
if ( ! function_exists( 'lsx_tec_scripts_add_styles' ) ) :
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
14
15
	/**
16
	 * The Events Calendar enqueue styles.
17
	 *
18
	 * @package    lsx
19
	 * @subpackage the-events-calendar
20
	 */
21
	function lsx_tec_scripts_add_styles() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
22
23
		// Get plugin version.
24
		$plugin  = 'the-events-calendar/the-events-calendar.php';
25
		$data    = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
26
		$version = $data['Version'];
27
28
		if ( substr( $version, 0, 1 ) >= '5' ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
29
			// New Version 5.0 and up.
30
			wp_enqueue_style( 'the-events-calendar-lsx', LSX_CUSTOMIZER_URL . 'assets/css/the-events-calendar/the-events-calendar-5.css', array( 'lsx_main' ), LSX_VERSION );
31
		} else {
32
			// Old Version.
33
			wp_enqueue_style( 'the-events-calendar-lsx', LSX_CUSTOMIZER_URL . 'assets/css/the-events-calendar/the-events-calendar.css', array( 'lsx_main' ), LSX_VERSION );
34
		}
35
36
		wp_enqueue_style( 'the-events-calendar-lsx', LSX_CUSTOMIZER_URL . 'assets/css/the-events-calendar/the-events-calendar.css', array( 'lsx_main' ), LSX_VERSION );
37
		wp_style_add_data( 'the-events-calendar-lsx', 'rtl', 'replace' );
38
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
39
40
	add_action( 'wp_enqueue_scripts', 'lsx_tec_scripts_add_styles' );
41
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
42
endif;
43
44
if ( ! function_exists( 'lsx_tec_theme_wrapper_start' ) ) :
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
45
46
	/**
47
	 * The Events Calendar wrapper start.
48
	 *
49
	 * @package    lsx
50
	 * @subpackage the-events-calendar
51
	 */
52
	function lsx_tec_theme_wrapper_start() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
53
		if ( function_exists( 'lsx_is_rest_api_request' ) && lsx_is_rest_api_request() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
54
			return;
55
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
56
		lsx_content_wrap_before();
57
		echo '<div id="primary" class="content-area ' . esc_attr( lsx_main_class() ) . '">';
58
		lsx_content_before();
59
		echo '<main id="main" class="site-main" role="main">';
60
		lsx_content_top();
61
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
62
63
	add_action( 'tribe_events_before_html', 'lsx_tec_theme_wrapper_start', 9 );
64
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
65
endif;
66
67
if ( ! function_exists( 'lsx_tec_theme_wrapper_end' ) ) :
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
68
69
	/**
70
	 * The Events Calendar wrapper end.
71
	 *
72
	 * @package    lsx
73
	 * @subpackage the-events-calendar
74
	 */
75
	function lsx_tec_theme_wrapper_end() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
76
		if ( function_exists( 'lsx_is_rest_api_request' ) && lsx_is_rest_api_request() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
77
			return;
78
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
79
		lsx_content_bottom();
80
		echo '</main>';
81
		lsx_content_after();
82
		echo '</div>';
83
		lsx_content_wrap_after();
84
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
85
86
	add_action( 'tribe_events_after_html', 'lsx_tec_theme_wrapper_end', 11 );
87
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
88
endif;
89
90
if ( ! function_exists( 'lsx_tec_global_header_title' ) ) :
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
91
92
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$title" missing
Loading history...
93
	 * Move the events title into the global header
94
	 *
95
	 * @package    lsx
96
	 * @subpackage the-events-calendar
97
	 */
98
	function lsx_tec_global_header_title( $title ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
99
100
		if ( tribe_is_community_edit_event_page() ) {
0 ignored issues
show
Bug introduced by
The function tribe_is_community_edit_event_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
		if ( /** @scrutinizer ignore-call */ tribe_is_community_edit_event_page() ) {
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
101
102
			$is_route = get_query_var( 'WP_Route' );
103
			switch ( $is_route ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
104
				case 'ce-edit-route':
105
					$title = apply_filters( 'tribe_ce_edit_event_page_title', __( 'Edit an Event', 'lsx' ) );
106
					break;
107
108
				case 'ce-edit-organizer-route':
109
					$title = __( 'Edit an Organizer', 'lsx' );
110
					break;
111
112
				case 'ce-edit-venue-route':
113
					$title = __( 'Edit a Venue', 'lsx' );
114
					break;
115
116
				default:
117
					$title = apply_filters( 'tribe_ce_submit_event_page_title', __( 'Submit an Event', 'lsx' ) );
118
					break;
119
			}
120
		} elseif ( tribe_is_community_my_events_page() ) {
0 ignored issues
show
Bug introduced by
The function tribe_is_community_my_events_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

120
		} elseif ( /** @scrutinizer ignore-call */ tribe_is_community_my_events_page() ) {
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
121
			$title = apply_filters( 'tribe_ce_submit_event_page_title', __( 'My Events', 'lsx' ) );
122
		} elseif ( tribe_is_event() && ( ! is_tag() ) ) {
0 ignored issues
show
Bug introduced by
The function tribe_is_event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
		} elseif ( /** @scrutinizer ignore-call */ tribe_is_event() && ( ! is_tag() ) ) {
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
123
			$title = tribe_get_events_title();
0 ignored issues
show
Bug introduced by
The function tribe_get_events_title was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

123
			$title = /** @scrutinizer ignore-call */ tribe_get_events_title();
Loading history...
124
		}
125
126
		// Only disable the title after we have retrieved it.
127
		add_filter( 'tribe_get_events_title', 'lsx_text_disable_body_title', 200, 1 );
128
129
		if ( is_singular( 'tribe_events' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
130
			add_filter( 'the_title', 'lsx_text_disable_body_title', 200, 1 );
131
		}
132
133
		if ( class_exists( 'LSX_Banners' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
134
			if ( is_archive() && is_post_type_archive( 'tribe_events' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
135
				$options = get_option( '_lsx_settings', false );
136
				if ( is_array( $options ) && isset( $options['tribe_events'] ) && isset( $options['tribe_events']['title'] ) && '' !== $options['tribe_events']['title'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
137
					$title = $options['tribe_events']['title'];
138
				}
139
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
140
			$title = '<h1 class="page-title">' . $title . '</h1>';
141
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
142
		return $title;
143
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
144
	add_filter( 'lsx_banner_title', 'lsx_tec_global_header_title', 200, 1 );
145
	add_filter( 'lsx_global_header_title', 'lsx_tec_global_header_title', 200, 1 );
146
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
147
endif;
148
149
if ( ! function_exists( 'lsx_text_disable_body_title' ) ) :
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
150
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$title" missing
Loading history...
151
	 * Disable the events title for the post archive if the dynamic setting is active.
152
	 *
153
	 * @param $title
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
154
	 * @return string
155
	 */
156
	function lsx_text_disable_body_title( $title ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
157
		$title = '';
158
		remove_filter( 'the_title', 'lsx_text_disable_body_title', 200, 1 );
0 ignored issues
show
Unused Code introduced by
The call to remove_filter() has too many arguments starting with 1. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

158
		/** @scrutinizer ignore-call */ 
159
  remove_filter( 'the_title', 'lsx_text_disable_body_title', 200, 1 );

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.

Loading history...
159
		return $title;
160
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
161
162
endif;
163
164
if ( ! function_exists( 'lsx_tec_breadcrumb_filter' ) ) :
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
165
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$crumbs" missing
Loading history...
166
	 * Fixes the community events breadcrumb
167
	 *
168
	 * @package    lsx
169
	 * @subpackage the-events-calendar
170
	 */
171
	function lsx_tec_breadcrumb_filter( $crumbs ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
172
173
		if ( tribe_is_venue() || tribe_is_organizer() || tribe_is_community_edit_event_page() || tribe_is_community_my_events_page() ) {
0 ignored issues
show
Bug introduced by
The function tribe_is_community_edit_event_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
		if ( tribe_is_venue() || tribe_is_organizer() || /** @scrutinizer ignore-call */ tribe_is_community_edit_event_page() || tribe_is_community_my_events_page() ) {
Loading history...
Bug introduced by
The function tribe_is_community_my_events_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
		if ( tribe_is_venue() || tribe_is_organizer() || tribe_is_community_edit_event_page() || /** @scrutinizer ignore-call */ tribe_is_community_my_events_page() ) {
Loading history...
Bug introduced by
The function tribe_is_organizer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
		if ( tribe_is_venue() || /** @scrutinizer ignore-call */ tribe_is_organizer() || tribe_is_community_edit_event_page() || tribe_is_community_my_events_page() ) {
Loading history...
Bug introduced by
The function tribe_is_venue was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
		if ( /** @scrutinizer ignore-call */ tribe_is_venue() || tribe_is_organizer() || tribe_is_community_edit_event_page() || tribe_is_community_my_events_page() ) {
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
174
			$new_crumbs    = array();
175
			$new_crumbs[0] = $crumbs[0];
176
177
			if ( function_exists( 'woocommerce_breadcrumb' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
178
				$new_crumbs[1] = array(
179
					0 => __( 'Events', 'lsx' ),
180
					1 => get_post_type_archive_link( 'tribe_events' ),
181
				);
182
			} else {
183
				$new_crumbs[1] = array(
184
					'text' => __( 'Events', 'lsx' ),
185
					'url'  => get_post_type_archive_link( 'tribe_events' ),
186
				);
187
			}
188
189
			if ( tribe_is_community_my_events_page() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
190
				$new_crumbs[2] = $crumbs[2];
191
			} elseif ( tribe_is_community_edit_event_page() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
192
193
				if ( function_exists( 'woocommerce_breadcrumb' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
194
					$new_crumbs[2] = array(
195
						0 => apply_filters( 'tribe_ce_submit_event_page_title', __( 'My Events', 'lsx' ) ),
196
						1 => tribe_community_events_list_events_link(),
0 ignored issues
show
Bug introduced by
The function tribe_community_events_list_events_link was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

196
						1 => /** @scrutinizer ignore-call */ tribe_community_events_list_events_link(),
Loading history...
197
					);
198
				} else {
199
					$new_crumbs[2] = array(
200
						'text' => apply_filters( 'tribe_ce_submit_event_page_title', __( 'My Events', 'lsx' ) ),
201
						'url'  => tribe_community_events_list_events_link(),
202
					);
203
				}
204
205
				$new_crumbs[3] = $crumbs[2];
206
			} else {
207
				$new_crumbs[2] = $crumbs[1];
208
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
209
			$crumbs = $new_crumbs;
210
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
211
		return $crumbs;
212
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
213
	add_filter( 'wpseo_breadcrumb_links', 'lsx_tec_breadcrumb_filter', 30, 1 );
214
	add_filter( 'woocommerce_get_breadcrumb', 'lsx_tec_breadcrumb_filter', 30, 1 );
215
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
216
endif;
217