is_enabled(); $unmet = $module->unmet_requirement(); printf( '', $on ? 'true' : 'false', esc_attr( $module->title() ), esc_attr( $module->id() ), ( '' !== $unmet && ! $on ) ? ' disabled' : '' ); } /** * Title badges. * * @since 1.0.0 * @param AbstractModule $module Module. * @return void */ public static function badges( AbstractModule $module ) { foreach ( $module->get_badges() as $badge ) { printf( '%s', esc_html( $badge ) ); } } /** * Risk badge: "Safe" (outline, shield), "Review recommended" (amber) or "Advanced" (red text * and border). Unknown levels show as Advanced. * * @since 1.0.0 * @param string $level `safe`, `review` or `advanced` (Support\DevGuard levels). * @return void */ public static function risk_badge( string $level ) { $level = DevGuard::level( $level ); $labels = array( DevGuard::SAFE => array( 'shield-check', __( 'Safe', 'admin-powerups-for-woocommerce' ) ), DevGuard::REVIEW => array( 'triangle-alert', __( 'Review recommended', 'admin-powerups-for-woocommerce' ) ), DevGuard::ADVANCED => array( 'octagon-alert', __( 'Advanced', 'admin-powerups-for-woocommerce' ) ), ); echo ''; Icons::render( $labels[ $level ][0] ); echo esc_html( $labels[ $level ][1] ) . ''; } /** * A power-up's risk badge, shown only for admin-only (Developer and Performance) power-ups. * * @since 1.0.0 * @param AbstractModule $module Module. * @return void */ public static function module_risk_badge( AbstractModule $module ) { if ( $module->is_admin_only() ) { self::risk_badge( $module->risk() ); } } /** * Outline "Admins only" badge, for Developer and Performance group headings. * * @since 1.0.0 * @param bool $show False prints nothing (lets templates pass a group's flag). * @return void */ public static function admins_only_badge( bool $show = true ) { if ( ! $show ) { return; } echo '' . esc_html__( 'Admins only', 'admin-powerups-for-woocommerce' ) . ''; } /** * The amber warning shown under each admin-only group heading on the list and at the top of * every admin-only power-up's page. * * @since 1.0.0 * @return void */ public static function admin_only_warning() { echo '
'; Icons::render( 'circle-alert' ); echo '

' . esc_html__( 'These tools can make permanent changes that can’t be undone. Take a backup first. SmartWP Plugins isn’t responsible for lost data or downtime.', 'admin-powerups-for-woocommerce' ) . '

'; } /** * Typed confirmation for an Advanced action: what will happen, a text box and a red button * that unlocks once the word is typed (any case). admin.js then fires `apwc:confirm` on the * form with `{ form, word, action }` (`word` = what was typed, to send as `confirm`); the * feature script sends the request and fires `apwc:done` with `{ error }` on the form to * finish. The server must still check the word (DevGuard::check_confirm()). * * @since 1.0.0 * @param array $args Arguments: `confirm` (a DevGuard::confirm_actions() key: the * same key the route passes to DevGuard::permission(); the * word comes from DevGuard::confirm_word(); default `delete`), * `consequence` (what happens, one or two short sentences), * `button` (label, default "Delete"), `action` (read by the * feature script; default the `confirm` key) and `hidden` * (true: printed hidden, shown by the feature script). A * literal `word` is still read when `confirm` is left out. * @return void */ public static function typed_confirm( array $args ) { $key = isset( $args['confirm'] ) && is_string( $args['confirm'] ) && in_array( $args['confirm'], DevGuard::confirm_actions(), true ) ? $args['confirm'] : ''; if ( '' !== $key ) { $word = DevGuard::confirm_word( $key ); } elseif ( isset( $args['word'] ) && is_string( $args['word'] ) && '' !== trim( $args['word'] ) ) { $word = trim( $args['word'] ); } else { $key = 'delete'; $word = DevGuard::confirm_word( 'delete' ); } $consequence = isset( $args['consequence'] ) && is_string( $args['consequence'] ) ? $args['consequence'] : ''; $button = isset( $args['button'] ) && is_string( $args['button'] ) && '' !== $args['button'] ? $args['button'] : __( 'Delete', 'admin-powerups-for-woocommerce' ); $action = isset( $args['action'] ) && is_string( $args['action'] ) && '' !== $args['action'] ? $args['action'] : $key; $id = wp_unique_id( 'apwc-confirm-' ); ?>
>

/>
'; Icons::render( $module->icon() ); echo ''; } /** * Light / dark / system segmented control. * * @since 1.0.0 * @param string $current Current theme. * @return void */ public static function theme_switcher( $current ) { $options = array( 'light' => array( 'sun', __( 'Light', 'admin-powerups-for-woocommerce' ) ), 'dark' => array( 'moon', __( 'Dark', 'admin-powerups-for-woocommerce' ) ), 'system' => array( 'monitor', __( 'System', 'admin-powerups-for-woocommerce' ) ), ); echo '
'; foreach ( $options as $value => $option ) { printf( ''; } echo '
'; } /** * Print a machine name (hook, option, callback) escaped, with a line-break chance (``) * after each _ - . / : so long names wrap at their parts. * * @since 1.0.0 * @param string $name Name. * @return void */ public static function breakable( $name ) { foreach ( (array) preg_split( '#(?<=[_\-./:])#', (string) $name ) as $index => $part ) { if ( $index > 0 ) { echo ''; } echo esc_html( (string) $part ); } } /** * Print a value escaped, or a quiet dash when it's empty. `$code` wraps the value in ``. * * @since 1.0.0 * @param string $text Value. * @param bool $code Wrap in ``. * @return void */ public static function or_dash( $text, $code = false ) { $text = (string) $text; if ( '' === $text ) { echo ''; } elseif ( $code ) { echo '' . esc_html( $text ) . ''; } else { echo esc_html( $text ); } } /** * Print an HTML attribute (` name="value"`), escaped; nothing when the value is ''. * * @since 1.0.0 * @param string $name Attribute name. * @param string $value Value (`href`/`src` go through esc_url(), others esc_attr()). * @param bool $space Print a space before the attribute. * @return void */ public static function attr( $name, $value, $space = true ) { $value = (string) $value; if ( '' === $value ) { return; } if ( $space ) { echo ' '; } echo esc_attr( $name ) . '="' . ( in_array( $name, array( 'href', 'src' ), true ) ? esc_url( $value ) : esc_attr( $value ) ) . '"'; } /** * Print a simple element with escaped text and attributes; nothing when the text is ''. * * @since 1.0.0 * @param string $tag Element name, e.g. `span`. * @param string $text Text content. * @param array $attrs Attributes (see attr()). * @param string $before Text printed before the element (escaped). * @return void */ public static function tag( $tag, $text, array $attrs = array(), $before = '' ) { $text = (string) $text; if ( '' === $text ) { return; } echo esc_html( $before ) . '<' . tag_escape( $tag ); foreach ( $attrs as $name => $value ) { self::attr( (string) $name, (string) $value ); } echo '>' . esc_html( $text ) . ''; } /** * Print text as a link, or as plain text when there's no URL. * * @since 1.0.0 * @param string $url URL ('' for plain text). * @param string $text Text. * @return void */ public static function link_or_text( $url, $text ) { if ( '' === (string) $url ) { echo esc_html( (string) $text ); return; } echo '' . esc_html( (string) $text ) . ''; } /** * Toast region (filled by admin.js). * * @since 1.0.0 * @return void */ public static function toasts() { echo '
    '; } /** * Page numbers to show: first, last, and a window around the current page, with null for the * gaps ("1 2 3 4 5 6 7 … 20", "1 … 8 9 10 11 12 … 20"). * * @since 1.0.0 * @param int $current Current page. * @param int $total Pages. * @return array */ public static function page_numbers( $current, $total ) { $total = max( 1, (int) $total ); $current = min( max( 1, (int) $current ), $total ); if ( $total <= 9 ) { return range( 1, $total ); } if ( $current <= 5 ) { return array_merge( range( 1, 7 ), array( null, $total ) ); } if ( $current >= $total - 4 ) { return array_merge( array( 1, null ), range( $total - 6, $total ) ); } return array_merge( array( 1, null ), range( $current - 2, $current + 2 ), array( null, $total ) ); } /** * Numbered pager (previous, page numbers with gaps, next). Prints nothing for one page. * * @since 1.0.0 * @param int $paged Current page. * @param int $pages Pages. * @param callable(int):string $link URL of a page (unescaped). * @return void */ public static function pager( $paged, $pages, callable $link ) { $paged = (int) $paged; $pages = (int) $pages; if ( $pages <= 1 ) { return; } ?>