Skip to content

Instantly share code, notes, and snippets.

Avatar

Drew Baker drewbaker

View GitHub Profile
@drewbaker
drewbaker / downloadInstagramImages.js
Last active Jul 2, 2022
A bookmarklet to download all images from a user on Instagram
View downloadInstagramImages.js
/*
* Bookmarklet to download all IG images for the current account page.
* Use https://katanya.co.uk/labs/bookmarklet-generator to generate the bookmarklet.
*
* SEE: https://www.instagram.com/web/search/topsearch/?query=casetify
* SEE: https://www.instagram.com/graphql/query/?query_id=17888483320059182&variables={"id":"6662673","first":50,after:"QVFEaEJRR0tiTXpVUVV5ZVlfQktDUFJYNUpRWlhOMktKbWZXWEh4cHNCSFV2ZDA5RVBaUzFfWmxVOWlaMHNfVU1wNTQ1dFVXZlVoT05oUzRVVHYyNVBZMQ=="}
*/
(async function () {
let userId = "";
@drewbaker
drewbaker / theme.liquid
Last active Mar 8, 2022
Shopify redirect header
View theme.liquid
<script>
// Redirect from the Shopify site (except for any account or cart pages)
switch(true) {
case document.location.href.includes('/cart') :
case document.location.href.includes('/account') :
break;
default:
window.top.location.href = 'https://shop.example.com/';
break;
@drewbaker
drewbaker / gql-functions.php
Created Jan 28, 2022
Extend WP-GraphQL to allow users/authors to be public. Useful to query all posts by Author.
View gql-functions.php
/*
* Extend WP-GraphQL to allow users/authors to be public. Useful to query all posts by Author.
*/
function enable_authors_public( $is_private, $model_name, $data, $visibility, $owner, $current_user ) {
// Allow Users to be considered publicly queryable
if ( 'UserObject' === $model_name ) {
return false;
}
@drewbaker
drewbaker / php
Created Jun 21, 2021
A PHP script as a starting point to convert old WP meta fields to ACF meta fields. Add this to theme's functions.php file.
View php
/*
* Use this script as a starting point to convert old WP meta fields to ACF meta fields.
* You should edit the script, and only run it once.
*/
function custom_convert_meta_to_acf()
{
// Get all pages/posts/cpts
$args = array(
'post_type' => 'any',
'posts_per_page' => -1,
@drewbaker
drewbaker / mock-api.gql
Last active Jan 4, 2021
This is used to generate the mock-api.json file used by fuxt
View mock-api.gql
query MockApi {
home: page(id: "/home", idType: URI) {
id
title
excerpt
content
uri
featuredImage {
node {
...MediaImage
@drewbaker
drewbaker / style.scss
Last active Dec 11, 2020
This makes sure portrait images used in wp-images don't become too tall
View style.scss
// This makes sure portrait images don't become too long
.wp-image.is-orientation-portrait {
max-height: 80vh;
/deep/ {
.sizer {
position: static;
}
.media {
object-fit: contain;
@drewbaker
drewbaker / custom-post-types.php
Last active Jun 2, 2022
Create custom post types for different regions
View custom-post-types.php
<?php
/*
* Setup Custom Post Types
*/
function create_custom_posts() {
// Create a loop of all the post types we need
$types = array(
[
'name' => 'US Region',
@drewbaker
drewbaker / custom-taxonomies.php
Created Nov 18, 2020
Register custom "filter" taxonomy in WordPress
View custom-taxonomies.php
<?php
/*
* Add a custom taxonomy my for "Work Filter" certain post types
*/
function setup_work_filters() {
$labels = array(
'name' => 'Work filter',
'singular_name' => 'Work filter',
'search_items' => 'Search filters',
'popular_items' => 'Popular filters',
@drewbaker
drewbaker / api.php
Created Oct 29, 2020
WP JSON API SearchWP endpoint
View api.php
<?php
/*
* Register custom API endpoints
*/
function add_fuxt_api_routes()
{
// Sitemap
register_rest_route('fuxt', '/search', [
[
'methods' => 'GET',
@drewbaker
drewbaker / functions.php
Last active Jun 19, 2017
GeoIP functions for WordPress. Requires some external GeoIP files and .dat file from MaxMind.
View functions.php
/*
* Region Select Custom Post Type
*/
function cutandrun2016_post_type() {
// US editors
$us_post_labels = array(
'name' => _x('US Region', ''),
'singular_name' => _x('US Region', ''),
'add_new' => _x('Add New', 'editor'),