Priority modifier

Nzymes injections are filtered with priority ´9´. That’s because Enzymes 2 injections are filtered with priority ´10´, which is the default priority for most of the WordPress plugins. To guarantee that Nzymes is always run before Enzymes 2, the priority of the former is higher than that of the latter. Remember that filters priorities are like points on a time line, so that ´5´ happens before ´9´ which happens before ´10´…

If you injected enzymes into your content but they were not filtered at all, it could be that there is some syntax error that makes Nzymes ignore an injection altogether. Let’s say that you forgot a dot before a custom field name. In such a case, Nzymes will check the syntax of the injection before interpreting its enzymes and immediately reject it because it doesn’t comply with the expected format.

And if the syntax was correct? That happened to me. I created a table in TablePress (very good plugin) and put an injection into a cell. Then I saved it and put its shortcode where I wanted my table. When I reloaded the post, I didn’t expect that the cell still showed the injection.

The problem was that Nzymes injections are filtered at priority ´9´ while TablePress tables are filtered at priority ´20´. So, when TablePress replaces its shortcode with my table, my injection doesn’t get filtered by Nzymes because it already run in the past. I had to find a solution.

Enter the ´defer(X)´ modifier. This is a special literal execution enzyme. It’s special because the number between its parentheses doesn’t represent how many previous enzymes are to be popped from the internal stack. In fact, the X is the later priority at which Nzymes has to run again and filter the injection where ´defer(X)´ appears.

How does it work?

  1. When a priority modifier enzyme like ´defer(X)´ is processed, its result (pushed onto the internal stack) is ´null´.
  2. If Nzymes is currently executing at a priority ´P´ which happens on or after ´X´ (numerically, ´X <= P´) then ´defer(X)´ is disabled and Nzymes ignores it. (nothing more than a ´null´ pushed onto the internal stack happens).
  3. If Nzymes is currently executing at a priority ´P´ which happens before ´X´ (numerically, ´P < X´) then ´defer(X)´ is enabled and Nzymes
    1. stops processing the rest of the injection;
    2. rejects the injection as a whole now, to be able to process it later; (see below)
    3. hooks a later execution at priority ´X´ of Nzymes on the same filter. (see below)

Be aware that, for an injection that contains a ´defer(X)´, the enzymes placed before ´defer(X)´ are orderly processed, while those placed after ´defer(X)´ are completely ignored. This matters when the enzymes placed before cause some side effects.

Tip. If you don’t really need those side effects, make a habit of putting ´defer(X)´ at the start of an injection, so that it stops the injection completely, until a proper filter is run.

Rest assured that no hook is added after the first one (with the same filter and priority). This matters when you copy and paste injections with priority modifiers: you can just ignore duplicates.

Example

If Nzymes is currently executing at priority ´9´ (default) and it finds these injections

´{[ defer(5) | 1 ]}{[ 2 ]}{[ defer(15) | 3 ]}{[ defer(9) | 4 ]}´

then after priority ´9´ the content would be ´12{[ defer(15) | 3 ]}4´
and after priority ´15´ it would be ´1234´ as expected.

Note that ´{[ defer(X) ]}´ is not only a valid injection, but also a very useful one. In such a case, once processed, the current filter will erase the injection from the content only after having prepared a later execution. That deferred execution will probably process new injections introduced by filters in the middle, just like in my TablePress use case.


Nzymes | WordPress Plugin

{[ defer(15) | 1.enable-enzymes() ]}