Current status: Solved. . Done
Applying the_content filters on wysiwyg fields should be optional
  • /plugins/advanced-custom-fields/core/fields/wysiwyg.php:193
    $value = apply_filters('the_content',$value);

    This should be opt-in, with a checkbox in the field editor, because it can create all kinds of problems (incompatiblities with other plugins, infinitite loops when using a filter on the_content to display the custom fields...)
  • Hi jessor,

    I have used the same code as WP (the_content. See below). I don't believe there should be any problems with it. Can you be more specific to the problem / solution?
    <?php
     
    /**
    * Display the post content.
    *
    * @since 0.71
    *
    * @param string $more_link_text Optional. Content for when there is more text.
    * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
    */

    function the_content($more_link_text = null, $stripteaser = false) {
    $content = get_the_content($more_link_text, $stripteaser);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    echo $content;
    }
     
    ?>
  • For instance, I use a filter on the_content to list custom fields on every page (instead of adding it to a page template or creating a shortcode to be inserted manually on every page). Some fields are wysiwyg fields and the filters are applied again, creating an infinite loop.

    Right now I commented apply_filters in wysiwyg.php and display those fields with wpautop(get_field('foo')) but this is obviously not upgrade-safe.

    One solution would be a checkbox in the Avanced Custom Fields Editor to make applying the filters optional.
  • Hi jessor,

    Thanks for the detail. I can understand your problem but unfortunately your situation is not the normal and changing ACF to suit your needs will effect thousands of developers expecting it to behave differently.

    I'll keep it in mind but I recommend coding templates instead of using filters on the_content.

    Cheers
    E
  • yes, please add optional checkbox to disable this option, actually i use the "br" and "p" tag, but now the filter remove all tags. i must put "//$value = apply_filters('the_content',$value); " to disable this option.

    In second time, this filter apply also the_content(); and it's not a good thing. Please disable it for the_content();

  • We shouldn't be re-inventing the wheel on the_content() filter. Please adjust this - causing all sorts of havoc.
  • How do you expect around 100,000 developers having to change their templates to manually apply the the_content filter will feel about this request?
  • Have you guys thought about making a custom function in your theme to get the field value without formatting? Like the default get_field in core/field/acf_field.php

    like:
     
    function get_field_without_formatting($post_id, $field)
    {
    $value = false;
     
    // if $post_id is a string, then it is used in the everything fields and can be found in the options table
    if( is_numeric($post_id) )
    {
    $value = get_post_meta( $post_id, $field['name'], false );
     
    // value is an array, check and assign the real value / default value
    if( empty($value) )
    {
    if( isset($field['default_value']) )
    {
    $value = $field['default_value'];
    }
    else
    {
    $value = false;
    }
    }
    else
    {
    $value = $value[0];
    }
    }
    else
    {
    $value = get_option( $post_id . '_' . $field['name'], null );
     
    if( is_null($value) )
    {
    if( isset($field['default_value']) )
    {
    $value = $field['default_value'];
    }
    else
    {
    $value = false;
    }
    }
     
    }
     
     
    return $value;
    }
  • Hi Elliot,
    I appreciate the response. Not to be rude, but it does sound like you know this is a problem. The function above -- so is that just an addition that "fixes" the issue, or just another workaround? I really hope you consider fixing this. While I agree, would be a pain in the butt to change something -- how about the devs that are having trouble with it now? If you visit the codex, read about the_content() filter and then a plugin says, "no - you can't do that" --> who should a dev place blame on?

    Really love ACF - but would love to get this hashed out. Thanks.
  • Hi yellowhousedesign,

    The blame should not be place on anyone. A plugin can never deliver 100% satisfaction to any 1 user. This to me is not a bug. Out of the 300,000+ downloads, only 3 people have asked about this.

    ACF is to be used by editing your template files and using the API functions. It was never intended to work for this "inception" style embedding of WYSIWYG editors.

    I really urge you to use template files instead of hooks.

    If in the future, I find time to add this in, I will, but for now, please use a custom function as mentioned above.

    Thanks
  • Hi Elliot,
    Thanks for the continued correspondence. I'll give that function a shot for now. Thanks again for ACF - always glad to purchase the add-ons, well worth it!
  • Hi yellowhousedesign,

    After some time working with the shopp plugin, I can now see the issue you are talking about first hand. Yes it is annoying and yes we should find a solution.

    I think the best way is to remove the "the_content" filter and replace it with the wpautop function.

    Then have "the_content" as an option to run so that users can turn it off for compatibility reasons

    Thanks for flagging the issue.

    Cheers
    Elliot
  • Elliot,
    I tried the function you posted above in my theme's functions.php file, but I cannot get it to work. Any suggestions?

    My template code follows:
    `echo get_field_without_formatting('upper_section_header');`

    Any thoughts on how to make this work?
  • Hi @themightymo,

    Can't get it to work? Can you please be a tad more descriptive?
    Also, in the later versions ( check the changelog ) I have added a 3rd param to the get_field / the_field functions to disable formatting.

    Cheers
    Elliot
  • I really wish that there was a way to remove wpautop as well. I expected the "remove the_content filter" to remove the whole thing, which would be perfect. It is weird to me that it only removes part of the the_content filter and still runs the wpautop portion...