Codemirror compatibility on User Listing

This function adds Codemirror compatibility on User Listing.

wp_print_scripts is located in wp-includes/functions/wp-scripts.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Codemirror compatibility on User Listing. Tag: codemirror, compatibility
 */
 
/**
 * Dequeue
 *
 * Hooked to the wp_print_scripts action, with a late priority (100),
 * so that it is after the script was enqueued.
 */
add_action( 'wp_print_scripts', 'wppbc_dequeue_conflicting_scripts', 100 );
function wppbc_dequeue_conflicting_scripts() {
	$post_type = '';
	if (isset($_GET['post_type'])){
		$post_type = $_GET['post_type'];
	} elseif( isset($_GET['post']) && isset($_GET['action']) && $_GET['action'] == 'edit' ) {
		$post_id = $_GET['post'];
		$post_type = get_post_type( $post_id );
	}
	$admin_page = '';
	if ( is_admin() && isset($_GET['page'])){
		$admin_page = $_GET['page'];
	}
 
	if( $post_type == 'wppb-ul-cpt' || $admin_page == 'user-email-customizer' || $admin_page == 'admin-email-customizer'){
		global $wp_scripts;
		//var_dump($wp_scripts);
		foreach($wp_scripts->queue as $script){
			if ( strpos($script, 'codemirror' ) && ( $script != 'codemirror' && $script != 'codemirror-mode-overlay-js' && $script != 'codemirror-mode-xml-js' && $script != 'codemirror-fullscreen-js') ){
				//wp_dequeue_script( 'soliloquy-lite-codemirror');
				wp_dequeue_script( $script );
			}
		}
	}
}