Skip to content

Instantly share code, notes, and snippets.

@alpha1
alpha1 / mass_insert_terms.php
Last active June 20, 2016 05:32
Wordpress: Mass Insert Terms (Including Children and Meta)
<?php
function wpcrmio_mass_insert_terms( $taxonomy, $terms_array = array() ){
/*
$terms_array = array(
'slug' => array(
'name' => '',
'description' => '',
'meta' => '',
'children' => array(
@alpha1
alpha1 / gravity_forms_phone_validation.php
Last active November 9, 2017 18:03
Graivty Forms Phone Field Validation - Disallow a phone number consisting of entirely the same digits
<?php
add_filter( 'gform_field_validation', 'wphacks_prevent_fake_phone_numbers', 1, 4);
function wphacks_prevent_fake_phone_numbers( $result, $value, $form, $field ){
$error = array( 'is_valid' => 0, 'message' => 'Please use a real phone number' );
//the 3 built in phone number fields, phone and text with input masks
if ( ($field->type == 'phone') || ( $field->type == 'text' && $field['inputMaskValue'] == '(999) 999-9999? x99999' ) || ( $field->type == 'text' && $field['inputMaskValue'] == '(999) 999-9999' ) ){
//remove all special characters to make a numbers only string
$numbers_only = implode("", array_filter(str_split($value),function($array){ return is_numeric($array); }));
@alpha1
alpha1 / allow_nbsp_in_tinymce.php
Created November 19, 2015 16:29
Allow Spaces in Wordpress TinyMCE
<?php
function allow_nbsp_in_tinymce( $mceInit ) {
$mceInit['entities'] = '160,nbsp,38,amp,60,lt,62,gt';
return $mceInit;
}
add_filter( 'tiny_mce_before_init', 'allow_nbsp_in_tinymce' );
?>
@alpha1
alpha1 / gravity_forms_allow_html.php
Last active August 29, 2015 14:27
Gravity Forms: Allow (Displaying) HTML in notes
<?php
/*
This will allow Gravity Forms Notes to display HTML. You can already add html to notes, but it will be displayed out as code.
*/
add_action('gform_entry_detail','gravity_forms_add_filter_allow_html');
add_action('gform_entry_detail_content_before','gravity_forms_add_filter_allow_html');
add_action('gform_entry_detail_content_after','gravity_forms_remove_filter_allow_html');
function gravity_forms_add_filter_allow_html(){
@alpha1
alpha1 / gf_add_comment_when_entry_value_is_changed.php
Last active May 6, 2017 10:56
Gravity Forms Add Comment for Edited Entry Values
/*
Gravity Forms 1.9.12.9 and above. Needs the 3rd arg on gform_after_update_entry
Compares values from the previous entry to the current (updated) entry, and adds a comment marking the user, time, field, and previous to current values that was changes - one comment per change.
*/
function gf_add_note($entry_id, $note){
RGFormsModel::add_note($entry_id, 0, __('gravity Forms'), $note);
}
add_action( 'gform_after_update_entry', 'magx_add_comment_for_changes_details', 10, 3 );
function magx_add_comment_for_changes_details($form, $entry_id, $original_entry){
$entry = GFAPI::get_entry( $entry_id );
<?php
$css = "style=''";
if ( has_post_thumbnail( get_the_ID ) ) :
$size = 'large'; // choose size of image to be used
$thumb_id = get_post_thumbnail_id();
$thumb_object = wp_get_attachment_image_src($thumb_id, $size, true);
$thumb_url = $thumb_object[0];
$css = "background-image:url('$thumb_url'); background-size:cover; background-position:top-center no-repeat;"
endif;
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@alpha1
alpha1 / form_export.json
Last active August 29, 2015 14:15
Gravity Forms Doesn't Play Well With Checking Checkboxes using dynamic population
{"0":{"title":"Edit Profile","description":"User Edit Profile","labelPlacement":"top_label","descriptionPlacement":"below","button":{"type":"text","text":"Update","imageUrl":""},"fields":[{"type":"hidden","adminLabel":"","adminOnly":"","allowsPrepopulate":true,"defaultValue":"","description":"","content":"","cssClass":"","errorMessage":"","id":16,"inputName":"saved","isRequired":false,"label":"Hidden Field","noDuplicates":"","size":"medium","postCustomFieldName":"","displayAllCategories":false,"displayCaption":"","displayDescription":"","displayTitle":"","inputType":"","rangeMin":"","rangeMax":"","calendarIconUrl":"","dateFormat":"","phoneFormat":"","defaultCountry":"","defaultProvince":"","defaultState":"","hideAddress2":"","hideCountry":"","hideState":"","inputs":"","nameFormat":"","allowedExtensions":"","captchaType":"","captchaTheme":"","simpleCaptchaSize":"","simpleCaptchaFontColor":"","simpleCaptchaBackgroundColor":"","failed_validation":"","productField":"","enablePasswordInput":"","maxLength":"","ena
@alpha1
alpha1 / new_gist_file_0
Last active August 9, 2026 01:09
To Do List for setting up a new domain
New Domain Setup
- Setup DNS for site
- Setup DNS for subdomains
- Setup DNS for email
- Setup DKIM
- Setup SPF
- Setup DMARC
- Complete google site verification
- Setup abuse@domain https://support.google.com/a/answer/33389
- Setup postmaster@domain https://support.google.com/a/answer/33389
@alpha1
alpha1 / new_gist_file.mysql
Created December 12, 2014 03:47
MYSQL: Get Counts for each unique value in a single column in a single tablet
SELECT `Column1`,`Column2`,COUNT(*) as count FROM `TABLE` GROUP BY `COLUMN1` ORDER BY `X` ASC, `count` DESC