How to access certain WP functions inside custom class, in theme folder

You’re actually calling the add_meta_box() function before it’s defined, when you run this directly:

\ci\wp\Metaboxes::addMetabox(
    'front_page_slide_settings', 
    'Slide settings', 
    'page', 
    'normal', 
    'high'
);

You don’t mention where you run it, but it’s too early or you run it in the front-end, where add_meta_box() is not defined.

The add_meta_box() function is defined within this file:

/** WordPress Template Administration API */
require_once(ABSPATH . 'wp-admin/includes/template.php');

Make sure to run your problematic snippet afterwards, e.g. within the add_meta_boxes action, like you do within the Metaboxes::init() call.

The core init action, as an example, fires before that Template Administration API is loaded.

Leave a Comment