Skip to content

Instantly share code, notes, and snippets.

@drewbaker
drewbaker / simian-sync.php
Last active September 6, 2023 03:07
A script that creates a Video CPT that gets synced to your Simian
<?php
/*
* This file contains code to create a Video CPT, and a "Download" button in the admin header.
* When clicking that download button, it creates a Video post with all the meta data saved as `simian_data`.
*
* Requires a site options field for `simian_api_key` that is the API key from Simian.
* Eg: This must work: get_field("simian_api_key", "option");
*
* Also need an option field for `simian_api_url` that is something like `https://clientNameHere.gosimian.com/api/simian/get_media`
*
@drewbaker
drewbaker / downloadInstagramImages.js
Last active July 2, 2022 06:26
A bookmarklet to download all images from a user on Instagram
/*
* 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 March 8, 2022 06:13
Shopify redirect header
<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 January 28, 2022 01:37
Extend WP-GraphQL to allow users/authors to be public. Useful to query all posts by Author.
/*
* 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 / convert-wordpress-meta-fields.php
Last active October 12, 2023 20:34
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.
/*
* Use this script as a starting point to convert old WP meta fields to ACF meta fields.
* Add ?convert_meta to the URL and load any page in backend.
* You should edit the script, and only run it once.
*/
function custom_convert_meta_to_acf()
{
// Abort if no query param in URL
if(! isset($_GET["convert_meta"])) {
return;
@drewbaker
drewbaker / mock-api.gql
Last active February 1, 2023 15:11
This is used to generate the mock-api.json file used by fuxt
query MockApi {
home: page(id: "/featured", idType: URI) {
id
title
excerpt
content
uri
featuredImage {
node {
...MediaImage
@drewbaker
drewbaker / custom-post-types.php
Last active June 2, 2022 00:44
Create custom post types for different regions
<?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 November 18, 2020 16:48
Register custom "filter" taxonomy in WordPress
<?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
Last active June 8, 2023 21:46
A custom WP JSON API SearchWP endpoint
<?php
/*
* Register custom API endpoints
*
* NOTE: Will be accessable at: https://example.com/wp-json/fuxt/v1/search?term=Netflix&engine=work
*/
function add_fuxt_api_routes()
{
// Sitemap
register_rest_route("fuxt/v1", "/search", [
@drewbaker
drewbaker / functions.php
Last active June 19, 2017 09:02
GeoIP functions for WordPress. Requires some external GeoIP files and .dat file from MaxMind.
/*
* 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'),