PHP 8.0.30
Preview: lvmr-header.php Size: 16.59 KB
/home/certprox/test.certproxywizard.com/wp-content/plugins/lvmr-header/lvmr-header.php

<?php
/**
 * Plugin Name: LVMR Header
 * Plugin URI: https://sabbir.me/
 * Description: A custom design header for Hello Elementor with perfect responsiveness and sticky functionality.
 * Version: 1.0.0
 * Author: sabbir
 * Author URI: https://sabbir.me/
 * Text Domain: lvmr-header
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

// Define plugin constants
define( 'LVMR_HEADER_VERSION', '1.0.0' );
define( 'LVMR_HEADER_PATH', plugin_dir_path( __FILE__ ) );
define( 'LVMR_HEADER_URL', plugin_dir_url( __FILE__ ) );

// Include Customizer settings
require_once LVMR_HEADER_PATH . 'includes/customizer.php';

// Register scripts and styles
function lvmr_header_enqueue_assets() {
	wp_enqueue_style( 'lvmr-header-css', LVMR_HEADER_URL . 'assets/css/lvmr-header.css', array(), LVMR_HEADER_VERSION );
	wp_enqueue_script( 'lvmr-header-js', LVMR_HEADER_URL . 'assets/js/lvmr-header.js', array('jquery'), LVMR_HEADER_VERSION, true );

	// Dynamically enqueue Google Font if set
	$font_family = get_theme_mod( 'lvmr_menu_font_family', '' );
	if ( ! empty( $font_family ) ) {
		$font_slug = urlencode( trim( $font_family ) );
		wp_enqueue_style(
			'lvmr-google-font',
			'https://fonts.googleapis.com/css2?family=' . $font_slug . ':wght@300;400;500;600;700;800&display=swap',
			array(),
			null
		);
	}
}
add_action( 'wp_enqueue_scripts', 'lvmr_header_enqueue_assets' );

// Output Customizer CSS in Head
function lvmr_header_customizer_css() {
	$bg_color       = get_theme_mod( 'lvmr_header_bg_color', '#ffffff' );
	$text_color     = get_theme_mod( 'lvmr_header_text_color', '#000000' );
	$accent_color   = get_theme_mod( 'lvmr_header_accent_color', '#0000ff' );
    $topbar_bg      = get_theme_mod( 'lvmr_topbar_bg_color', '#000a8b' );
    $topbar_text_col= get_theme_mod( 'lvmr_topbar_text_color', '#ffffff' );
	$header_height  = get_theme_mod( 'lvmr_header_height', '80' );
    $header_height_t = get_theme_mod( 'lvmr_header_height_tablet', '70' );
    $header_height_m = get_theme_mod( 'lvmr_header_height_mobile', '60' );
	$logo_width     = get_theme_mod( 'lvmr_header_logo_width', '150' );
    $logo_width_t   = get_theme_mod( 'lvmr_header_logo_width_tablet', '120' );
    $logo_width_m   = get_theme_mod( 'lvmr_header_logo_width_mobile', '100' );
    $sticky_bg      = get_theme_mod( 'lvmr_header_sticky_bg', '#ffffff' );
    $logo_gap       = get_theme_mod( 'lvmr_header_logo_gap', '150' );
    $menu_gap       = get_theme_mod( 'lvmr_header_menu_gap', '25' );
    $icons_gap      = get_theme_mod( 'lvmr_header_icons_gap', '20' );
    $menu_font_size      = get_theme_mod( 'lvmr_menu_font_size', '14' );
    $menu_font_weight    = get_theme_mod( 'lvmr_menu_font_weight', '500' );
    $menu_text_transform = get_theme_mod( 'lvmr_menu_text_transform', 'capitalize' );
    $menu_letter_spacing = get_theme_mod( 'lvmr_menu_letter_spacing', '0' );
    $menu_link_color     = get_theme_mod( 'lvmr_menu_link_color', '#000000' );
    $menu_hover_color    = get_theme_mod( 'lvmr_menu_hover_color', '#0000ff' );
    $menu_font_family    = get_theme_mod( 'lvmr_menu_font_family', '' );
    $header_padding      = get_theme_mod( 'lvmr_header_padding', '30' );
    $header_border_radius = get_theme_mod( 'lvmr_header_border_radius', '40' );
    $cart_badge_color    = get_theme_mod( 'lvmr_cart_badge_color', '#f07c00' );

	?>
	<style id="lvmr-header-dynamic-css">
		:root {
			--lvmr-header-bg: <?php echo esc_attr( $bg_color ); ?>;
			--lvmr-header-text: <?php echo esc_attr( $text_color ); ?>;
			--lvmr-header-accent: <?php echo esc_attr( $accent_color ); ?>;
            --lvmr-topbar-bg: <?php echo esc_attr( $topbar_bg ); ?>;
            --lvmr-topbar-text: <?php echo esc_attr( $topbar_text_col ); ?>;
			--lvmr-header-height: <?php echo esc_attr( $header_height ); ?>px;
            --lvmr-header-height-tablet: <?php echo esc_attr( $header_height_t ); ?>px;
            --lvmr-header-height-mobile: <?php echo esc_attr( $header_height_m ); ?>px;
			--lvmr-header-logo-w: <?php echo esc_attr( $logo_width ); ?>px;
            --lvmr-header-logo-w-tablet: <?php echo esc_attr( $logo_width_t ); ?>px;
            --lvmr-header-logo-w-mobile: <?php echo esc_attr( $logo_width_m ); ?>px;
            --lvmr-header-sticky-bg: <?php echo esc_attr( $sticky_bg ); ?>;
            --lvmr-header-logo-gap: <?php echo esc_attr( $logo_gap ); ?>px;
            --lvmr-menu-gap: <?php echo esc_attr( $menu_gap ); ?>px;
            --lvmr-icons-gap: <?php echo esc_attr( $icons_gap ); ?>px;
            --lvmr-menu-font-size: <?php echo esc_attr( $menu_font_size ); ?>px;
            --lvmr-menu-font-weight: <?php echo esc_attr( $menu_font_weight ); ?>;
            --lvmr-menu-text-transform: <?php echo esc_attr( $menu_text_transform ); ?>;
            --lvmr-menu-letter-spacing: <?php echo esc_attr( $menu_letter_spacing ); ?>px;
            --lvmr-menu-link-color: <?php echo esc_attr( $menu_link_color ); ?>;
            --lvmr-menu-hover-color: <?php echo esc_attr( $menu_hover_color ); ?>;
            --lvmr-menu-font-family: <?php echo ! empty( $menu_font_family ) ? "'" . esc_attr( $menu_font_family ) . "', sans-serif" : 'inherit'; ?>;
            --lvmr-header-padding: <?php echo esc_attr( $header_padding ); ?>px;
            --lvmr-header-border-radius: <?php echo esc_attr( $header_border_radius ); ?>px;
            --lvmr-cart-badge-color: <?php echo esc_attr( $cart_badge_color ); ?>;
		}
        /* Hide theme header if it exists */
        header#site-header, .site-header, .elementor-location-header {
            display: none !important;
        }
	</style>
	<?php
}
add_action( 'wp_head', 'lvmr_header_customizer_css' );

// Localize AJAX data for JS
function lvmr_header_localize_script() {
    wp_localize_script( 'lvmr-header-js', 'lvmrCart', array(
        'ajaxurl' => admin_url( 'admin-ajax.php' ),
        'nonce'   => wp_create_nonce( 'lvmr-cart-nonce' ),
    ) );
}
add_action( 'wp_enqueue_scripts', 'lvmr_header_localize_script', 20 );

// WooCommerce cart fragment — keep badge count in sync after add-to-cart
function lvmr_cart_count_fragment( $fragments ) {
    if ( ! class_exists( 'WooCommerce' ) ) return $fragments;
    ob_start();
    ?><span class="lvmr-cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></span><?php
    $fragments['span.lvmr-cart-count'] = ob_get_clean();
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'lvmr_cart_count_fragment' );

// Main Header Output Hook
// We use wp_body_open to inject right after <body>
function lvmr_header_output() {
    if ( is_admin() ) return;

    $cart_link    = class_exists( 'WooCommerce' ) ? wc_get_cart_url() : get_theme_mod( 'lvmr_header_cart_link', '#' );
    $account_link = class_exists( 'WooCommerce' ) ? wc_get_account_endpoint_url( 'dashboard' ) : get_theme_mod( 'lvmr_header_account_link', '#' );
    $checkout_url = class_exists( 'WooCommerce' ) ? wc_get_checkout_url() : '#';
    $sticky_enabled = get_theme_mod( 'lvmr_header_sticky', true );
    
    $topbar_enable = get_theme_mod( 'lvmr_topbar_enable', false );
    $topbar_text   = get_theme_mod( 'lvmr_topbar_text', 'Free U.S. shipping on subscriptions $100+ & standard orders $150+' );

    if ( $topbar_enable && ! empty( $topbar_text ) ) {
        echo '<div id="lvmr-top-bar">' . wp_kses_post( $topbar_text ) . '</div>';
    }

    // Set initial inline CSS for smooth loading if topbar active
    $inline_header_style = '';
    if ( $topbar_enable && ! empty( $topbar_text ) && ! is_admin() ) {
        // Assume default top bar height 40px at start to prevent some FOUC
        $inline_header_style = ' style="top: 40px;"';
    }

    ?>
    <header id="lvmr-header" class="<?php echo $sticky_enabled ? 'is-sticky' : ''; ?>"<?php echo $inline_header_style; ?>>
        <div class="lvmr-header-container">
            <div class="lvmr-header-inner">
                <!-- Mobile Menu Toggle -->
                <button class="lvmr-mobile-toggle" aria-label="Toggle Menu">
                    <span></span>
                    <span></span>
                    <span></span>
                </button>

                <!-- Left Menu -->
            <nav class="lvmr-nav lvmr-nav-left">
                <?php
                if ( has_nav_menu( 'lvmr-left-menu' ) ) {
                    wp_nav_menu( array(
                        'theme_location' => 'lvmr-left-menu',
                        'container'      => false,
                        'menu_class'     => 'lvmr-menu',
                    ) );
                } else {
                    echo '<ul class="lvmr-menu"><li><a href="#">Setup Left Menu</a></li></ul>';
                }
                ?>
            </nav>

            <!-- Center Logo -->
            <div class="lvmr-logo">
                <?php
                if ( has_custom_logo() ) {
                    the_custom_logo();
                } else {
                    echo '<h1><a href="' . esc_url( home_url( '/' ) ) . '">' . get_bloginfo( 'name' ) . '</a></h1>';
                }
                ?>
            </div>

            <!-- Right Menu -->
            <nav class="lvmr-nav lvmr-nav-right">
                <?php
                if ( has_nav_menu( 'lvmr-right-menu' ) ) {
                    wp_nav_menu( array(
                        'theme_location' => 'lvmr-right-menu',
                        'container'      => false,
                        'menu_class'     => 'lvmr-menu',
                    ) );
                } else {
                    echo '<ul class="lvmr-menu"><li><a href="#">Setup Right Menu</a></li></ul>';
                }
                ?>
            </nav>

            <!-- Right Icons (Cart & Account) -->
            <div class="lvmr-icons">
                <a href="<?php echo esc_url($account_link); ?>" class="lvmr-icon lvmr-account" aria-label="My Account">
                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
                </a>

                <div class="lvmr-cart-wrap" id="lvmr-cart-wrap">
                    <a href="<?php echo esc_url($cart_link); ?>" class="lvmr-icon lvmr-cart" id="lvmr-cart-trigger" aria-label="Cart">
                        <div class="lvmr-cart-icon-wrap">
                            <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"/><path d="M3 6h18"/><path d="M16 10a4 4 0 0 1-8 0"/></svg>
                            <?php if ( class_exists( 'WooCommerce' ) ) : ?>
                                <span class="lvmr-cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
                            <?php endif; ?>
                        </div>
                    </a>

                    <?php if ( class_exists( 'WooCommerce' ) ) : ?>
                    <!-- Cart Offcanvas Panel -->
                    <div class="lvmr-cart-panel" id="lvmr-cart-panel" role="dialog" aria-label="Shopping Cart">
                        <div class="lvmr-cart-panel-inner">
                            <div class="lvmr-cart-panel-header">
                                <h3>Your Cart <span class="lvmr-panel-count">(<?php echo WC()->cart->get_cart_contents_count(); ?>)</span></h3>
                                <button class="lvmr-cart-panel-close" id="lvmr-cart-close" aria-label="Close cart">
                                    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
                                </button>
                            </div>
                            <div class="lvmr-cart-panel-items">
                                <?php
                                $cart_items = WC()->cart->get_cart();
                                if ( empty( $cart_items ) ) : ?>
                                <div class="lvmr-cart-empty">
                                    <svg width="52" height="52" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1"><path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"/><path d="M3 6h18"/><path d="M16 10a4 4 0 0 1-8 0"/></svg>
                                    <p>Your cart is currently empty.</p>
                                    <a href="<?php echo esc_url( wc_get_page_permalink('shop') ); ?>" class="lvmr-btn lvmr-btn-primary">Browse Shop</a>
                                </div>
                                <?php else : foreach ( $cart_items as $cart_item_key => $cart_item ) :
                                    $product    = $cart_item['data'];
                                    $qty        = $cart_item['quantity'];
                                    $thumbnail  = $product->get_image( array(64,64) );
                                    $name       = $product->get_name();
                                    $price      = WC()->cart->get_product_price( $product );
                                    $remove_url = wc_get_cart_remove_url( $cart_item_key );
                                ?>
                                <div class="lvmr-cart-item">
                                    <div class="lvmr-cart-item-img"><?php echo $thumbnail; ?></div>
                                    <div class="lvmr-cart-item-info">
                                        <span class="lvmr-cart-item-name"><?php echo esc_html( $name ); ?></span>
                                        <div class="lvmr-cart-item-meta">
                                            <span class="lvmr-cart-item-qty">Qty: <?php echo esc_html( $qty ); ?></span>
                                            <span class="lvmr-cart-item-price"><?php echo $price; ?></span>
                                        </div>
                                    </div>
                                    <a href="<?php echo esc_url( $remove_url ); ?>" class="lvmr-cart-item-remove" aria-label="Remove">
                                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
                                    </a>
                                </div>
                                <?php endforeach; endif; ?>
                            </div>
                            <?php if ( ! empty( $cart_items ) ) : ?>
                            <div class="lvmr-cart-panel-footer">
                                <div class="lvmr-cart-subtotal">
                                    <span>Subtotal</span>
                                    <strong><?php echo WC()->cart->get_cart_subtotal(); ?></strong>
                                </div>
                                <div class="lvmr-cart-panel-actions">
                                    <a href="<?php echo esc_url( $cart_link ); ?>" class="lvmr-btn lvmr-btn-outline">View Cart</a>
                                    <a href="<?php echo esc_url( $checkout_url ); ?>" class="lvmr-btn lvmr-btn-primary">Checkout</a>
                                </div>
                            </div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="lvmr-cart-backdrop" id="lvmr-cart-backdrop"></div>
                    <?php endif; ?>
                </div>
            </div>
            </div>
        </div>

        <!-- Mobile Fullscreen Menu -->
        <div class="lvmr-mobile-overlay">
            <div class="lvmr-mobile-content">
                <nav class="lvmr-mobile-nav">
                    <?php
                    // Combine both menus for mobile
                    wp_nav_menu( array( 'theme_location' => 'lvmr-left-menu', 'container' => false, 'menu_class' => 'lvmr-mobile-menu' ) );
                    wp_nav_menu( array( 'theme_location' => 'lvmr-right-menu', 'container' => false, 'menu_class' => 'lvmr-mobile-menu' ) );
                    ?>
                </nav>
            </div>
        </div>
    </header>
    <?php
}
add_action( 'wp_body_open', 'lvmr_header_output' );

// Register Menus
function lvmr_header_register_menus() {
	register_nav_menus( array(
		'lvmr-left-menu'  => __( 'LVMR Left Menu', 'lvmr-header' ),
		'lvmr-right-menu' => __( 'LVMR Right Menu', 'lvmr-header' ),
	) );
}
add_action( 'init', 'lvmr_header_register_menus' );

Directory Contents

Dirs: 2 × Files: 1

Name Size Perms Modified Actions
assets DIR
- drwxr-xr-x 2026-03-11 09:38:09
Edit Download
includes DIR
- drwxr-xr-x 2026-03-11 09:38:09
Edit Download
16.59 KB lrw-r--r-- 2026-03-11 09:38:09
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).