Access of custom roles to the log in front-end
-
Please tell me how, in the example from the plugin documentation, to allow access to logs on the frontend for roles other than administrator. I tried using the
simple_history/view_history_capabilityfilter – it doesn’t work.Can you tell me what I’m doing wrong? In the page template, I call the
simple_history_user_action_output($paged)function and get zero entries, although they actually exist if you give the user the administrator role.add_filter( 'simple_history/view_history_capability', function( $capability ) {
$capability = 'view_fileinput';
return $capability;
} );
function simple_history_user_action_output($paged) {
$log_query = new \Simple_History\Log_Query;
$simple_history = \Simple_History\Simple_History::get_instance();
$current_user = wp_get_current_user();
$user_id = $current_user -> ID;
$query_results = $log_query->query( [
'posts_per_page' => 5,
'user' => $user_id,
'loggers' => ['SimplePostLogger', 'SimpleUserLogger', 'SimpleLogger'],
'paged' => $paged
] );
printf(
'
<p>Найдено %1$d строк(и).</p>
<p>Страница %2$d из %3$d.</p>
',
esc_html( $query_results['total_row_count'] ),
esc_html( $query_results['page_current'] ),
esc_html( $query_results['pages_count'] )
);
echo "<ul>";
foreach ( $query_results['log_rows'] as $row ) {
$header_output = $simple_history->getLogRowHeaderOutput( $row );
$text_output = $simple_history->getLogRowPlainTextOutput( $row );
$details_output = $simple_history->getLogRowDetailsOutput( $row );
echo "<li>";
echo "<hr />";
echo "<p>{$header_output}</p>";
echo "<p>{$text_output}</p>";
echo "<p>{$details_output}</p>";
echo "</li>";
}
echo "</ul>";
}
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.