Test Failed
Push — master ( e83d9a...ade7ac )
by Stiofan
15:14
created

Kleo.php ➔ kleo_title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Kleo theme compatibility functions.
4
 *
5
 * This file lets the GeoDirectory Plugin use the X theme HTML wrappers to fit and work perfectly.
6
 *
7
 * @since 1.0.0
8
 * @package GeoDirectory
9
 */
10
11
// Page titles translatable CPT names
12
function geodir_kelo_title_translation( $args) {
13
    if(function_exists('geodir_is_geodir_page') && geodir_is_page('preview') ){
14
        $args['title'] = __(stripslashes_deep(esc_html($_POST['post_title'])),'geodirectory');
15
    }elseif(function_exists('geodir_is_geodir_page')){
16
        $args['title'] = __($args['title'],'geodirectory');
17
    }
18
19
    return $args;
20
}
21
add_filter( 'kleo_title_args', 'geodir_kelo_title_translation', 10, 1 );
22
23
/**
24
 * Fix search returns all the posts for Kleo theme.
25
 *
26
 * Kleo sets the search page to use whether post or page, we need it to be 'any'.
27
 *
28
 * @since 1.0.0
29
 *
30
 * @param object $query Current query object.
31
 * @return object Modified query object.
32
 */
33
function geodir_kleo_search_filter( $query ) {
34
    if ( !empty( $query->is_search ) && geodir_is_page('search') && is_search() ) {
35
        $query->set( 'post_type', 'any' );
36
    }
37
    return $query;
38
}
39
if ( !is_admin() ) {
40
    add_filter( 'pre_get_posts', 'geodir_kleo_search_filter', 11 );
41
}
42
43
if( ! function_exists( 'kleo_title' ) ){
44
    function kleo_title(){ return geodir_kleo_custom_the_title();}
45
}
46
47
/**
48
 * Alter the CPT and Cat page titles
49
 *
50
 * 1.6.19
51
 * @return mixed
52
 */
53
function geodir_kleo_custom_the_title()
54
{
55
56
    $output = '';
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
    if (is_tag()) {
58
        $output = __('Tag Archive for:','kleo_framework')." ".single_tag_title('',false);
59
    }
60
    elseif(is_tax()) {
61
        $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
62
        $output = $term->name;
63
    }
64
    elseif ( is_category() ) {
65
        $output = __('Archive for category:', 'kleo_framework') . " " . single_cat_title('', false);
66
    }
67
    elseif (is_day())
68
    {
69
        $output = __('Archive for date:','kleo_framework')." ".get_the_time('F jS, Y');
70
    }
71
    elseif (is_month())
72
    {
73
        $output = __('Archive for month:','kleo_framework')." ".get_the_time('F, Y');
74
    }
75
    elseif (is_year())
76
    {
77
        $output = __('Archive for year:','kleo_framework')." ".get_the_time('Y');
78
    }
79
    elseif (is_author())  {
80
        $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
81
        $output = __('Author Archive','kleo_framework')." ";
82
83
        if( isset( $curauth->nickname ) ) {
84
            $output .= __('for:','kleo_framework')." ".$curauth->nickname;
85
        }
86
    }
87
    elseif ( is_archive() )  {
88
        $output = post_type_archive_title( '', false );
89
    }
90
    elseif (is_search())
91
    {
92
        global $wp_query;
93
        if(!empty($wp_query->found_posts))
94
        {
95
            if($wp_query->found_posts > 1)
96
            {
97
                $output =  $wp_query->found_posts ." ". __('search results for:','kleo_framework')." ".esc_attr( get_search_query() );
98
            }
99
            else
100
            {
101
                $output =  $wp_query->found_posts ." ". __('search result for:','kleo_framework')." ".esc_attr( get_search_query() );
102
            }
103
        }
104
        else
105
        {
106
            if(!empty($_GET['s']))
107
            {
108
                $output = __('Search results for:','kleo_framework')." ".esc_attr( get_search_query() );
109
            }
110
            else
111
            {
112
                $output = __('To search the site please enter a valid term','kleo_framework');
113
            }
114
        }
115
116
    }
117
    elseif ( is_front_page() && !is_home() ) {
118
        $output = get_the_title(get_option('page_on_front'));
119
120
    } elseif ( is_home() ) {
121
        if (get_option('page_for_posts')) {
122
            $output = get_the_title(get_option('page_for_posts'));
123
        } else {
124
            $output = __( 'Blog', 'kleo_framework' );
125
        }
126
127
    } elseif ( is_404() ) {
128
        $output = __('Error 404 - Page not found','kleo_framework');
129
    }
130
    else {
131
        $output = get_the_title();
132
    }
133
134
    if (isset($_GET['paged']) && !empty($_GET['paged']))
135
    {
136
        $output .= " (".__('Page','kleo_framework')." ".$_GET['paged'].")";
137
    }
138
139
140
    $gd_page = '';
141
    if(geodir_is_page('pt')){
142
        $gd_page = 'pt';
143
        $output = (get_option('geodir_page_title_pt')) ? get_option('geodir_page_title_pt') : '';
144
    }
145
    elseif(geodir_is_page('listing')){
146
        $gd_page = 'listing';
147
        $output = (get_option('geodir_page_title_cat-listing')) ? get_option('geodir_page_title_cat-listing') : '';
148
    }
149
150
151
152
    /**
153
     * Filter page meta title to replace variables.
154
     *
155
     * @since 1.5.4
156
     * @param string $title The page title including variables.
157
     * @param string $gd_page The GeoDirectory page type if any.
158
     */
159
    return apply_filters('geodir_seo_meta_title', __($output, 'geodirectory'), $gd_page);
160
161
}