Support

Account

Home Forums General Issues Message field, and wp_kses_allowed_html Reply To: Message field, and wp_kses_allowed_html

  • Yes it is. I have it set up to allow both input and textarea fields for a plugin. I use it to shoe input and textareas to allow copy and paste of shortcodes from the editor for my CPT.

    
    <?php 
    
    add_filter('acf/prepare_field/key=field_619663d258c1e', 'shortcodes_messages', 20);
    function shortcodes_messages($field) {
      global $post;
      if (is_a($post, 'WP_POST')) {
        ob_start();
        
        // I generate message here
        
        $field['message'] = ob_get_clean();
      }
      return $field;
    }
    
    add_filter('wp_kses_allowed_html', 'allow_input_in_acf', 20, 2);
    function allow_input_in_acf($tags, $context) {
      $attributes = array(
        'type',
        'disabled',
        'checked',
        'style',
        'name',
        'value',
        'class',
        'id',
        'style',
        'readonly'
      );
      if ('acf' === $context) {
        if (!isset($tags['input'])) {
          $tags['input'] = array();
        }
        foreach ($attributes as $attribute) {
          $tags['input'][$attribute] = true;
        }
        if (!isset($tags['textarea'])) {
          $tags['textarea'] = array();
        }
        foreach ($attributes as $attribute) {
          $tags['textarea'][$attribute] = true;
        }
      }
      return $tags;
    }