Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added assets cleanup optimization script #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the WPFoundation library.
*
* Copyright (c) 2015-2016 LIN3S <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\WPFoundation\Configuration\Optimization;

class AssetsCleanup
{
public function __construct()
{
add_action('wp_default_scripts', [$this, 'dequeueJQueryMigrate']);

if (defined('ICL_LANGUAGE_CODE')) {
// DO NOT LOAD WPML LANG SWITCHER CSS
define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);
add_action('wp_head', [$this, 'dequeueSitepressJs'], 11);
}
}

public function dequeueJQueryMigrate($scripts)
{
if (!is_admin() && !empty($scripts->registered['jquery'])) {
$jquery_dependencies = $scripts->registered['jquery']->deps;
$scripts->registered['jquery']->deps = array_diff($jquery_dependencies, ['jquery-migrate']);
}
}

public function dequeueSitepressJs()
{
wp_dequeue_script('sitepress');
wp_deregister_script('sitepress');
}
}