true, 'class' => true, 'style' => true, 'title' => true, 'role' => true, 'hidden' => true, 'tabindex' => true,
'aria-*' => true, 'data-*' => true, 'contenteditable' => true, 'spellcheck' => true, 'dir' => true, 'lang' => true,
);
$field = array_merge( $common, array(
'name' => true, 'value' => true, 'type' => true, 'disabled' => true, 'readonly' => true, 'required' => true,
'placeholder' => true, 'autocomplete' => true, 'form' => true, 'autofocus' => true,
) );
$tags = wp_kses_allowed_html( 'post' );
foreach ( $tags as $t => $attrs ) {
$tags[ $t ] = array_merge( is_array( $attrs ) ? $attrs : array(), $common );
}
$tags['form'] = array_merge( $common, array( 'action' => true, 'method' => true, 'enctype' => true, 'novalidate' => true, 'target' => true, 'autocomplete' => true ) );
$tags['input'] = array_merge( $field, array( 'checked' => true, 'min' => true, 'max' => true, 'step' => true, 'pattern' => true, 'maxlength' => true, 'minlength' => true, 'size' => true, 'accept' => true, 'multiple' => true, 'list' => true, 'inputmode' => true ) );
$tags['select'] = array_merge( $field, array( 'multiple' => true, 'size' => true ) );
$tags['option'] = array_merge( $common, array( 'value' => true, 'selected' => true, 'disabled' => true, 'label' => true ) );
$tags['optgroup'] = array_merge( $common, array( 'label' => true, 'disabled' => true ) );
$tags['textarea'] = array_merge( $field, array( 'rows' => true, 'cols' => true, 'maxlength' => true, 'minlength' => true, 'wrap' => true ) );
$tags['button'] = array_merge( $field, array( 'formaction' => true, 'formmethod' => true ) );
$tags['label'] = array_merge( $common, array( 'for' => true ) );
$tags['fieldset'] = array_merge( $common, array( 'disabled' => true, 'name' => true ) );
$tags['legend'] = $common;
$tags['details'] = array_merge( $common, array( 'open' => true ) );
$tags['summary'] = $common;
$tags['main'] = $common;
$tags['progress'] = array_merge( $common, array( 'value' => true, 'max' => true ) );
self::$allowed = apply_filters( 'frontglut_allowed_html', $tags );
return self::$allowed;
}
/** Escape plugin-built HTML (forms, tables, panels) for output. */
public static function kses( $html ) {
return wp_kses( (string) $html, self::allowed_html() );
}
public static function icon( $name ) {
return '';
}
public static function notice( $msg, $type = 'info' ) {
return '
' . wp_kses_post( $msg ) . '
';
}
public static function badge( $text, $type = '' ) {
return '' . esc_html( $text ) . '';
}
public static function status_badge( $status ) {
$map = array( 'publish' => 'ok', 'published' => 'ok', 'completed' => 'ok', 'approved' => 'ok', 'active' => 'ok', 'processing' => 'info', 'pending' => 'warn', 'on-hold' => 'warn', 'draft' => '', 'open' => 'warn', 'closed' => '', 'rejected' => 'bad', 'cancelled' => 'bad', 'failed' => 'bad', 'refunded' => 'bad', 'trash' => 'bad', 'private' => '' );
$label = ucwords( str_replace( array( '-', '_' ), ' ', $status ) );
return self::badge( $label, isset( $map[ $status ] ) ? $map[ $status ] : '' );
}
/** $actions_html must already be escaped. */
public static function header( $title, $actions_html = '', $sub = '' ) {
return '' . esc_html( $title ) . '
' . ( $sub ? '
' . esc_html( $sub ) . '
' : '' ) . '
' . $actions_html . '
';
}
public static function btn( $label, $url = '#', $class = '', $attrs = '' ) {
return '' . esc_html( $label ) . '';
}
public static function stat( $label, $value, $sub = '' ) {
return '' . esc_html( $label ) . '' . wp_kses_post( $value ) . '' . ( $sub ? '' . esc_html( $sub ) . '' : '' ) . '
';
}
public static function empty_state( $msg, $cta_html = '' ) {
return '' . esc_html( $msg ) . '
' . $cta_html . '
';
}
/**
* @param array $cols key => label
* @param array $rows list of assoc rows; cell values are HTML (caller escapes!). Optional '_id' for bulk checkbox.
* @param array $o bulk (bool), id (string)
*/
public static function table( array $cols, array $rows, array $o = array() ) {
if ( ! $rows ) {
return self::empty_state( isset( $o['empty'] ) ? $o['empty'] : __( 'Nothing here yet.', 'frontglut' ) );
}
$bulk = ! empty( $o['bulk'] );
$h = '';
}
public static function pager( $total, $per, $page, array $args = array() ) {
$pages = (int) ceil( $total / max( 1, $per ) );
if ( $pages < 2 ) {
return '';
}
$args = array_merge( $args, Request::args() );
$h = '';
}
/** Search + select filters bar. $filters: name => [label, options(value=>label)] */
public static function filters( array $filters, array $current, $search = true ) {
$h = '';
}
/** Open an AJAX form. Returned markup must be closed with form_close(). */
public static function form_open( $do, array $o = array() ) {
$o = array_merge( array( 'after' => 'none', 'class' => '', 'extra' => '' ), $o );
return '';
}
public static function hidden( $name, $value ) {
return '';
}
/** Button that fires an ajax action. */
public static function action_btn( $label, $do, array $data = array(), $class = '', $confirm = false, $after = 'reload' ) {
$a = ' data-frontglut-do="' . esc_attr( $do ) . '" data-frontglut-after="' . esc_attr( $after ) . '"' . ( $confirm ? ' data-frontglut-confirm="1"' : '' );
foreach ( $data as $k => $v ) {
$a .= ' data-' . esc_attr( sanitize_key( $k ) ) . '="' . esc_attr( $v ) . '"';
}
return '';
}
public static function money( $v ) {
return function_exists( 'wc_price' ) ? wc_price( $v ) : esc_html( number_format_i18n( (float) $v, 2 ) );
}
public static function date( $mysql_or_ts ) {
$ts = is_numeric( $mysql_or_ts ) ? (int) $mysql_or_ts : strtotime( $mysql_or_ts . ( is_string( $mysql_or_ts ) && false === strpos( $mysql_or_ts, '+' ) ? ' UTC' : '' ) );
return $ts ? esc_html( wp_date( get_option( 'date_format' ), $ts ) ) : '—';
}
}