Created
December 9, 2014 23:45
-
-
Save jwenerd/9cde899deacc86022dfc to your computer and use it in GitHub Desktop.
The following PHP is a plugin that shows all categories (including non-empty categories) in the Jetpack Widget Visibility dropdown. It typically hides empty by default...
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 | |
if( ! defined('ABSPATH') ) { | |
exit; | |
} | |
// inlcude this seperately from the other jetpack fixes | |
// because of widget visiability being loaded independently | |
// of actual jetpack | |
if ( defined('DOING_AJAX') && DOING_AJAX | |
&& ! empty( $_REQUEST['action'] ) | |
&& ( $_REQUEST['action'] == 'widget_conditions_options' || $_REQUEST['action'] == 'save-widget') ) { | |
add_action( 'wp_ajax_widget_conditions_options' , 'psu_jetpack_widget_conditions_add_filter' , 5 ); | |
if ( is_array( $_REQUEST['conditions']['rules_major'] ) ) { | |
add_action( 'widget_conditions_save' , 'psu_jetpack_widget_conditions_add_filter' , 5 ); | |
} | |
} | |
else if ( is_admin() && $_SERVER['SCRIPT_NAME'] == '/wp-admin/widgets.php' ) { | |
add_action( 'in_widget_form', 'psu_jetpack_widget_conditions_in_widget_form', 5 , 3 ); | |
} | |
// hook this early to add our thing | |
function psu_jetpack_widget_conditions_add_filter() { | |
add_filter( 'get_terms_args', 'psu_jetpack_widget_conditions_show_empty_terms', 10 , 2 ); | |
} | |
function psu_jetpack_widget_conditions_in_widget_form( $widget, $return, $instance ) { | |
$conditions = array(); | |
if ( ! isset( $instance['conditions'] ) ) | |
return; | |
if ( ! is_array( $instance['conditions']['rules'] ) ) | |
return; | |
foreach( $instance['conditions']['rules'] as $rule ) { | |
if( $rule['major'] == 'category' ) { | |
psu_jetpack_widget_conditions_add_filter(); | |
break; | |
} | |
} | |
} | |
function psu_jetpack_widget_conditions_show_empty_terms( $args, $taxonomies ) { | |
if ( $args['taxonomy'] == 'category' ) { | |
$args['hide_empty'] = false; | |
remove_filter( 'get_terms_args', 'psu_jetpack_widget_conditions_show_empty_terms', 10); | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment