Skip to content

Instantly share code, notes, and snippets.

@8ctopotamus
8ctopotamus / var_awesome.php
Last active September 30, 2018 18:38
var_dump() looks like s***. Make it readable for humans.
function var_awesome($value) {
echo '<pre>';
var_export($value);
echo '</pre>';
}
// useage
$example_arr = array('testing', 1, 2, 3);
var_awesome($example_arr);
@8ctopotamus
8ctopotamus / woocommerce.php
Created November 9, 2018 07:26 — forked from marcosnakamine/woocommerce.php
WooCommerce - Get variable product attributes
<?php $attributes = $product->get_attributes() // GET ALL ATRIBUTES ?>
<?php foreach( $attributes as $key => $value ): ?>
<?php $attribute_name = preg_replace( '/pa_/', '', $key ) // GET ATTRIBUTE NAME ?>
<label>
<select name="attribute_pa_<?php echo $attribute_name ?>" id="attribute_pa_<?php echo $attribute_name ?>">
<option value=""><?php echo $attribute_name ?></option>
<?php $attribute_name = wc_get_product_terms( get_the_ID(), $key ) // GET ATTRIBUTE NAME ?>
<?php $attribute_slug = wc_get_product_terms( get_the_ID(), $key, array( 'fields' => 'slugs' ) ) // GET ATTRIBUTE SLUG ?>
<?php for ( $i=0; $i<count( $attribute_name ); $i++ ): // array_slice BECAUSE ARRAY INDEX IS NOT SEQUENCIAL ?>
<option value="<?php $slug = array_slice( $attribute_slug, $i, 1 ); echo $slug[0]; ?>"><?php $name = array_slice( $attribute_name, $i, 1 ); echo $name[0]; ?></option>
@8ctopotamus
8ctopotamus / .htaccess
Last active September 11, 2020 21:40
Leverage Browser Caching Gzip all the things
# Headers for Mozilla Observatory test #
Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options nosniff
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy: no-referrer-when-downgrade
Header set Feature-Policy "vibrate none;
# START EXPIRES CACHING #
@8ctopotamus
8ctopotamus / detect-ie.js
Last active April 15, 2019 21:42
Detect IE 11 and tell user to use a real browser ;P
// detect IE
if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/))) {
document.write('<p style="text-align: center;">You are using a browser no longer supported by Microsoft. To use What Plow Fits, please use a <a href="http://outdatedbrowser.com/en" target="_blank">modern browser</a>.</p>')
}
@8ctopotamus
8ctopotamus / wp-generate-i18n.md
Last active August 11, 2019 20:45
Genrate a .pot file for i18n from your source code.
  1. Download https://github.com/wp-mirrors/wp-i18n-tools
  2. Extract contents to /wp-includes
  3. Run following in command line to generate .pot file (Fix paths as needed)

Plugin

php wp-includes/makepot.php wp-plugin wp-content/plugins/YOURPLUGIN/ wp-content/plugins/YOURPLUGIN/YOURPLUGINSLANGFOLDER/YOURPLUGIN.pot

Theme

php wp-includes/makepot.php wp-theme wp-content/themes/YOURTHEME/ wp-content/themes/YOURTHEME/YOURTHEMESLANGFOLDER/YOURTHEME.pot

@8ctopotamus
8ctopotamus / Fetch.cs
Created August 27, 2019 17:40
Fetch data from REST API in C# example
using System.IO;
using System.Net;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
@8ctopotamus
8ctopotamus / react-var_dump.js
Last active October 18, 2023 17:34
Display data in React, kinda like PHP's var_dump();
const dataDump = props => <pre>{JSON.stringify(props, null, 2)}</pre>
@8ctopotamus
8ctopotamus / populate-infusionsoft-field.js
Created December 19, 2019 16:11
Populate an infusionsoft field based off of query param.
const inputToFill = document.getElementById('390')
const presentation = getQueryVariable('presentation')
function unSlugify(slug) {
var title = slug.split('-').join(' ');
var firstLetterCapital = title.charAt(0).toUpperCase();
var theRest = title.substring(1);
return firstLetterCapital + theRest;
}
@8ctopotamus
8ctopotamus / form-tester.js
Last active October 11, 2020 19:02
Quickly fill out a form for testing
Array.from( document.querySelectorAll('input, textarea') ).forEach(function(el) {
if (el.type === 'text' || el.tagName === 'TEXTAREA') {
el.value = 'test'
} else if (el.type === 'number' || el.type === 'tel') {
el.value = 100
} else if (el.type === 'date') {
el.value = '2020-10-20'
} else if (el.type === 'checkbox') {
el.checked = true
}
@8ctopotamus
8ctopotamus / functions.php
Created November 3, 2020 00:35 — forked from mrkdevelopment/functions.php
remove divi cpt style action
/**
* Disable new divi crazy crap code for CPT
**/
function disable_cptdivi()
{
remove_action( 'wp_enqueue_scripts', 'et_divi_replace_stylesheet', 99999998 );
}
add_action('init', 'disable_cptdivi');