12.7. Filter Commands

This section explains the commands defined in a Filter. Each command is composed of a subject, a property, and options. There are two types of commands, which are a condition command and an action command.

Fig. 12.28 shows a condition command. A condition command checks a condition and results in either true or false. With a condition command, you check if something is true. If it is true, then we say that the condition is met. The command shown in Fig. 12.28 checks if an element exists in the page. You simply give one or more CSS selectors to the command. If the command can find an element with the given CSS selectors, then it meets the condition. If it cannot, then it does not meet the condition.

Fig. 12.29 shows an action command. An action command performs an action, as its name suggests. The command shown in Fig. 12.29 finds something in the post’s title and replaces it with something. You simply define what to find and with what to replace in the title, and the command does that.

../../_images/sample-cond-cmd.png

Fig. 12.28 A condition command

../../_images/sample-action-cmd.png

Fig. 12.29 An action command

As it can be seen in Fig. 12.28 and Fig. 12.29, regardless of its type, a command needs to have a subject and a property. A subject simply defines what the command should work with. A property defines what part of the subject the command should work with. For example, in Fig. 12.28, the command should work with an element’s value. Likewise, in Fig. 12.29, the command should work with the post title’s value, meaning that the command should find something in the post’s title and replace it with something else. You can read the command in Fig. 12.28 as “if an element’s value exists” and the command in Fig. 12.29 as “find and replace something in the title’s value”. When these two commands form a Filter together, you can read the filter as “if an element’s value exists, then find and replace something in the title’s value”.

When you select a subject and its property, you will see the suitable commands for the subject-property combination. So, not every command is suitable for every subject-property combination. For example, you cannot check if apple word is greater than 20, since one of them is a text while the other one is a number. You do not need to worry about this, because the plugin will show only the suitable commands for you.

In Fig. 12.28, there is a checkbox named as Stop after first match. This comes in handy when the selected subject has many items in it. When this checkbox is checked, the execution of the condition command is stopped when it finds a single item that meets the condition. For example, let’s say there are 20 post tags, and you want to check if one of them contains Mars in it. Let’s also say that the first tag contains Mars in it. When you check this checkbox, the command stops checking if the remaining 19 tags contain the word. So, the command does less work, takes less time, and spends less resources. If you do not check this checkbox, then the command checks all the 20 tags in this hypothetical case. If you check this checkbox, and the 20th item also contains Mars, then the 20th item will not be considered as a matched subject. So, if you work with the matched subjects in an action command, only the 1st match will be available. Please keep reading to learn how to work with the matched subjects in an action command.

In Fig. 12.29, there is a checkbox named as Only the items matched by conditions. When you check this checkbox, the action command will be executed only for the items matched by the conditions. This means that, if there is a true condition having the same subject as the action command’s, the action command is executed only for the items matched by the condition(s). When checked, if no condition has the same subject, then the action command is definitely executed without any limitations. For example, let’s say there are three post tags as product price, product color, and size, and you want to add product before a tag if it does not start with product. To do this, you first add a condition command that checks if a tag’s value starts with product. Then, you add an action command that also targets the tags’ values with template command, and check Only the items matched by conditions checkbox. In this case, the action command will be executed only for the size tag.

Note

The following video tutorial explains what the filters are and how they are used.

The plugin contains many condition and action commands, as well as many subjects and properties. You can find out about these in the sections below.

Contents