Skip to content

Instantly share code, notes, and snippets.

View m-thomson's full-sized avatar

Mark Thomson m-thomson

  • Vancouver Canada
View GitHub Profile
#!/usr/bin/env bash
########################################################
## .bash_reuse
########################################################
## This file contains aliases and functions that can be
## re-used across systems (Mac and Linux). These must be
## sourced from the .bashrc or .bash_profile but can also
## be used in a Keyboard Maestro macro (or similar) to
## "type" them into a terminal window
########################################################
@m-thomson
m-thomson / google_button_duckduckgo_gm.js
Created May 27, 2020 15:52
Adds a 'Google' button below the DDG search box to retry the search at Google using !g
// ==UserScript==
// @name Add 'Google' button to duckduckgo.com
// @description Adds a 'Google' button below the DDG search box to retry the search at Google using !g
// @encoding utf-8
// @namespace google_button_duckduckgo
// @match *://duckduckgo.com/*
// @grant none
// @run-at document-end
// @version 0.0.1.20190401105002
// ==/UserScript==
@m-thomson
m-thomson / airtable-to-csv.php
Last active March 13, 2021 11:33
Dump airtable contents to CSV
<?php
/*
* Totally simple way to dump an Airtable to CSV.
* Uses https://github.com/sleiman/airtable-php
*/
// When true, first field is the row number (starting with 1)
define("NUMBER_OUTPUT_ROWS", true);
@m-thomson
m-thomson / get-feed.php
Last active August 25, 2017 20:40
Create "friendly" URLs to access your WP All Export data feed like http://example.com/get-feed.php . Just (1) change the URL where indicated (2) name this file what you want and (3) upload it to your server. When this script is fetched the user will be transparently redirected.
<?php
// Redirect browser to the WP All Export feed of your choice. Just put the correct URL below.
// Note: Anyone could access your data if they guess the URL of this script. You can gain a little protection by naming
// it something "unguessable". For proper security you should use an .htaccess rule or other mechanism.
// Disclaimer: This is provided with the hope it will be useful but custom PHP is not officially supported.
$url = "http://example.com/wp-cron.php?export_hash=ed5a94029a05b1c9&export_id=1&action=get_data";
header("Location: $url");
@m-thomson
m-thomson / att_id.md
Last active August 21, 2017 17:50
Image/attachment lookup in WP All Import.

Sometimes you might need to look up the attachment id for an imported image (or other media library file) to accommodate a third party plugin. You can use this code in the function editor.

/* Returns attachment ID for the given filename, path or URL. Argument can be a
 * URL or local file path because this will only look at the file basename. Ex - These
 * would return the same thing:
 * $id = img_id("myfile.jpg");
 * $id = img_id("http://domain.com/images/myfile.jpg");
 */
function att_id($image_filename) {
@m-thomson
m-thomson / _example-import-files.md
Last active May 1, 2017 21:54
All Import sample files.

Custom text mapping in WP All Import

Below is a PHP function you can use in WP All Import to enable custom text mapping anywhere in your import. You would use it in your import field like this:

[my_map({field[1]})]

Where "{field[1]}" would be the correct field name from your file.

@m-thomson
m-thomson / dropbox-linux-install.sh
Last active March 17, 2017 19:08
dropbox-linux-install.sh
#!/bin/bash
# Dropbox linux install
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
wget -O dropbox.py https://www.dropbox.com/download?dl=packages/dropbox.py
chmod +x dropbox.py
# comment3
@m-thomson
m-thomson / import-image-fix.md
Last active September 21, 2024 21:01
WP All Import duplicate image problem

When an image is imported, the name used in the media library is derived from the URL "basename". This can cause problems, especially when using the option "Search through the Media Library for existing images before importing new images". For example, even though they are different images, these URLs all have the same "basename" (in bold). They will generate the same file my-image.jpg in the WordPress library:

http:// example.com/ my-image.jpg
http:// example.com/ my-image?id=1
http:// example.com/subfolder/ my-image.jpg

The solution is to put this PHP code in your function editor:

function fix_img_url($url){

WP All Import - IF/ELSE statement examples

Here are some example WP All Import [IF] statements. The criteria for an IF statment is written in XPath 1.0 syntax and can use XPath functions. Although powerful, XPath syntax can be quite complex. In many cases it might be easier to use a PHP function as shown here.

Note: The [ELSE]<something> part is optional

Number is equal to:

[IF({price[.=0]})]Zero[ELSE]Not Zero[ENDIF]