'; } $out = '
'; $shown = 0; foreach ( $fields as $field ) { if ( $shown >= 4 ) { break; } $type = isset( $field['type'] ) ? $field['type'] : 'text'; $label = isset( $field['label'] ) ? $field['label'] : ''; // Layout-only fields don't help the preview. if ( in_array( $type, [ 'section', 'pagebreak', 'html', 'hidden' ], true ) ) { continue; } $out .= '
'; if ( '' !== $label ) { $out .= '' . esc_html( $label ) . ''; } switch ( $type ) { case 'name': case 'address': $out .= ''; break; case 'textarea': $out .= ''; break; case 'radio': case 'checkbox': case 'image_choice': case 'payment_multiple': $dot = 'checkbox' === $type ? 'phf-mini-square' : 'phf-mini-dot'; $out .= ''; for ( $i = 0; $i < 2; $i++ ) { $out .= ''; } $out .= ''; break; case 'select': case 'country': case 'payment_select': $out .= ''; break; case 'consent': $out .= ''; break; case 'rating': $out .= '★★★★★'; break; case 'signature': $out .= '✎'; break; case 'payment_single': case 'payment_total': $out .= '' . esc_html( \PhemightForms\Payments::symbol() ) . ''; break; case 'payment_coupon': $out .= ''; break; default: $out .= ''; } $out .= '
'; $shown++; } $out .= ''; $out .= '
'; return $out; } /** * Render the gallery. */ public static function render_page() { if ( ! current_user_can( Admin::CAPABILITY ) ) { wp_die( esc_html__( 'Permission denied.', 'phemightforms' ) ); } $templates = Templates::all(); $categories = Templates::categories(); $counts = []; foreach ( $templates as $template ) { $cat = isset( $template['category'] ) ? $template['category'] : 'business'; $counts[ $cat ] = isset( $counts[ $cat ] ) ? $counts[ $cat ] + 1 : 1; } ?>

$template ) : ?> Admin::SLUG_FORMS, 'action' => 'create', 'template' => $slug, ], admin_url( 'admin.php' ) ), 'phemightforms_create_' . $slug ); $cat = isset( $template['category'] ) ? $template['category'] : 'business'; $cat_label = isset( $categories[ $cat ] ) ? $categories[ $cat ] : ''; $is_blank = 'blank' === $slug; ?>
( function () { var search = document.getElementById( 'phf-tpl-search' ); var grid = document.getElementById( 'phf-tpl-grid' ); var none = document.getElementById( 'phf-tpl-none' ); var cats = document.querySelectorAll( '.phf-tpl-cat' ); var activeCat = 'all'; function apply() { var term = ( search.value || '' ).toLowerCase().trim(); var visible = 0; grid.querySelectorAll( '.phf-tpl-card' ).forEach( function ( card ) { var matchCat = activeCat === 'all' || card.getAttribute( 'data-cat' ) === activeCat; var matchTerm = ! term || card.getAttribute( 'data-search' ).indexOf( term ) !== -1; var show = matchCat && matchTerm; card.style.display = show ? '' : 'none'; if ( show ) { visible++; } } ); none.hidden = visible > 0; } cats.forEach( function ( btn ) { btn.addEventListener( 'click', function () { cats.forEach( function ( b ) { b.classList.remove( 'is-active' ); } ); btn.classList.add( 'is-active' ); activeCat = btn.getAttribute( 'data-cat' ); apply(); } ); } ); if ( search ) { search.addEventListener( 'input', apply ); } } )();