true ) ); $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() ); foreach ( $post_types as $post_type ) { if ( !isset( $post_types_option[$post_type]['add_meta_box'] ) || $post_types_option[$post_type]['add_meta_box'] ) { if ( ( $post_type == 'attachment' ) ) { // filters to display the media's access restriction groups add_filter( 'manage_media_columns', array( __CLASS__, 'columns' ) ); // args: string $column_name, int $media_id add_action( 'manage_media_custom_column', array( __CLASS__, 'custom_column' ), 10, 2 ); // make the groups column sortable add_filter( 'manage_upload_sortable_columns', array( __CLASS__, 'manage_edit_post_sortable_columns' ) ); } else { // filters to display the posts' access restriction groups add_filter( 'manage_' . $post_type . '_posts_columns', array( __CLASS__, 'columns' ) ); // args: string $column_name, int $post_id add_action( 'manage_' . $post_type . '_posts_custom_column', array( __CLASS__, 'custom_column' ), 10, 2 ); // make the groups column sortable add_filter( 'manage_edit-' . $post_type . '_sortable_columns', array( __CLASS__, 'manage_edit_post_sortable_columns' ) ); } } } } } /** * Adds a new column to the post type's table showing the access * restriction groups. * * @param array $column_headers * @return array column headers */ public static function columns( $column_headers ) { $column_headers[self::GROUPS] = sprintf( '%s', esc_attr( __( 'One or more groups granting access to entries.', 'groups' ) ), esc_html( _x( 'Groups', 'Column header', 'groups' ) ) ); return $column_headers; } /** * Renders custom column content. * * @param string $column_name * @param int $post_id * @return string custom column content */ public static function custom_column( $column_name, $post_id ) { $output = ''; switch ( $column_name ) { case self::GROUPS : $entries = array(); $groups_read = get_post_meta( $post_id, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ ); if ( count( $groups_read ) > 0 ) { $groups = Groups_Group::get_groups( array( 'order_by' => 'name', 'order' => 'ASC', 'include' => $groups_read ) ); if ( ( count( $groups ) > 0 ) ) { foreach( $groups as $group ) { $entries[] = wp_strip_all_tags( $group->name ); } } } if ( function_exists( 'get_term_meta' ) && // >= WordPress 4.4 class_exists( 'Groups_Restrict_Categories' ) && method_exists( 'Groups_Restrict_Categories', 'get_controlled_taxonomies' ) && method_exists( 'Groups_Restrict_Categories', 'get_term_read_groups' ) // >= Groups Restrict Categories 2.0.0 ) { $taxonomies = Groups_Restrict_Categories::get_controlled_taxonomies(); if ( count( $taxonomies ) > 0 ) { $terms = wp_get_object_terms( $post_id, $taxonomies ); if ( !( $terms instanceof WP_Error ) ) { foreach( $terms as $term ) { if ( in_array( $term->taxonomy, $taxonomies ) ) { $term_group_ids = Groups_Restrict_Categories::get_term_read_groups( $term->term_id ); if ( count( $term_group_ids ) > 0 ) { if ( !empty( $term_group_ids ) ) { $edit_term_link = self::get_edit_term_link( $term->term_id, $term->taxonomy ); $taxonomy_label = ''; if ( $taxonomy = get_taxonomy( $term->taxonomy ) ) { $taxonomy_label = isset( $taxonomy->label ) ? __( $taxonomy->label ) : ''; $labels = isset( $taxonomy->labels ) ? $taxonomy->labels : null; if ( $labels !== null ) { if ( isset( $labels->singular_name ) ) { $taxonomy_label = __( $labels->singular_name ); } } } $term_taxonomy_title = !empty( $term->name ) ? $term->name : ''; $term_taxonomy_title.= !empty( $taxonomy_label ) ? ' ' . $taxonomy_label : ''; foreach( $term_group_ids as $group_id ) { if ( $group = Groups_Group::read( $group_id ) ) { $entries[] = sprintf( '%s %s', esc_html( $group->name ), esc_url( $edit_term_link ), esc_attr( $term_taxonomy_title), esc_html( $term->name ) ); } } } } } } } } } if ( !empty( $entries ) ) { sort( $entries ); $output .= '