Passed
Push — master ( 1da117...139142 )
by Amit
03:41
created

cleanup.php ➔ podium_start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 77.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * WordPress.com-specific functions and definitions.
4
 *
5
 * This file is centrally included from `wp-content/mu-plugins/wpcom-theme-compat.php`.
6
 *
7
 * @package podium
8
 */
9
10
// TODO clean this functions
11
12
if (!function_exists('podium_setup')) {
13
14
    /**
15
     * Sets up theme defaults and registers support for various WordPress features.
16
     *
17
     * Note that this function is hooked into the after_setup_theme hook, which
18
     * runs before the init hook. The init hook is too late for some features, such
19
     * as indicating support for post thumbnails.
20
     */
21
    function podium_setup()
22
    {
23
24
        /*
25
         * Make theme available for translation.
26
         * Translations can be filed in the /languages/ directory.
27
         * If you're building a theme based on podium, use a find and replace
28
         * to change 'podium' to the name of your theme in all the template files
29
         */
30
        load_theme_textdomain('podium', get_template_directory() . '/languages');
31
32
33
        /*
34
         * Let WordPress manage the document title.
35
         * By adding theme support, we declare that this theme does not use a
36
         * hard-coded <title> tag in the document head, and expect WordPress to
37
         * provide it for us.
38
         */
39
        add_theme_support('title-tag');
40
41
        /*
42
         * Enable support for Post Thumbnails on posts and pages.
43
         *
44
         * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
45
         */
46
        add_theme_support('post-thumbnails');
47
48
        /*
49
         * Switch default core markup for search form, comment form, and comments
50
         * to output valid HTML5.
51
         */
52
        add_theme_support('html5', [
53
            'search-form',
54
            'comment-form',
55
            'comment-list',
56
            'gallery',
57
            'caption'
58
        ]);
59
60
        /*
61
         * Enable support for Post Formats.
62
         * See http://codex.wordpress.org/Post_Formats
63
         */
64
        add_theme_support('post-formats', [
65
            'aside',
66
            'image',
67
            'video',
68
            'quote',
69
            'link'
70
        ]);
71
72
    }
73
74
}
75
76
// podium_setup
77
add_action('after_setup_theme', 'podium_setup');
78
79
// Fire all our initial functions at the start
80
add_action('after_setup_theme', 'podium_start', 16);
81
82
function podium_start()
83
{
84
85
    // launching operation cleanup
86
    add_action('init', 'podium_head_cleanup');
87
88
    // remove pesky injected css for recent comments widget
89
    add_filter('wp_head', 'podium_remove_wp_widget_recent_comments_style', 1);
90
91
    // clean up comment styles in the head
92
    add_action('wp_head', 'podium_remove_recent_comments_style', 1);
93
94
    // clean up gallery output in wp
95
    add_filter('gallery_style', 'podium_gallery_style');
96
97
}
98
99
/* end podium start */
100
101
//The default wordpress head is a mess. Let's clean it up by removing all the junk we don't need.
102
function podium_head_cleanup()
103
{
104
105
    // Remove EditURI link
106
    remove_action('wp_head', 'rsd_link');
107
108
    // Remove Windows live writer
109
    remove_action('wp_head', 'wlwmanifest_link');
110
111
    // Remove index link
112
    remove_action('wp_head', 'index_rel_link');
113
114
    // Remove previous link
115
    remove_action('wp_head', 'parent_post_rel_link', 10, 0);
116
117
    // Remove start link
118
    remove_action('wp_head', 'start_post_rel_link', 10, 0);
119
120
    // Remove links for adjacent posts
121
    remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
122
123
    // Remove WP version
124
    remove_action('wp_head', 'wp_generator');
125
126
    remove_action('wp_head', 'adjacent_posts_rel_link');
127
    remove_action('wp_head', 'wp_shortlink_wp_head');
128
}
129
130
/* end podium head cleanup */
131
132
// Remove injected CSS for recent comments widget
133
function podium_remove_wp_widget_recent_comments_style()
134
{
135
136
    if (has_filter('wp_head', 'wp_widget_recent_comments_style')) {
137
        remove_filter('wp_head', 'wp_widget_recent_comments_style');
138
    }
139
140
}
141
142
// Remove injected CSS from recent comments widget
143
function podium_remove_recent_comments_style()
144
{
145
    global $wp_widget_factory;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
146
147
    if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
148
        remove_action('wp_head', [$wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style']);
149
    }
150
151
}
152
153
// Remove injected CSS from gallery
154
/**
155
 * @param $css
156
 */
157
function podium_gallery_style($css)
158
{
159
    return preg_replace("!<style type='text/css'>(.*?)</style>!s", '', $css);
160
}
161
162
//  Stop WordPress from using the sticky class (which conflicts with Foundation), and style WordPress sticky posts using the .wp-sticky class instead
163
/**
164
 * @param  $classes
165
 * @return mixed
166
 */
167
function remove_sticky_class($classes)
168
{
169
    $classes   = array_diff($classes, ['sticky']);
170
    $classes[] = 'wp-sticky';
171
    return $classes;
172
}
173
174
add_filter('post_class', 'remove_sticky_class');
175
176
//This is a modified the_author_posts_link() which just returns the link. This is necessary to allow usage of the usual l10n process with printf()
177
/**
178
 * @return mixed
179
 */
180
function podium_get_the_author_posts_link()
181
{
182
    global $authordata;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
183
184
    if (!is_object($authordata)) {
185
        return false;
186
    }
187
188
    $link = sprintf(
189
        '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
190
        get_author_posts_url($authordata->ID, $authordata->user_nicename),
191
        esc_attr(sprintf(__('Posts by %s', 'podium'), get_the_author())), // No further l10n needed, core will take care of this one
192
        get_the_author()
193
    );
194
    return $link;
195
}
196