__( 'Primary Navigation', 'weedops' ),
'footer' => __( 'Footer Navigation', 'weedops' ),
'account' => __( 'Account Menu', 'weedops' ),
] );
}
add_action( 'after_setup_theme', 'weedops_setup' );
// ─────────────────────────────────────────────────────────────────────────────
// Scripts & Styles
// ─────────────────────────────────────────────────────────────────────────────
function weedops_enqueue_assets(): void {
// Google Fonts — Inter
wp_enqueue_style(
'weedops-fonts',
'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap',
[],
null
);
// Main stylesheet
wp_enqueue_style(
'weedops-style',
get_stylesheet_uri(),
[ 'weedops-fonts' ],
WEEDOPS_VERSION
);
// Main JS bundle
wp_enqueue_script(
'weedops-main',
WEEDOPS_URI . '/assets/js/main.js',
[],
WEEDOPS_VERSION,
true
);
// Pass data to JS
wp_localize_script( 'weedops-main', 'WeedopsData', [
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'restUrl' => esc_url_raw( rest_url( 'weedops/v1/' ) ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'siteUrl' => get_site_url(),
'isLoggedIn'=> is_user_logged_in(),
] );
}
add_action( 'wp_enqueue_scripts', 'weedops_enqueue_assets' );
// ─────────────────────────────────────────────────────────────────────────────
// Custom Post Types, Taxonomies & Meta Fields
// ─────────────────────────────────────────────────────────────────────────────
// Post types, taxonomies, and meta field registration live in their own file.
require_once WEEDOPS_DIR . '/inc/custom-post-types.php';
// ─────────────────────────────────────────────────────────────────────────────
// Widget Areas
// ─────────────────────────────────────────────────────────────────────────────
function weedops_register_sidebars(): void {
$sidebars = [
[ 'id' => 'sidebar-main', 'name' => __( 'Main Sidebar', 'weedops' ) ],
[ 'id' => 'sidebar-catalog', 'name' => __( 'Catalog Sidebar', 'weedops' ) ],
[ 'id' => 'footer-col-1', 'name' => __( 'Footer Column 1', 'weedops' ) ],
[ 'id' => 'footer-col-2', 'name' => __( 'Footer Column 2', 'weedops' ) ],
[ 'id' => 'footer-col-3', 'name' => __( 'Footer Column 3', 'weedops' ) ],
];
foreach ( $sidebars as $s ) {
register_sidebar( [
'id' => $s['id'],
'name' => $s['name'],
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '',
] );
}
}
add_action( 'widgets_init', 'weedops_register_sidebars' );
// ─────────────────────────────────────────────────────────────────────────────
// Helper Functions
// ─────────────────────────────────────────────────────────────────────────────
/**
* Render a strain type badge.
*
* @param string $type indica | sativa | hybrid | cbd
* @param bool $echo Echo or return.
*/
function weedops_strain_badge( string $type, bool $echo = true ): string {
$label = ucfirst( $type );
$class = 'wo-badge wo-badge--' . sanitize_html_class( strtolower( $type ) );
$html = sprintf( '%s', esc_attr( $class ), esc_html( $label ) );
if ( $echo ) echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return $html;
}
/**
* Return formatted THC/CBD string for a strain.
*
* @param int $post_id
*/
function weedops_get_cannabinoid_str( int $post_id ): string {
$thc = get_post_meta( $post_id, 'wo_thc_percent', true );
$cbd = get_post_meta( $post_id, 'wo_cbd_percent', true );
$parts = [];
if ( $thc !== '' ) $parts[] = 'THC ' . number_format( (float) $thc, 1 ) . '%';
if ( $cbd !== '' ) $parts[] = 'CBD ' . number_format( (float) $cbd, 1 ) . '%';
return implode( ' · ', $parts );
}
/**
* Check if a product has a valid COA (lab test certificate).
*/
function weedops_has_valid_coa( int $post_id ): bool {
$coa = get_post_meta( $post_id, 'wo_coa_url', true );
$tested = get_post_meta( $post_id, 'wo_lab_tested', true );
return ! empty( $coa ) && (bool) $tested;
}
/**
* Age-gate: returns true if the user has confirmed they are 21+.
* Stored in a session cookie.
*/
function weedops_age_verified(): bool {
return ! empty( $_COOKIE['wo_age_verified'] );
}
// ─────────────────────────────────────────────────────────────────────────────
// Age Verification AJAX Handler
// ─────────────────────────────────────────────────────────────────────────────
function weedops_ajax_age_verify(): void {
check_ajax_referer( 'wo_age_verify', 'nonce' );
setcookie( 'wo_age_verified', '1', time() + ( 30 * DAY_IN_SECONDS ), COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );
wp_send_json_success( [ 'verified' => true ] );
}
add_action( 'wp_ajax_nopriv_wo_age_verify', 'weedops_ajax_age_verify' );
add_action( 'wp_ajax_wo_age_verify', 'weedops_ajax_age_verify' );
// ─────────────────────────────────────────────────────────────────────────────
// Title Tag
// ─────────────────────────────────────────────────────────────────────────────
function weedops_document_title_parts( array $parts ): array {
$parts['tagline'] = get_bloginfo( 'description' );
return $parts;
}
add_filter( 'document_title_parts', 'weedops_document_title_parts' );
// ─────────────────────────────────────────────────────────────────────────────
// Excerpt length
// ─────────────────────────────────────────────────────────────────────────────
add_filter( 'excerpt_length', fn() => 30 );
add_filter( 'excerpt_more', fn() => '…' );