Last active
April 12, 2020 10:53
-
-
Save wpmudev-sls/bd1a80a56cecb928dbf281f17f4de724 to your computer and use it in GitHub Desktop.
[Hummingbird Pro] - Fix conflict with plugin Oxygen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Hummingbird Pro] - Fix conflict with plugin Oxygen | |
* Description: [Hummingbird Pro] - Fix conflict with plugin Oxygen - 1152415940647285 | |
* Task: 0/11289012348292/117091689172289 | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
add_action( 'after_setup_theme', 'wpmudev_hmbp_fix_conflict_with_plugin_oxygen_func', 100 ); | |
function wpmudev_hmbp_fix_conflict_with_plugin_oxygen_func() { | |
if( defined('WPHB_VERSION') && class_exists( 'Hummingbird\WP_Hummingbird' ) && class_exists('Hummingbird\Core\Settings') && defined('CT_VERSION') ){ | |
if( is_admin() || ! Hummingbird\Core\Settings::get_setting( 'enabled', 'minify' ) ){ | |
return; | |
} | |
function wpmudev_custom_oxy_print_cached_css() { | |
if ( !defined("SHOW_CT_BUILDER") ) { | |
global $wp_current_filter; | |
// remove 'wp_head' from current filters | |
array_pop( $wp_current_filter ); | |
// push fake filter name to be popped later instead of actual 'wp_head' | |
array_push( $wp_current_filter, "wp_head_fake"); | |
do_action("ct_builder_start"); | |
do_action("ct_builder_end"); | |
/** | |
* Add-on hook | |
* | |
* @since 1.4 | |
*/ | |
do_action("oxygen_enqueue_frontend_scripts"); | |
global $wp_styles, $oxygen_vsb_css_styles; | |
if( is_null( $oxygen_vsb_css_styles ) ){ | |
$oxygen_vsb_css_styles = new WP_Styles; | |
$oxygen_vsb_css_styles->registered = array();//reset register | |
} | |
// check whether to load universal css or not | |
if ( get_option("oxygen_vsb_universal_css_cache")=='true' && get_option("oxygen_vsb_universal_css_cache_success")==true | |
// TODO: check if there are other cases that may load universal CSS into builder | |
&& (!isset($_REQUEST['action']) || stripslashes($_REQUEST['action']) !== 'ct_render_widget') ) { | |
$universal_css_url = get_option('oxygen_vsb_universal_css_url'); | |
$universal_css_url = add_query_arg("cache", get_option("oxygen_vsb_last_save_time"), $universal_css_url); | |
if(is_admin()) $universal_css_url = str_replace("universal.css", "universal_admin.css", $universal_css_url); | |
// check if to load dynamic xlink or cached CSS files | |
if (!oxygen_vsb_load_cached_css_files()) { | |
$oxygen_vsb_css_styles->add("oxygen-styles", ct_get_current_url('xlink=css&nouniversal=true') ); | |
$oxygen_vsb_css_styles->enqueue(array('oxygen-styles')); | |
} | |
$oxygen_vsb_css_styles->add("oxygen-universal-styles", $universal_css_url); | |
$oxygen_vsb_css_styles->enqueue(array('oxygen-universal-styles')); | |
} | |
else { | |
// check if to load dynamic xlink or cached CSS files | |
if (!oxygen_vsb_load_cached_css_files()) { | |
$oxygen_vsb_css_styles->add("oxygen-styles", ct_get_current_url( 'xlink=css' ) ); | |
$oxygen_vsb_css_styles->enqueue(array('oxygen-styles')); | |
} | |
} | |
// Register/Enque assets | |
if( $oxygen_vsb_css_styles->registered ){ | |
// registered | |
foreach( $oxygen_vsb_css_styles->registered as $dependency ){ | |
$wp_styles->add( $dependency->handle, $dependency->src ); | |
} | |
// enqueue | |
if( $oxygen_vsb_css_styles->queue ){ | |
$wp_styles->enqueue( $oxygen_vsb_css_styles->queue ); | |
} | |
} | |
} | |
} | |
remove_action( 'wp_head', 'oxy_print_cached_css', 999999 ); | |
add_action( 'wp_head', 'wpmudev_custom_oxy_print_cached_css', 4 ); | |
// fix CTFrontendBuilderUI is not defined | |
function wpmudev_oxygen_reenqueue_script() { | |
wp_deregister_script( 'selector-detector-controller' ); | |
wp_dequeue_script( 'selector-detector-controller' ); | |
wp_register_script( 'selector-detector-controller', OSD_URI . 'includes/osd.controller.js', array('ct-angular-ui') ); | |
wp_enqueue_script( 'selector-detector-controller' ); | |
} | |
if( defined('OSD_URI') ){ | |
add_action( 'wp_enqueue_scripts', 'wpmudev_oxygen_reenqueue_script', 99 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment