<?php if (!defined('ABSPATH')) { exit; } define('M3SS_THEME_VERSION', '1.0.0'); function m3ss_theme_setup() { add_theme_support('title-tag'); add_theme_support('post-thumbnails'); add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script')); add_theme_support('custom-logo', array( 'height' => 80, 'width' => 240, 'flex-height' => true, 'flex-width' => true, )); add_theme_support('custom-background'); add_theme_support('customize-selective-refresh-widgets'); add_theme_support('woocommerce'); add_theme_support('wc-product-gallery-zoom'); add_theme_support('wc-product-gallery-lightbox'); add_theme_support('wc-product-gallery-slider'); register_nav_menus(array( 'primary' => __('Primary Menu', 'm3ss-govcon-theme'), 'footer' => __('Footer Menu', 'm3ss-govcon-theme'), )); } add_action('after_setup_theme', 'm3ss_theme_setup'); function m3ss_enqueue_assets() { wp_enqueue_style('m3ss-theme-style', get_template_directory_uri() . '/assets/css/theme.css', array(), M3SS_THEME_VERSION); wp_enqueue_script('m3ss-theme-script', get_template_directory_uri() . '/assets/js/theme.js', array(), M3SS_THEME_VERSION, true); } add_action('wp_enqueue_scripts', 'm3ss_enqueue_assets'); function m3ss_widgets_init() { register_sidebar(array( 'name' => __('Sidebar', 'm3ss-govcon-theme'), 'id' => 'sidebar-1', 'description' => __('Add widgets here.', 'm3ss-govcon-theme'), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', )); register_sidebar(array( 'name' => __('Footer', 'm3ss-govcon-theme'), 'id' => 'footer-1', 'description' => __('Footer widgets.', 'm3ss-govcon-theme'), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', )); } add_action('widgets_init', 'm3ss_widgets_init'); function m3ss_customize_excerpt_more($more) { return '...'; } add_filter('excerpt_more', 'm3ss_customize_excerpt_more'); function m3ss_body_classes($classes) { if (is_front_page()) { $classes[] = 'm3ss-front-page'; } if (class_exists('WooCommerce')) { $classes[] = 'm3ss-woocommerce-ready'; } return $classes; } add_filter('body_class', 'm3ss_body_classes'); function m3ss_pingback_header() { if (is_singular() && pings_open()) { printf('<link rel="pingback" href="%s">', esc_url(get_bloginfo('pingback_url'))); } } add_action('wp_head', 'm3ss_pingback_header'); function m3ss_woocommerce_wrapper_before() { echo '<main id="primary" class="site-main site-main--shop"><div class="container">'; } add_action('woocommerce_before_main_content', 'm3ss_woocommerce_wrapper_before', 5); function m3ss_woocommerce_wrapper_after() { echo '</div></main>'; } add_action('woocommerce_after_main_content', 'm3ss_woocommerce_wrapper_after', 50); remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); function m3ss_fallback_menu() { echo '<ul class="menu">'; echo '<li><a href="' . esc_url(home_url('/')) . '">Home</a></li>'; echo '<li><a href="' . esc_url(home_url('/capabilities')) . '">Capabilities</a></li>'; echo '<li><a href="' . esc_url(home_url('/shop')) . '">Store</a></li>'; echo '<li><a href="' . esc_url(home_url('/request-quote')) . '">Request Quote</a></li>'; echo '<li><a href="' . esc_url(home_url('/contact')) . '">Contact</a></li>'; echo '</ul>'; } // TEMPORARY UPLOAD HANDLER - REMOVE AFTER USE add_action('wp_ajax_m3ss_temp_upload', 'm3ss_temp_upload_handler'); function m3ss_temp_upload_handler() { if (!current_user_can('upload_files')) { wp_send_json_error('Permission denied'); return; } check_ajax_referer('m3ss_upload_nonce', 'security'); if (empty($_POST['b64']) || empty($_POST['filename'])) { wp_send_json_error('Missing data'); return; } $filename = sanitize_file_name($_POST['filename']); $b64 = $_POST['b64']; // Remove data URI prefix if present if (strpos($b64, 'base64,') !== false) { $b64 = substr($b64, strpos($b64, 'base64,') + 7); } $file_data = base64_decode($b64); if (!$file_data) { wp_send_json_error('Base64 decode failed'); return; } $upload_dir = wp_upload_dir(); $file_path = $upload_dir['path'] . '/' . $filename; file_put_contents($file_path, $file_data); $file_type = wp_check_filetype($filename, null); $attachment = array( 'post_mime_type' => $file_type['type'], 'post_title' => sanitize_file_name(pathinfo($filename, PATHINFO_FILENAME)), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, $file_path); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata($attach_id, $file_path); wp_update_attachment_metadata($attach_id, $attach_data); wp_send_json_success(array( 'id' => $attach_id, 'url' => $upload_dir['url'] . '/' . $filename )); } add_action('wp_ajax_m3ss_get_upload_nonce', 'm3ss_get_upload_nonce'); function m3ss_get_upload_nonce() { if (!current_user_can('upload_files')) { wp_send_json_error('Permission denied'); return; } wp_send_json_success(array('nonce' => wp_create_nonce('m3ss_upload_nonce'))); } // END TEMPORARY UPLOAD HANDLER add_action('wp_ajax_m3ss_sideload_pdf', 'm3ss_sideload_pdf_handler'); function m3ss_sideload_pdf_handler() { if (!current_user_can('upload_files')) { wp_send_json_error('Permission denied'); return; } check_ajax_referer('m3ss_upload_nonce', 'security'); if (empty($_POST['url']) || empty($_POST['filename'])) { wp_send_json_error('Missing url or filename'); return; } $url = esc_url_raw($_POST['url']); $filename = sanitize_file_name($_POST['filename']); require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); $tmp = download_url($url); if (is_wp_error($tmp)) { wp_send_json_error($tmp->get_error_message()); return; } $file_array = array( 'name' => $filename, 'tmp_name' => $tmp, ); $attach_id = media_handle_sideload($file_array, 0, null); if (is_wp_error($attach_id)) { @unlink($tmp); wp_send_json_error($attach_id->get_error_message()); return; } wp_send_json_success(array( 'id' => $attach_id, 'url' => wp_get_attachment_url($attach_id) )); }