• Sliced Invoices is the only plugin I use that relies on CMB2. It turns out that your scripts push themselves into every Admin page.

    Now, cmb2.js is causing errors with other plugins limiting their functionality.

    As soon as I deactivate Sliced Invoices, the error disappears and all plugins function perfectly.

    Please advise how I can keep Sliced Invoices contained to when it’s actually needed.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello Patrick

    May I please know what errors do you see in your browser Console? Thank you in advance.

    Kindest regards,
    Andrew

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    It defines a variable “locale” and echos that as json. It clashes with several other plugins, mainly because “locale” is a very basic variable name.

    Sliced Invoices loads all its styles and scripts in every admin page, because you use ‘admin_init’ to load them. That is not best practice! Using ‘admin_print_styles-‘.$page’ when defining the submenu pages will solve that – loading only on Sliced Invoice-specific pages.

    Loading unneeded assets slows down a user’s Dashboard.

    Thank you very much Patrick

    I’ll create a bug report regarding this once I check some pieces of code. I appreciate your help so much. I hope the problem will be fixed soon.

    Cheers,
    Andrew

    Thread Starter Stonehenge Creations

    (@duisterdenhaag)

    Glad to help out, Andrew ??
    The best way is to not use wp_enqueue with register in one, like most do.

    “You” need to separate the two.

    function register_sliced_assets() {
       // Registering does not yet enqueue/load them.
       wp_register_style('sliced-css', $file, $version, $screen);
       wp_register_script('sliced-js', $file, $deps, $version, true);
    }
    add_action('admin_init', 'register_sliced_assets');

    Then a second function to enqueue them on call:

    function load_sliced_assets() {
       // Enqueue/load the assets only when this function is called.
       wp_enqueue_scripts( 'sliced-js');
       wp_enqueue_style('sliced-css');
    }

    In creating the admin pages:

    function create_sliced_admin_page() {
        $hook = add_submenu_page( ...... );
        add_action('admin_print_styles-'.$hook, 'load_sliced_assets');
    }
    add_action('admin_menu', 'create_sliced_admin_page');

    Pretty simple and keeps everything much cleaner. It will also make it easier to prevent clashing with other plugins/variables. LOL. ??

    Once again, my greatest thanks to you, Patrick. The ticket has been submitted.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘CBM2.js causing errors.’ is closed to new replies.