Skip to content

Instantly share code, notes, and snippets.

View wolfcoder's full-sized avatar
💭
Full Stack Developer

Bams wolfcoder

💭
Full Stack Developer
View GitHub Profile
{
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"php.validate.executablePath": "C:/Users/bbg20/.config/herd/bin/php83/php.exe",
"json.schemas": [
{
"fileMatch": ["/package.json"],
"url": "https://json.schemastore.org/package"
}
],
"workbench.editor.enablePreview": false,
@wolfcoder
wolfcoder / useWindowWidth.ts
Created October 22, 2024 07:50
React Hook Use Window Width
import { useState, useEffect } from 'react';
const useWindowWidth = () => {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
useEffect(() => {
const handleResize = () => {
setWindowWidth(window.innerWidth);
};
@wolfcoder
wolfcoder / useDeviceDetection.ts
Created October 22, 2024 07:49
React hook device detection
import { useState, useEffect } from 'react';
const useDeviceDetection = () => {
const [device, setDevice] = useState('');
useEffect(() => {
const handleDeviceDetection = () => {
const userAgent = navigator.userAgent.toLowerCase();
const isMobile =
/iphone|ipad|ipod|android|blackberry|windows phone/g.test(userAgent);
@wolfcoder
wolfcoder / disable-command.js
Created August 28, 2024 00:54
Disable right click command on browser
document.addEventListener('contextmenu', event => event.preventDefault());
@wolfcoder
wolfcoder / gist:b3cf1fd231b3b84c428eea38ba096eb4
Created November 1, 2023 06:26
Colorado Woocommerce fee WordPress
//Colorado fee
/**
* Add a .27 surcharge to orders shipping to Colorado
* https://www.thathandsomebeardedguy.com/woocommerce-colorado-retail-delivery-fee/
*/
add_action('woocommerce_cart_calculate_fees', 'handsome_bearded_guy_custom_surcharge');
function handsome_bearded_guy_custom_surcharge() {
global $woocommerce;
@wolfcoder
wolfcoder / sample-guttenberg-block.php
Last active May 18, 2023 03:45
sample guttenberg block
const { registerBlockType } = wp.blocks;
registerBlockType( 'my-plugin/hello-world', {
title: 'Hello World',
icon: 'smiley',
category: 'common',
edit: () => {
return (
<p>Hello World!</p>
);
<?php
/*
Plugin Name: Meta Box Example
Description: Example demonstrating how to add Meta Boxes.
Plugin URI: https://plugin-planet.com/
Author: Jeff Starr
Version: 1.0
*/
// register meta box
@wolfcoder
wolfcoder / navigation-ii.js
Created June 11, 2022 12:01
navigation menu open overlay
class NavigationII{
//1. Describe and initiate our object
constructor() {
this.openMenu = document.getElementById('open-menu')
this.closeMenu = document.getElementById('close-menu')
this.mobileMenu = document.getElementById('mobile-menu')
this.htmlBody = document.getElementsByTagName('body')
this.events()
}
@wolfcoder
wolfcoder / index.php
Last active June 9, 2022 14:13
wordpress database management
<?php
global $wpdb;
$tbl = $wpdb->prefix . 'posts';
$post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", 1 ) ); // posts can reference in the phpstorm
$prefix_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $tbl WHERE ID = %d", 1 ) ); // phpstorm: unable to resolve ID
$prepare_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", 1 );
$prepare_result = $wpdb->get_col( $prepare_query ); // 1
<?php
defined( 'ABSPATH' ) || exit;
global $vap, $vap_sync;
$lastsync_option = $vap_sync->vap_get_lastsync();
$ls_timestamp = $lastsync_option['timestamp'];
$ls_category = $lastsync_option['category'];
$ls_page = $lastsync_option['page'];