'dashboard', 'general' => 'admin-generic', 'forms' => 'feedback', 'google' => 'google', 'woocommerce' => 'cart', 'otp' => 'lock', 'channels' => 'megaphone', 'providers' => 'smartphone', 'messages' => 'format-chat', 'captcha' => 'shield-alt', 'twofa' => 'privacy', 'security' => 'shield', 'tools' => 'admin-tools', 'deliveries' => 'list-view', 'audit' => 'clipboard', ); return 'dashicons dashicons-' . ( isset( $icons[ $tab ] ) ? $icons[ $tab ] : 'admin-generic' ); } /** * Opens a card. * * @param string $title Card title. * @param string $desc Short description, may be empty. * @param array $args Optional: class, badge (array of text and state). * @return void */ public static function card_open( $title, $desc = '', array $args = array() ) { $class = 'aslo-card' . ( isset( $args['class'] ) ? ' ' . $args['class'] : '' ); echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Attributes are escaped in attributes(). if ( '' !== $title ) { echo '

' . esc_html( $title ) . '

'; if ( '' !== $desc ) { echo '

' . esc_html( $desc ) . '

'; } echo '
'; if ( isset( $args['badge'] ) ) { echo '' . esc_html( $args['badge'][0] ) . ''; } if ( isset( $args['toggle'] ) ) { echo '
'; self::switch_input( $args['toggle']['name'], $args['toggle']['checked'], $args['toggle']['id'], '', isset( $args['toggle']['form'] ) ? $args['toggle']['form'] : '' ); echo '
'; } echo '
'; } echo '
'; } /** * Closes a card. * * @return void */ public static function card_close() { echo '
'; } /** * Opens a settings row: label and help on one side, the control on the other. * * @param string $label Label text. * @param string $help Help text. * @param string $target Id of the control. * @param array $attrs Extra attributes for the row, for example data-dep. * @return void */ public static function row_open( $label, $help, $target = '', array $attrs = array() ) { $attrs['class'] = 'aslo-row' . ( isset( $attrs['class'] ) ? ' ' . $attrs['class'] : '' ); echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in attributes(). echo '' . esc_html( $label ) . ''; if ( '' !== $help ) { echo '

' . esc_html( $help ) . '

'; } echo '
'; } /** * Closes a settings row. * * @return void */ public static function row_close() { echo '
'; } /** * Prints an on/off switch. A hidden zero is sent first so unchecked boxes are saved. * * @param string $name Input name. * @param bool $checked Current state. * @param string $id Element id. * @param string $text Optional text beside the switch. * @param string $form Id of the form the switch belongs to, when it sits outside it. * @return void */ public static function switch_input( $name, $checked, $id, $text = '', $form = '' ) { $form_attr = '' !== $form ? ' form="' . esc_attr( $form ) . '"' : ''; echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above. echo ''; } /** * Prints a group of radio buttons styled as one segmented control. * * @param string $name Input name. * @param string[] $choices Value to label. * @param string $value Current value. * @param string $id Base id. * @return void */ public static function segmented( $name, array $choices, $value, $id ) { echo '
'; foreach ( $choices as $choice => $label ) { $choice_id = $id . '-' . sanitize_html_class( (string) $choice ); echo ''; echo ''; } echo '
'; } /** * Opens a block that slides open and closed. * * @param bool $open Whether it starts open. * @param array $attrs Extra attributes, for example data-dep. * @return void */ public static function collapse_open( $open, array $attrs = array() ) { $attrs['class'] = 'aslo-collapse' . ( $open ? ' is-open' : '' ) . ( isset( $attrs['class'] ) ? ' ' . $attrs['class'] : '' ); echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in attributes(). } /** * Closes a collapsible block. * * @return void */ public static function collapse_close() { echo '
'; } /** * Turns an attribute map into escaped HTML attributes. * * @param array $attrs Attribute values. * @return string */ private static function attributes( array $attrs ) { $out = array(); foreach ( $attrs as $name => $value ) { $out[] = esc_attr( $name ) . '="' . esc_attr( (string) $value ) . '"'; } return implode( ' ', $out ); } }