Support » Plugin: Prismatic » PHP warnings with ACF Pro

  • Resolved hiroprot

    (@hiroprot)


    I am getting two warnings in the Apache error log that are caused by treating ACF Pro fields as strings, which they sometimes are not, apparently.

    Warning #1:

    PHP message: PHP Warning: strpos() expects parameter 1 to be string, array given in /wp-content/plugins/prismatic/inc/resources-enqueue.php on line 353

    Line 353 looks like this:

    if (strpos($value, $cls) !== false) {

    The following crude fix seems to work, but there might be more elegant solutions:

    if (is_string($value) && strpos($value, $cls) !== false) {

    Warning #2:

    PHP message: PHP Warning: preg_split() expects parameter 2 to be string, array given in /wp-content/plugins/prismatic/inc/prismatic-core.php on line 28

    Line 28 looks like this:

    $split = preg_split("/(<code[^>]*>.*<\/code>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE);

    I am guessing this happens when $text holds an ACF Pro field value.

    • This topic was modified 2 years, 6 months ago by hiroprot.
    • This topic was modified 2 years, 6 months ago by hiroprot.
    • This topic was modified 2 years, 6 months ago by hiroprot.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Jeff Starr

    (@specialk)

    Thanks for reporting, @hiroprot. I’m not seeing any of these warnings with default WP. Can you let me know the simplest/fewest steps possible to cause them, so I can recreate on default WP install and try to resolve for the next plugin update. Thank you.

    Thread Starter hiroprot

    (@hiroprot)

    Hi Jeff,

    Thanks for the quick answer. I don’t have a vanilla WordPress installation at the moment, but I think I have an idea where the problem is coming from.

    ACF (Pro) has certain field types that are represented as arrays. This is documented with the get_field function: please note that each field type returns different forms of data (string, int, array, etc).

    An example of a field that is returned as an array is the repeater field.

    I hope this helps.

    • This reply was modified 2 years, 6 months ago by hiroprot.
    Plugin Author Jeff Starr

    (@specialk)

    Thanks @hiroprot, it definitely helps. Will take a closer look and try to implement a solution. If you discover any further/related infos, please let me know. Thank you.

    Thread Starter hiroprot

    (@hiroprot)

    Here are some resources that might be useful:

    1. Working with Array values
    2. ACF loop Repeater values with get_field
    Plugin Author Jeff Starr

    (@specialk)

    Thanks. Issue #1 looks straightforward to resolve. For issue #2, I’m hoping that there is a uniform/simple way to get a string value for $text, regardless of the ACF field type (e.g., int, array, et al).

    Plugin Author Jeff Starr

    (@specialk)

    Just to follow up with this. The reported PHP warnings are resolved in the next version of the plugin. Should be available before the WP v5.4 release. Thanks again for reporting @hiroprot.

    Thread Starter hiroprot

    (@hiroprot)

    Awesome, happy to hear this.

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘PHP warnings with ACF Pro’ is closed to new replies.