Skip to content

Instantly share code, notes, and snippets.

View stgoos's full-sized avatar

Steven stgoos

  • The Netherlands
View GitHub Profile
@stgoos
stgoos / UploadSupportDetection.js
Created January 15, 2017 15:11 — forked from jacobtwlee/UploadSupportDetection.js
Upload support detection
function isUploadSupported() {
if (navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/)) {
return false;
}
var elem = document.createElement('input');
elem.type = 'file';
return !elem.disabled;
};
@stgoos
stgoos / ReadFile.js
Created January 15, 2017 15:12 — forked from jacobtwlee/ReadFile.js
Reading the file
function readFile(file) {
var reader = new FileReader();
reader.onloadend = function () {
processFile(reader.result, file.type);
}
reader.onerror = function () {
alert('There was an error reading the file!');
}
@stgoos
stgoos / SendFile.js
Created January 15, 2017 15:12 — forked from jacobtwlee/SendFile.js
Uploading the file with AJAX
function sendFile(fileData) {
var formData = new FormData();
formData.append('imageData', fileData);
$.ajax({
type: 'POST',
url: '/your/upload/url',
data: formData,
contentType: false,
@stgoos
stgoos / ProcessFile.js
Created January 15, 2017 15:12 — forked from jacobtwlee/ProcessFile.js
Processing the image with canvas
function processFile(dataURL, fileType) {
var maxWidth = 800;
var maxHeight = 800;
var image = new Image();
image.src = dataURL;
image.onload = function () {
var width = image.width;
var height = image.height;
@stgoos
stgoos / HandlingFileInput.js
Created January 15, 2017 15:12 — forked from jacobtwlee/HandlingFileInput.js
Handling file input
if (window.File && window.FileReader && window.FormData) {
var $inputField = $('#file');
$inputField.on('change', function (e) {
var file = e.target.files[0];
if (file) {
if (/^image\//i.test(file.type)) {
readFile(file);
} else {
@stgoos
stgoos / FileSelect.html
Created January 15, 2017 15:12 — forked from jacobtwlee/FileSelect.html
File select
<input id="file" type="file" accept="image/*">
<?php
if(!function_exists('wc_get_products')) {
return;
}
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$ordering = WC()->query->get_catalog_ordering_args();
$ordering['orderby'] = array_shift(explode(' ', $ordering['orderby']));
$ordering['orderby'] = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
@stgoos
stgoos / external-product-embed-snippets.php
Created December 28, 2020 22:00 — forked from WPprodigy/external-product-embed-snippets.php
Short snippets to edit the product data retrieved by the shortcodes.
<?php
/**
* Change the default shortcode button text for both shortcodes
*/
add_filter( 'wcepe_external_product_shortcode', 'wcepe_change_default_button_text' );
add_filter( 'wcepe_recent_external_products_shortcode', 'wcepe_change_default_button_text' );
function wcepe_change_default_button_text( $atts ) {
@stgoos
stgoos / email-confirmation.php
Created March 11, 2021 22:21 — forked from elclanrs/email-confirmation.php
Simple e-mail confirmation plugin for WordPress.
<?php
/**
* Plugin Name: Email Confirmation
* Description: Send an email to the user with confirmation code and store form data in database until user confirms.
* Author: Cedric Ruiz
*/
class EmailConfirmation
{
const PREFIX = 'email-confirmation-';
<?php
# SHORTS
# DIRECTORY SEPARATOR
define( 'DS', DIRECTORY_SEPARATOR );
# PATH SEPARATOR
define( 'PS', PATH_SEPARATOR );
# Absolute path to the WordPress directory.
! defined( 'ABSPATH' )
AND define( 'ABSPATH', dirname( __FILE__ ).DS );