Dear @programmin,
Thank you for opening the thread!
The error you’re seeing ({“code”:”not_found_meta_box”,”message”:”Invalid MetaBox Name in Request.”}) is occurring because the MetaBox functionality has been deprecated in version 14.12 of WP Statistics.
Recommended Solution:
Use the new methods provided by WP Statistics to retrieve hits data:
// Using the Hits class directly
$hits = WP_STATISTICS\Hits::record();
If you need to maintain the same API endpoint structure, you can create a custom endpoint in your theme’s functions.php:
add_action('rest_api_init', function () {
register_rest_route('wp-statistics/v2', '/metabox', array(
'methods' => 'GET',
'callback' => 'custom_metabox_callback',
'permission_callback' => function () {
return current_user_can('manage_options');
}
));
});
function custom_metabox_callback($request) {
$name = $request->get_param('name');
if ($name === 'hits') {
$hits = WP_STATISTICS\Hits::record();
return rest_ensure_response($hits);
}
return new WP_REST_Response(array('code' => 'not_found_meta_box', 'message' => 'Invalid MetaBox Name in Request.'), 400);
}
Let us know if you need any further assistance!
Regards,
Mehmet
-
This reply was modified 1 year ago by
Mehmet.