Skip to content

Instantly share code, notes, and snippets.

View aliciaduffy's full-sized avatar

Alicia Duffy aliciaduffy

View GitHub Profile
add_action( 'admin_init', 'do_something_152677' );
function do_something_152677 () {
// Global object containing current admin page
global $pagenow;
if ( 'edit.php' === $pagenow && ) && ( isset($_GET['post_type']) && 'heroes' == $_GET['post_type'] ) ) )
// update vote counts postmeta
}
}
$taxonomy = get_term( $category_id )->taxonomy;
// get all post IDs within selected category
$posts_in_category = new WP_Query( array(
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'terms' => $category_id,
),
.en__field--1895 .en__field__element--checkbox input {
margin-right: 5px !important;
float: left;
}
.en__field--1895 .en__field__element--checkbox label {
display: block;
margin: -3px 0 0;
overflow: hidden;
}
@aliciaduffy
aliciaduffy / gist:ee9ad71ca79f5b4cb5593c41576e094f
Last active May 1, 2017 13:30
Gravity Forms Pre-Submission age check and redirect
<?php
// update form id # (2)
add_action( 'gform_validation_2', 'custom_validate_not_too_old_pre_save' );
function validate_old_enough_pre_save( $validation_result ) {
$birth_date = $_POST["input_16"];
$birth_date = strtotime( $birth_date[0] . '/' . $birth_date[1] . '/' . $birth_date[2] );
// user is under 13
@aliciaduffy
aliciaduffy / gist:4aeed943a4f0ac06e3cc
Created March 21, 2016 19:02
GA Events Gravity Forms Example
$(document).on('gform_confirmation_loaded', function(){
if ( window.location.pathname == '/' ){
sendEvent( petaGA_FormCategory_eNews, petaGA_FormAction_Submitted, 'Subscribe to E-News: Front Page');
} else {
sendEvent( petaGA_FormCategory_eNews, petaGA_FormAction_Submitted, 'Subscribe to E-News: Interior Page');
}
});
$old_credits = array();
$old_credits[] = get_metadata('post', 275142, '_media_credit', true);
$old_credits[] = get_metadata('post', 275142, '_media_credit_2', true);
$old_credits[] = get_metadata('post', 275142, '_media_credit_3', true);
if ( $old_credits ) {
$number = 0;
$number_credits = count($old_credits);
add_metadata( 'post', 275142, 'media_credit', $number_credits );
add_metadata( 'post', 275142, '_media_credit', 'field_548e1e18a4b85' );
@aliciaduffy
aliciaduffy / gist:32191674fa96400fe995
Last active August 29, 2015 14:15
Comment count check
<a name="respond"><span style="display: none;">Respond</span></a>
<div id="peta_comments">
<?php
// Get comment count
$comment_count = wp_count_comments( get_the_ID() );
// If there are comments, display note and comments
if ( $comment_count->approved > 0 ) { ?>
<h6>Commenting is closed.</h6>
<div class="clear"></div>
@aliciaduffy
aliciaduffy / gist:13179f2b3def3c9cf236
Created December 2, 2014 20:22
responsive email columns
mobile CSS:
@media only screen and (max-width: 480px) {
table[id=footer] table {
margin: 0 auto 0;
width: 100% !important;
}
}
@aliciaduffy
aliciaduffy / gist:7a8c88058e1b93d9566b
Created November 19, 2014 18:05
Add media credit below images in content
function filter_images($content){
$original_content = $content;
$inlineImages = array();
// Find all images with an ID in content
preg_match_all( '/wp-image-([^"]*)/i', $content, $inlineImages );
if ($inlineImages) {
// For each image build the credit and add to content
foreach ($inlineImages[1] as $attachment_id) {
@aliciaduffy
aliciaduffy / index.html
Last active August 29, 2015 14:06
Inline SVG Ratio Fix for Safari and Android webkit
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<title>SVG Test Safari No Worky</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
<div class="wrapper">