AdvancedCustomFields / AdvancedCustomFields/acf

Working with the wp_kses_allowed_html

Open
#501 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Originally posted by @CreativeDive in https://github.com/AdvancedCustomFields/acf/issues/500#issuecomment-844809750

add_filter( 'wp_kses_allowed_html', function( $tags, $context ) {
        
	if( 'post' !== $context ) {
		return $tags;	
	}

	global $tags;

	// allowed attributes
	$allowed_atts = array(
		'class' => array(),
		'id' => array(),
		'style' => array(),
		'isolation' => array (),
		'align' => array(),
		'src' => array(),
		'alt' => array(),
		'title' => array(),
		'href' => array(),
		'rel' => array(),
		'rev' => array(),
		'target' => array(),
		'name' => array(),
		'tabindex' => array(),
		'for' => array(),
		'width' => array(),
		'height' => array(),
		'data' => array(),
		'data-parent' => array(),
		'data-toggle' => array(),
		'data-id' => array(),
		'srcset' => array(),
		'loading' => array(),
		'sizes' => array(),
		'itemprop' => array(),
		'frameborder' => array(),
		'allowfullscreen' => array(),
		'allowtransparency' => array(),
		'd' => array(),
		'version' => array(),
		'viewbox' => array(), // <= Must be lower case!
		'xmlns' => array(),
		'xmlns:xlink' => array(),
		'x' => array(),
		'y' => array(),
		'xml:space' => array(),
		'fill' => array(),
		'fill-opacity' => array(),
		'opacity' => array(),
		'points' => array(),
		'preserveaspectratio' => array(), // <= Must be lower case!
		'clippathunits' => array(), // <= Must be lower case!
		'transform' => array(),
		'role' => array(),
		'focusable' => array(),
		'aria-hidden' => array(),
	);

	// allowed tags
	$tags['iframe'] = $allowed_atts;
	$tags['style'] = $allowed_atts;
	$tags['noscript'] = $allowed_atts;
	$tags['div'] = $allowed_atts;
	$tags['img'] = $allowed_atts;
	$tags['svg'] = $allowed_atts;
	$tags['defs'] = $allowed_atts;
	$tags['clippath'] = $allowed_atts;
	$tags['foreignobject'] = $allowed_atts;
	$tags['g'] = $allowed_atts;
	$tags['path'] = $allowed_atts;
	$tags['rect'] = $allowed_atts;
	$tags['polygon'] = $allowed_atts;
	$tags['strong'] = $allowed_atts;
	$tags['small'] = $allowed_atts;
	$tags['caption'] = $allowed_atts;
	$tags['table'] = $allowed_atts;
	$tags['tbody'] = $allowed_atts;
	$tags['thead'] = $allowed_atts;
	$tags['tfoot'] = $allowed_atts;
	$tags['th'] = $allowed_atts;
	$tags['tr'] = $allowed_atts;
	$tags['td'] = $allowed_atts;
	$tags['form'] = $allowed_atts;
	$tags['fieldset'] = $allowed_atts;
	$tags['legend'] = $allowed_atts;
	$tags['label'] = $allowed_atts;
	$tags['input'] = $allowed_atts;
	$tags['button'] = $allowed_atts;
	$tags['select'] = $allowed_atts;
	$tags['datalist'] = $allowed_atts;
	$tags['optgroup'] = $allowed_atts;
	$tags['option'] = $allowed_atts;
	$tags['textarea'] = $allowed_atts;
	$tags['keygen'] = $allowed_atts;
	$tags['output'] = $allowed_atts;
	$tags['progress'] = $allowed_atts;
	$tags['meter'] = $allowed_atts;
	$tags['span'] = $allowed_atts;
	$tags['abbr'] = $allowed_atts;
	$tags['acronym'] = $allowed_atts;
	$tags['mark'] = $allowed_atts;
	$tags['address'] = $allowed_atts;
	$tags['files'] = $allowed_atts;
	$tags['blockquote'] = $allowed_atts;
	$tags['figure'] = $allowed_atts;
	$tags['figcaption'] = $allowed_atts;
	$tags['time'] = $allowed_atts;
	$tags['data'] = $allowed_atts;
	$tags['cite'] = $allowed_atts;
	$tags['q'] = $allowed_atts;
	$tags['code'] = $allowed_atts;
	$tags['pre'] = $allowed_atts;
	$tags['header'] = $allowed_atts;
	$tags['main'] = $allowed_atts;
	$tags['nav'] = $allowed_atts;
	$tags['section'] = $allowed_atts;
	$tags['article'] = $allowed_atts;
	$tags['aside'] = $allowed_atts;
	$tags['footer'] = $allowed_atts;
	$tags['embed'] = $allowed_atts;
	$tags['object'] = $allowed_atts;
	$tags['param'] = $allowed_atts;
	$tags['video'] = $allowed_atts;
	$tags['audio'] = $allowed_atts;
	$tags['source'] = $allowed_atts;
	$tags['track'] = $allowed_atts;
	$tags['canvas'] = $allowed_atts;
	$tags['map'] = $allowed_atts;
	$tags['area'] = $allowed_atts;
	$tags['math'] = $allowed_atts;
	$tags['h1'] = $allowed_atts;
	$tags['h2'] = $allowed_atts;
	$tags['h3'] = $allowed_atts;
	$tags['h4'] = $allowed_atts;
	$tags['h5'] = $allowed_atts;
	$tags['h6'] = $allowed_atts;
	$tags['ol'] = $allowed_atts;
	$tags['ul'] = $allowed_atts;
	$tags['li'] = $allowed_atts;
	$tags['sup'] = $allowed_atts;
	$tags['sub'] = $allowed_atts;
	$tags['del'] = $allowed_atts;
	$tags['ins'] = $allowed_atts;
	$tags['dl'] = $allowed_atts;
	$tags['dt'] = $allowed_atts;
	$tags['dd'] = $allowed_atts;
	$tags['em'] = $allowed_atts;
	$tags['hr'] = $allowed_atts;
	$tags['br'] = $allowed_atts;
	$tags['wbr'] = $allowed_atts;
	$tags['p'] = $allowed_atts;
	$tags['a'] = $allowed_atts;
	$tags['b'] = $allowed_atts;
	$tags['i'] = $allowed_atts;
	$tags['u'] = $allowed_atts;
	$tags['s'] = $allowed_atts;
	$tags['extended_valid_elements'] = 'style';

	return $tags;
        
}, 10, 2 );

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue only provides a wp_kses_allowed_html filter snippet and does not name a repository file, test, or expected change. Start by locating the filter integration point in the WordPress-related code, then clarify the intended behavior and how completion would be verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.