Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Publicious.org
Plugins
User Groups
Commits
f62b70c2
Commit
f62b70c2
authored
Oct 23, 2015
by
John James Jacoby
Browse files
Add support for WP User Profiles.
parent
0e8223c0
Pipeline
#19
skipped
Changes
6
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
assets/css/user-groups.css
View file @
f62b70c2
...
...
@@ -124,4 +124,15 @@ table.user-groups .inactive .plugin-title strong {
table
.user-groups
{
min-width
:
650px
;
}
}
\ No newline at end of file
}
#wp_user_taxonomy_user-group
.inside
,
#wp_user_taxonomy_user-type
.inside
{
margin
:
0
;
padding
:
0
;
}
body
.users_page_groups
.metabox-holder
table
.user-groups
{
border
:
none
;
margin
:
0
;
padding
:
0
;
}
includes/admin.php
View file @
f62b70c2
...
...
@@ -17,3 +17,27 @@ defined( 'ABSPATH' ) || exit;
function
wp_user_groups_admin_assets
()
{
wp_enqueue_style
(
'wp_user_groups'
,
wp_user_groups_get_plugin_url
()
.
'/assets/css/user-groups.css'
,
false
,
wp_user_groups_get_asset_version
(),
false
);
}
/**
* Add new section to User Profiles
*
* @since 0.1.9
*
* @param array $sections
*/
function
wp_user_groups_add_profile_section
(
$sections
=
array
()
)
{
// Copy for modifying
$new_sections
=
$sections
;
// Add the "Activity" section
$new_sections
[
'groups'
]
=
array
(
'slug'
=>
'groups'
,
'name'
=>
esc_html__
(
'Groups'
,
'wp-user-activity'
),
'cap'
=>
'edit_user'
);
// Filter & return
return
apply_filters
(
'wp_user_groups_add_profile_section'
,
$new_sections
,
$sections
);
}
includes/class-user-taxonomy.php
View file @
f62b70c2
...
...
@@ -133,6 +133,9 @@ class WP_User_Taxonomy {
add_action
(
'show_user_profile'
,
array
(
$this
,
'edit_user_relationships'
),
99
);
add_action
(
'edit_user_profile'
,
array
(
$this
,
'edit_user_relationships'
),
99
);
// WP User Profile support
add_action
(
'add_meta_boxes'
,
array
(
$this
,
'add_meta_box'
)
);
// Cleanup stuff
add_action
(
'delete_user'
,
array
(
$this
,
'delete_term_relationships'
)
);
add_filter
(
'sanitize_user'
,
array
(
$this
,
'disable_username'
)
);
...
...
@@ -235,6 +238,49 @@ class WP_User_Taxonomy {
wp_add_inline_style
(
'wp_user_groups'
,
$style
);
}
/**
*
* @since 0.1.6
*/
public
function
add_meta_box
()
{
// Get the taxonomy
$tax
=
get_taxonomy
(
$this
->
taxonomy
);
$user_id
=
!
empty
(
$_GET
[
'user_id'
]
)
?
(
int
)
$_GET
[
'user_id'
]
:
get_current_user_id
();
// Make sure the user can assign terms of the group taxonomy before proceeding.
if
(
!
current_user_can
(
'edit_user'
,
$user_id
)
||
!
current_user_can
(
$tax
->
cap
->
assign_terms
)
)
{
return
;
}
// Bail if no UI for taxonomy
if
(
false
===
$tax
->
show_ui
)
{
return
;
}
// Get the terms of the taxonomy.
$terms
=
get_terms
(
$this
->
taxonomy
,
array
(
'hide_empty'
=>
false
)
);
// Maybe add the metabox
add_meta_box
(
'wp_user_taxonomy_'
.
$this
->
taxonomy
,
$tax
->
label
,
array
(
$this
,
'user_profile_metabox'
),
'users_page_groups'
,
'normal'
,
'default'
,
array
(
'user_id'
=>
$user_id
,
'tax'
=>
$tax
,
'terms'
=>
$terms
)
);
}
/**
* Save terms for a user for this taxonomy
*
...
...
@@ -354,70 +400,7 @@ class WP_User_Taxonomy {
</label>
</th>
<td>
<table
class=
"wp-list-table widefat fixed striped user-groups"
>
<thead>
<tr>
<td
id=
"cb"
class=
"manage-column column-cb check-column"
>
<label
class=
"screen-reader-text"
for=
"cb-select-all-1"
>
<?php
esc_html_e
(
'Select All'
,
'wp-user-groups'
);
?>
</label>
<input
id=
"cb-select-all-1"
type=
"checkbox"
>
</td>
<th
scope=
"col"
class=
"manage-column column-name column-primary"
>
<?php
esc_html_e
(
'Name'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-description"
>
<?php
esc_html_e
(
'Description'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-users"
>
<?php
esc_html_e
(
'Users'
,
'wp-user-groups'
);
?>
</th>
</tr>
</thead>
<tbody>
<?php
if
(
!
empty
(
$terms
)
)
:
foreach
(
$terms
as
$term
)
:
$active
=
is_object_in_term
(
$user
->
ID
,
$this
->
taxonomy
,
$term
->
slug
);
?>
<tr
class=
"
<?php
echo
(
true
===
$active
)
?
'active'
:
'inactive'
;
?>
"
>
<th
scope=
"row"
class=
"check-column"
>
<input
type=
"checkbox"
name=
"
<?php
echo
esc_attr
(
$this
->
taxonomy
);
?>
[]"
id=
"
<?php
echo
esc_attr
(
$this
->
taxonomy
);
?>
-
<?php
echo
esc_attr
(
$term
->
slug
);
?>
"
value=
"
<?php
echo
esc_attr
(
$term
->
slug
);
?>
"
<?php
checked
(
$active
);
?>
/>
<label
for=
"
<?php
echo
esc_attr
(
$this
->
taxonomy
);
?>
-
<?php
echo
esc_attr
(
$term
->
slug
);
?>
"
></label>
</th>
<td
class=
"column-primary"
>
<strong>
<?php
echo
esc_html
(
$term
->
name
);
?>
</strong>
<div
class=
"row-actions"
>
<?php
echo
$this
->
row_actions
(
$tax
,
$term
);
?>
</div>
</td>
<td
class=
"column-description"
>
<?php
echo
!
empty
(
$term
->
description
)
?
esc_html
(
$term
->
description
)
:
'—'
;
?>
</td>
<td
class=
"column-users"
>
<?php
echo
esc_html
(
$term
->
count
);
?>
</td>
</tr>
<?php
endforeach
;
// If there are no user groups
else
:
?>
<tr>
<td
colspan=
"4"
>
<?php
echo
esc_html
(
$tax
->
labels
->
not_found
);
?>
</td>
</tr>
<?php
endif
;
?>
</tbody>
<tfoot>
<tr>
<td
class=
"manage-column column-cb check-column"
>
<label
class=
"screen-reader-text"
for=
"cb-select-all-2"
>
<?php
esc_html_e
(
'Select All'
,
'wp-user-groups'
);
?>
</label>
<input
id=
"cb-select-all-2"
type=
"checkbox"
>
</td>
<th
scope=
"col"
class=
"manage-column column-name column-primary"
>
<?php
esc_html_e
(
'Name'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-description"
>
<?php
esc_html_e
(
'Description'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-users"
>
<?php
esc_html_e
(
'Users'
,
'wp-user-groups'
);
?>
</th>
</tr>
</tfoot>
</table>
<?php
$this
->
table_contents
(
$user
,
$tax
,
$terms
);
?>
</td>
</tr>
</table>
...
...
@@ -425,6 +408,91 @@ class WP_User_Taxonomy {
<?php
}
/**
* Output metabox for user profiles
*
* @since 0.1.6
*/
public
function
user_profile_metabox
(
$user
=
null
,
$args
=
array
()
)
{
$this
->
table_contents
(
$user
,
$args
[
'args'
][
'tax'
],
$args
[
'args'
][
'terms'
]
);
}
/**
* Output metabox contents
*
* @since 0.1.6
*/
protected
function
table_contents
(
$user
,
$tax
,
$terms
)
{
?>
<table
class=
"wp-list-table widefat fixed striped user-groups"
>
<thead>
<tr>
<td
id=
"cb"
class=
"manage-column column-cb check-column"
>
<label
class=
"screen-reader-text"
for=
"cb-select-all-1"
>
<?php
esc_html_e
(
'Select All'
,
'wp-user-groups'
);
?>
</label>
<input
id=
"cb-select-all-1"
type=
"checkbox"
>
</td>
<th
scope=
"col"
class=
"manage-column column-name column-primary"
>
<?php
esc_html_e
(
'Name'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-description"
>
<?php
esc_html_e
(
'Description'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-users"
>
<?php
esc_html_e
(
'Users'
,
'wp-user-groups'
);
?>
</th>
</tr>
</thead>
<tbody>
<?php
if
(
!
empty
(
$terms
)
)
:
foreach
(
$terms
as
$term
)
:
$active
=
is_object_in_term
(
$user
->
ID
,
$this
->
taxonomy
,
$term
->
slug
);
?>
<tr
class=
"
<?php
echo
(
true
===
$active
)
?
'active'
:
'inactive'
;
?>
"
>
<th
scope=
"row"
class=
"check-column"
>
<input
type=
"checkbox"
name=
"
<?php
echo
esc_attr
(
$this
->
taxonomy
);
?>
[]"
id=
"
<?php
echo
esc_attr
(
$this
->
taxonomy
);
?>
-
<?php
echo
esc_attr
(
$term
->
slug
);
?>
"
value=
"
<?php
echo
esc_attr
(
$term
->
slug
);
?>
"
<?php
checked
(
$active
);
?>
/>
<label
for=
"
<?php
echo
esc_attr
(
$this
->
taxonomy
);
?>
-
<?php
echo
esc_attr
(
$term
->
slug
);
?>
"
></label>
</th>
<td
class=
"column-primary"
>
<strong>
<?php
echo
esc_html
(
$term
->
name
);
?>
</strong>
<div
class=
"row-actions"
>
<?php
echo
$this
->
row_actions
(
$tax
,
$term
);
?>
</div>
</td>
<td
class=
"column-description"
>
<?php
echo
!
empty
(
$term
->
description
)
?
esc_html
(
$term
->
description
)
:
'—'
;
?>
</td>
<td
class=
"column-users"
>
<?php
echo
esc_html
(
$term
->
count
);
?>
</td>
</tr>
<?php
endforeach
;
// If there are no user groups
else
:
?>
<tr>
<td
colspan=
"4"
>
<?php
echo
esc_html
(
$tax
->
labels
->
not_found
);
?>
</td>
</tr>
<?php
endif
;
?>
</tbody>
<tfoot>
<tr>
<td
class=
"manage-column column-cb check-column"
>
<label
class=
"screen-reader-text"
for=
"cb-select-all-2"
>
<?php
esc_html_e
(
'Select All'
,
'wp-user-groups'
);
?>
</label>
<input
id=
"cb-select-all-2"
type=
"checkbox"
>
</td>
<th
scope=
"col"
class=
"manage-column column-name column-primary"
>
<?php
esc_html_e
(
'Name'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-description"
>
<?php
esc_html_e
(
'Description'
,
'wp-user-groups'
);
?>
</th>
<th
scope=
"col"
class=
"manage-column column-users"
>
<?php
esc_html_e
(
'Users'
,
'wp-user-groups'
);
?>
</th>
</tr>
</tfoot>
</table>
<?php
}
/**
* Output row actions when editing a user
*
...
...
includes/hooks.php
View file @
f62b70c2
...
...
@@ -15,3 +15,6 @@ add_action( 'init', 'wp_register_default_user_type_taxonomy' );
// Enqueue assets
add_action
(
'admin_head'
,
'wp_user_groups_admin_assets'
);
// WP User Profiles
add_filter
(
'wp_user_profiles_sections'
,
'wp_user_groups_add_profile_section'
);
readme.txt
View file @
f62b70c2
...
...
@@ -3,7 +3,7 @@ Contributors: johnjamesjacoby, stuttter
Tags: taxonomy, term, user, group, type
Requires at least: 4.3
Tested up to: 4.4
Stable tag: 0.1.
5
Stable tag: 0.1.
6
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
...
...
@@ -72,6 +72,9 @@ http://github.com/stuttter/wp-user-groups/
== Changelog ==
= 0.1.6 =
* Add support for WP User Profiles
= 0.1.5 =
* Added `user_group` property to taxonomies
* Added functions for retrieving only user-groups from taxonomies global
...
...
wp-user-groups.php
View file @
f62b70c2
...
...
@@ -5,7 +5,7 @@
* Plugin URI: https://wordpress.org/plugins/wp-user-groups/
* Description: Group users together with taxonomies & terms.
* Author: John James Jacoby
* Version: 0.1.
5
* Version: 0.1.
6
* Author URI: https://profiles.wordpress.org/johnjamesjacoby/
* License: GPL v2 or later
*/
...
...
@@ -24,11 +24,11 @@ function _wp_user_groups() {
$plugin_path
=
plugin_dir_path
(
__FILE__
);
// Required files
require
$plugin_path
.
'includes/
class-user-taxonomy
.php'
;
require
$plugin_path
.
'includes/taxonom
ies
.php'
;
require
$plugin_path
.
'includes/functions.php'
;
require
$plugin_path
.
'includes/
admin
.php'
;
require
$plugin_path
.
'includes/hooks.php'
;
require
_once
$plugin_path
.
'includes/
admin
.php'
;
require
_once
$plugin_path
.
'includes/
class-user-
taxonom
y
.php'
;
require
_once
$plugin_path
.
'includes/functions.php'
;
require
_once
$plugin_path
.
'includes/
taxonomies
.php'
;
require
_once
$plugin_path
.
'includes/hooks.php'
;
}
add_action
(
'plugins_loaded'
,
'_wp_user_groups'
);
...
...
@@ -51,5 +51,5 @@ function wp_user_groups_get_plugin_url() {
* @return int
*/
function
wp_user_groups_get_asset_version
()
{
return
201510
1
30001
;
return
201510
2
30001
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment