Skip to content

Instantly share code, notes, and snippets.

View philipdowner's full-sized avatar

Philip Downer philipdowner

View GitHub Profile
@philipdowner
philipdowner / wp-team-post-save-link-user.php
Last active April 2, 2018 16:07 — forked from chaance/wp-team-post-save-link-user.php
Function to dynamically sync CPT team posts with WP users. The post type requires custom meta fields for linked_author (user ID) and email.
<?php
/**
* Create new users to match team members.
*
* @param integer $post_id Post ID.
*/
function xx_team_post_save_link_user( $post_id ) {
$user_email = get_post_meta( $post_id, 'email', true );
$author_id = (int)get_post_meta( $post_id, 'linked_author', true );
@philipdowner
philipdowner / Contract Killer 3.md
Last active September 21, 2017 02:08
The latest version of my ‘killer contract’ for web designers and developers

Between [company name]

And [customer name].

Summary:

We’ll always do our best to fulfill your needs and meet your expectations, but it’s important to have things written down so that we both know what’s what, who should do what and when, and what will happen if something goes wrong. In this contract you won’t find any complicated legal terms or long passages of unreadable text. We’ve no desire to trick you into signing something that you might later regret. What we do want is what’s best for both parties, now and in the future.

So in short;

@philipdowner
philipdowner / gravityforms-all-fields.json
Created November 13, 2015 05:20
Export of all Gravity Forms field types for styling and development
{
"0": {
"title": "Gravity Forms - All Fields",
"description": "This is the optional form description. Here you can offer a bit of motivation on why the user should fill out and submit your form. The following form shows the list of advanced fields available through the Gravity Forms plugin that will be available on your site.\r\n\r\nForms are incredibly customizable, and all entries can be e-mailed to a specified address and are also saved in your site\u2019s database.",
"labelPlacement": "top_label",
"descriptionPlacement": "below",
"button": {
"type": "text",
"text": "Submit",
"imageUrl": ""
@philipdowner
philipdowner / update-subscription.php
Created May 6, 2015 14:48
Allow WordPress user to update category subscriptions
<?php
/**
* Allow users to save categories they wish to subscribe to
*/
//First make sure the user is logged in
if( !is_user_logged_in() || !current_user_can('read_posts') ) { //You can change the capability from 'read_posts' if needed
echo '<div class="loginForm">';
@philipdowner
philipdowner / permissions-metabox.php
Created February 7, 2015 14:51
Quick example of adding a meta box to WordPress based on user permissions
<?php
// This is the important part. You only add the meta box if the user has the required capability(ies).
// http://codex.wordpress.org/Roles_and_Capabilities
//
// You could add additional checks to ensure the meta box is only displayed on certain pages.
if( current_user_can('my_custom_capability') ) { //Change the capability depending on your user permissions
add_action('add_meta_boxes_page', 'my_callback_function');
}
/**
@philipdowner
philipdowner / zf_compare.php
Created April 23, 2013 19:03
Troubleshooting Zebra_Form with password comparison
<?php
function ne_explorer_signup_form() {
//ZF Library
require_once(INCLUDES_DIR.'/lib/zebra_form/Zebra_Form.php');
$form = new Zebra_Form('explorer-signup', 'POST');
$form->add('label', 'label_firstname', 'explorer_firstname', 'Your name');
$field = $form->add('text', 'explorer_firstname');
$field->set_rule(array(
'required' => array('error', 'Name is required'),
@philipdowner
philipdowner / jdp-attachment-fields.php
Created August 8, 2012 16:45
Allow selection of a post type on media attachments in WordPress
<?php
/**
* Add Photographer selection to media upload
*
* @param $form_fields array, fields to include in attachment form
* @param $post object, attachment record in database
* @return $form_fields, modified form fields
*/
function bsj_attachment_field_credit( $form_fields, $post ) {
//do_dump($post);
@philipdowner
philipdowner / gist:2937316
Created June 15, 2012 16:10
USGS Plugin Example Usage
<?php
$rivers_desired = array('jefferson', 'madison', 'bighole', 'beaverhead', 'ruby'); //Create an array of desired rivers
$rivers = usgs_fetch_sites($rivers_desired); //Fetch a list of site identifiers
$dataparameters = usgs_fetch_dataParameters(); //The codes for the measurements you're interested in
$river_data = usgs_fetch_riverData($rivers,$dataparameters); //Make the call to the USGS server
echo usgs_display_RiverData($river_data, 'true'); //Display each river's data along with a Google map
?>
@philipdowner
philipdowner / gist:1535047
Created December 29, 2011 17:16
Hidden text with background image
<style type="text/css">
body.about h1 { /*Let's presume your banner title is an h1 element */
width: 150px; /* Set this to the width of your image */
height: 75px; /* Set this to the height of your image */
background: transparent url('my-image.png') no-repeat top left; /* Change the URL to point to your image */
text-indent: -9999em; /* This ensures that the text itself will not show. */
}
</style>
<html>
@philipdowner
philipdowner / gist:1535015
Created December 29, 2011 17:08
WordPress If/Else
<?php
if ( is_page('my-page-slug') ) {
echo '<img src="'.get_bloginfo('template_url').'/path/to/img.png">';
} else {
get_the_title(); //Or similar code from the template
}
?>