-
Notifications
You must be signed in to change notification settings - Fork 7
/
fabrica-pending-revisions.php
49 lines (39 loc) · 1.53 KB
/
fabrica-pending-revisions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
Plugin Name: Fabrica Pending Revisions
Plugin URI: https://github.com/wikitribune/fabrica-pending-revisions
Description: Enables updates to published content to be held in a draft state, or to be submitted for moderation and approval before they go live. Also makes WP’s native Revisions more accountable by extending the system’s tracking of changes to taxonomy items and featured images, and improves the ‘Compare Revisions’ interface.
Version: 0.1.0
Author: Fabrica
Author URI: https://fabri.ca/
Text Domain: fabrica-pending-revisions
License: MIT
License URI: https://opensource.org/licenses/MIT
*/
namespace Fabrica\PendingRevisions;
if (!defined('WPINC')) { die(); }
require_once('inc/singleton.php');
class Plugin extends Singleton {
const MAIN_FILE = __FILE__;
public function init() {
if (!is_admin()) { return; }
register_activation_hook(self::MAIN_FILE, array($this, 'activate'));
}
// Create `accept_revisions` capability and add to Admin role
public function activate() {
if (!current_user_can('activate_plugins')) { return; }
$plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
check_admin_referer('activate-plugin_' . $plugin);
// Check if Admin already has capability and if not add it
$role = get_role('administrator');
if (!$role || isset($role->capabilities['accept_revisions'])) { return; }
$role->add_cap('accept_revisions');
}
}
Plugin::instance()->init();
if (is_admin()) {
require_once('inc/base.php');
require_once('inc/settings.php');
} else {
require_once('inc/front.php');
}