• Resolved Bjarne Oldrup

    (@oldrup)


    Do you have any suggestion to enable MRW Simplified Editor for, say, any role but the administrator only?

    So an editor or an author would have the simpler experience, while an administrator would have the default full experience, including query loops and whatnot for landing pages.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author mrwweb

    (@mrwweb)

    This is an interesting request. I’ve never done this.

    The cleanest way would be to see if there are any generic techniques for preventing a plugin from running/loading so the plugin doesn’t execute at all. However, I’ve never thought about doing that before and I don’t know if it’s feasible.

    The plugin hides/deactivates features through a variety of JavaScript, CSS, and PHP, so it would be pretty difficult to prevent the plugin from acting.

    So if you can’t literally prevent the plugin from running, I think I would recommend return empty arrays for all the plugin’s filters by user role. Something like this (untested):

    if( current_user_can( 'manage_options') {
        add_filter( 'mrw_hidden_blocks', '__return_empty_array' );
        add_filter( 'mrw_hidden_block_styles', '__return_empty_array' );
        add_filter( 'mrw_hidden_block_editor_settings', '__return_empty_array' );
        add_filter( 'mrw_hidden_embeds', '__return_empty_array' );
        // continue for all other plugin filters
    }

    I’m curious if you end up doing this and how it works out, so I’d love to have you report back. I can potentially foresee some issues with admins using settings like margin that editors can’t adjust (or unwittingly clone), but I can also see the rationale for doing it.

    While not quite the same, there’s also a somewhat experimental $context parameter passed to all the hidden block filters (and not others) that can be useful for adjust the behavior of those filters based on the screen in the admin being looked at. I could potentially foresee extending that to be on most filters, as possible.

    Thread Starter Bjarne Oldrup

    (@oldrup)

    So here’s what I settled on; MRW Simplified Editor remains enabled for admins (me). I’m personally not interested in applying inline styling to blocks anyway, it’s a maintenance nightmare and not scalable. It’s ok for prototyping a pattern, but once the layout is done, I move the styling to a proper style sheet, and apply a class to the pattern. That’s reasonably robust and paves the road for a client-friendly workflow.

    So that means I only need to hide additional stuff for, say, editors. That’s easily done using the small snippets discussed – and – I can conditionally run these snippets depending on user role and whether one is logged in.

    Most (premium) tools for adding code snippets to WordPress, feature a UI to create such conditionals. Screenshot from the tool I use to run snippet if user has the editor role:

    Screenshot: A code snippet plugin’s “condition builder”

    If using free tools to add snippets, the condition can be built with a line of PHP, so that’s doable – I’m just using the tools I have.

    Thanks again! Your plugin really helps to create a simpler editing experience 🕺

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A way to enable plugin for non-admins only?’ is closed to new replies.