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 / location-categories.php
Last active August 29, 2015 14:23
Enable Categories for the Location Post Type (Simple Locator)
<?php
/**
* Enable Categories for the Location Post Type
*/
function enable_categories_in_locations()
{
register_taxonomy_for_object_type('category', 'location');
}
add_action( 'init', 'enable_categories_in_locations' );
@kylephillips
kylephillips / simple-locator-post-column-filters.php
Last active February 22, 2016 20:30
Create a sortable state column with state dropdown using simple locator data.
/**
* Set the Location Columns
* @param array $columns
*/
function locationColumns($columns)
{
$columns['wpsl_state'] = 'State';
return $columns;
}
add_filter('manage_edit-location_columns', 'locationColumns');
@kylephillips
kylephillips / simple-locator-categories.php
Created March 7, 2016 15:26
Include category filters in location search forms.
/**
* To Enable Category filtering for the location post type
* 1) Register categories for the post type
* 2) Include "category" in the "taxonomies" shortcode option
*/
function add_categories_to_locations()
{
register_taxonomy_for_object_type( 'category', 'property' );
}
add_action( 'init', 'add_categories_to_locations' );
add_filter('simple_locator_result', 'location_result', 10, 3);
/**
* Filter the individual results in the list
* @param string $output – HTML to return
* @param object $result - SQL result. If custom fields have been added to the query using the JOIN filter, they will be available
* @param int $count - current result count
*/
function location_result($output, $result, $count)
{
$out = '<li>';
add_filter('the_title', 'filterNestedPagesTitles', 10, 3);
function filterNestedPagesTitles($title, $post_id, $view = false)
{
if ( !is_admin() ) return $title;
$screen = get_current_screen();
if ( $screen->base != 'toplevel_page_nestedpages' ) return $title;
if ( !isset($view) || $view != 'nestedpages_title' ) return $title;
// Code to configure custom title here
$title = 'Custom Title';
return $title;
@kylephillips
kylephillips / simple-locator-infowindow-filter.php
Last active November 16, 2016 17:31
Filter the output of Simple Locator infowindows
add_filter('simple_locator_infowindow', 'location_infowindow', 10, 3);
/**
* Returns the infowindow HTML content
* @param string $infowindow – the html content
* @param obj $result - the result object
* @param int $count - the current result count
* @return string $infowindow
*/
function location_infowindow($infowindow, $result, $count)
@kylephillips
kylephillips / favorites-post-table.php
Created September 2, 2015 19:11
Add favorite counts to the WP admin post tables
<?php
// Place this code in your theme's functions.php file
/**
* First, add the column to the view
* Change the post type by substituting 'post' with the post type
* Ex: a post type of recipe would be manage_recipe_posts_columns
*/
add_filter('manage_post_posts_columns', 'add_favorite_count_column');
@kylephillips
kylephillips / favorites-button-styling.php
Created September 19, 2015 03:03
Add custom styling to the favorites button
<?php
/**
* Styling should ideally be placed in your theme's style.css file.
* If you are not comfortable editing this file, or with CSS, the following
* may be placed in your theme's functions.php
**/
add_action('wp_head', 'style_favorites_button');
function style_favorites_button()
{
echo '
@kylephillips
kylephillips / favorites-open-new-window.js
Created June 28, 2017 13:10
Open a new window after a user has favorited an item (Favorites for WordPress)
$(document).on('favorites-updated-single', function(event, favorites, post_id, site_id, status){
if ( status === 'inactive' ) return;
window.open("http://yourfavoriteurl.com", '_blank');
});
@kylephillips
kylephillips / nested-pages-gutenberg-edit-link.php
Last active March 23, 2018 13:50
Point the "edit" links in Nested Pages to the Gutenberg editor if installed.