{"id":10791453,"date":"2018-10-18T07:17:25","date_gmt":"2018-10-18T07:17:25","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/fix-function-hooks-in-wcff-builder-php\/"},"modified":"2018-10-18T14:32:00","modified_gmt":"2018-10-18T14:32:00","slug":"fix-function-hooks-in-wcff-builder-php","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/fix-function-hooks-in-wcff-builder-php\/","title":{"rendered":"Fix function hooks in wcff-builder.php"},"content":{"rendered":"<p>Hi, <\/p>\n<p>we&#8217;ve noticed that inside <code>function built_field_wrapper<\/code>, there are 2 calls to has_action()\/do_filter() function instead of has_filter()\/apply_filters().<br \/>\nCould you please change this code snippet inside \/includes\/<strong>wcff-builder.php<\/strong>: <\/p>\n<pre><code>\n...\n\/* CHeck for the custom wrapper action registered *\/\nif (has_action(&#039;wccpf_before_field_rendering&#039;) &amp;&amp; has_action(&#039;wccpf_after_field_rendering&#039;)) {\n    $before = do_filter(&#039;wccpf_before_field_rendering&#039;, $_meta);\t                $after = do_filter(&#039;wccpf_after_field_rendering&#039;, $_meta);\n    $html = $before . $_html . $after;\n} else {\n    \/* Special property for URL field alone *\/\n...\n\n<\/code><\/pre>\n<p>with:<\/p>\n<pre><code>\n...\n\/* CHeck for the custom wrapper action registered *\/\nif (has_filter(&#039;wccpf_before_field_rendering&#039;) &amp;&amp; has_filter(&#039;wccpf_after_field_rendering&#039;)) {\n    $before = apply_filters(&#039;wccpf_before_field_rendering&#039;, &#039;&#039;, $_meta);\t                $after = apply_filters(&#039;wccpf_after_field_rendering&#039;, &#039;&#039;, $_meta);\n    $html = $before . $_html . $after;\n} else {\n    \/* Special property for URL field alone *\/\n...\n\n<\/code><\/pre>\n<p>The do_filter() function is not defined in WP and causes a Execution error, moreover it would be nicer to change the logic to the following one: <\/p>\n<pre><code>\nif ($_meta[&quot;type&quot;] != &quot;url&quot;) {\n            \t$_html .= &#039;&lt;span class=&quot;wccpf-validation-message&quot;&gt;&#039; . (isset($_meta[&quot;message&quot;]) ? $_meta[&quot;message&quot;] : &quot;&quot;) . &#039;&lt;\/span&gt;&#039;;\n            }\n\n            \/* Special property for URL field alone *\/\n            $show_label = isset($_meta[&quot;show_label&quot;]) ? $_meta[&quot;show_label&quot;] : &quot;yes&quot;;\n            \/* Default field wrapper *\/\n            $wrapper_class = (isset($_meta[&quot;field_class&quot;]) &amp;&amp; !empty($_meta[&quot;field_class&quot;])) ? $_meta[&quot;field_class&quot;] : $_meta[&quot;name&quot;];\n            \/* Is init field show or hide *\/\n            $onload_field = (isset($_meta[&quot;initial_show&quot;]) &amp;&amp; $_meta[&quot;initial_show&quot;] == &quot;no&quot; ) ? &quot;display: none;&quot; : &quot;&quot;;\n            $html_before = &#039;&lt;table style=&quot;&#039;.$onload_field.&#039;&quot; class=&quot;wccpf_fields_table &#039; . apply_filters(&#039;wccpf_fields_container_class&#039;, &#039;&#039;) . &#039; &#039;. $wrapper_class.&#039;-wrapper&quot;&gt;&#039;;\n            $html_before .= &#039;&lt;tbody&gt;&#039;;\n            $html_before .= &#039;&lt;tr&gt;&#039;;\n            \n            if ($_meta[&quot;type&quot;] != &quot;url&quot; || $show_label == &quot;yes&quot;) {\n                $html .= &#039;&lt;td class=&quot;wccpf_label&quot;&gt;&lt;label for=&quot;&#039; . esc_attr($_meta[&quot;name&quot;] . $_index) . &#039;&quot;&gt;&#039; . esc_html($_meta[&quot;label&quot;]) . &#039;&#039; . ((isset($_meta[&quot;required&quot;]) &amp;&amp; $_meta[&quot;required&quot;] == &quot;yes&quot;) ? &#039; &lt;span&gt;*&lt;\/span&gt;&#039; : &#039;&#039;) . &#039;&lt;\/label&gt;&lt;\/td&gt;&#039;;\n            }\n            $html_before .= &#039;&lt;td class=&quot;wccpf_value&quot;&gt;&#039;;\n            \n            $html_before = apply_filters(&#039;wccpf_before_field_rendering&#039;, $html_before, $_meta, $_index);\n            \n            $html_after = &#039;&lt;\/td&gt;&#039;;\n            $html_after .= &#039;&lt;\/tr&gt;&#039;;\n            $html_after .= &#039;&lt;\/tbody&gt;&#039;;\n            $html_after .= &#039;&lt;\/table&gt;&#039;;                \n            \n            $html_after = apply_filters(&#039;wccpf_after_field_rendering&#039;, $html_after, $_meta, $_index);\n\n            $html = $html_before . $_html . $html_after;\n<\/code><\/pre>\n<p>This allows not to replicate the template when applying the filters.<\/p>\n<p>Please let us know,<br \/>\nThank you<\/p>\n","protected":false},"template":"","class_list":["post-10791453","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10791453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10791453\/revisions"}],"predecessor-version":[{"id":10791461,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10791453\/revisions\/10791461"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=10791453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}