Skip to content

Instantly share code, notes, and snippets.

View interactiveRob's full-sized avatar

Rob Kirkner interactiveRob

View GitHub Profile
@interactiveRob
interactiveRob / start_session.php
Created January 11, 2019 18:55
Start Session for Wordpress
/* In order to use SESSION with AJAX etc in Wordpress. you must use add_action to hook into 'wp' */
add_action('wp', 'rk_start_session');
function rk_start_session() {
global $post;
//if you want to use anything from the $post variable you can
if(!session_id()):
@interactiveRob
interactiveRob / disable_gutenberg.php
Last active January 13, 2019 02:27
Disable Gutenberg Editor in one line of PHP
/* To disable the Gutenberg editor sitewide,
add the following snippet to functions.php or
any other PHP file that has been included in functions.php */
add_filter('use_block_editor_for_post', '__return_false', 10);
@interactiveRob
interactiveRob / conditional-wp-config.php
Last active January 14, 2019 17:48
Load config files conditionally into wp_config based on environment $_SERVER['HTTP_HOST']
<?php
/*———— -Determine environment and load the corresponding config file- ————*/
//builds RegEx patterns with any number of optional hostnames
function host_pattern($carry, $item, $initial){
return $carry . '(' . preg_quote($item) . ')?';
}
$local_hosts = [
'.docker',
@interactiveRob
interactiveRob / es6-dom-utils.js
Last active January 16, 2019 19:17
ES6 Dom Helpers/Utilities Boilerplate (to use instead of jQuery)
//dom_utils Class, keep this in a utils file of some sort
class dom_utils {
constructor(selector) {
this.node = selector;
}
exists() {
return typeof this.node !== 'undefined';
}
@interactiveRob
interactiveRob / page-some-template.php
Last active August 6, 2021 15:22
Standard Wordpress Page Template Boilerplate with required comment
<?php
/*Template Name: Some Template */
?>
@interactiveRob
interactiveRob / plain-js-siblings-es6.js
Created January 18, 2019 20:03
Plain JS get siblings ES6 Method
getSiblings(elem) {
var siblings = [];
var sibling = elem.parentNode.firstChild;
for (; sibling; sibling = sibling.nextSibling) {
if (sibling.nodeType !== 1 || sibling === elem) continue;
siblings.push(sibling);
}
return siblings;
}
@interactiveRob
interactiveRob / custom-dev-uploads-dir.php
Created January 20, 2019 01:46
Custom Wordpress uploads directory for dev-only files
<?php
$upload_dir = wp_upload_dir();
$custom_files_path = $upload_dir['baseurl'] . '/files/';
//...continued
?>
@interactiveRob
interactiveRob / scss.json
Created January 22, 2019 19:15
VS Code Shortcut Snippet for include-media.scss
"Include Media Breakpoint": {
"prefix": "media",
"body": [
"@include media('${1|>=,<=,>,<|}${2|480px,768px,1024px,1170px|}') {",
"\t$0",
"}",
],
"description": "@include-media plugin sccs breakpoint"
},
@interactiveRob
interactiveRob / copy-to-clipboard-es6.js
Last active October 6, 2021 10:09
Copy String to Clipboard ES6 Method
copyToClipboard(str) {
/* ——— Derived from: https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
improved to add iOS device compatibility——— */
const el = document.createElement('textarea'); // Create a <textarea> element
let storeContentEditable = el.contentEditable;
let storeReadOnly = el.readOnly;
el.value = str; // Set its value to the string that you want copied
el.contentEditable = true;
@interactiveRob
interactiveRob / archive.php
Last active February 11, 2019 17:25
Basic WP_Query template for displaying a custom selection of posts per category
<?php
get_header();
$cat_id = get_queried_object_id();
$is_category = is_category($cat_id);
$query_cat_id = $is_category ? $cat_id : null;
$cat_data = get_category($cat_id);
$post_id = $is_category ? $cat_id : get_option('page_for_posts');
//means-- if it's a category, set the ID to that category page so we can get its title etc.