Skip to content

Instantly share code, notes, and snippets.

View Magnacarter's full-sized avatar

Adam Carter Magnacarter

  • React and WordPress Dev
  • United States
View GitHub Profile
@Magnacarter
Magnacarter / wp-pagination.php
Created February 10, 2023 17:30
Simple Pagination for WordPress
<?php
function soundst_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
@Magnacarter
Magnacarter / use-track-location.js
Created March 6, 2022 06:02
React hook for getting a user's latlong from their browser.
import { useState, useContext } from 'react'
import { ACTION_TYPES, StoreContext } from '../pages/_app'
const useTrackLocation = () => {
const [locationErrorMsg, setLocationErrorMsg] = useState('');
//const [latlong, setLatLong] = useState('');
const [isFindingLocation, setIsFindingLoaction] = useState(false);
const { dispatch } = useContext(StoreContext);
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
// Discount sidebar disclaimer on subscriptions.
var discountDiv = document.querySelector('#discount_inactive'),
child = document.createElement('div');
child.innerHTML = `<p style="padding-top:10px;">Good news, you’re earning rewards for you order. Unfortunately, due to software limitations, rewards can’t be redeemed for orders with subscriptions. If you’d like to use rewards towards a purchase, please make sure to not have any Subscribe & Save products in your cart.</p>`;
discountDiv.appendChild(child);
});
</script>
<?php
/**
* Load the Placement API class
* These methods can be used to interact with
* the peta_placements db table
*
* @package PETA\Placement_Plugin\inc
* @since 4.0.0
* @author adamc
* @licence GNU-2.0+
/**
* Track pageviews when the page is translated directly from translate.google.com or bing.com/translator
* and return an individual query parameter.
*
* @param string name
* @return string results
*/
const getUrlParameter = ( name ) => {
name = name.replace( /[\[]/, '\\[').replace(/[\]]/, '\\]' );
@Magnacarter
Magnacarter / custom-table.php
Last active November 6, 2019 21:57
How to build a WP custom db table
<?php
/**
* Install placement table
* upon plugin activation, create custom table to store user placements
*
* @since 4.0.0
* @author acarter
*
* @return void
*/
"use strict";
var gulp = require( 'gulp' ),
maps = require( 'gulp-sourcemaps' ),
autoprefixer = require( 'gulp-autoprefixer' ),
concat = require( 'gulp-concat' ),
uglify = require( 'gulp-uglify' ),
rename = require( 'gulp-rename' ),
sass = require( 'gulp-sass' ),
cleanCSS = require( 'gulp-clean-css' ),
@Magnacarter
Magnacarter / plugin-get-prod-images.php
Last active June 25, 2019 15:17
Pull in prod images by setting a live and local url in Production Images Options page
<?php
/**
* Plugin bootstrap file
*
* @link https://github.com/PETAF/plugin-get-prod-images
* @since 1.0.0
* @package PETA\Plugin_Get_Prod_Images\
*
* @wordpress-plugin
* Plugin Name: Plugin Get Prod Images
@Magnacarter
Magnacarter / gulpfile.js
Created March 21, 2019 13:46
Gulp file with auto broswer refresh and auto-prefix
"use strict";
var gulp = require( 'gulp' ),
maps = require( 'gulp-sourcemaps' ),
autoprefixer = require( 'gulp-autoprefixer' ),
concat = require( 'gulp-concat' ),
uglify = require( 'gulp-uglify' ),
rename = require( 'gulp-rename' ),
sass = require( 'gulp-sass' ),
cleanCSS = require( 'gulp-clean-css' ),
@Magnacarter
Magnacarter / custom-fields.js
Last active December 1, 2017 22:36
JS needed for WordPress modal for media uploads. Use wp_enqueue_media(); in your enqueue function to get the modal to show
jQuery( function( $ ) {
"use strict";
/**
* Open media library in modal
*/
function imageModal( metaBoxSelector ) {
let frame,
metaBox = $( metaBoxSelector ),