Skip to content

Commit b151fab

Browse files
author
Nikola Miljković
committed
Move code to the right place
1 parent 0441119 commit b151fab

3 files changed

Lines changed: 57 additions & 40 deletions

File tree

includes/class-sm-post-types.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -282,46 +282,6 @@ public static function register_post_types() {
282282
),
283283
) ) );
284284

285-
// Add sermon managing capabilities to administrator, editor, author.
286-
$role = get_role( 'administrator' );
287-
if ( is_object( $role ) && ! $role->has_cap( 'edit_wpfc_sermon' ) ) {
288-
$role_list = array( 'administrator', 'editor', 'author' );
289-
foreach ( $role_list as $role_name ) {
290-
$role = get_role( $role_name );
291-
if ( null === $role || ! ( $role instanceof WP_Role ) ) {
292-
continue;
293-
}
294-
// Read sermons.
295-
$role->add_cap( 'read_wpfc_sermon' );
296-
// Edit sermons.
297-
$role->add_cap( 'edit_wpfc_sermon' );
298-
$role->add_cap( 'edit_wpfc_sermons' );
299-
$role->add_cap( 'edit_private_wpfc_sermons' );
300-
$role->add_cap( 'edit_published_wpfc_sermons' );
301-
// Delete sermons.
302-
$role->add_cap( 'delete_wpfc_sermon' );
303-
$role->add_cap( 'delete_wpfc_sermons' );
304-
$role->add_cap( 'delete_published_wpfc_sermons' );
305-
$role->add_cap( 'delete_private_wpfc_sermons' );
306-
// Publish sermons.
307-
$role->add_cap( 'publish_wpfc_sermons' );
308-
// Read private sermons.
309-
$role->add_cap( 'read_private_wpfc_sermons' );
310-
// Manage categories & tags.
311-
$role->add_cap( 'manage_wpfc_categories' );
312-
// Add additional roles for administrator
313-
if ( 'administrator' === $role_name ) {
314-
// Access to Sermon Manager Settings.
315-
$role->add_cap( 'manage_wpfc_sm_settings' );
316-
}
317-
// Add additional roles for administrator and editor
318-
if ( 'author' !== $role_name ) {
319-
$role->add_cap( 'edit_others_wpfc_sermons' );
320-
$role->add_cap( 'delete_others_wpfc_sermons' );
321-
}
322-
}
323-
}
324-
325285
do_action( 'sm_after_register_post_type' );
326286
}
327287

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();

sermons.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ private function _includes() {
316316
include SM_PATH . 'includes/class-sm-api.php'; // API.
317317
include SM_PATH . 'includes/class-sm-post-types.php'; // Register post type, taxonomies, etc.
318318
include SM_PATH . 'includes/class-sm-install.php'; // Install and update functions.
319+
include SM_PATH . 'includes/class-sm-roles.php'; // Adds roles support.
319320
include SM_PATH . 'includes/sm-deprecated-functions.php'; // Deprecated SM functions.
320321
include SM_PATH . 'includes/sm-formatting-functions.php'; // Data formatting.
321322
include SM_PATH . 'includes/vendor/taxonomy-images/taxonomy-images.php'; // Images for Custom Taxonomies.

0 commit comments

Comments
 (0)