Skip to content

Commit 0b91660

Browse files
author
Nikola Miljković
authored
Merge pull request #211 from zSeriesGuy/dev
Add support for custom WP Roles
2 parents f31fcbe + b151fab commit 0b91660

5 files changed

Lines changed: 77 additions & 3 deletions

File tree

includes/admin/class-sm-admin-menus.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct() {
3030
* Add menu item.
3131
*/
3232
public function settings_menu() {
33-
add_submenu_page( 'edit.php?post_type=wpfc_sermon', __( 'Sermon Manager Settings', 'sermon-manager-for-wordpress' ), __( 'Settings', 'sermon-manager-for-wordpress' ), 'manage_options', 'sm-settings', array(
33+
add_submenu_page( 'edit.php?post_type=wpfc_sermon', __( 'Sermon Manager Settings', 'sermon-manager-for-wordpress' ), __( 'Settings', 'sermon-manager-for-wordpress' ), 'manage_wpfc_sm_settings', 'sm-settings', array(
3434
$this,
3535
'settings_page',
3636
) );
@@ -40,7 +40,7 @@ public function settings_menu() {
4040
* Add menu item.
4141
*/
4242
public function import_export_menu() {
43-
add_submenu_page( 'edit.php?post_type=wpfc_sermon', __( 'Sermon Manager Import/Export', 'sermon-manager-for-wordpress' ), __( 'Import/Export', 'sermon-manager-for-wordpress' ), 'manage_options', 'sm-import-export', array(
43+
add_submenu_page( 'edit.php?post_type=wpfc_sermon', __( 'Sermon Manager Import/Export', 'sermon-manager-for-wordpress' ), __( 'Import/Export', 'sermon-manager-for-wordpress' ), 'manage_wpfc_sm_settings', 'sm-import-export', array(
4444
$this,
4545
'import_export_page',
4646
) );

includes/class-sm-post-types.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public static function register_taxonomies() {
4343
$preacher_label = ( \SermonManager::getOption( 'preacher_label' ) ? strtolower( \SermonManager::getOption( 'preacher_label' ) ) : __( 'Preacher', 'sermon-manager-for-wordpress' ) );
4444
$preacher_label_plural = $preacher_label . 's';
4545

46+
$capabilities = array(
47+
'manage_terms' => 'manage_wpfc_categories',
48+
'edit_terms' => 'manage_wpfc_categories',
49+
'delete_terms' => 'manage_wpfc_categories',
50+
'assign_terms' => 'manage_wpfc_categories'
51+
);
52+
4653
register_taxonomy( 'wpfc_preacher',
4754
apply_filters( 'sm_taxonomy_objects_wpfc_preacher', array( 'wpfc_sermon' ) ),
4855
apply_filters( 'sm_taxonomy_args_wpfc_preacher', array(
@@ -76,6 +83,7 @@ public static function register_taxonomies() {
7683
'slug' => $permalinks['wpfc_preacher'],
7784
'with_front' => false,
7885
),
86+
'capabilities' => $capabilities,
7987
) )
8088
);
8189

@@ -105,6 +113,7 @@ public static function register_taxonomies() {
105113
'slug' => $permalinks['wpfc_sermon_series'],
106114
'with_front' => false,
107115
),
116+
'capabilities' => $capabilities,
108117
) )
109118
);
110119

@@ -134,6 +143,7 @@ public static function register_taxonomies() {
134143
'slug' => $permalinks['wpfc_sermon_topics'],
135144
'with_front' => false,
136145
),
146+
'capabilities' => $capabilities,
137147
) )
138148
);
139149

@@ -163,6 +173,7 @@ public static function register_taxonomies() {
163173
'slug' => $permalinks['wpfc_bible_book'],
164174
'with_front' => false,
165175
),
176+
'capabilities' => $capabilities,
166177
) )
167178
);
168179

@@ -192,6 +203,7 @@ public static function register_taxonomies() {
192203
'slug' => $permalinks['wpfc_service_type'],
193204
'with_front' => false,
194205
),
206+
'capabilities' => $capabilities,
195207
) )
196208
);
197209

@@ -238,7 +250,11 @@ public static function register_post_types() {
238250
),
239251
'public' => true,
240252
'show_ui' => true,
241-
'capability_type' => 'post',
253+
'capability_type' => 'wpfc_sermon',
254+
'capabilities' => array(
255+
'manage_wpfc_categories' => 'manage_wpfc_categories',
256+
'manage_wpfc_sm_settings' => 'manage_wpfc_sm_settings'
257+
),
242258
'map_meta_cap' => true,
243259
'publicly_queryable' => true,
244260
'exclude_from_search' => false,

includes/class-sm-roles.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Adds custom roles to Sermon Manager.
4+
*
5+
* @since 2.13.0
6+
*
7+
* @package SermonManager
8+
*/
9+
10+
/**
11+
* Define SM_Roles.
12+
*/
13+
class SM_Roles {
14+
/**
15+
* Add sermon managing capabilities to administrator, editor, author.
16+
*/
17+
public static function init() {
18+
$role_list = array( 'administrator', 'editor', 'author' );
19+
foreach ( $role_list as $role_name ) {
20+
$role = get_role( $role_name );
21+
if ( null === $role || ! ( $role instanceof WP_Role ) ) {
22+
continue;
23+
}
24+
// Read sermons.
25+
$role->add_cap( 'read_wpfc_sermon' );
26+
// Edit sermons.
27+
$role->add_cap( 'edit_wpfc_sermon' );
28+
$role->add_cap( 'edit_wpfc_sermons' );
29+
$role->add_cap( 'edit_private_wpfc_sermons' );
30+
$role->add_cap( 'edit_published_wpfc_sermons' );
31+
// Delete sermons.
32+
$role->add_cap( 'delete_wpfc_sermon' );
33+
$role->add_cap( 'delete_wpfc_sermons' );
34+
$role->add_cap( 'delete_published_wpfc_sermons' );
35+
$role->add_cap( 'delete_private_wpfc_sermons' );
36+
// Publish sermons.
37+
$role->add_cap( 'publish_wpfc_sermons' );
38+
// Read private sermons.
39+
$role->add_cap( 'read_private_wpfc_sermons' );
40+
// Manage categories & tags.
41+
$role->add_cap( 'manage_wpfc_categories' );
42+
// Add additional roles for administrator
43+
if ( 'administrator' === $role_name ) {
44+
// Access to Sermon Manager Settings.
45+
$role->add_cap( 'manage_wpfc_sm_settings' );
46+
}
47+
// Add additional roles for administrator and editor
48+
if ( 'author' !== $role_name ) {
49+
$role->add_cap( 'edit_others_wpfc_sermons' );
50+
$role->add_cap( 'delete_others_wpfc_sermons' );
51+
}
52+
}
53+
}
54+
}
55+
56+
SM_Roles::init();

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man
107107
* New: Add excerpt support (thanks @robertmain!)
108108
* New: Add read more link to the sermon description (thanks @robertmain!)
109109
* New: Add revisions support (thanks @robertmain!)
110+
* New: Add support for custom WP role capabilities (thanks @zSeriesGuy!)
110111
* New: Add support for sermon password protection
111112
* New: Add working file for rendering the feed
112113
* New: Add a tab in settings for controlling the import

sermons.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ private function _includes() {
285285
include SM_PATH . 'includes/class-sm-api.php'; // API.
286286
include SM_PATH . 'includes/class-sm-post-types.php'; // Register post type, taxonomies, etc.
287287
include SM_PATH . 'includes/class-sm-install.php'; // Install and update functions.
288+
include SM_PATH . 'includes/class-sm-roles.php'; // Adds roles support.
288289
include SM_PATH . 'includes/sm-deprecated-functions.php'; // Deprecated SM functions.
289290
include SM_PATH . 'includes/sm-formatting-functions.php'; // Data formatting.
290291
include SM_PATH . 'includes/vendor/taxonomy-images/taxonomy-images.php'; // Images for Custom Taxonomies.

0 commit comments

Comments
 (0)