Skip Navigation

[Resolved] Possible limit on content within [wpv-conditional]

This thread is resolved. Here is a description of the problem and solution.

Problem: Conditionals are not behaving as expected. If I add or remove content inside the conditional tags, the behavior of the conditional is different.

Solution: Add this line to your wp-config.php file:

ini_set('pcre.jit', false);

Relevant Documentation:
http://php.net/manual/en/pcre.installation.php

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by KenG8581 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1101556
wrong output - page title used instead of client title.png
expected output.png

We have a View that return certain values from a CPT called Client.
The Template for the view is enclosed in a [wpv-conditional] to limit the output to certain situations.
In the Template, we use values from "The current post being displayed either directly or in a View loop" - and this is expected to be from the CPT of Client. Eg. the Post Title which for that CPT contains the name of the client.

After we have put more Template content within the wpv-conditional, the output is not behaving as expected, and we suspect the wpv-conditional to have a limitation of how much content it can contain.

Now the Template has started output unexpected values. Eg. at the place where we expect the client name (Post Title of the CPT Client) it now returns the Post Title of the Page that includes the View.

When we shorten the content in the Template - enclosed by the wpv-conditional - we find a "break point" after which the output is as expected.

We just realised that we may be able use the wpv-conditional in the Loop section instead. Like:

      [wpv-conditional if="( $(wpcf-skabelon-version) ne '' )"]
		[wpv-post-body view_template="loop-item-in-return-links-to-current-templates"]
      [/wpv-conditional]

Dont know if that is a recommended approach or if it will make a difference at all.

Hope to get some clarity. Maybe there is a limitation or maybe we are using wpv-conditional in a wrong way.

Best
Ken

Here is the View Template content that doesnt work (unexpectedly return Page post title rather than Client post title):

  [wpv-conditional if="( $(wpcf-skabelon-version) ne '' )"]
  <h2>Find dine skabeloner her</h2>
  <div class="row">
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-fortegnelse.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full center" /></a>
      </div>
      <div class="doc-list-txt">
        <p>Fortegnelse over behandlingsaktiviteter<br /><a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-fortegnelse.docx">Klik her for hente ned</a></p>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-privatlivspolitik.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full center" /></a>
      </div>
      <div class="doc-list-txt">
        <p>[wpv-post-title output="sanitize"]'s privatlivspolitik<br /><a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-privatlivspolitik.docx">Klik her for hente ned</a></p>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-samtykkeerklæring.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full" /></a>
      </div>
      <div class="doc-list-txt">
        <p>Samtykkeerklæring i forbindelse med behandling/terapi<br /><a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-samtykkeerklæring.docx">Klik her for hente ned</a></p>
      </div>
    </div>
  </div>
  
  <div class="row">
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/Oversigt-over-databehandlere-template.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full" /></a>
      </div>
      <div class="doc-list-txt">
        <p>Oversigt over databehandlere (template)<br /><a href="/wp-content/uploads/Oversigt-over-databehandlere-template.docx">Klik her for hente ned</a></p>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/Vejledning-til-dokumentskabeloner.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full" /></a>
      </div>
      <div class="doc-list-txt">
        <p>Vejledning til dokumentskabeloner<br /><a href="/wp-content/uploads/Vejledning-til-dokumentskabeloner.docx">Klik her for hente ned</a></p>
      </div>
    </div>
  </div>
  <br />
  <p><em>(Hvis du har brug for at lave et opdateret sæt skabeloner, <a href="<em><u>hidden link</u></em>">så klik her</a>)</em></p>
  [/wpv-conditional]

Here is the shortened code that returns the expected output:

[wpv-conditional if="( $(wpcf-skabelon-version) ne '' )"]
<h2>Find dine skabeloner her</h2>

  <div class="row">
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-fortegnelse.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full center" /></a>
      </div>
      <div class="doc-list-txt">
        <p>Fortegnelse over behandlingsaktiviteter<br /><a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-fortegnelse.docx">Klik her for hente ned</a></p>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-privatlivspolitik.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full center" /></a>
      </div>
      <div class="doc-list-txt">
        <p>[wpv-post-title output="sanitize"]'s privatlivspolitik<br /><a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-privatlivspolitik.docx">Klik her for hente ned</a></p>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="doc-list-img">
        <a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-samtykkeerklæring.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png" width="114" height="114" class="size-full" /></a>
      </div>
      <div class="doc-list-txt">
        <p>Samtykkeerklæring i forbindelse med behandling/terapi<br /><a href="/wp-content/uploads/[wpv-post-id][types field='randomid' output='raw'][/types]-[types field='skabelon-version' output='raw'][/types]-samtykkeerklæring.docx">Klik her for hente ned</a></p>
      </div>
    </div>
  </div>

Oversigt over databehandlere (template)<br /><a href="/wp-content/uploads/Oversigt-over-databehandlere-template.docx">Klik her for hente ned</a>

<a href="/wp-content/uploads/Vejledning-til-dokumentskabeloner.docx"><img src="/wp-content/uploads/man_symbole_blue_close_114px.png"></a>

Vejledning til dokumentskabeloner<br /><a href="/wp-content/uploads/Vejledning-til-dokumentskabeloner.docx">Klik her for hente ned</a>

<em>(Hvis du har brug for at lave et opdateret sæt skabeloner, <a href="<em><u>hidden link</u></em>">så klik her</a>)</em>
[/wpv-conditional]
#1101730

Hi, as a test, please add this code to your wp-config.php file, just before the line "That's all, stop editing! Happy blogging."

ini_set('pcre.jit', false);

Then test the longer conditional content and let me know the results.

#1105473

Thanks Christian - I will try that and get back to you.

#1105477

Hi Christian

Smiling - that was a quick and easy thing to test 🙂

Changing back (moving the conditional from the Loop Editor to the Template) made the output appear wrong (as expected).
After adding

ini_set('pcre.jit', false);

to wp-config-php, the output renders as expected (Client title is shown and not the Page title).

So - what does this mean?

Thanks
Ken

#1105564

The pcre.jit config turns off a specific parsing algorithm used by PHP to evaluate regular expressions (regex). These patterns are used by software to perform inspection, comparison, and manipulation of text strings. In some versions of PHP, the regular expressions used to evaluate conditional HTML in Toolset will cause problems with that algorithm, and lead to strange issues like you're experiencing here. When you disable pcre.jit, an alternate algorithm is used to evaluate those expressions. The difference between the two algorithms in terms of performance is usually not very significant. Our developers have an internal ticket in place to improve the efficiency of some of our regexes used for parsing conditional HTML, but it's not finished yet. We have found that disabling pcre.jit is the most effective solution that can be applied globally right now. You can also try simplifying your conditionals and including less content inside the conditional tags, but often this is not practical.

#1105620

Hi Christian

Okay - thanks for the explanation.

What puzzles me is that when I move the wpv-conditional in the Loop section instead (as shown in code above), the output appears correct evne with the regex code enabled.

Do you have an explanation for that or maybe something interesting for the developers to include in their ticket?

Also - moving the wpv-conditional in the Loop section instead, is that correct use of Views? I actually like it better, but would like to hear your opinion first.

Best
Ken

#1105667

What puzzles me is that when I move the wpv-conditional in the Loop section instead (as shown in code above), the output appears correct evne with the regex code enabled.
The short answer is you moved text blocks around, which changed the patterns analyzed and applied by the regular expression(s). The new arrangement of text doesn't experience the same issues caused by the original arrangement of text, because it's surrounded by different text, in a different order. This is why I say the issue is "strange" - it's not predictable what arrangement of text will experience problems. https://en.wikipedia.org/wiki/Regular_expression

Also - moving the wpv-conditional in the Loop section instead, is that correct use of Views? I actually like it better, but would like to hear your opinion first.
There's nothing inherently right or wrong with it. Just keep in mind that any time you put a conditional in a View's Loop, whether or not it's in a Content Template, the number of results displayed by the View, relative to pagination, may be inaccurate. For example, say your View is set to display 4 posts per page and 6 results are found. A conditional in the View hides one post in the Loop on the first page of results. This means the View will not show 4 posts on the first page. It will only display 3 posts.

#1106561

Thanks for the explanation Christian.

Re the expression: I did notice that reducing the length of the whole expression made a difference. So removing elements of the expression - part for part - eventually made the output correct. So I suspect that length has something to do with it.
Anyway - will leave that to you and the developers to figure out for a long term solution.

Re conditions in the loop: Thanks - I did not consider that because, in this case, I don't use pagination. In fact I only return a single post. But good to know.

So - what is best? To use wpv_filter_query in the backend, use the conditional around the template (output) or use the conditional in the loop?

Also, if I leave the pcre.jit disabled, will it have any negative effects and how will I know when the disabling is no longer needed?

Best
Ken

#1106743

So - what is best? To use wpv_filter_query in the backend, use the conditional around the template (output) or use the conditional in the loop?
The wpv_filter_query in the backend option is best. Pagination consistency will be maintained.

Also, if I leave the pcre.jit disabled, will it have any negative effects
The performance difference between these two algorithms is usually not significant. You would have to run performance tests to see the impact over time on various pages of the site. I am not aware of any other known issues with disabling pcre.jit.

and how will I know when the disabling is no longer needed?
I would consider it a long-term requirement, until you change PHP versions. If you change PHP versions on the server, you could temporarily reactivate pcre.jit and test these conditionals again to see if it's still necessary. When we release a major change to regex functionality, I will search for tickets related to pcre.jit and update all those clients.

#1109261

Thanks a lot Christian.

We have rearranged the View in question and now get the output we expect.

Best
Ken