true, 'id' => true, 'style' => true, 'aria-label' => true, 'aria-hidden' => true, 'aria-describedby' => true, 'data-*' => true, ); $field = $common + array( 'name' => true, 'value' => true, 'type' => true, 'placeholder' => true, 'required' => true, 'disabled' => true, 'checked' => true, 'selected' => true, 'multiple' => true, 'min' => true, 'max' => true, 'step' => true, 'maxlength' => true, 'rows' => true, 'cols' => true, 'for' => true, 'autocomplete' => true, ); $svg = array( 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'fill-rule' => true, 'clip-rule' => true, 'transform' => true, 'opacity' => true, 'class' => true, 'style' => true, ); $extra = array( 'template' => $common, 'dialog' => $common + array( 'open' => true ), 'iframe' => $common + array( 'src' => true, 'width' => true, 'height' => true, 'title' => true, 'frameborder' => true, 'allow' => true, 'allowfullscreen' => true, 'loading' => true, 'referrerpolicy' => true, ), 'form' => $common + array( 'action' => true, 'method' => true, 'role' => true, ), 'input' => $field, 'select' => $field, 'option' => $field, 'textarea' => $field, 'button' => $field, 'label' => $field, 'svg' => $svg + array( 'xmlns' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'role' => true, 'aria-hidden' => true, 'focusable' => true, ), 'g' => $svg, 'path' => $svg + array( 'd' => true ), 'circle' => $svg + array( 'cx' => true, 'cy' => true, 'r' => true, ), 'ellipse' => $svg + array( 'cx' => true, 'cy' => true, 'rx' => true, 'ry' => true, ), 'rect' => $svg + array( 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true, 'ry' => true, ), 'line' => $svg + array( 'x1' => true, 'y1' => true, 'x2' => true, 'y2' => true, ), 'polyline' => $svg + array( 'points' => true ), 'polygon' => $svg + array( 'points' => true ), ); foreach ( $extra as $tag => $attrs ) { $allowed[ $tag ] = array_merge( isset( $allowed[ $tag ] ) ? $allowed[ $tag ] : array(), $attrs ); } // Attributes the plugin's own markup uses on any tag (accessibility, state, data). $global = array( 'role' => true, 'tabindex' => true, 'hidden' => true, 'title' => true, 'aria-controls' => true, 'aria-current' => true, 'aria-expanded' => true, 'aria-haspopup' => true, 'aria-label' => true, 'aria-labelledby' => true, 'aria-live' => true, 'aria-modal' => true, 'aria-pressed' => true, 'aria-selected' => true, 'data-*' => true, ); foreach ( $allowed as $tag => $attrs ) { if ( is_array( $attrs ) ) { $allowed[ $tag ] = $attrs + $global; } } /** * Filters the tags and attributes allowed in block and shortcode content. * * @param array $allowed wp_kses() allowed HTML. */ $allowed = (array) apply_filters( 'cpod_allowed_html', $allowed ); return $allowed; } } if ( ! function_exists( 'cpod_strip_code_tags' ) ) { /** * HTML without script, style and title elements (their content included, so * code does not show up as text), then filtered with cpod_allowed_html(). * * @param string $html HTML. * @return string */ function cpod_strip_code_tags( $html ) { $html = (string) preg_replace( '#<(script|style|title)\b[^>]*>.*?#is', '', (string) $html ); $html = (string) preg_replace( '#<(script|style|title)\b[^>]*>.*$#is', '', $html ); // Left open. return wp_kses( $html, cpod_allowed_html() ); } } if ( ! function_exists( 'cpod_admin_script' ) ) { /** * Enqueue an admin script file of the plugin (footer, after jQuery), with * optional data it reads as window.cpodData_. * * @param string $handle Handle. * @param string $file Path of the file inside the plugin folder. * @param array $data Data for the script. */ function cpod_admin_script( $handle, $file, $data = array() ) { $path = CPOD_DIR . $file; wp_enqueue_script( $handle, CPOD_URL . $file, array( 'jquery' ), CPOD_VERSION . ( is_readable( $path ) ? '.' . filemtime( $path ) : '' ), true ); if ( $data ) { wp_add_inline_script( $handle, 'var cpodData_' . str_replace( '-', '_', $handle ) . ' = ' . wp_json_encode( $data ) . ';', 'before' ); } } } if ( ! function_exists( 'cpod_admin_style' ) ) { /** * Enqueue an admin stylesheet of the plugin. * * @param string $handle Handle. * @param string $file Path of the file inside the plugin folder. */ function cpod_admin_style( $handle, $file ) { $path = CPOD_DIR . $file; wp_enqueue_style( $handle, CPOD_URL . $file, array(), CPOD_VERSION . ( is_readable( $path ) ? '.' . filemtime( $path ) : '' ) ); } }