-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotaract-unfiltered-mu.php
103 lines (87 loc) · 3.61 KB
/
rotaract-unfiltered-mu.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* This file is read by WordPress to generate the plugin information in the plugin admin area.
*
* @link https://github.com/rotaract/rotaract-unfiltered-mu
* @since 1.0.0
* @package Rotaract_Unfiltered_MU
* @category Core
*
* @wordpress-plugin
* Plugin Name: Rotaract Unfiltered MU
* Plugin URI: https://github.com/rotaract/rotaract-unfiltered-mu
* Description: Adds the <code>unfiltered_html</code> capablitiy to Administrators and Editors so that content posted by users with those roles is not filtered by KSES; Embeds, Iframe, etc. are preserved. <strong>Note</strong>: If for any reason the <code>unfiltered_html</code> capability is ever lost, simply deactivate, and then reactivate this plugin.
* Version: 0.1.0
* Author: Ressort IT-Entwicklung - Rotaract Deutschland
* Author URI: https://rotaract.de/ueber-rotaract/rdk/
* License: EUPL-1.2
* License URI: https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
* Text Domain: rotaract-unfiltered-mu
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// Remove KSES if user has unfiltered_html cap
function um_kses_init() {
if ( current_user_can( 'unfiltered_html' ) )
kses_remove_filters();
}
add_action( 'init', 'um_kses_init', 11 );
add_action( 'set_current_user', 'um_kses_init', 11 );
/*
If you install this plugin in wp-content/plugins, the following code
will add the cap on plugin activation, and remove it on deactivation.
It will be a per-blog setting (the plugin will need to be activated on
each blog you want the unfiltered_html cap).
*/
function um_unfilter_roles() {
// Makes sure $wp_roles is initialized
get_role( 'administrator' );
global $wp_roles;
// Dont use get_role() wrapper, it doesn't work as a one off.
// (get_role does not properly return as reference)
$wp_roles->role_objects['administrator']->add_cap( 'unfiltered_html' );
$wp_roles->role_objects['editor']->add_cap( 'unfiltered_html' );
}
function um_refilter_roles() {
get_role( 'administrator' );
global $wp_roles;
// Could use the get_role() wrapper here since this function is never
// called as a one off. It is always called to alter the role as
// stored in the DB.
$wp_roles->role_objects['administrator']->remove_cap( 'unfiltered_html' );
$wp_roles->role_objects['editor']->remove_cap( 'unfiltered_html' );
}
register_activation_hook( __FILE__, 'um_unfilter_roles' ); // Add on activate
register_deactivation_hook( __FILE__, 'um_refilter_roles' ); // Remove on deactivate
/*
If you install this plugin in wp-content/mu-plugins, the following code
will add give all admins and all editors on every blog the
unfiltered_html cap. Deleting this plugin will remove the cap.
*/
function um_unfilter_roles_one_time() {
get_role( 'administrator' );
global $wp_roles, $current_user;
$use_db = $wp_roles->use_db;
$wp_roles->use_db = false; // Don't store in db. Just do a one off mod to the role.
um_unfilter_roles(); // Add caps for this page load only: - ^^^^^^^
$wp_roles->use_db = $use_db;
if ( is_user_logged_in() ) // Re-prime the current user's caps
$current_user->for_site();
}
if ( false !== strpos( __FILE__, MUPLUGINDIR ) )
add_action( 'init', 'um_unfilter_roles_one_time', 1 );
// Add the unfiltered_html capability back in to WordPress 5.8 multisite.
function um_unfilter_multisite( $caps, $cap ) {
$map_caps = array(
'edit_css',
'manage_privacy_options',
'unfiltered_html'
);
if ( in_array( $cap, $map_caps ) ) {
$caps = array( 'unfiltered_html' );
}
return $caps;
}
add_filter( 'map_meta_cap', 'um_unfilter_multisite', 10, 2 );