itthinx / groups

Groups provides group-based user membership management, group-based capabilities and content access control. It integrates standard WordPress capabilities and application-specific capabilities along with an extensive API.
GNU General Public License v3.0
49 stars 35 forks source link

Add support for custom column in admin. #66

Open cjhaas opened 7 years ago

cjhaas commented 7 years ago

These changes allow custom columns to be displayed in the backend for groups using WordPress filters. To be clear, it doesn't add support to set these values, it just exposes filters for other plugins to add their own columns and value.

Usage:

//Add a new column that is not sortable
add_filter(
            'groups_admin_columns',
            function( $column_display_names )
            {
                return array_merge(
                                    $column_display_names,
                                    array(
                                            'test' => array( 'column_display_name' => 'Test' )
                                        )
                                );
            }
        );

//Render the custom column
add_filter(
            'groups_admin_columns_cell_html_contents_test',
            function( $cell_html_contents, $result )
            {
                return 'Custom test for group ' . $result->group_id;
            },
            10,
            2
        );

//Set the column's CSS classes
add_filter(
            'groups_admin_columns_cell_html_classes_test',
            function( $cell_html_classes, $result )
            {
                return array( 'test-column' );
            },
            10,
            2
        );

//Optionally change the cell's wrapper tag. No real good reason but consistent with other changes
add_filter(
            'groups_admin_columns_cell_html_tag_test',
            function( $cell_html_tag, $result )
            {
                return 'th';
            },
            10,
            2
        );