Last active
February 3, 2019 13:31
-
-
Save wpmudev-sls/03e125f84ee4fbd729865b2ceeeebc86 to your computer and use it in GitHub Desktop.
[Huslte] - Adblock Delay. Adds an option to delay trigger for Adblock option in Popup and Slide ins
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: [Huslte] - Adblock Delay | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Adds an option to delay trigger for Adblock option in Popup and Slide ins | |
* Author: Panos Lyrakis @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
if ( ! class_exists( 'WPMUDEV_Hustle_Adblock_Delay' ) ) { | |
class WPMUDEV_Hustle_Adblock_Delay { | |
private static $_instance = null; | |
public static function get_instance() { | |
if( is_null( self::$_instance ) ){ | |
self::$_instance = new WPMUDEV_Hustle_Adblock_Delay(); | |
} | |
return self::$_instance; | |
} | |
private function __construct() { | |
add_action( 'admin_footer', array( $this, 'inject_delay_options' ) ); | |
add_action( 'wp_ajax_hustle_save_popup_module', array( $this, 'save_module_delay' ), 1 ); | |
add_action( 'wp_ajax_hustle_save_slidein_module', array( $this, 'save_module_delay' ), 1 ); | |
} | |
public function inject_delay_options() { | |
$screens = array( 'hustle_page_hustle_popup', 'hustle_page_hustle_slidein' ); | |
if ( ! is_callable( 'get_current_screen' ) || ! in_array( get_current_screen()->id , $screens ) || ! isset( $_GET['section'] ) || 'settings' != isset( $_GET['section'] ) ) { | |
return; | |
} | |
?> | |
<script type="text/javascript"> | |
(function($){ | |
$( document ).ready(function(){ | |
$( '#wpmudev-display-trigger-adblock-options' ).removeClass( 'wpmudev-hidden' ).addClass( 'wpmudev-show' ); | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
} | |
public function save_module_delay() { | |
$settings = isset( $_POST['settings']['triggers'] ) ? $_POST['settings']['triggers'] : false; | |
if ( isset( $settings['adblock_delay'] ) && is_numeric( $settings['adblock_delay'] ) && 0 < $settings['adblock_delay'] ) { | |
$_POST['settings']['triggers']['on_adblock_delayed'] = true; | |
$_POST['settings']['triggers']['on_adblock_delayed_time'] = $settings['adblock_delay']; | |
} | |
else { | |
$_POST['settings']['triggers']['on_adblock_delayed'] = false; | |
} | |
} | |
} | |
if ( ! function_exists( 'wpmudev_hustle_adblock_delay' ) ) { | |
function wpmudev_hustle_adblock_delay(){ | |
return WPMUDEV_Hustle_Adblock_Delay::get_instance(); | |
}; | |
add_action( 'plugins_loaded', 'wpmudev_hustle_adblock_delay', 10 ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment