Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: super editor role that allows for safe permissions in headless wp #233

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions wordpress/wp-content/themes/headless/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function bubs_theme_options($wp_customize)
include_once 'setup/helpers/permalinks.php';
}

include_once 'setup/helpers/role-super-editor.php';
include_once 'setup/helpers/webhooks.php';
include_once 'setup/helpers/wpgraphql.php';
include_once 'setup/helpers/wysiwyg.php';
Expand All @@ -84,5 +85,4 @@ function bubs_theme_options($wp_customize)
// REMOVAL OF THESE = POTIENTAL LOSS OF DATA

add_theme_support('post-thumbnails');
add_theme_support('menus');

add_theme_support('menus');
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/* Create Super Editor User Role */
function bubs_role_super_editor() {
// Sometimes caching causes havoc, so we remove then re-add
remove_role( 'super_editor' );

// We want to start with administrator as a base
$administrator = get_role( 'administrator' );
$super_editor = clone( $administrator );
$super_editor->name = 'Super Editor';

// And then remove the capabilities that we don't want (like edit_themes, plugins, etc.)
$super_editor->capabilities['switch_themes'] = 0;
$super_editor->capabilities['update_themes'] = 0;
$super_editor->capabilities['edit_themes'] = 0;
$super_editor->capabilities['delete_themes'] = 0;
$super_editor->capabilities['install_themes'] = 0;

// $super_editor->capabilities['manage_options'] = 0;
$super_editor->capabilities['export'] = 0;
$super_editor->capabilities['import'] = 0;

$super_editor->capabilities['update_core'] = 0;
$super_editor->capabilities['activate_plugins'] = 0;
$super_editor->capabilities['edit_plugins'] = 0;
$super_editor->capabilities['update_plugins'] = 0;
$super_editor->capabilities['delete_plugins'] = 0;
$super_editor->capabilities['install_plugins'] = 0;

add_role(
'super_editor', // System name of the role.
__( 'Super Editor' ), // Display name of the role.
$super_editor->capabilities // Array of capabilities.
);
}

add_action('admin_init', 'bubs_role_super_editor');