Skip to content

Instantly share code, notes, and snippets.

View kylephillips's full-sized avatar

Kyle Phillips kylephillips

  • Atlanta, Georgia
View GitHub Profile
@kylephillips
kylephillips / most-favorited.php
Last active July 27, 2020 03:11
Favorites for WordPress - Display the most favorited posts
<?php
/**
* Display a list of the 10 most favorited posts
* @see https://wordpress.org/plugins/favorites/
*/
$favorites_query = new WP_Query(array(
'post_type' => array('post'),
'posts_per_page' => 10,
'meta_key' => 'simplefavorites_count',
'orderby' => 'meta_value_num',
@kylephillips
kylephillips / simple-locator-dynamic-population.php
Created December 20, 2016 18:05
Populate and submit a simple locator form dynamically and automatically on page load, using a GET parameter
<?php
/**
* Using this method, a GET parameter can be passed to the page, enabling a simple locator form to be populated and submitted dynamically.
* One use case may exist where the user submits a gravity form, and is redirected to a list of locations without needing to resubmit the simple locator form.
* This code would be placed in a page template.
*/
// First, we check if a GET parameter named "search" exists. If so, we sanitize it and set it for our use
// This could be passed via a link, or through another form submission
$location_search = ( isset($_GET['search']) ) ? sanitize_text_field($_GET['search']) : false;
@kylephillips
kylephillips / favorites-logged-in.php
Created August 17, 2015 18:05
Show Favorites Button only for logged users
<?php
if ( is_user_logged_in() ) :
the_favorites_button();
else :
// Place any logged-out messaging/JS here
?>
<p>Please log in to save favorites</p>
<?php endif; ?>
@kylephillips
kylephillips / favorites-gravityform-notification.php
Last active June 18, 2020 16:04
Email a list of favorites using Gravity Forms
/**
* Allow a user to email a list of favorites
* Place in functions.php and update to suit your specific form and needs
* @link https://www.gravityhelp.com/documentation/article/gform_notification/
*/
add_filter( 'gform_notification_1', 'email_favorites_list', 10, 3 );
function email_favorites_list($notification, $form, $entry)
{
// Get the user's favorites and create a list
$favorites = get_user_favorites();
<?php
/**
* Filters radio choices to include the next 14 days
*
* Place in the theme's functions.php file
* @link https://docs.gravityforms.com/dynamically-populating-drop-down-fields/
*/
add_filter( 'gform_pre_render_1', 'populate_dates' );
add_filter( 'gform_pre_validation_1', 'populate_dates' );
add_filter( 'gform_pre_submission_filter_1', 'populate_dates' );
<?php
/**
* Filters radio choices to include the next 14 days
*
* Place in the theme's functions.php file
* @link https://docs.gravityforms.com/dynamically-populating-drop-down-fields/
*/
add_filter( 'gform_pre_render_1', 'populate_dates' );
add_filter( 'gform_pre_validation_1', 'populate_dates' );
add_filter( 'gform_pre_submission_filter_1', 'populate_dates' );
@kylephillips
kylephillips / nested-pages-query-filter.php
Created September 15, 2015 21:40
Apply a filter on the Nested Pages Query
<?php
/**
* Remove Posts from Being Displayed in the Nested Pages List
* @param $args - array of WP_Query arguments
* @see wp-nested-pages/app/Entities/Listing/Listing: Line 274
*/
add_filter('nestedpages_page_listing', 'remove_from_nested_pages');
function remove_from_nested_pages($args)
{
$remove_ids = array(); // Array of Post IDs to exclude
@kylephillips
kylephillips / gravityforms-replace-radio-choices-textarea.php
Created August 19, 2019 21:31
Replace input text elements in the Gravity Forms "choice" editor with textareas, form multi-line values
add_action( 'gform_editor_js', 'replaceInputsWithTextareas' );
function replaceInputsWithTextareas() {
?>
<script type='text/javascript'>
gform.addAction('gform_load_field_choices', function(field){
field = GetSelectedField();
replaceInputs(field.id)
});
jQuery(document).on('gform_load_field_settings', function(e,field){
setTimeout(function(){
add_filter('nestedpages_quickedit_custom_fields', addCustomPageFieldsLeft, 10, 3);
function addCustomPageFieldsLeft($fields, $post_type, $column)
{
if ( $column !== 'left' ) return $fields; // fields may be added to the left and right column
if ( $post_type->name !== 'post-type-name' ) return $fields; // add fields based on post type
$fields = [
[
'key' => 'field_name', // The meta key name
'label' => __('Custom Field', 'wp-nested-pages'), // The label for the field
'type' => 'date', // date|text|select
@kylephillips
kylephillips / favorites-button-css-filter.php
Last active July 9, 2019 14:06
Favorites for Wordpress: Using the button CSS filter
add_filter('favorites/button/css_classes', 'favoriteButtonCss', 10, 3);
function favoriteButtonCss($classes, $post_id, $site_id)
{
$classes .= ' my-custom-class';
return $classes;
}