PluginProbe
Inactive Logout / trunk
Inactive Logout vtrunk
3.6.3 trunk 1.9.9 2.0.2 3.3.1 3.3.2 3.3.3 3.3.4 3.4.0 3.4.1 3.4.10 3.4.11 3.4.12 3.4.13 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 All 31 releases
inactive-logout / core / Compatibility.php

Compatibility.php in Inactive Logout trunk, at core/Compatibility.php

68 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codemanas\InactiveLogout;
4
5 class Compatibility {
6
7 public function __construct() {
8 if ( is_admin() ) {
9 $this->removeWishListMemberRestrictions();
10 }
11 }
12
13 public function removeWishListMemberRestrictions() {
14 $removeActions = apply_filters( 'ina_removeWishListMemberRestrictions', true );
15 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
16 if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'wishlist-member/wpm.php' ) && $removeActions ) {
17 global $WishListMemberInstance;
18 remove_action( 'admin_enqueue_scripts', [ $WishListMemberInstance, 'remove_theme_and_plugins_scripts_and_styles' ], 999999999 );
19 remove_action( 'admin_head', [ $WishListMemberInstance, 'remove_theme_and_plugins_scripts_and_styles' ], 999999999 );
20 remove_action( 'admin_footer', [ $WishListMemberInstance, 'remove_theme_and_plugins_scripts_and_styles' ], 999999999 );
21
22 add_action( 'admin_enqueue_scripts', [ $this, 'onlyEnqueueInactiveScripts' ], 999999999 );
23 add_action( 'admin_head', [ $this, 'onlyEnqueueInactiveScripts' ], 999999999 );
24 add_action( 'admin_footer', [ $this, 'onlyEnqueueInactiveScripts' ], 999999999 );
25 }
26 }
27
28
29 public function onlyEnqueueInactiveScripts() {
30 global $wp_styles, $wp_scripts;
31
32 if ( wlm_get_data()['page'] != 'WishListMember' ) {
33 return;
34 }
35
36 // Regex to match all themes and plugins except ours.
37 $regex = '#/wp-content/(themes/|plugins/(?!' . preg_quote( basename( WLM_PLUGIN_DIR ) ) . ').+?/)#i';
38
39 // Regex of style handles to remove.
40 // Dg_admin_styles = Divi Carousel Plugin.
41 // Widgetkit-admin = All-in-One Addons for Elementor - WidgetKitwidgetkit-for-elementor.
42 $style_handles_regex = '#^(testify\-|optimizepress\-|dg_admin_styles|widgetkit\-admin|offloadingstyle|publitio)#';
43
44 // Selectively remove styles.
45 foreach ( $wp_styles->registered as $style ) {
46 if ( preg_match( $regex, $style->src ) && preg_match( $style_handles_regex, $style->handle ) ) {
47 wp_deregister_style( $style->handle );
48 }
49 }
50
51 $allowed_scripts = [ 'inactive-logout', 'ina-logout-addon-bundler' ];
52 foreach ( $wp_scripts->registered as $handle => $script ) {
53 if ( isset( $script->src, $script->handle ) && ! in_array( $script->handle, $allowed_scripts, true ) && preg_match( $regex, $script->src ) ) {
54 wp_deregister_script( $handle );
55 }
56 }
57 }
58
59 private static $_instance = null;
60
61 public static function getInstance() {
62 if ( is_null( self::$_instance ) ) {
63 self::$_instance = new self();
64 }
65
66 return self::$_instance;
67 }
68 }