• Admin scripts are enqueued on all admin pages instead of just the plugin page.
    This can cause conflicts with 3rd-party plugins, and in the case of a client for example the WooCommerce tabs when creating a new product were not functioning (combination of DK-PDF, WooCommerce & Mapify-Pro plugins).

    Solution was to add this in a php file in mu-plugins:

    <?php 
    
    /**
     * Remove DK-PDF scripts when the current page is not dkpdf_settings.
     */
    add_action( 'admin_enqueue_scripts', function() {
        if ( is_admin() && ( ! $_GET || ! isset( $_GET['page'] ) || 'dkpdf_settings' !== $_GET['page'] ) ) {
            remove_action( 'admin_enqueue_scripts', 'dkpdf_admin_enqueue_scripts', 10, 1 );
        }
    }, 1 );

    However we shouldn’t have to do that… Instead the plugin should be just adding its assets on its own page and not everywhere. More details on https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts#Example:_Target_a_Specific_Admin_Page

Viewing 3 replies - 1 through 3 (of 3 total)
  • Interesting…

    Could the code you’ve posted be added to functions.php?

    Thread Starter Ari Stathopoulos

    (@aristath)

    Sure, you can add it in your functions.php file. It doesn’t make any difference… Putting it in mu-plugins will simply make it run regardless of the active theme, and doesn’t require creating a child theme (you should never edit a theme’s functions.php file directly, only in child themes – unless it’s a custom theme).

    Plugin Author dinamiko

    (@dinamiko)

    Hi Aristeides Stathopoulos,

    Good catch! thank you 🙂

    I’m going to implement it in the next release of the plugin.

    p.d. DK PDF is always open to contributions via pull requests, here is an example:
    https://github.com/Dinamiko/dk-pdf/pull/40

    so I encourage developers to contribute to DK PDF in GitHub 🙂
    https://github.com/Dinamiko/dk-pdf

    Thanks,
    Emili

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Admin scripts enqueued on all pages cause conflicts’ is closed to new replies.