Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / JSON REST API Basic Authentication
Created August 23, 2014 23:05
Use authentication with the JSON REST API
//Note: requires the Basic Auth plugin
$username = 'username';
$password = 'password';
$args = array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ),
),
);
$queryFilters = array(
@rileypaulsen
rileypaulsen / JSON REST API Tax Query
Created August 23, 2014 23:03
Use a tax_query in a JSON REST API request
//requires authentication
add_filter('json_query_vars','accept_new_queries');
add_filter('json_query_var-tax_query', 'filter_by_taxonomy');
function accept_new_queries($filters){
return array_merge($filters,array('tax_query'));
}
function filter_by_taxonomy($val){
@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 / lipsum.php
Created March 19, 2014 12:09
Lorem Ipsum Generator Function
function random_lipsum($amount = 1, $what = 'paras') {
$start = rand(0,30);
return simplexml_load_file("http://www.lipsum.com/feed/xml?amount=$amount&what=$what&start=$start")->lipsum;
}
@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);
}