| 306 | * Add custom views to the attendee listing post listing. |
| 307 | */ |
| 308 | public function add_custom_filters( $views ) { |
| 309 | global $wpdb; |
| 310 | if ( 'tix_attendee' != $GLOBALS['typenow'] || ! $this->flags ) { |
| 311 | return $views; |
| 312 | } |
| 313 | |
| 314 | $meta_counts = $wpdb->get_results( "SELECT meta_value, COUNT(post_id) AS count FROM {$wpdb->postmeta} WHERE meta_key = 'camptix-admin-flag' GROUP BY meta_value", ARRAY_A ); |
| 315 | $meta_counts = wp_list_pluck( $meta_counts, 'count', 'meta_value' ); |
| 316 | if ( ! $meta_counts ) { |
| 317 | return $views; |
| 318 | } |
| 319 | |
| 320 | $currently_viewed_flag = !empty( $_GET['camptix_flag'] ) ? wp_unslash( $_GET['camptix_flag'] ) : false; |
| 321 | |
| 322 | $base_url = add_query_arg( 'post_type', 'tix_attendee', 'edit.php' ); |
| 323 | |
| 324 | foreach ( $this->flags as $flag => $label ) { |
| 325 | $url = add_query_arg( 'camptix_flag', $flag, $base_url ); |
| 326 | |
| 327 | $class_html = ''; |
| 328 | if ( $currently_viewed_flag && $currently_viewed_flag == $flag ) { |
| 329 | $class_html = ' class="current"'; |
| 330 | } |
| 331 | |
| 332 | $count = 0; |
| 333 | if ( isset( $meta_counts[ $flag ] ) ) { |
| 334 | $count = $meta_counts[ $flag ]; |
| 335 | } |
| 336 | |
| 337 | $views[ $flag ] = sprintf( |
| 338 | '<a href="%s"%s>%s <span class="count">(%s)</span></a>', |
| 339 | esc_url( $url ), |
| 340 | $class_html, |
| 341 | $label, |
| 342 | number_format_i18n( $count ) |
| 343 | ); |
| 344 | |
| 345 | } |
| 346 | |
| 347 | return $views; |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Filter the wp-admin post listing query to filter to admin flags. |
| 352 | */ |
| 353 | public function add_custom_filters_post_filter( $query ) { |
| 354 | if ( ! is_admin() || 'tix_attendee' != $GLOBALS['typenow'] ) { |
| 355 | return $query; |
| 356 | } |
| 357 | |
| 358 | $flag = !empty( $_GET['camptix_flag'] ) ? wp_unslash( $_GET['camptix_flag'] ) : false; |
| 359 | if ( ! isset( $this->flags[ $flag ] ) ) { |
| 360 | $flag = false; |
| 361 | } |
| 362 | |
| 363 | if ( $flag ) { |
| 364 | if ( ! isset( $query->query_vars['meta_query'] ) ) { |
| 365 | $query->query_vars['meta_query'] = array(); |
| 366 | } |
| 367 | |
| 368 | $query->query_vars['meta_query'][] = array( |
| 369 | 'key' => 'camptix-admin-flag', |
| 370 | 'value' => $flag, |
| 371 | 'compare' => '=', |
| 372 | 'type' => 'CHAR', |
| 373 | ); |
| 374 | } |
| 375 | |
| 376 | return $query; |
| 377 | } |
| 378 | |
| 379 | /** |