Snippets

Merkulove Team Disable thirt-party scripts and styles on the Speaker plugin settings page

Created by Dmitry Merkulov
/**
 *  Remove all third-party scripts from the Speaker settings page
 */
if ( ! function_exists('speaker_remove_thirdparty_scripts') ){
	function speaker_remove_thirdparty_scripts()
	{
		// Third-party scripts
		$script_names = [
			"bf-modal",
		];

		/** Get current screen props */
		$screen = get_current_screen();
		if ( null === $screen ) { return; }

		/** Run only on the Speaker plugin settings page */
		if ( ! in_array( $screen->base, ["toplevel_page_mdp_speaker_settings","speaker_page_mdp_speaker_settings"], true ) ) { return; }

		global $wp_scripts;
		foreach($wp_scripts->queue as $handler) {
			if ( in_array( $handler, $script_names ) ) {
				wp_dequeue_script($handler);
				wp_deregister_script($handler);
			}
		}
	}
}
add_action('wp_print_scripts', 'speaker_remove_thirdparty_scripts', 100);

/**
 * Remove all third-party scripts from the Speaker settings page
 */
if ( ! function_exists('speaker_remove_thirdparty_styles') ){
    function speaker_remove_thirdparty_styles()
	{	
        /** Third-party styles */
        $style_names = [
			"bf-modal",
			"bf-admin-pages"
		];

        /** Get current screen props */
        $screen = get_current_screen();
        if ( null === $screen ) { return; }

        /** Run only on the Speaker plugin settings page */
        if ( ! in_array( $screen->base, ["toplevel_page_mdp_speaker_settings","speaker_page_mdp_speaker_settings"], true ) ) { return; }
		
        global $wp_styles;
		
        foreach($wp_styles->queue as $handler) {
            if ( in_array( $handler, $style_names ) ) {
                wp_dequeue_style($handler);
                wp_deregister_style($handler);
            }
        }
    }
}
add_action('admin_enqueue_scripts', 'speaker_remove_thirdparty_styles', 100);

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.