$value ) { if ( null === $value || false === $value ) { continue; } $out .= true === $value ? ' ' . esc_attr( $name ) : sprintf( ' %s="%s"', esc_attr( $name ), esc_attr( $value ) ); } return $out; } /** Tags and attributes of the form controls built by input(), for wp_kses(). */ private static function control_html() { $common = array( 'class' => true, 'id' => true, 'data-setting' => true, ); return array( 'div' => array( 'class' => true ), 'span' => array( 'class' => true ), 'input' => $common + array( 'type' => true, 'value' => true, 'placeholder' => true, 'min' => true, 'max' => true, 'disabled' => true, 'autocomplete' => true, 'spellcheck' => true, ), ); } /** Tags and attributes of the plugin's SVG logo, for wp_kses(). */ public static function svg_html() { return array( 'svg' => array( 'class' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'aria-hidden' => true, ), 'rect' => array( 'width' => true, 'height' => true, 'rx' => true, 'fill' => true, ), 'path' => array( 'd' => true, 'fill' => true, ), ); } /** Tags and attributes of a Dashicons icon, for wp_kses(). */ public static function icon_html() { return array( 'span' => array( 'class' => true, 'aria-hidden' => true, ), ); } public static function kses() { return array( 'code' => array(), 'strong' => array(), 'em' => array(), 'br' => array(), 'a' => array( 'href' => true, 'target' => true, 'rel' => true ), ); } /** Opening markup of a setting row. $stack puts the control under the text. */ private static function row_start( $id, $label, $args, $stack = false, $extra_class = '' ) { printf( '
', $stack ? ' cfsp-row-stack' : '', $extra_class ? ' ' . esc_attr( $extra_class ) : '', empty( $args['show_if'] ) ? '' : ' data-show-if="' . esc_attr( $args['show_if'] ) . '"', esc_attr( $id ), esc_html( $label ) ); if ( ! empty( $args['help'] ) ) { echo '

' . wp_kses( $args['help'], self::kses() ) . '

'; } if ( ! empty( $args['warn'] ) ) { echo '

' . esc_html( $args['warn'] ) . '

'; } echo '
'; } private static function row_end() { echo '
'; } public static function card_start( $title, $desc = '', $args = array() ) { printf( '
', empty( $args['show_if'] ) ? '' : ' data-show-if="' . esc_attr( $args['show_if'] ) . '"', empty( $args['id'] ) ? '' : ' id="' . esc_attr( $args['id'] ) . '"' ); echo '

' . esc_html( $title ) . '

'; if ( $desc ) { echo '

' . wp_kses( $desc, self::kses() ) . '

'; } echo '
'; if ( ! empty( $args['badge'] ) ) { echo '' . esc_html( $args['badge'][0] ) . ''; } echo '
'; } public static function card_end() { echo '
'; } public static function toggle( $key, $label, $args = array() ) { $id = 'cfsp-f-' . $key; self::row_start( $id, $label, $args, false, 'cfsp-row-toggle' ); printf( '', esc_attr( $id ), esc_attr( $key ), checked( (bool) self::value( $key ), true, false ) ); self::row_end(); } public static function input( $key, $label, $args = array() ) { $id = 'cfsp-f-' . $key; $type = $args['type'] ?? 'text'; $input = sprintf( '', self::attrs( array( 'type' => $type, 'id' => $id, 'class' => 'cfsp-input ' . ( $args['class'] ?? '' ), 'data-setting' => $key, 'value' => 'secret' === ( CFSP_Settings::schema()[ $key ]['type'] ?? '' ) ? '' : self::value( $key ), 'placeholder' => $args['placeholder'] ?? null, 'min' => $args['min'] ?? null, 'max' => $args['max'] ?? null, 'disabled' => ! empty( $args['disabled'] ), 'autocomplete' => 'password' === $type ? 'new-password' : 'off', 'spellcheck' => 'false', ) ) ); if ( ! empty( $args['prefix'] ) || ! empty( $args['suffix'] ) ) { $input = '
' . ( empty( $args['prefix'] ) ? '' : '' . esc_html( $args['prefix'] ) . '' ) . $input . ( empty( $args['suffix'] ) ? '' : '' . esc_html( $args['suffix'] ) . '' ) . '
'; } self::row_start( $id, $label, $args, ! empty( $args['wide'] ), 'number' === $type ? 'cfsp-row-narrow' : '' ); echo wp_kses( $input, self::control_html() ); self::row_end(); } public static function select( $key, $label, array $options, $args = array() ) { $id = 'cfsp-f-' . $key; $current = (string) self::value( $key ); self::row_start( $id, $label, $args ); printf( ''; self::row_end(); } public static function textarea( $key, $label, $args = array() ) { $id = 'cfsp-f-' . $key; self::row_start( $id, $label, $args, true ); printf( '', esc_attr( $id ), (int) ( $args['rows'] ?? 5 ), esc_attr( $key ), esc_attr( $args['placeholder'] ?? '' ), esc_textarea( self::value( $key ) ) ); self::row_end(); } /** Multi-select rendered as removable chips by admin.js. */ public static function tags( $key, $label, array $options, $args = array() ) { $id = 'cfsp-f-' . $key; $selected = (array) self::value( $key ); self::row_start( $id, $label, $args, true ); printf( ''; self::row_end(); } public static function notice( $html, $type = 'info', $args = array() ) { $icons = array( 'info' => 'info-outline', 'tip' => 'lightbulb', 'warn' => 'warning', 'error' => 'dismiss', ); printf( '
%4$s
', esc_attr( $type ), empty( $args['show_if'] ) ? '' : ' data-show-if="' . esc_attr( $args['show_if'] ) . '"', esc_attr( $icons[ $type ] ?? 'info-outline' ), wp_kses( $html, self::kses() ) ); } public static function icon( $name ) { return ''; } /** * The Static Push mark: one green stroke that draws an S and ends in a push arrow, on a rounded slate tile. * Drawn as a single filled outline (not a stroke) so the admin menu icon can reuse it. * Brand colours: #21B68E (green) and #364058 (slate). */ public static function logo( $size = 32 ) { return sprintf( '', (int) $size ); } /** * Monochrome mark as a data URI for the WordPress admin menu. WordPress recolours the fills to match the * admin colour scheme, so the mark is one filled outline, never a stroke. The view box is cropped to the mark. */ public static function menu_icon() { $svg = ''; return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions } }