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 '
' . 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' ) . '
`.
*
* @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 ) . '' . tag_escape( $tag ) . '>';
}
/**
* 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;
}
?>