Skip to content

Instantly share code, notes, and snippets.

View kylephillips's full-sized avatar

Kyle Phillips kylephillips

  • Atlanta, Georgia
View GitHub Profile
<?php
// Place this in functions.php
add_filter('nestedpages_default_submenu_text', 'defaultPagesText', 10, 2);
function defaultPagesText($text, $post_type)
{
return ( $post_type->name == 'page' ) ? 'WordPress Pages' : $text;
}
@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 / favorites-display.php
Last active October 14, 2022 19:33
Using the Favorites get_user_favorites() function to display favorited post data in a custom format
<?php
// Method 1: simple foreach loop
$favorites = get_user_favorites();
if ( isset($favorites) && !empty($favorites) ) :
foreach ( $favorites as $favorite ) :
// You'll have access to the post ID in this foreach loop, so you can use WP functions like get_the_title($favorite);
endforeach;
endif;
@kylephillips
kylephillips / block-animations-allowed-blocks-filter.js
Created June 21, 2022 21:09
Apply a JS filter to the allowed blocks in wp-block-animations plugin
/**
* In this example, we're adding a custom "acf/carousel" block to the array of supported block types for block animations
* We've added this JS file to the script dependencies required by the plugin, using the wp_block_animations_script_dependencies hook.
* Additionally, when enqueueing this file, we've added `wp-hooks` as a dependency to ensure the global object is available
*/
wp.hooks.addFilter(
'wp_block_animations_allowed_blocks',
'allowed_blocks',
addCustomBlockAnimations
<?php
add_filter('wp_block_animations_script_dependencies', 'blockAnimationDependencies);
/**
* We are adding our custom script containing our addFilter reference to the plugin dependencies.
* This way, we ensure the plugin scripts run after we add our filter
*/
function blockAnimationDependencies($deps)
{
$deps[] = 'custom-script-handle';
@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.
<?php
add_filter('nestedpages_row_parent_css_classes', 'nestedpages_filter_row_css_classes', 10, 3);
/**
* Filter the <li> element css classes for nested pages rows
* @param str - $row_classes - the CSS classes for output
* @param obj - $post - the current post object
* @param obj - $post_type_object - the current post type object
*/
function nestedpages_filter_row_css_classes($row_classes, $post, $post_type_object)
{
@kylephillips
kylephillips / favorites-user-list-filter.php
Created August 15, 2015 03:31
Example of using the User List filter in the Favorites WordPress plugin
add_filter('simplefavorites_user_list', 'filter_favorites_user_list', 10, 3);
function filter_favorites_user_list($output, $users, $anonymous_count)
{
$output = '<ul>';
foreach($users as $user){
$output .= '<li><a href="' . site_url() . '/members/' . $user->user_login . '">' . $user->display_name . '</a></li>';
}
$output .= '</ul>';
$output .= '(+' . $anonymous_count . ' Anonymous Users)';
return $output;
@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>';