Skip to content

Instantly share code, notes, and snippets.

View mike-at-redspace's full-sized avatar
🎧

Mike Vardy mike-at-redspace

🎧
View GitHub Profile
@mike-at-redspace
mike-at-redspace / functions.php
Created June 24, 2021 09:17
Preload Scripts
<?php
add_action('wp_head', function () {
global $wp_scripts;
foreach($wp_scripts->queue as $handle) {
$script = $wp_scripts->registered[$handle];
//-- Weird way to check if script is being enqueued in the footer.
if($script->extra['group'] === 1) {
@mike-at-redspace
mike-at-redspace / distance.js
Created June 24, 2021 09:20
Calculate Distance between two coords
// Passed to function: :::
//::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :::
//::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :::
//::: unit = the unit you desire for results :::
//::: where: 'M' is statute miles (default) :::
//::: 'K' is kilometers :::
//::: 'N' is nautical miles
function distance(lat1, lon1, lat2, lon2, unit) {
@mike-at-redspace
mike-at-redspace / wordpress_export-post-data.php
Created June 24, 2021 09:29 — forked from musamamasood/wordpress_export-post-data.php
WordPress: Simple, configurable script to export post data to a CSV file
<?php
/**
* Export WordPress post data to CSV
* Based on <http://stackoverflow.com/a/3474698> and <http://ran.ge/2009/10/27/howto-create-stream-csv-php/>
*/
/**
*********************************************************************
* Configuration
*********************************************************************
@mike-at-redspace
mike-at-redspace / git_remove-ignored-files.sh
Created June 24, 2021 09:30
Remove all files ignored by .gitignore from repository
git rm -r --cached .
git add .
git commit -m 'Removed all files that are in the .gitignore'
@mike-at-redspace
mike-at-redspace / header.html
Created June 24, 2021 09:40
Lazyload external fonts
<link rel="preload" href="https://font-service/whatever.css" as="style" />
<link rel="stylesheet" href="https://font-service/whatever.css" media="print" onload="media='all'" />
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/
@mike-at-redspace
mike-at-redspace / custom-post-type.php
Created June 24, 2021 09:50
Register Custom Post Type
<?php
# Register custom post types on the 'init' hook.
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 1.0.0
* @access public
@mike-at-redspace
mike-at-redspace / custom-acf-search.php
Created June 24, 2021 10:02
Add ACF fields to WordPress Search
<?php
/**
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
*/
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
}
@mike-at-redspace
mike-at-redspace / functions.php
Created June 24, 2021 10:03
Disable Comments from WordPress
<?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
@mike-at-redspace
mike-at-redspace / touch.js
Created June 24, 2021 10:08
Detect Touch
export function detectTouch() {
window.addEventListener('touchstart', function onFirstTouch() {
// we could use a class
document.body.classList.add('user-is-touching');
// or set some global variable
// window.USER_IS_TOUCHING = true;
// or set your app's state however you normally would
// frameworkOfChoice.dispatchEvent('USER_IS_TOUCHING', true);