Skip to content

Instantly share code, notes, and snippets.

@mustardBees
Created May 11, 2021 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustardBees/7624ace9a973d031c830479ceec2f9c8 to your computer and use it in GitHub Desktop.
Save mustardBees/7624ace9a973d031c830479ceec2f9c8 to your computer and use it in GitHub Desktop.
Filter Jetpack widget visibility page list - include all pages, not just those which are published.
<?php
/**
* Filter Jetpack widget visibility page list - include all pages, not just those which are published.
*
* @param stdClass[] $pages Array of objects containing only the ID, post_parent, and post_title fields.
* @param array $parsed_args Array of get_pages() arguments.
*/
function iweb_jetpack_widget_visibility_get_pages( $pages, $parsed_args ) {
global $wpdb;
$last_changed = wp_cache_get_last_changed( 'posts' );
$cache_key = "iweb_get_pages:$last_changed";
$pages = wp_cache_get( $cache_key, 'widget_conditions' );
if ( false === $pages ) {
$pages = $wpdb->get_results( "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_parent, {$wpdb->posts}.post_title FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_type = 'page' AND ({$wpdb->posts}.post_status = 'publish' OR technics_posts.post_status = 'future' OR technics_posts.post_status = 'draft' OR technics_posts.post_status = 'pending' OR technics_posts.post_status = 'private') ORDER BY {$wpdb->posts}.post_title ASC" );
wp_cache_set( $cache_key, $pages, 'widget_conditions' );
}
return $pages;
}
add_filter( 'jetpack_widget_visibility_get_pages', 'iweb_jetpack_widget_visibility_get_pages', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment