Completed
Push — master ( 76014d...2d5ff7 )
by Warwick
03:54 queued 01:53
created

the-events-calendar.php ➔ lsx_tec_global_header_title()   C

Complexity

Conditions 13
Paths 42

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
nc 42
nop 1
dl 0
loc 44
rs 6.6166
c 0
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' ) ) {
10
	exit;
11
}
12
13
if ( ! function_exists( 'lsx_tec_scripts_add_styles' ) ) :
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() {
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' ) {
29
			// New Version 5.0 and up.
30
			wp_enqueue_style( 'the-events-calendar-lsx', get_template_directory_uri() . '/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', get_template_directory_uri() . '/assets/css/the-events-calendar/the-events-calendar.css', array( 'lsx_main' ), LSX_VERSION );
34
		}
35
36
		wp_enqueue_style( 'the-events-calendar-lsx', get_template_directory_uri() . '/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
	}
39
40
	add_action( 'wp_enqueue_scripts', 'lsx_tec_scripts_add_styles' );
41
42
endif;
43
44 View Code Duplication
if ( ! function_exists( 'lsx_tec_theme_wrapper_start' ) ) :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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() {
53
		lsx_content_wrap_before();
54
		echo '<div id="primary" class="content-area ' . esc_attr( lsx_main_class() ) . '">';
55
		lsx_content_before();
56
		echo '<main id="main" class="site-main" role="main">';
57
		lsx_content_top();
58
	}
59
60
	add_action( 'tribe_events_before_html', 'lsx_tec_theme_wrapper_start', 9 );
61
62
endif;
63
64 View Code Duplication
if ( ! function_exists( 'lsx_tec_theme_wrapper_end' ) ) :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
66
	/**
67
	 * The Events Calendar wrapper end.
68
	 *
69
	 * @package    lsx
70
	 * @subpackage the-events-calendar
71
	 */
72
	function lsx_tec_theme_wrapper_end() {
73
		lsx_content_bottom();
74
		echo '</main>';
75
		lsx_content_after();
76
		echo '</div>';
77
		lsx_content_wrap_after();
78
	}
79
80
	add_action( 'tribe_events_after_html', 'lsx_tec_theme_wrapper_end', 11 );
81
82
endif;
83
84
if ( ! function_exists( 'lsx_tec_global_header_title' ) ) :
85
86
	/**
87
	 * Move the events title into the global header
88
	 *
89
	 * @package    lsx
90
	 * @subpackage the-events-calendar
91
	 */
92
	function lsx_tec_global_header_title( $title ) {
93
94
		if ( tribe_is_community_edit_event_page() ) {
95
96
			$is_route = get_query_var( 'WP_Route' );
97
			switch ( $is_route ) {
98
				case 'ce-edit-route':
99
					$title = apply_filters( 'tribe_ce_edit_event_page_title', __( 'Edit an Event', 'lsx' ) );
100
					break;
101
102
				case 'ce-edit-organizer-route':
103
					$title = __( 'Edit an Organizer', 'lsx' );
104
					break;
105
106
				case 'ce-edit-venue-route':
107
					$title = __( 'Edit a Venue', 'lsx' );
108
					break;
109
110
				default:
111
					$title = apply_filters( 'tribe_ce_submit_event_page_title', __( 'Submit an Event', 'lsx' ) );
112
					break;
113
			}
114
		} elseif ( tribe_is_community_my_events_page() ) {
115
			$title = apply_filters( 'tribe_ce_submit_event_page_title', __( 'My Events', 'lsx' ) );
116
		} elseif ( tribe_is_event() ) {
117
			$title = tribe_get_events_title();
118
		}
119
120
		// Only disable the title after we have retrieved it.
121
		add_filter( 'tribe_get_events_title', 'lsx_text_disable_body_title', 200, 1 );
122
123
		if ( is_singular( 'tribe_events' ) ) {
124
			add_filter( 'the_title', 'lsx_text_disable_body_title', 200, 1 );
125
		}
126
127
		if ( class_exists( 'LSX_Banners' ) ) {
128
			$options = get_option( '_lsx_settings', false );
129
			if ( is_array( $options ) && isset( $options['tribe_events'] ) && isset( $options['tribe_events']['title'] ) && '' !== $options['tribe_events']['title'] ) {
130
				$title = $options['tribe_events']['title'];
131
			}
132
			$title = '<h1 class="page-title">' . $title . '</h1>';
133
		}
134
		return $title;
135
	}
136
	add_filter( 'lsx_banner_title', 'lsx_tec_global_header_title', 200, 1 );
137
	add_filter( 'lsx_global_header_title', 'lsx_tec_global_header_title', 200, 1 );
138
139
endif;
140
141
if ( ! function_exists( 'lsx_text_disable_body_title' ) ) :
142
	/**
143
	 * Disable the events title for the post archive if the dynamic setting is active.
144
	 *
145
	 * @param $title
146
	 * @return string
147
	 */
148
	function lsx_text_disable_body_title( $title ) {
0 ignored issues
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
		$title = '';
150
		remove_filter( 'the_title', 'lsx_text_disable_body_title', 200, 1 );
151
		return $title;
152
	}
153
154
endif;
155
156
if ( ! function_exists( 'lsx_tec_breadcrumb_filter' ) ) :
157
	/**
158
	 * Fixes the community events breadcrumb
159
	 *
160
	 * @package    lsx
161
	 * @subpackage the-events-calendar
162
	 */
163
	function lsx_tec_breadcrumb_filter( $crumbs ) {
164
165
		if ( tribe_is_venue() || tribe_is_organizer() || tribe_is_community_edit_event_page() || tribe_is_community_my_events_page() ) {
166
			$new_crumbs    = array();
167
			$new_crumbs[0] = $crumbs[0];
168
169 View Code Duplication
			if ( function_exists( 'woocommerce_breadcrumb' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
170
				$new_crumbs[1] = array(
171
					0 => __( 'Events', 'lsx' ),
172
					1 => get_post_type_archive_link( 'tribe_events' ),
173
				);
174
			} else {
175
				$new_crumbs[1] = array(
176
					'text' => __( 'Events', 'lsx' ),
177
					'url'  => get_post_type_archive_link( 'tribe_events' ),
178
				);
179
			}
180
181
			if ( tribe_is_community_my_events_page() ) {
182
				$new_crumbs[2] = $crumbs[2];
183
			} elseif ( tribe_is_community_edit_event_page() ) {
184
185 View Code Duplication
				if ( function_exists( 'woocommerce_breadcrumb' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
					$new_crumbs[2] = array(
187
						0 => apply_filters( 'tribe_ce_submit_event_page_title', __( 'My Events', 'lsx' ) ),
188
						1 => tribe_community_events_list_events_link(),
189
					);
190
				} else {
191
					$new_crumbs[2] = array(
192
						'text' => apply_filters( 'tribe_ce_submit_event_page_title', __( 'My Events', 'lsx' ) ),
193
						'url'  => tribe_community_events_list_events_link(),
194
					);
195
				}
196
197
				$new_crumbs[3] = $crumbs[2];
198
			} else {
199
				$new_crumbs[2] = $crumbs[1];
200
			}
201
			$crumbs = $new_crumbs;
202
		}
203
		return $crumbs;
204
	}
205
	add_filter( 'wpseo_breadcrumb_links', 'lsx_tec_breadcrumb_filter', 30, 1 );
206
	add_filter( 'woocommerce_get_breadcrumb', 'lsx_tec_breadcrumb_filter', 30, 1 );
207
208
endif;
209