Created
May 11, 2021 10:03
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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