Support

Account

Home Forums Bug Reports WYSIWYG and apply_filters 'the_content' issue

Solved

WYSIWYG and apply_filters 'the_content' issue

  • Hey everybody,
    I’m stuck with trying to apply_filters('the_content', $value) in order to validate a Jetpack Contact Form.

    I’m using the Flexible Content field. Been reading some possible solutions here in the forum but no success.

    First I tried this solution: http://support.advancedcustomfields.com/forums/topic/wysiwyg-editor-jetpack-contact-form/

    … then this one:
    http://support.advancedcustomfields.com/forums/topic/repeater-wywiwyg-bug-with-shortcode/

    And I’m echoing the fields in this fashion:
    echo $field ? $field : ' ';
    … also tried:
    echo $field ? apply_filters('the_content', $field) : ' ';

    … but still no luck. Is this a current issue?

    Any help would be really appreciated.
    Cheers!

  • Hi @angel.meraz

    Can you please debug the value to $field to make sure the code will work correctly?
    http://www.advancedcustomfields.com/resources/debug/

    Thanks
    E

  • Thanks @Elliot Condon

    I put this little test page up http://galo.prompt-dev.com where:
    Debug is enabled: define('WP_DEBUG', true);
    Inside functions.php I’ve got:

    add_filter('acf/format_value/type=wysiwyg', 'format_value_wysiwyg', 10, 3);
    function format_value_wysiwyg( $value, $post_id, $field ) {
    	$value = apply_filters( 'the_content', $value );
    	return $value;
    }

    Also tried to apply_filters directly when printing the $value but not in combination with the previous function, like this:
    (like suggested here http://support.advancedcustomfields.com/forums/topic/wysiwyg-editor-jetpack-contact-form/ )

    $wysiwyg = get_field('editor');	
    echo apply_filters('the_content', $wysiwyg);

    But still haven’t got it working… I’m trying to add a working Jetpack Contact Form from a WYSIWYG Editor within a Flexible Content Field. The example page is a stand-alone test case using just a WYSIWYG Editor field.

    Find some print screens attached.

  • Hi @angel.meraz

    Please debug the value of $field. What is the value printed using a print_r statement?

    Is there any value at all? Is it a string? Does it contain the shortcode?

  • Hey @Elliot Condon, thanks again for looking into this.
    I’m using this code to print the value of the field in the test page:
    http://galo.prompt-dev.com

    <?php the_content();
    // ACF
    $wysiwyg = get_field('editor');	
    echo $wysiwyg; ?>
    <hr><br>
    <code>print_r($wysiwyg):</code>
    <br><br>
    <pre><?php print_r($wysiwyg); ?></pre>

    When printing the value the form is being displayed, it contains the shortcode’s result (?).

    Also both ACF(v5.1.9) and Jetpack(v3.3.2) plugins are running latest versions.

    If ever needed I can give you access to the test page.
    Cheers!

  • Hey @Elliot Condon any news on the issue?
    I’m about to publish a project that needs this particular functionality! :S

    Cheers mate and thanks in advance!

  • Hi @angel.meraz

    In your last comment you mentioned:
    When printing the value the form is being displayed

    So the shortcode is working correctly?

    This means that the the_content filter is working correctly.

    Lets head back to the start of this thread where you mentioned:
    I’m stuck with trying to apply_filters('the_content', $value) in order to validate a Jetpack Contact Form.

    Perhaps validating a Jetpack form has nothing to do with the the_content filter? Why do you think it is related?

    Thanks
    E

  • Probably you’re right and it has nothing to do with the_content filter.
    I adopted that idea from similar posts of people having the same issue.

    Problem is -although the form is being displayed- it just doesn’t works. But if the shortcode was placed in the default WYSIWYG WordPress editor it would.

    In the example test page provided ( http://galo.prompt-dev.com ) the Jetpack form is being inserted via an ACF WYSIWYG field.

    What could it be then?

  • Hi @angel-meraz

    I’m not sure what is meant to be happening, but the form is displayed and has submitted.

    Perhaps you can contact the developer of the form plugin? Also, please do some debugging through the form plugin code to test where the issue could be.

    Please note that it just doesn’t works is not very helpful for me to understand the issue and to provide useful feedback. Descriptive language is needed to fully understand what the issue is and where it is coming from.

  • Hey @elliot thank you for looking into this.

    Basically, the problem is that the form is not submitting.

    If the shortcode were entered through the native WordPress WYSIWYG editor after submitting it should display a message, create a data entry inside Jetpack’s Feedback menu tab and send an email. None of that happens when the shortcode is inserted through an ACF field.

    Please take a look a this tests and try to submit the forms:
    Test 1 http://galo.prompt-dev.com/
    Test 2 http://galo.prompt-dev.com/jetpack-form-shortcode-test-2/

    Any pointers are welcome.

  • Hi @angel-meraz

    I’ve just taken a look at both links, and have found some interesting results.

    Test 1: Content area – This form works perfectly.
    Test 2: Content area – This form does not work
    Test 2: ACF area – This form does not work

    It is possible that the issue is not with ACF, but more the fact that the form does not work at all on the second link. Perhaps try removing your ACF code from ‘Test 2’ and trying to submit the form within the ‘Content area’, does it work? If not, the issue is not related to ACF.

    The other thing to note is that you are using print_r to render the form within a ‘pre’ tag. This is good for testing data, but may cause a form to not work as expected. Please remove the ‘pre’ tags, remove the print_r and use the_field instead of get_field

  • I updated the test site, followed your recommendation and I can confirm that the Jetpack Form shortcode does not work when inserted via an ACF field.

    The code used to display the ACF field is:

    <?php $wysiwyg = get_field('editor');
    if ( $wysiwyg ) {
    	the_field('editor');
    } else {
    	echo 'ACF field is empty';
    } ?>

    The shortcode used to display the Jetpack Form in both tests is:

    [contact-form to='[email protected]' subject='Shortcode Test 1'][contact-field label='Name' type='name' required='1'/][contact-field label='Comment' type='textarea' required='1'/][/contact-form]

  • Hi @angel-meraz

    Thanks for the info.
    I have attached a screenshot of what I see – a working shortcode.

    The form is rendered correctly, so perhaps there is something else which I do not understand.

    If the issue is with ‘saving’ the data which is posted from the form, this may not be related to the WYSIWYG field at all, but something to do with the 3rd party plugin.

    Are you able to contact the form developers and ask them what the solution is? I’m sure that someone else has used ACF with their form before and they have a solution

    Thanks
    E

  • Hey @elliot I really thank you very much for following this up.

    Just to leave clear what the real issue is, its not about the shortcode not printing the form when inserted through an ACF field -because it does- but that the form fails to submit.

    I also created a support topic for the Jetpack plugin in the WordPress repository: https://wordpress.org/support/topic/jetpack-contact-form-shortcode-not-working-when-inserted-via-a-custom-field?replies=1
    …but still waiting for a reply.

    I do think that due to the relevance of both plugins -ACF and Jetpack- this issue shouldn’t be consider as a minor issue.

  • Howdy,

    Kraft from Automattic/Jetpack:

    The Contact Form on submit reloads the current page with items in the POST (using the PHP superglobal). Not being sure how ACF handles this exactly, if the POST isn’t able to be passed through the form and/or the code isn’t loaded until late, etc, I could see this short-circuiting the process.

    We look for the POST here: https://github.com/Automattic/jetpack/blob/master/modules/contact-form/grunion-contact-form.php#L111-121

    and then process that via
    https://github.com/Automattic/jetpack/blob/master/modules/contact-form/grunion-contact-form.php#L141-210

    Thanks!

  • Hi @kraft

    Thanks for the info.

    All the $_POST data should be fine, as ACF is rendering the form via do_shortcode and all input names within the form look correct.

    perhaps the issue is explained by the code on line https://github.com/Automattic/jetpack/blob/master/modules/contact-form/grunion-contact-form.php#L180.

    If you are running the the_content filter during the function, perhaps you have some code which is looking for an embeded form, which you then use as a validation method to continue processing the form.

    ACF save’s the shortcode (string) value within the post meta, not the $post->post_content so this validation would fail each time.

    Perhaps as a temp solution @angel-meraz could place the embed code within the post’s content as well as the ACF WYSIWYG field?

  • Hi @elliot thank you for your input.
    I did follow your recommendation as a temp solution.

    Do you see this being implemented in a future release?
    Having the embed code in both the post’s editor and the ACF WYSIWYG field isn’t ideal.

    Cheers and thanks again!

  • Hi @angel-meraz

    Thanks for the reply.

    This issue can’t be fixed from my end, due to the contact-form looking within the $post->post_content instead of looking within the shortcode.

    I believe this could be addressed by the contact-form plugin developer to add compatibility for the shortcode being used within a custom field instead of the post_content.

    Thanks
    E

Viewing 18 posts - 1 through 18 (of 18 total)

The topic ‘WYSIWYG and apply_filters 'the_content' issue’ is closed to new replies.