Skip to content

Instantly share code, notes, and snippets.

@rileypaulsen
rileypaulsen / plugin-name-here.php
Last active October 19, 2023 14:51
Basic plugin boilerplate
<?php
/**
* Plugin Name: Name
* Plugin URI: http://
* Description: Description
* Version: 1.0.0
* Author: Name
* Author URI: http://
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@rileypaulsen
rileypaulsen / functions.php
Created August 19, 2014 16:08
Add Advanced Custom Fields Fields to the WP REST API
function wp_api_encode_acf($data,$post,$context){
$data['meta'] = array_merge($data['meta'],get_fields($post['ID']));
return $data;
}
if( function_exists('get_fields') ){
add_filter('json_prepare_post', 'wp_api_encode_acf', 10, 3);
}
@rileypaulsen
rileypaulsen / touchmove-zoom-disable.js
Created July 16, 2022 21:22
Disables pinch zoom on mobile
if(window.TouchEvent) {
document.addEventListener('touchmove', (event) => {
if(event.scale !== 1) {
event.preventDefault();
}
}, false);
}
@rileypaulsen
rileypaulsen / Force make_clickable() to generate target="_blank" links
Last active May 25, 2022 02:34
extend WordPress's make_clickable function to have target="_blank"
@rileypaulsen
rileypaulsen / click-options.js
Created April 30, 2019 15:00
Examples of how to add click listeners using various JavaScript paradigms
//Given this HTML, here are the ways to add click events
<button id="specialButton">Click Here</button>
//traditional plain JS way
document.getElementById('specialButton').addEventListener('click', function(){
alert('button clicked!');
});
//--------------------------------------
@rileypaulsen
rileypaulsen / mail.php
Created July 6, 2016 03:10
Basic PHP-based mail script for portfolio contact forms
<?php
########################################################
### CONFIG ###
########################################################
const YOUR_EMAIL = 'YOUREMAIL@DOMAIN.COM';
//define a math problem as a field in your form to prevent spam;
//or use a word problem with a string as the answer, but be careful since the case and spelling of the user's answer will need to be exact
const ANSWER = 5;
########################################################
@rileypaulsen
rileypaulsen / File Permissions.sh
Last active July 6, 2016 03:12
Set correct file permissions for WordPress. Must be run from the root of the WP directory.
sudo chown -R www-data:www-data .
sudo find . -type f -exec chmod 664 {} +
sudo find . -type d -exec chmod 775 {} +
sudo chmod 660 wp-config.php
@rileypaulsen
rileypaulsen / string.transforms
Created January 3, 2014 22:34
JavaScript String Transformations
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
@rileypaulsen
rileypaulsen / GoogleSpreadsheets.json.php
Last active December 27, 2015 19:18
Outputs a Google Spreadsheet's CSV feed as valid JSON
<?php
header('Content-type: application/json');
// Based on http://www.ravelrumba.com/blog/json-google-spreadsheets/
//#########################################################
$key = '';
$gid = '0'; //the sheet of the spreadsheet
//#########################################################
@rileypaulsen
rileypaulsen / Select terms from Taxonomy
Last active December 22, 2015 11:29
SQL select all terms from a taxonomy
SELECT a.name as term_name, wp_term_taxonomy.term_id
FROM wp_term_taxonomy
JOIN
wp_terms a
ON (wp_term_taxonomy.term_id = a.term_id)
LEFT JOIN
wp_terms b
ON (wp_term_taxonomy.parent = b.term_id)
WHERE wp_term_taxonomy.taxonomy = 'newscategory'
GROUP BY wp_term_taxonomy.term_id