/**
* STANDALONE FEATURED SHOWCASE ENGINE: Pulls automated purchasers AND manual admin choices!
*/
public function render_featured_vendors_showcase() {
if ( get_option( 'cp_enable_profiles', 'yes' ) === 'no' ) { return ''; }
global $wpdb;
$promotions_table = $wpdb->prefix . 'connectpay_promotions';
// 1. Fetch vendor IDs holding an active unexpired completed promotion package
$purchased_featured_ids = $wpdb->get_col( "
SELECT DISTINCT vendor_id FROM $promotions_table
WHERE expires_at > NOW() AND payment_status = 'completed'
ORDER BY CASE WHEN package_type = 'gold' THEN 1 ELSE 2 END ASC, expires_at DESC
" );
if ( ! is_array( $purchased_featured_ids ) ) { $purchased_featured_ids = array(); }
// 2. NEW OVERRIDE: Fetch your manual admin checkbox options choices from settings
$manual_featured_string = get_option( 'cp_manual_featured_vendors', '' );
$manual_featured_ids = array_map( 'intval', array_filter( explode( ',', $manual_featured_string ) ) );
if ( ! is_array( $manual_featured_ids ) ) { $manual_featured_ids = array(); }
// Merge both arrays cleanly to build a master featured pool group
$master_featured_pool = array_unique( array_merge( $purchased_featured_ids, $manual_featured_ids ) );
if ( empty( $master_featured_pool ) ) {
return '
No featured promotional profiles spotlighted today.
';
}
// Parse through active vendor permissions checks layers safely
$vendor_ids = array();
if ( get_option( 'cp_enable_kyc', 'yes' ) === 'yes' ) {
$vendor_ids = $wpdb->get_col( "
SELECT DISTINCT u.ID FROM $wpdb->users u
INNER JOIN $wpdb->usermeta m1 ON u.ID = m1.user_id
INNER JOIN $wpdb->usermeta m2 ON u.ID = m2.user_id
WHERE m1.meta_key LIKE '%capabilities' AND m1.meta_value LIKE '%connectpay_vendor%'
AND m2.meta_key = 'connectpay_verified' AND m2.meta_value = '1'
" );
}
if ( empty( $vendor_ids ) ) {
$vendor_ids = $wpdb->get_col( "
SELECT DISTINCT u.ID FROM $wpdb->users u
INNER JOIN $wpdb->usermeta m ON u.ID = m.user_id
WHERE m.meta_key LIKE '%capabilities' AND m.meta_value LIKE '%connectpay_vendor%'
" );
}
// FIXED KEY-INDEX ALIGNMENT: Reset array keys cleanly to guarantee proper rank ordering
$ordered_featured_ids = array_values( array_intersect( $master_featured_pool, $vendor_ids ) );
if ( empty( $ordered_featured_ids ) ) { return ''; }
// Enforce fetching all matched accounts in sequence order
$user_query = new WP_User_Query( array( 'include' => $ordered_featured_ids, 'orderby' => 'include', 'number' => -1 ) );
$users = $user_query->get_results();
$page_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_content LIKE '%[connectpay_profile_view]%' AND post_status = 'publish' AND post_type = 'page' LIMIT 1" );
$profile_base_url = $page_id ? get_permalink( $page_id ) : home_url( '/profile/' );
$output = '';
$styles_path = CONNECTPAY_PATH . 'directory-grid-styles.php';
if ( file_exists( $styles_path ) ) { ob_start(); include $styles_path; $output .= ob_get_clean(); }
$output .= '';
// 2. FEATURED RENDERING LOOP: Formats both manual selections and organic buyers
foreach ( $users as $user ) {
if ( ! $user ) { continue; }
$seller_id = $user->ID;
$location = get_user_meta( $seller_id, 'connectpay_location', true );
$gender = get_user_meta( $seller_id, 'connectpay_gender', true );
$age = get_user_meta( $seller_id, 'connectpay_age', true );
$about = get_user_meta( $seller_id, 'connectpay_about', true );
// Determine if they are gold, silver, or forced featured via admin settings
$package_tier = $wpdb->get_var( $wpdb->prepare( "SELECT package_type FROM $promotions_table WHERE vendor_id = %d AND expires_at > NOW() AND payment_status = 'completed' LIMIT 1", $seller_id ) );
$is_manually_featured = in_array( $seller_id, $manual_featured_ids, true );
$is_gold = ( $package_tier === 'gold' || ( $is_manually_featured && empty($package_tier) ) );
$avatar_id = get_user_meta( $seller_id, 'connectpay_custom_avatar', true );
$avatar_html = '';
// NO GUESSWORK FIX: Returns the exact valid HTML image tag markup dynamically
if ( $avatar_id ) {
$img_url = wp_get_attachment_image_url( $avatar_id, 'medium_large' );
if ( ! $img_url ) { $img_url = wp_get_attachment_image_url( $avatar_id, 'medium' ); }
if ( $img_url ) {
$avatar_html = '
 . ')
';
}
}
if ( empty( $avatar_html ) ) {
$initial = strtoupper( substr( $user->display_name, 0, 1 ) );
$avatar_html = '
' . esc_html( $initial ) . '
';
}
$automated_profile_url = add_query_arg( 'vendor_id', $seller_id, $profile_base_url );
// Apply priority gold frame accents to admin selections and gold tier purchases
$featured_card_style = $is_gold ? 'border: 2px solid #fcd34d; box-shadow: 0 10px 25px rgba(252,211,77,0.18); background: #fffdfa;' : 'border: 1px solid #cbd5e1; box-shadow: 0 4px 14px rgba(0,0,0,0.02); background: #ffffff;';
$output .= '
';
$output .= '
' . $avatar_html . '
';
$output .= '
';
$output .= esc_html( $user->display_name );
$output .= ' ⭐';
$output .= '
';
$output .= '
';
if ( $gender ) { $output .= ' ' . esc_html( $gender ) . ''; }
if ( $age ) { $output .= ' ' . esc_html( $age ) . ' Yrs'; }
if ( $location ) { $output .= ' 📍 ' . esc_html( $location ) . ''; }
$output .= '
';
$output .= '
' . ( $about ? esc_html( $about ) : 'No bio summary description details provided.' ) . '
';
$output .= '
✨ View Featured Profile';
$output .= '
';
}
$output .= '
';
return $output;
}
}