Skip to content

Instantly share code, notes, and snippets.

<?php
defined( 'ABSPATH' ) or die( 'Plugin file cannot be accessed directly.' );
class HoneypotSpamTrap {
protected $fields;
public function __construct() {}
// Set fields and setup actions for comments and registration forms
// delete previous days folders
function delete_old_folders() {
$uploads = wp_upload_dir();
$uploadPath = trailingslashit( $uploads['path'] ) . 'user-uploads/';
$folders = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($uploadPath, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach( $folders as $name => $folder ){
// save button
jQuery('.save-crop').on('click', function() {
console.log('saving the cropped image');
jQuery('#cropperModal').foundation('reveal', 'close'); // TODO: this doesn't seem to work...
currentFile.cropData = jQuery('#cropper').cropper('getData');
var printOverlay = new Image();
jQuery(printOverlay).on('load', function() {
console.log('creating Print Overlay ');
// create a 300dpi scaled canvas based off of print overlay width/height
var scaledCanvas = jQuery('#cropper').cropper('getCroppedCanvas', {width: this.width, height: this.height});
function upandup_ajax_cropper_upload() {
$response = array();
if ( check_ajax_referer( 'upandup_cropper_nonce', 'nonce', false ) ) {
$uploads = wp_upload_dir();
$uploadPath = trailingslashit( $uploads['path'] );
$uploadURL = trailingslashit( $uploads['url'] );
// get and sanitize global variables
if ( isset( $_POST['sessionID'] ) ) {
$sessionID = sanitize_text_field( $_POST['sessionID'] );
$uploadPath .= $sessionID . '/';
@ascottmccauley
ascottmccauley / gist:550b8ba1e9861be15064
Created June 18, 2015 15:43
Better WordPress Media Handling
if ( current_user_can( 'edit_posts' ) ) {
// Tell the TinyMCE editor to use a custom stylesheet
// See http://codex.wordpress.org/Function_Reference/add_editor_style
add_theme_support( 'editor_style' );
add_editor_style( 'assets/css/editor-style.css' );
// Prevent WordPress from uploading duplicate files
// Checks to see if both filenames match and then overwrites only if the filesizes are different
function groundup_remove_duplicate_attachment( $file ) {
$upload_dir = wp_upload_dir();
@ascottmccauley
ascottmccauley / layered_nav_exclusion
Last active August 29, 2015 14:15
This is a quick version of creating a layered nav sidebar that excludes selected attributes instead.
////// Layered Nav //////
/**
* fin_woo_layered_nav
*
* adds woocommerce layered_nav widgets for every global attribute to a unique hidden sidebar
**/
function fin_woo_layered_nav() {
global $woocommerce;
if(is_post_type_archive('product') || is_tax(array('product_cat', 'product_tag'))) {
$attribute_taxonomies = wc_get_attribute_taxonomies();
@ascottmccauley
ascottmccauley / spamtrap.php
Last active August 29, 2015 14:04
WordPress SpamTrap
/**
* Add a spam-trap to comment form and registration form
*
* Include hidden fields. If it receives an input, we have a bot!
* Add a unique number (changes daily) to all the fields to keep bots from learning what fields to ignore.
* Store spam entries as spam so that the bot is not aware the form failed
*/
function get_decoy_fields() {
$decoys = array( 'firstname', 'lastname', 'email2', 'address', 'address2', 'city', 'state', 'zipcode', 'telephone', 'phone');
return $decoys;
@ascottmccauley
ascottmccauley / gist:3c3ad4e1772059234be5
Created June 14, 2014 12:36
WordPress Honeypot Functions
/**
* Add a spam-trap to comment form and registration form
*
* Include a hidden field called name and set it to hidden. If it receives an input, we have a bot!
*/
function get_decoy_fields() {
$decoys = array( 'firstname', 'lastname', 'email2', 'address', 'address2', 'city', 'state', 'zipcode', 'telephone', 'phone');
return $decoys;
}
function get_dailyID() {
@ascottmccauley
ascottmccauley / _settings.scss
Created April 8, 2013 14:52
(work in progress) An adaptation of the _settings.scss for Foundation 4 that hinges colors based around the $body-bg color. I had to add the reverse-lightness function so that the settings would work for both light and dark schemes.
// Required global settings and mixins for Foundation
@import "foundation/foundation-global";
// Find the opposite lightness value of a color for more contrast. Neutral colors will see less difference
@function reverse-lightness($color, $percent: 'auto') {
@if(lightness($color) < 50%) { // dark colors
@if($percent == 'auto') {
$percent: 2* ( 50 - lightness($color));
}
$color: lighten($color, $percent);