Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
leepettijohn / functions.php
Last active June 11, 2019 16:34
Gravity Forms - Dropdown populated with posts
// https://docs.gravityforms.com/dynamically-populating-drop-down-fields/
/* Instructions
- Create a form
- Add a "Dropdown" field
- Add "populate-posts" as the CSS class
*/
add_filter( 'gform_pre_render_51', 'populate_posts' );
add_filter( 'gform_pre_validation_51', 'populate_posts' );
@leepettijohn
leepettijohn / functions.php
Created May 19, 2018 20:09
Add Widget Area to Non-Genesis Theme
/*** add widget area *** */
register_sidebar( array(
'name' => __( 'New Widget Area'),
'id' => 'new-widget-area',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>'
));
@leepettijohn
leepettijohn / functions.php
Last active March 19, 2020 16:37
Gravity Forms - dynamically populate fields
<?php
/* *** replace "your_parameter" with the parameter in the advanced tab
https://docs.gravityforms.com/using-dynamic-population/ */
add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
return 'boom!';
}
/*Use this for a real estate form */
@leepettijohn
leepettijohn / custom-button-class.php
Created March 30, 2018 12:33
Add button to tinyMCE editor
<?php
/**
* Plugin Name: TinyMCE Custom Link Class
* Plugin URI: http://wpbeginner.com
* Version: 1.0
* Author: WPBeginner
* Author URI: http://www.wpbeginner.com
* Resource: http://www.wpbeginner.com/wp-tutorials/how-to-create-a-wordpress-tinymce-plugin/
* Description: A simple TinyMCE Plugin to add a custom link class in the Visual Editor
* License: GPL2
@leepettijohn
leepettijohn / functions.php
Created January 9, 2018 16:43
Create a zip folder from media
<?
function create_zip_file(){
$zip = new ZipArchive();
$filename = "test114.zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
$zip->addFile($_SERVER['DOCUMENT_ROOT']."/wp-content/uploads/2018/01/Bus-Card-ABC-Domestic-Live-Kelly-Ryan.jpg");
$zip->close();
}
@leepettijohn
leepettijohn / loop.php
Created December 6, 2017 13:00
WordPress custom toggle on Archive Loop
<?php
/* *** add the below code to the page where all the information that should be displayed in the Loop */
/* *** this is the link to click */ ?>
<a class="more-info-link <?php tribe_events_event_classes() ?>" style="cursor:pointer">More Info</a>
<? /* *** this is the box that holds more info */ ?>
<div class="more-info <?php tribe_events_event_classes() ?>" style="display:none;">
<? /* *** This is where all the info goes that should be in the hidden box */ ?>
</div>
@leepettijohn
leepettijohn / functions.php
Created September 25, 2017 20:29
Gravity Forms - Limit checkbox choices after chosen
<?
// Change 'XXX' to your form id
$location_form_id = XXX;
add_filter( 'gform_pre_render_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_pre_validation_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_pre_submission_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_pre_submission_filter_'.$location_form_id, 'limit_choices' );
add_filter( 'gform_admin_pre_render_'.$location_form_id, 'limit_choices' );
function limit_choices( $form ) {
@leepettijohn
leepettijohn / query.php
Created August 28, 2017 17:16
Basic Loop
<?php /**
* The WordPress Query class.
* @link http://codex.wordpress.org/Function_Reference/WP_Query
*
*/
$args = array(
//Post & Page Parameters
'p' => 1,
'name' => 'hello-world',
@leepettijohn
leepettijohn / functions.php
Created July 28, 2017 18:10
Gravity Forms - File / Image Upload to Featured Image
<?php
form_id = 1;
add_action("gform_post_submission_".$form_id, "add_new_post_featured_image");
function add_new_post_featured_image($entry){
$title_id = 1;
$content_id = 2;
$file_id = 3;
$new_post = array(
'post_title' => $entry[$title_id],
@leepettijohn
leepettijohn / functions.php
Created July 28, 2017 18:02
Gravity Forms - Checkboxes to Updating Tags
<?
// see this gist for creating dynamic checkboxes - https://gist.github.com/leepettijohn/28499de95fae967845728ec0be7a43d0
$checktag = 1; //This should stay as 1
$beertag = 16; //This should be the field_id of the checkbox field
while (isset($entry["{$beertag}.{$checktag}"])){
if (!empty($entry["{$beertag}.{$checktag}"])){
wp_set_post_terms($new_beer_id,$entry["{$beertag}.{$checktag}"],'post_tag',true);
}
$checktag++;
if ($checktag % 10 == 0){