Last active
September 11, 2019 18:26
-
-
Save wpmudev-sls/ede1cc99f3f5f70cc4df33ad456cffc4 to your computer and use it in GitHub Desktop.
[Branda] - Load Custom Assets In Maintenance Mode
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: [Branda] - Load Custom Assets In Maintenance/Comming Soon Mode | |
* Description: [Branda] - Load Custom Assets In Maintenance/Comming Soon Mode - Supported Forminator and Hustle - Tested on Branda: <=3.1.2; Forminator: <=1.7.1; Hustle: <=4.0 | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
add_action( 'plugins_loaded', 'wpmudev_bd_support_shortcode_on_web_mode', 100 ); | |
function wpmudev_bd_support_shortcode_on_web_mode() { | |
if( class_exists('Brenda_Maintenance') ){ | |
// return; | |
class WPMUDEV_BD_Support_Shortcode_On_Web_Mode extends Brenda_Maintenance{ | |
private static $_instance; | |
public $is_web_mode = false; | |
public function __construct(){ | |
if ( 'off' !== $this->get_value( 'mode', 'mode' ) ) { | |
$this->is_web_mode = true; | |
} | |
if ( ! is_admin() ) { | |
if ( $this->is_web_mode && ! is_user_logged_in() ){ | |
add_filter( 'ub_get_value', array( $this, 'output_assets' ), 10, 3 ); | |
} | |
}else{ | |
add_filter( 'ultimatebranding_settings_maintenance_process', array( $this, 'reformat_maintenance_options_value' ), 9 ); | |
} | |
} | |
public static function get_instance(){ | |
if( is_null( self::$_instance ) ){ | |
self::$_instance = new self(); | |
} | |
return self::$_instance; | |
} | |
public function reformat_maintenance_options_value( $status ){ | |
if( isset( $_POST['simple_options']['content']['content'] ) ){ | |
$_POST['simple_options']['content']['content'] = stripslashes( $_POST['simple_options']['content']['content'] ); | |
} | |
} | |
public function output_assets( $data, $module, $section ){ | |
static $done; | |
if( null !== $section || $done || ! is_array( $data ) ){ | |
return $data; | |
} | |
$done = 1; | |
if( ! isset( $data['content']['content_meta'], $data['content']['content'] ) ){ | |
return $data; | |
} | |
$content_meta = $data['content']['content_meta']; | |
global $wp_styles, $wp_scripts; | |
$wp_styles = wp_styles(); | |
$wp_scripts = wp_scripts(); | |
$custom_inline_assets = []; | |
// load assets forminator | |
if( defined('FORMINATOR_PRO') && FORMINATOR_PRO && strpos( $content_meta, 'forminator-module-' ) !== false ){ | |
// call style | |
if( function_exists('forminator_print_front_styles') ){ | |
forminator_print_front_styles(); | |
} | |
if( function_exists('forminator_print_front_scripts') ){ | |
forminator_print_front_scripts(); | |
} | |
} | |
// load assets hustle | |
if( defined('HUSTLE_SUI_VERSION') && HUSTLE_SUI_VERSION && strpos( $content_meta, 'hustle_module_id_' ) !== false && class_exists('Hustle_Module_Front') ){ | |
if( isset( $GLOBALS['hustle'] ) ){ | |
$hustle = $GLOBALS['hustle']; | |
$hustle_front = new Hustle_Module_Front( $hustle ); | |
$hustle_front->create_modules(); | |
$hustle_front->register_scripts(); | |
// Enqueue it in the footer to overrider all the css that comes with the popup | |
$hustle_front->register_styles(); | |
if( method_exists($hustle_front, 'add_layout_templates') ){ | |
$hustle_front->add_layout_templates(); | |
}else{ | |
$modules = Hustle_Module_Collection::instance()->get_all( true ); | |
if( $modules ){ | |
$disable_module_type = ['popup']; | |
foreach( $modules as $module ){ | |
if( in_array( $module->module_type, $disable_module_type ) ){ | |
continue; | |
} | |
if( $module->is_allowed_to_display( $module->module_type ) ){ | |
$disable_module_type[] = $module->module_type; | |
$render = $module->get_renderer(); | |
$render->module = $module; | |
// ddd( $module->get_renderer() ); | |
ob_start(); | |
$render->print_styles(); | |
$custom_style = ob_get_clean(); | |
if( $custom_style ){ | |
$custom_inline_assets[] = $custom_style; | |
} | |
} | |
} | |
$custom_inline_assets[] = "<script> | |
if( window.Modules && 'function' === typeof(_) ){ | |
(function($){ | |
$(function(){ | |
_.each( Modules, function( module, key ) { | |
module.el = '.hustle_module_id_' + module.module_id; | |
// if ( 'popup' === module.module_type ) { | |
// new Optin.PopUp( module ); | |
// } else | |
if ( 'slidein' === module.module_type ) { | |
new Optin.SlideIn( module ); | |
} else if ( 'embedded' === module.module_type ) { | |
const embededs = $( module.el ); | |
embededs.each( function() { | |
module.el = this; | |
new Optin.Embedded( module ); | |
}); | |
} else if ( 'social_sharing' === module.module_type ) { | |
const sshares = $( module.el ); | |
sshares.each( function() { | |
module.el = this; | |
new Optin.SShare( module ); | |
}); | |
} | |
}); | |
}); | |
})(window.jQuery) | |
} | |
</script>"; | |
} | |
} | |
} | |
} | |
// add hook custom assets | |
do_action( 'wpmudev_bd_maintenance_assets', $data, $this ); | |
$custom_inline_assets = apply_filters( 'wpmudev_bd_maintenance_assets_custom_inline_assets', $custom_inline_assets ); | |
$wp_styles->do_items(); | |
$wp_scripts->do_items(); | |
if( $custom_inline_assets ){ | |
echo join("\n", $custom_inline_assets); | |
} | |
return $data; | |
} | |
public function enqueue_js( $src, $version = false ) { | |
return sprintf( | |
'<script type="text/javascript" src="%s?version=%s"></script>%s', | |
$src, | |
$version, | |
PHP_EOL | |
); | |
} | |
public function enqueue_css( $src, $version = false ){ | |
return sprintf( | |
'<link rel="stylesheet" href="%s?version=%s" type="text/css" media="all" />%s', | |
$src, | |
$version, | |
PHP_EOL | |
); | |
} | |
} | |
$run = WPMUDEV_BD_Support_Shortcode_On_Web_Mode::get_instance(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment