array(), 'columns' => array() ); foreach ( array( 'rows' => $rows, 'columns' => $cols ) as $k => $n ) { $src = ( isset( $vis[ $k ] ) && is_array( $vis[ $k ] ) ) ? array_values( $vis[ $k ] ) : array(); for ( $i = 0; $i < $n; $i++ ) { $out[ $k ][] = ( isset( $src[ $i ] ) && 0 === (int) $src[ $i ] ) ? 0 : 1; } } return $out; } /** Defaults for a new table (search and sorting follow the global settings). */ public static function default_options() { return array( 'table_head' => 1, 'highlight' => 0, // Badge on the first data row (e.g. the newest release). 'highlight_label' => '', // Empty: global label. 'search_min' => (int) Settings::get( 'search_min' ), 'sortable' => (int) Settings::get( 'sortable' ), 'extra_css_classes' => '', 'column_types' => array(), // Per column: auto, text, number, date, link, key. ); } public static function normalize_options( $opt, $cols = null ) { $d = self::default_options(); $opt = is_array( $opt ) ? $opt : array(); $out = array( 'table_head' => isset( $opt['table_head'] ) ? (int) (bool) $opt['table_head'] : $d['table_head'], 'highlight' => isset( $opt['highlight'] ) ? (int) (bool) $opt['highlight'] : $d['highlight'], 'highlight_label' => isset( $opt['highlight_label'] ) ? mb_substr( sanitize_text_field( (string) $opt['highlight_label'] ), 0, 40 ) : '', 'search_min' => isset( $opt['search_min'] ) ? max( 0, min( 1000, (int) $opt['search_min'] ) ) : $d['search_min'], 'sortable' => isset( $opt['sortable'] ) ? (int) (bool) $opt['sortable'] : $d['sortable'], 'extra_css_classes' => isset( $opt['extra_css_classes'] ) ? trim( preg_replace( '/[^A-Za-z0-9_\- ]/', '', (string) $opt['extra_css_classes'] ) ) : '', 'column_types' => array(), ); $types = ( isset( $opt['column_types'] ) && is_array( $opt['column_types'] ) ) ? array_values( $opt['column_types'] ) : array(); $n = null === $cols ? count( $types ) : (int) $cols; for ( $i = 0; $i < $n; $i++ ) { $out['column_types'][] = ( isset( $types[ $i ] ) && in_array( $types[ $i ], self::COL_TYPES, true ) ) ? $types[ $i ] : 'auto'; } return $out; } /** Does this post content use table $id through a shortcode or the block? */ public static function content_uses( $content, $id ) { $id = (int) $id; if ( preg_match( '/\[(?:nitida_table|table)\s+[^\]]*\bid=["\']?' . $id . '["\']?[\s\/\]]/', (string) $content ) ) { return true; } return (bool) preg_match( '/