Skip to content

Instantly share code, notes, and snippets.

View scottopolis's full-sized avatar

Scott Bolinger scottopolis

View GitHub Profile
@scottopolis
scottopolis / ga-track-outbound.js
Last active January 4, 2024 21:14
Google Analytics track all outbound links with no markup change
// listen for all clicks on anything. You could change document to a selector like #content to make it more efficient.
$(document).on('click', function( e ) {
// if this is a link, and the href does not contain our domain, it's an external link. Track it.
if( e.target.href && e.target.href.indexOf( window.location.hostname ) < 0 ) {
ga('send', 'event', {
eventCategory: 'Outbound Link',
eventAction: 'click',
eventLabel: e.target.href, // the outbound link url will appear as the event label in GA. Find under Behavior -> Events -> Event Label
transport: 'beacon' // not supported in some versions of IE
});
@scottopolis
scottopolis / apppresser-iap-pmp.php
Last active December 10, 2023 16:11
AppPresser In App Purchase integration for Paid Memberships Pro
<?php
/*
Plugin Name: AppPresser In App Purchases for Paid Memberships Pro
Plugin URI: https://apppresser.com
Description: This plugin listens for in app purchases or cancellations and adds/removes members from a membership level.
Version: 2.0.0
Author: Scott Bolinger
Author URI: https://apppresser.com
License: GPLv2
*/
@scottopolis
scottopolis / splice-object-array.js
Last active January 31, 2023 06:54
Remove object from array of objects in Javascript
// we have an array of objects, we want to remove one object using only the id property
const apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
// get index of object with id of 37
const removeIndex = apps.findIndex( item => item.id === 37 );
// remove object
apps.splice( removeIndex, 1 );
@scottopolis
scottopolis / aws-nexttoken.php
Created February 27, 2015 00:08
How to use the AWS NextToken in PHP. This is for Amazon SNS specifically.
do {
// We only get 100 subscribers, if there's a nextToken, get the next 100
if( $nextToken ) {
$result = $client->listEndpointsByPlatformApplication(array(
'PlatformApplicationArn' => $gcm_arn,
'NextToken' => $nextToken
));
} else {
// Run this the first time, since there's no nextToken yet
$result = $client->listEndpointsByPlatformApplication(array(
@scottopolis
scottopolis / bp-redirect.php
Last active September 23, 2022 18:50
BuddyPress Profile redirect
<?php
function appp_redirect() {
global $wp;
$current_url = home_url( $wp->request );
$string = apply_filters( 'ap3_bp_me_url', '/me/' );
$me = stripos( $current_url, $string );
@scottopolis
scottopolis / woo-product-api-filter.php
Last active June 20, 2022 14:47
Modify WooCommerce REST API Product Response
<?php
// add this code to a custom plugin
add_filter( 'woocommerce_rest_prepare_product_object', 'wc_app_add_custom_data_to_product', 10, 3 );
// filter the product response here
function wc_app_add_custom_data_to_product( $response, $post, $request ) {
// in this case we want to display the short description, so we copy it over to the description, which shows up in the app
$response->data['description'] = $response->data['short_description'];
return $response;
@scottopolis
scottopolis / apppresser-iap-memberpress.php
Last active April 13, 2022 17:12
Add user to MemberPress after in app purchase, and cancel for AppPresser
<?php
/*
Plugin Name: In App Purchases for MemberPress
Plugin URI: https://apppresser.com
Description: This plugin listens for in app purchases or cancellations and adds/removes members from a membership level.
Version: 2.0.0
Author: Scott Bolinger
Author URI: https://apppresser.com
License: GPLv2
*/
@scottopolis
scottopolis / apppresser-iap-indeed.php
Created March 1, 2022 17:16
AppPresser IAP Indeed Memberships
<?php
/*
Plugin Name: AppPresser In App Purchases for Indeed Memberships
Plugin URI: https://apppresser.com
Description: This plugin listens for in app purchases or cancellations and adds/removes members from a membership level.
Version: 1.0.0
Author: Scott Bolinger
Author URI: https://apppresser.com
License: GPLv2
*/
@scottopolis
scottopolis / gatsby-dynamic.js
Created November 26, 2019 16:09
Dynamic Content in Gatsby with Apollo and WPGraphQL
// This is just for example purposes, copy/pasting this won't work out of context. It is from the Gatsby Publisher theme by Static Fuse.
import React from 'react'
import { Box } from '@chakra-ui/core'
import Layout from '../../components/Layout'
import PostEntry from '../../components/PostEntry'
import Pagination from '../../components/Pagination'
import HeaderArchive from '../../components/HeaderArchive'
import SEO from '../../components/SEO'
import { useQuery } from '@apollo/react-hooks'
import gql from 'graphql-tag'
@scottopolis
scottopolis / react-state-object-property.js
Created December 2, 2021 17:31
React set state for object property (one-liner)
// to update a property in an object, for example a title
setMyState({
...currentState,
title: newTitle,
});
/* Explanation below...
// we have an object set as state