Completed
Pull Request — master (#13)
by
unknown
04:25
created

AssetsCleanup::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the WPFoundation library.
5
 *
6
 * Copyright (c) 2015-2016 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\WPFoundation\Configuration\Optimization;
13
14
class AssetsCleanup
15
{
16
    public function __construct()
17
    {
18
        add_action('wp_default_scripts', [$this, 'dequeueJQueryMigrate']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_action() seems unnecessary as the function has no side-effects.
Loading history...
19
20
        if (defined('ICL_LANGUAGE_CODE')) {
21
            // DO NOT LOAD WPML LANG SWITCHER CSS
22
            define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);
23
            add_action('wp_head', [$this, 'dequeueSitepressJs'], 11);
0 ignored issues
show
Unused Code introduced by
The call to add_action() has too many arguments starting with 11.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to the function add_action() seems unnecessary as the function has no side-effects.
Loading history...
24
        }
25
    }
26
27
    public function dequeueJQueryMigrate($scripts)
28
    {
29
        if (!is_admin() && !empty($scripts->registered['jquery'])) {
30
            $jquery_dependencies = $scripts->registered['jquery']->deps;
31
            $scripts->registered['jquery']->deps = array_diff($jquery_dependencies, ['jquery-migrate']);
32
        }
33
    }
34
35
    public function dequeueSitepressJs()
36
    {
37
        wp_dequeue_script('sitepress');
38
        wp_deregister_script('sitepress');
39
    }
40
}
41