• Resolved Ryan

    (@updraft)


    Why is stencil-admin.js loaded on the frontend?

    There is a conflict with WP Rocket’s minification setting. I had to exclude this file in WP Rocket but it raises the bigger question of why the javascript file is even being loaded on the frontend of a site when not logged in.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Stencil

    (@getstencil)

    Hey Ryan –
    Super great point. The reason it’s loaded on the front end is because there are a number of WordPress Post Builder plugins that operate on the front end. Basically meaning when some people write or edit posts, it will take them to the front end for the editing process, rather than stay in the admin area.

    So to ensure WordPress works with those plugins, we’ve had to load the stencil-admin.js file there as well.

    The code is not minified, compressed or obfuscated, so feel free to take a look at the file if you’re interested.

    Thread Starter Ryan

    (@updraft)

    But if the user is not logged in or doesn’t have the WP capabilities to access the media library, there shouldn’t be a need to load scripts.

    How do I dequeue the scripts and styles added by your plugin?

    This is not working:

    add_action( 'admin_print_scripts', 'my_dequeue_scripts', 1000 );
    function my_dequeue_scripts() {
    	wp_dequeue_script( 'stencil' );
    	wp_dequeue_style( 'stencil' );
    }

    I tried the following action hooks and none worked:

    admin_print_scripts
    admin_enqueue_scripts
    wp_print_scripts
    wp_enqueue_scripts

    Plugin Author Stencil

    (@getstencil)

    Hey Ryan –
    It’s a good idea to check for authentication before making calls to have those files queued. I’ll look into that as soon as I can, but in the mean time, the easiest might be to just turn off the plugin from your Plugins tab when you’re not using it.

    Doing so will prevent anything from being inserted.

    Please offer either dequeue action, unfortunately this is causing people to drop the plugin once the site goes live for performance reasons.

    Plugin Author Stencil

    (@getstencil)

    Hi @mikesale
    Sorry to hear you’re running into this as well.

    Here’s why this is so tricky:
    Some WordPress plugins require the code to be loaded on the “front end”, because they offer a live preview/edit feature. So as you make changes to your post, you’re actually in the “front end” of the site.

    Not all plugins work this way, but some do.
    To make it even more complicated, some plugins allow you to edit a post/page in the “front end” or in the “back end”, so we can’t write code which says “dequeue if this plugin is loaded”.

    What about something in between: we offer an option for the plugin that allows you to turn off loading stencil-admin.js on the “front end”?

    Would that satisfy your concern?
    If so, I can’t give an exact estimate of how long it would take, but I don’t think it should be too tricky.

    Looking forward to your response.

    That would be more than sufficient! Thank you!

    Thread Starter Ryan

    (@updraft)

    @mikesale – I ended up having to do something like the following to dequeue the scripts:

    add_action( 'wp_print_styles', 'dequeue_scripts', 1000 );
    add_action( 'get_footer', 'dequeue_scripts', 1000 );
    function dequeue_scripts() {
      // If not in admin and current user cannot upload files, dequeue Stencil javascript.
      if( !is_admin() && !current_user_can('upload_files') ) {
        wp_dequeue_script( 'stencil' );
        wp_dequeue_style( 'stencil' );
      }
    }

    And yes, that’s using the wp_print_styles and get_footer action hooks. I realize that’s not typically how you dequeue scripts but due to how this plugin enqueues scripts using both of those hooks was the only way I could find to completely prevent Stencil from loading.

    Hope this helps you out.

    Plugin Author Stencil

    (@getstencil)

    That’s an interesting approach @updraft
    Thanks for posting; I’ll test whether baking that directly into the plugin would work!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘stencil-admin.js loads on frontend’ is closed to new replies.