Don’t beat your head against a wall like I did when trying to load a basic script using admin_enqueue_scripts
in my latest plugin that integrates some custom fields with a Subscriber in FluentCRM. Instead, read this article and learn something new.
Sometimes you just have to dig into the codebase of the thing you’re extending because the developers are working on more important things like new features, not documentation. I’m fine with that, actually. I like poking around in other people’s code. I typically learn things. I maybe feel confident about the things I write. Sometimes I gain more confidence with a plugin maker.
Well, for good reason I presume, FluentCRM decided to add a step in the script loading on an admin page. It runs it’s own method, unloadOtherScripts()
. This method appears to take the headaches out of most users’ use of FluentCRM–by limiting other plugin conflicts on the page.
Since FluentCRM uses a single page app (I think with Vue), it needs to make sure nothing else is getting in the way. So, it unloads scripts that it doesn’t need.
But, it also provides a filter to let other developers add things to the page without too much hassle. It does this via the fluent_crm_asset_listed_slugs
hook.
Here’s the code right out of app/Hooks/Handlers/AdminMenu.php
:
$approvedSlugs = apply_filters('fluent_crm_asset_listed_slugs', [
'\/gutenberg\/'
]);
$approvedSlugs[] = 'fluent-crm';
As you can see, it allows anything in the “gutenberg” plugin, as well as all things in the “fluent-crm” plugin.
If you need to allow scripts to load from your own plugin, simply add something like:
add_filter( 'fluent_crm_asset_listed_slugs', function( $slugs ) {
$slugs[] = 'my-plugin-slug';
return $slugs;
} );
It’s that simple.
I hope this helps somebody else out there!
And, if you need help developing a plugin, or want some cool integration with FluentCRM or GravityForms or Breakdance, feel free to reach out!