Skip to content

Instantly share code, notes, and snippets.

@altuno
Created March 19, 2020 12:06
Show Gist options
  • Save altuno/ee701858b6951f5163d453b5ac9f0847 to your computer and use it in GitHub Desktop.
Save altuno/ee701858b6951f5163d453b5ac9f0847 to your computer and use it in GitHub Desktop.
EE4 Add Author filter to Events view
//* EE4 Add User Filter Event View
add_action('admin_head','woocommerce_js');
function woocommerce_js()
{
echo '<style>
.authors_custom {
display:none;
}
</style>';
global $post_type;
if($_REQUEST['page'] == 'espresso_events' || $_REQUEST['EVT_wp_user'] != ""){
//get a listing of all users that are 'author' or above
$user_args = array(
'show_option_none'=>'All Users',
//'option_none_value'=>-1,
//'show_option_all' => 'All Users',
//'selected' => -1,
'orderby' => 'display_name',
'order' => 'ASC',
//'name' => 'aurthor_admin_filter',
'name' => 'EVT_wp_user',
'who' => 'authors',
'class' => 'authors_custom',
'include_selected' => true
);
if(isset($_GET['EVT_wp_user'])){
//set the selected value to the value of the author
$user_args['selected'] = (int)sanitize_text_field($_GET['EVT_wp_user']);
}
wp_dropdown_users($user_args);
if(!isset($_REQUEST['action']) || ($_REQUEST['action'] == -1 || $_REQUEST['action'] == "default" )){
?>
<script>
jQuery(document).ready(function($) {
jQuery("#EVT_CAT").after(jQuery("#EVT_wp_user").append() );
jQuery("#EVT_CAT").after("<input type='hidden' id='hiddenuser' value='<?php echo (isset($_REQUEST['hiddenuser']) &&$_REQUEST['hiddenuser'] != "-1")?$_REQUEST['hiddenuser']:"-1"; ?>' name='hiddenuser'>" );
jQuery(".authors_custom").css("display","inline-block");
jQuery( "#EVT_wp_user" ).change(function() {
if(jQuery(this).val() != "-1"){
jQuery("#hiddenuser").val(jQuery(this).val());
}else{
jQuery("#hiddenuser").val(jQuery(this).val());
}
});
jQuery("#post-query-submit").click(function(){
//alert(jQuery("#hiddenuser").val());
if(jQuery("#hiddenuser").val() == "-1"){
<?php //if($_REQUEST['EVT_wp_user'] != "-1"){ ?>
//jQuery( "#EVT_wp_user" ).attr("name","EVT_wp_user");
<?php //}else{?>
jQuery( "#EVT_wp_user" ).attr("name","EVT_wp_user1");
<?php// }?>
}else{
jQuery( "#EVT_wp_user" ).attr("name","EVT_wp_user");
}
});
//
});
</script>
<?php }}
}
function content( $limit = 50 ) {
global $post;
if( has_excerpt() ){
$content = the_excerpt();
} else {
$content = explode( ' ', get_the_content(), $limit );
if ( count($content) >= $limit ) {
array_pop( $content );
$content = implode( " ", $content );
$content = wp_strip_all_tags( $content, true );
$content = $content . '...';
} else {
$content = implode( " ", $content );
}
$content = preg_replace( '/\[.+\]/','', $content );
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]&gt;', $content );
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment