• Resolved Nox

    (@profnox)


    Hi,

    I’m creating a WordPress theme for a website with some customize fields inside the customizer panel, in order to make the render of different layout parts easy to custom.

    Overall everything is working, however I got a little problem with textaera fields. If I write somes lines (separated with a break line, with the Enter key), the field doesn’t seem to save this state, and put all the text on the same line like a common text field. The problem occurs on save (so at the input, not at the render’s output).

    Here’s the part of code relative to the textarea field in my customizer.php file :

        $wp_customize->add_setting( 'ef_footer_resume', array(
            'capability' => 'edit_theme_options',
            'default' => '',
            //'sanitize_callback' => 'sanitize_text_field',
        ) );
        $wp_customize->add_control( 'ef_footer_resume', array(
            'type' => 'textarea',
            'label' => __( 'à propos'),
            'section' => 'footer',
        ) );

    I tried to remove (put in comment) the sanitize callback, but it doesn’t change anything. Can someone help me on this point ?

    Thank you in advance.

    Developing on WordPress 4.9.6

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Try 'sanitize_callback' => 'addslashes',

    Thread Starter Nox

    (@profnox)

    Hi,

    Thanks, unfortunately, it doesn’t change anything…

    Moderator bcworkz

    (@bcworkz)

    I just confirmed my suggestion indeed does not work, however, this does:
    'sanitize_callback' => 'my_sanitation',

    then

    function my_sanitation( $text ) {
       return addslashes( $text );
    }

    This seems functionally equivalent to my initial suggestion, but somehow the results are different. Weird!

    Thread Starter Nox

    (@profnox)

    Thank you, indeed that is weird but this way works nice.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Customizer textarea field doesn’t keep break lines’ is closed to new replies.