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 / nested-pages-row-action-filters.php
Created January 11, 2019 22:02
Nested Pages Row Action Filters
<?php
/**
* For a list of all actions, see wp-nested-pages/app/Entities/PostType/PostTypeRepository, line 97
*/
// Hide/Show the "WPML" link if installed
add_filter('nestedpages_row_action_wpml', 'nestedPagesWpmlLink', 10, 2);
function nestedPagesWpmlLink($include, $post_type)
{
return true;
@kylephillips
kylephillips / nested-pages-hide-add-multiple.php
Created June 27, 2018 14:02
Hide the "Add Multiple" buttons from non-administrators in Nested Pages
/**
* Place in your theme's functions.php
*/
add_action('admin_head', 'hide_nested_pages_add_multiple');
function hide_nested_pages_add_multiple()
{
$user = wp_get_current_user();
$allowed_roles = ['administrator'];
if ( array_intersect($allowed_roles, $user->roles) ) return;
echo '<style>.open-bulk-modal, .nestedpages .action-buttons .nestedpages-dropdown ul li a.add-new-child, .nestedpages .action-buttons .nestedpages-dropdown ul li:nth-child(2) {display:none;}</style>';
@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.
@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 / 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;
}
@kylephillips
kylephillips / favorites-updated-single-event.js
Created June 13, 2017 15:59
Using the "Updated Single" event in Favorites
/**
* favorites-updated-single
* Fires after a favorite button has been submitted successfully
* @param favorites - Array of post objects the user has favorited
* @param post_id - The post ID that was updated
* @param site_id - The site ID for the post that was updated (for multisite)
* @param status - Whether the button was active or inactive
*/
$(document).on('favorites-updated-single', function(event, favorites, post_id, site_id, status){
// Do stuff here as needed.
@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 / 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)
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-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' );