Skip to content

Instantly share code, notes, and snippets.

@swissspidy
Created October 28, 2022 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swissspidy/4aad3fdb8451827e8a5a8ffbe547c8f5 to your computer and use it in GitHub Desktop.
Save swissspidy/4aad3fdb8451827e8a5a8ffbe547c8f5 to your computer and use it in GitHub Desktop.
Mini-plugin to debug the Web Stories plugin's custom capabilities
<?php
/**
* Plugin Name: Web Stories Debug Capabilities
* Description: Debugging plugin if you experience issues with capabilities and custom user roles.
* Plugin URI: https://wp.stories.google/
* Author: Pascal Birchler, Google
* Author URI: https://opensource.google.com/
* Version: 0.0.1
* License: Apache License 2.0
* License URI: https://www.apache.org/licenses/LICENSE-2.0
*/
add_action(
'admin_notices',
static function () {
if (
! defined( 'WEBSTORIES_VERSION' ) ||
! function_exists( '\Google\Web_Stories\get_plugin_instance' )
) {
return;
}
$post_type_object = get_post_type_object( 'web-story' );
if ( ! $post_type_object ) {
return;
}
if ( ! get_current_screen() || 'dashboard' !== get_current_screen()->base ) {
return;
}
$all_caps = $post_type_object->cap;
$all_caps_without_meta_caps = array_filter( (array) $all_caps, static function( $value ) {
return ! in_array( $value, [ 'edit_web-story', 'read_web-story', 'delete_web-story' ] );
});
?>
<div class="notice notice-warning">
<p>A list of all capabilities that exist for stories and whether you have them:</p>
<table class="widefat">
<thead>
<tr>
<th>Capability name</th>
<th>Granted</th>
</tr>
</thead>
<tbody>
<?php foreach ( $all_caps_without_meta_caps as $key => $value ) : ?>
<tr>
<td>
<code><?php echo $value; ?></code> (<code><?php echo $key; ?></code>)
</td>
<td>
<?php if ( current_user_can( $value ) ) : ?>
Yes :)
<?php else : ?>
No :(
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment