MT Conditional for WP Blocks editor active

Author Posts

Norm6257

I’ve been playing around with the folder conditionals… very nice! Thank you for doing this. I’m attempting to make the WP blocks editor be more representative of the frontend when MT styles are applied.

To do that I’m enabling some CSS folder rule using \Microthemer\is_public_or_admin(), however, when doing that the MT rules get applied to the entire backend. Is there a way that you could build a MT conditional to only be backend WP Block editor? That way the rules in the folder will apply to public or backend Blocks editor.

I suppose it could be done with just a single new conditional like “\Microthemer\is_block_editor” and then in the conditional rules I could set an ‘or’ condition like “\Microthemer\is_public() or \Microthemer\is_block_editor()“.


Norm6257

I just found this \Microthemer\query_admin_screen(“is_block_editor”, true) in the dropdown of Search Conditions. Checking to see if that is what I’m looking for.


Sebastian

Hey Norm,

I’m glad the conditional folders feature is useful.

The \Microthemer\is_public_or_admin() condition is probably mostly useful for setting specific CSS that appears on just a single frontend page and a single corresponding backend editing page – for that you need to pass in the page id e.g.

\Microthemer\is_public_or_admin(5)

Omitting a page id does make it apply to every single page (both the front and back) as you discovered.

But if you do want to apply styles to all frontend pages and every single backend page that uses the Gutenberg block editor, then yes the following condition should do the trick:

\Microthemer\is_public() or \Microthemer\query_admin_screen(“is_block_editor”, true)

Let me know if that doesn’t work, I have tested every combination of query_admin_screen parameters.

Cheers,
Sebastian


Norm6257

Hey again, Sebastian,

I’ve been trying the block editor conditional as detailed above, and so far it seems to be what I’m looking for. Interestingly though, on one site the query_admin_screeen conditional showed in the conditional dropdowns, but on another site it didn’t show and I had to manually enter it.

I’m going to guess that many users are not going to want styling applied to the entire back end, but rather just apply to the backend block editor (why, oh why, didn’t WP implement a modern page editor???) So I’m wondering if it makes sense to you to add a \Microthemer\is_block_editor() as one of the special MT checks to make it much more accessible?

Another way I’m looking at making the block editor more representative of the frontend is to prepend another selector .editor-styles-wrapper to all my MT selector rules and see if that works (mostly) to have the block editor render the MT rules.

So …
.wp-block-uagb-image__figure img

Becomes…
.editor-styles-wrapper .wp-block-uagb-image__figure img
when in the block editor.

What do you think of that idea, and is it even a possibility that MT could determine when it is in the block editor and automatically prepend all the MT selector rules with that?


Sebastian

Hey Norm,

query_admin_screen() will show in the dropdown menu Recent section if you have entered that condition and then clicked the Save logic button. That’s probably why it appeared in the list on one site but not the other. You can easily copy any of the conditions by clicking the condition label and then the clipboard icon.

I’m happy to add \Microthemer\query_admin_screen(“is_block_editor”, true) with the label “Is block editor” to the WordPress section of the dropdown menu though, so it’s always available.

Just to be clear, are you saying your would like

\Microthemer\is_block_editor()

As a shortcut for:

\Microthemer\query_admin_screen(“is_block_editor”, true)

If so, would that still be necessary if there’s a permanent entry for it in the dropdown menu. I’d like to keep the custom functions list concise if possible.

I’m not sure about prepending all selectors with .editor-styles-wrapper. However, I only had a few hours sleep last night so it’s hard for me to think about it clearly right now. Could you explain why the prefix is necessary in a bit more detail? And then I’ll respond properly tomorrow.

Cheers!
Sebastian


Norm6257

Going on little sleep definitely affects the thinking. I’ve read a couple of articles and studies on the effects of going without sleep and the negative effects that it has in multiple areas. What was also interesting in the one study that I read is that we can’t “catch up” on sleep. But I digress…

I see that down in the WordPress section of the dropdown there is already the is guttenburg conditional. That seems to align with my suggestion of is block editor. I guess it just wasn’t clear to me that testing for “guttenburg” was testing to see if the block editor was active. Maybe renaming it makes sense to align closer to the actual conditional of “is_block_editor”?

The only other suggestion I would have is to move it from the WordPress section in the dropdown to the Global section of the dropdown.

And since it’s in the dropdown it doesn’t need to be in the custom functions section — I was only suggesting it there for easy access

Regarding the prefixing of MT styles when in the editor, I’ll open another thread on that to keep the thread clean. I’ll open it if it looks like it would work after I’ve played around with it a bit more.

Thanks!
-Norm


Sebastian

Oh I love my sleep. But the kids are still learning to love it! And occasionally bring home tummy bugs.

OK, I’ve changed the label in the dropdown menu to Is Gutenberg block editor, that should be recognisable to most people. The global dropown menu section is only for the entire frontend or entire backend – that’s how MT uses the term global in the Auto folder options in the footer and the folder icon styling in the folders menu. So I think Is Gutenberg block editor might be best staying in the WordPress menu.

And no problem about the prefixing, we can discuss that another time.

Cheers!
Sebastian

You must login or register to reply to this topic.