Skip to content

Instantly share code, notes, and snippets.

View ccurtin's full-sized avatar
🤙
makka thangs

Christopher James Curtin ccurtin

🤙
makka thangs
View GitHub Profile
@ccurtin
ccurtin / woocommerce-search-products-by-category-dropdown.php
Created December 11, 2017 17:42
WooCommerce Search Products by Category Dropdown
<form name="myform" method="GET" action="<?php echo esc_url(home_url('/'));?>">
<?php if (class_exists('WooCommerce')): ?>
<?php
if (isset($_REQUEST['product_cat']) && !empty($_REQUEST['product_cat'])) {
$optsetlect = $_REQUEST['product_cat'];
} else {
$optsetlect = 0;
}
$args = array(
@ccurtin
ccurtin / braintree-upgrade-subscription.js
Last active December 7, 2023 08:51
Braintree API / node How to upgrade a MONTHLY subscription to YEARLY subscription. Rough example. Braintree does NOT automatically prorate user's monthly balance onto the yearly subscription so MUST refund the user's latest Transaction before cancelling current subscription and creating a new subscription.
// 1) Get the customer... required the get the payment method token
await braintreeGateway.customer.find(
billing_customer_id,
async (err, customer) => {
await braintreeGateway.subscription.find(
subscriptionId,
async (err, subscription) => {
if (err) {
res.status(400).json({
error_message: err && err.code
@ccurtin
ccurtin / WP-REST-API--self-served.htaccess
Last active June 20, 2023 03:46
DISMISS PUBLIC ACCESS to WordPress REST API; ONLY ALLOW API ACCESS VIA SAME DOMAIN. ALLOW ADMIN ACCESS FOR ALL THOUGH.... for dynamic IPs... *Ideally*, the Server should be making the requests to the API, not the Client/User. That way, all API access is invalid except from the server. Use CORS and this snippet to block all WP access though.
# - DISMISS PUBLIC ACCESS; ONLY ALLOW API ACCESS VIA OWN DOMAIN
# - ALLOW ADMIN ACESS FOR ALL
#
# This example is in the "public_html/api/" folder where
# the WP API is installed.
#
RewriteEngine On
# If the referer is not its own domain
RewriteCond %{HTTP_REFERER} !^http?://architectura.com [NC]
# Then make it forbidden if not an admin login th
@ccurtin
ccurtin / Custom Social Sharing Buttons for Wordpress Shortcode.php
Last active May 8, 2023 19:31
Custom Social Sharing Buttons for Wordpress
<?php
/*
http://stackoverflow.com/questions/12448134/social-share-links-with-custom-icons
http://petragregorova.com/articles/social-share-buttons-with-custom-icons
wp_enqueue_style('fontAwesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css', array(), '4.3.0', 'all');
use in template files:: <?php echo do_shortcode('[social_sharing]') ; ?>
*/
@ccurtin
ccurtin / ACF-searchable-fields-for-Wordpress-YOAST-SEO.php
Last active March 23, 2023 02:33
ACF searchable custom fields for Wordpress for YOAST SEO
<?php
add_filter('wpseo_pre_analysis_post_content', 'add_custom_to_yoast');
function add_custom_to_yoast( $content ) {
global $post;
$pid = $post->ID;
$custom = get_post_custom($pid); //gets all custom fields in an arry of the current post/page
unset($custom['_yoast_wpseo_focuskw']); // Don't count the keyword in the Yoast field!
@ccurtin
ccurtin / Wordpress: redirect attachment pages to homepage url.php
Created July 2, 2015 17:55
Wordpress: redirect attachment pages to homepage url
<?php
/*
* Redirect Attachment Pages
*/
add_action( 'template_redirect', 'wpse27119_template_redirect' );
function wpse27119_template_redirect()
{
// Get out of here if not headed to an attachment page
if( ! is_attachment() ) return;
@ccurtin
ccurtin / :WORDPRESS: using-PHP-variables-in-JS.md
Last active December 3, 2022 07:28
:WORDPRESS: using-PHP-variables-in-JS (wp localize script)
import React, { useEffect, useRef, useState } from "react"
export const VisualViewport = ({
as: Element = "div",
children,
style = {},
...props
}) => {
const ref = useRef (null)
@ccurtin
ccurtin / CSS-gradient-overlay.css
Created March 12, 2017 19:35
Gradient overlay CSS w/ using pseudo element.
div:before {
content: "";
position: absolute;
background: -webkit-linear-gradient(350deg, rgba(49, 27, 146, .8) 35%, rgba(125, 38, 205, .75));
background: linear-gradient(350deg, rgba(49, 27, 146, .8) 35%, rgba(125, 38, 205, .75));
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
@ccurtin
ccurtin / isNumber.js
Last active March 21, 2022 01:26
isNumber
// @see: https://jsben.ch/cQk7m
// NOTE: `+val === +val` is like isNaN(val) but much faster, esp in Chrome...
// `+val` will convert a string containing a number into a number
// const isNumeric = (val) => (val && val.length || typeof val === 'number') && (+val === +val);
const isNumeric = (val) => ((val?.length || typeof val === 'number') && (+val === +val)) && !isNaN(parseFloat(val))
isNumeric(12345678912345678912);
isNumeric('2');
isNumeric('-32.2');