MickeyKay / better-font-awesome-library

[WordPress] The easiest way to integrate Font Awesome into your WordPress theme or plugin.
34 stars 13 forks source link

Media button conflict #13

Open robincornett opened 6 years ago

robincornett commented 6 years ago

I have a post type where I would like to use the same Font Awesome icon picker for some custom meta fields. Everything is working nicely, except that I end up conflicting with Better Font Awesome.

I found the bfa_init_args filter, but it's loaded so early that functions such as get_current_screen() return null, so I'm unable to remove the media button only from a certain post type editor screen.

On the one hand, I would like to be able to use the filter, but my real issue is that I want to use both the media button and the custom fields. At this point, any time any instance of the iconpicker library select is clicked, the value and shortcode is inserted into the editor, even if the iconpicker isn't from the plugin media button. I've tested locally and found that if your icon insertion is modified to work only from the media button, we can coexist happily. This modification is working for me:

        // Set up icon insertion functionality.
        $( document ).on( 'iconpickerSelect', function ( e ) {
            if ( ! e.target.attributes.class.value.includes( 'bfa-iconpicker' ) ) {
                return;
            }
            wp.media.editor.insert( icon_shortcode( e.iconpickerItem.context.title.replace( '.', '' ) ) );
        } );

I'd be happy to submit a PR for this script change, as I would love to be able to use both instances of the icon picker. Thank you for an awesome plugin!

MickeyKay commented 3 years ago

@robincornett holy mole, I am just seeing this Robin :| First of all, thanks for your input! Second of all, sorry for the delay. I'd love if you want to file a PR, especially if you can do so in the next two weeks before I'm back to work from my current pat leave ;) Otherwise (and that's totally understandable if so), I can take a stab in a subsequent PR after the dust settles on https://github.com/MickeyKay/better-font-awesome/pull/17