[ad_1]
I am querying the Simple History API using the example Query API – Simple History (simple-history.com) here. However, I am getting a fatal error for the class ‘SimpleHistory’. Is there a workaround to this?
For reference here is my code
function register_simple_history_api_endpoint() {
register_rest_route('simple-history/v1', '/history', array(
'methods' => 'GET',
'callback' => 'get_simple_history_entries',
));
}
add_action('rest_api_init', 'register_simple_history_api_endpoint');
function get_simple_history_entries() {
$log_query = new SimpleHistoryLogQuery();
$simple_history = SimpleHistory::get_instance();
$query_results = $log_query->query([
'posts_per_page' => 99,
]);
if (is_wp_error($query_results)) {
return $query_results; // Return any error that occurred while fetching the entries.
}
$output="";
printf(
'
<p>Found %1$d rows.</p>
<p>Viewing page %2$d of %3$d.</p>
',
esc_html($query_results['total_row_count']),
esc_html($query_results['page_current']),
esc_html($query_results['pages_count'])
);
$log_rows = $query_results['log_rows'];
if (!empty($log_rows)) {
$output .= '<ul>';
foreach ($log_rows as $row) {
$header_output = $simple_history->getLogRowHeaderOutput($row);
$text_output = $simple_history->getLogRowPlainTextOutput($row);
$details_output = $simple_history->getLogRowDetailsOutput($row);
$output .= '<li>';
$output .= '<hr />';
$output .= '<p>' . $header_output . '</p>';
$output .= '<p>' . $text_output . '</p>';
$output .= '<p>' . $details_output . '</p>';
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}- This topic was modified 20 minutes ago by .
