Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
BronsonQuick / featured_custom_post_type_widget.php
Created March 5, 2012 04:00
A widget to display a Featured Custom Post Type in WordPress
<?php
/*
Plugin Name: Featured Custom Post Type Widget
Plugin URI: http://www.sennza.com.au
Description: Lists out all the custom post type posts in a dropdown so the user can selected a CPT to feature.
Version: 1.0
Author: Bronson Quick
Author URI: http://www.sennza.com.au
License: GPL2
@BronsonQuick
BronsonQuick / functions.php
Created March 26, 2012 05:59
Add a Gravity Forms validation filter to check default values
<?php
// Append the Gravity Forms ID to the end of the filter so that the validation only runs on this form
add_filter('gform_validation_1', 'custom_validation');
function custom_validation($validation_result){
$form = $validation_result["form"];
foreach($form['fields'] as &$field){
/* Check that the value of the field that was submitted. e.g. the name="input_1" that is generated by Gravity Forms */
if($_POST['input_1'] == "Your First Name"){
// set the form validation to false
$validation_result["is_valid"] = false;
@BronsonQuick
BronsonQuick / slider_custom_post_type.php
Created April 2, 2012 03:18
The backend for a Slider Custom Post Type which uses extra meta boxes and a wp_editor API for one of those boxes
<?php
/*
Plugin Name: Learning Seat Homepage Slider Custom Post Type
Plugin URI: http://www.sennza.com.au
Description: Custom Post Type to populate slider on the homepage
Version: 1.0
Author: Bronson Quick
Author URI: http://www.sennza.com.au
License: GPL2
*/
@BronsonQuick
BronsonQuick / fix_empty_paragraphs.php
Created April 6, 2012 10:30
Fix empty paragraphs around shortcodes
<?php add_filter('the_content', 'shortcode_empty_paragraph_fix');
// Shortcodes
function shortcode_empty_paragraph_fix($content)
{
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
@BronsonQuick
BronsonQuick / gravity_forms_validation.php
Created April 12, 2012 09:51
Change the default validation message and add validation on default values in Gravity Forms
<?php
//This is a filter to change the default validation message that Gravity Forms generates
add_filter('gform_validation_message', 'change_validation_message', 10, 2);
function change_validation_message($message, $form)
{
return "<div class='validation_error'><strong>Oops!</strong> Looks like there’s something wrong. Please review the form above.</div>";
}
// Often forms in Gravity Forms to need to start with default values and we need to check the form in case the user hasn't entered new data and give them a validation message back
@BronsonQuick
BronsonQuick / tagline_meta_box.php
Created April 17, 2012 03:10
Adds an extra metabox on WordPress pages to allow a page to have a tagline
<?php
function debthelpline_add_meta_boxes(){
// Add the Subheading meta box
add_meta_box( 'debthelpline_banner_subheading', __( 'Banner Subheading', 'debthelpline' ), 'debthelpline_subheading_meta_box', 'page', 'normal', 'high' );
}
add_action( 'add_meta_boxes', 'debthelpline_add_meta_boxes' );
function debthelpline_subheading_meta_box( $post ) {
@BronsonQuick
BronsonQuick / page_excerpts.php
Created April 28, 2012 04:42
Add Excerpts to Pages in WordPress
<?php
/* Quite often we create sites that need a blurb on the homepage that needs to be different than the page content.
To get around this we like adding excerpts to pages */
add_post_type_support( 'page', 'excerpt' );
?>
@BronsonQuick
BronsonQuick / link_inside_archive_and_category_widget.php
Created May 14, 2012 06:45
Move the posts count inside the link of the Archive and Category widgets of WordPress
@BronsonQuick
BronsonQuick / wordpress_menu_name.php
Created May 16, 2012 01:35
Output the menu name in WordPress
<?php
/* This function returns the menu name */
function wp_nav_menu_title( $theme_location ) {
$title = '';
if ( $theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
if( $menu && $menu->name ) {
$title = $menu->name;
}
@BronsonQuick
BronsonQuick / populate_gravity_forms_pre_submission.php
Created May 30, 2012 06:39
Populate a hidden field in Gravity Forms before submission
<?php
/* gform_pre_submission will do all forms. gform_pre_submission_1 will do a form with an ID of 1
* Keep an eye on the priority of the filter. In this case I used 9 because the Salesforce plugin we used ran a presubmission filter at 10 so we needed this to happen before it
*/
add_filter( "gform_pre_submission_1", "add_salesforce_campaign_id_footer", 9 );
function add_salesforce_campaign_id_footer( $form ){
foreach($form["fields"] as &$field)
if($field["id"] == 2){
/* Set the variable you want here - in some cases you might need a switch based on the page ID.
* $page_id = get_the_ID();